Skip to content

Instantly share code, notes, and snippets.

@lindenb
Created July 15, 2011 17:26
Show Gist options
  • Save lindenb/1085119 to your computer and use it in GitHub Desktop.
Save lindenb/1085119 to your computer and use it in GitHub Desktop.
OpenOffice Macro reverse complement DNA
' Author:
' Pierre Lindenbaum PhD
' Date:
' 2011-07-15
' Motivation:
' reverse complement a DNA in OpenOffice/LibreOffice
' WWW:
' http://plindenbaum@yahoo.fr
'
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"
Case Else
'.
End Select
result = result & acidNucleic
next x
End If
complementDNA = result
End Function
@cement-head
Copy link

Hi, I'm new to MACROS in LO, how do I import and run this?

@MPagel
Copy link

MPagel commented Apr 19, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment