15 July 2011

I can't save you, but I can help you: reverse-complementing a DNA in OpenOffice

People in my lab are using "Microsoft Word" to edit and annotate their sequences. Just like Neil, I can't save them but I can help them: here is an OpenOffice / LibreOffice macro reverse-complementing the current selected text.

' 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


  • open libreoffice/openoffice
  • Open menu "Tools / Macros / Organize macros / Basic...
  • Select "My Macros/Standard" and click on "New"
  • Copy+paste my macro here
  • Click on the top button "compile"
  • Close the dialog
  • Menu "Tools/Customize" , "Keyboard" tab, "Toolbar content" . Button "Add... " / Category "Libre Office Macros" . Select "My Macro/Standard/Modulexxx"/ReverseComplementSelection". Click on "Modify" to assign an icon to this new button
  • There is now a new button in the toolbar. Clicking on that button reverse-complements the selected text.


That's it,

Pierre

PS: Hum ? what did you say, they use Microsoft Word ? Not OpenOffice ? pfff....

1 comment:

Daniel Standage said...

Just saw a new paper today (www.biomedcentral.com/1471-2105/13/124/abstract) and it made me think of this post. Kind of sad...