Created
July 15, 2011 17:26
-
-
Save lindenb/1085119 to your computer and use it in GitHub Desktop.
OpenOffice Macro reverse complement DNA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Author: | |
' Pierre Lindenbaum PhD | |
' Date: | |
' 2011-07-15 | |
' Motivation: | |
' reverse complement a DNA in OpenOffice/LibreOffice | |
' WWW: | |
' http://[email protected] | |
' | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@cement-head https://ask.libreoffice.org/en/question/133411/how-do-i-use-ms-excel-macros-in-calc/ will probably point you in the right direction.