Skip to content

Instantly share code, notes, and snippets.

@MPagel
Forked from lindenb/ReverseComplementMacro.txt
Last active April 19, 2019 23:23
Show Gist options
  • Save MPagel/8db5bf1815cfc0131a8e586436358783 to your computer and use it in GitHub Desktop.
Save MPagel/8db5bf1815cfc0131a8e586436358783 to your computer and use it in GitHub Desktop.
OpenOffice Macro reverse complement DNA
' Original Author:
' Pierre Lindenbaum PhD
' Date:
' 2011-07-15
' Motivation:
' reverse complement a DNA in OpenOffice/LibreOffice
' WWW:
' http://plindenbaum@yahoo.fr
'
' Revision Author:
' Matthew Pagel
' Date:
' 2013-01-03
' Feature Additions:
' Added in 2-base option ambiguity codes (no BDHV nor I and other modified bases) 03 Jan 2013 M Pagel
' Work properly as functions inside localc as well (e.g. =COMPLEMENTDNA(REVERSESTRING(B2)) )
Sub ReverseComplementSelection
Dim oDoc
Dim oVC
oDoc = ThisComponent
oVC = oDoc.CurrentController.getViewCursor
If Len(oVC.String) > 0 Then
Dim result as String
result= reverseString(complementDNA(oVC.String))
oVC.setString( result )
EndIf
End Sub
Function reverseString( s As String) As String
dim result As String
dim x As Integer
result=""
If Not IsMissing (s) Then
For x = Len(s) To 1 Step -1
result = result & Mid(s, x, 1)
next x
End If
reverseString = result
End Function
Function complementDNA( s As String) As String
dim result As String
dim acidNucleic As String
dim x As Integer
result=""
If Not IsMissing (s) Then
For x = 1 To Len(s)
acidNucleic= Mid(s, x, 1)
Select Case acidNucleic
Case "A": acidNucleic = "T"
Case "a": acidNucleic = "t"
Case "T": acidNucleic = "A"
Case "t": acidNucleic = "a"
Case "G": acidNucleic = "C"
Case "g": acidNucleic = "c"
Case "C": acidNucleic = "G"
Case "c": acidNucleic = "g"
Case "N": acidNucleic = "N"
Case "n": acidNucleic = "n"
' ambiguity codes added Jan 2013 M Pagel
Case "Y": acidNucleic = "R"
Case "y": acidNucleic = "r"
Case "R": acidNucleic = "Y"
Case "r": acidNucleic = "y"
Case "K": acidNucleic = "M"
Case "k": acidNucleic = "m"
Case "M": acidNucleic = "K"
Case "m": acidNucleic = "k"
' in case RNA->DNA
' wouldn't want to go from A->U generally though - would potentially need a sep. DNA->RNA func
Case "U": acidNucleic = "A"
Case "u": acidNucleic = "a"
' these last 4 are potentially unneeded
Case "W": acidNucleic = "W"
Case "w": acidNucleic = "w"
Case "S": acidNucleic = "S"
Case "s": acidNucleic = "s"
Case Else
'.
End Select
result = result & acidNucleic
next x
End If
complementDNA = result
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment