-
-
Save MPagel/8db5bf1815cfc0131a8e586436358783 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
' Original Author: | |
' Pierre Lindenbaum PhD | |
' Date: | |
' 2011-07-15 | |
' Motivation: | |
' reverse complement a DNA in OpenOffice/LibreOffice | |
' WWW: | |
' http://[email protected] | |
' | |
' 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