View Single Post
  #18   Report Post  
Posted to microsoft.public.excel.programming
GysdeJongh GysdeJongh is offline
external usenet poster
 
Posts: 23
Default A function of reverse complement

Hi,
you are right , thank you very much for this suggestion. The job is to reverse
the string and replace A by T etc. It is called : calculating the Reverse
Complement in bioinformatics. There is of course dedicated software. Look here
if you like to see an example :

http://www.mbio.ncsu.edu/BioEdit/bioedit.html


I made this little piece of VBA to calculate the reverse complement for a very
large number of short sequences.

Your solution is more elegant and probably faster. It did not occur to me that
it can be done that way because I am in genetics and statistics . I am not a
programmer.
Thanks again for your time
Gys





"Myrna Larson" wrote in message
...
I believe By Complement, he means interchange A and T and C and G, as you (and
he) are doing.

But why do you not want to use Replace, StrReverse and UCase$? The code is
much shorter -- it can be reduced to just 7 lines.

On Mon, 17 Jan 2005 23:56:04 +0100, "GysdeJongh" wrote:

Hi,
sorry did not find the original posting so I answer this one.
I see how you reverse the strand .
I do not understand how you want to complement the strand.
So I can not comment your solution.
But have a solution for the problem if you want.
Feel free to adapt it to your needs.

'This function converts a DNA string to its
'reverse complement
'Gys de Jongh 16-jun-1999
Function Rev(Forw As String) As String
Dim ForwA(1 To 100) As String * 1
Dim RevA(1 To 100) As String * 1
N = Len(Forw)
If N 100 Then
Rev = "Input too long (max 100)"
Exit Function
End If
For I = 1 To N
ForwA(I) = Mid(Forw, I, 1)
Next I
For I = 1 To N
Select Case ForwA(N - I + 1)
Case "A"
RevA(I) = "T"
Case "a"
RevA(I) = "t"
'From A to T
Case "C"
RevA(I) = "G"
Case "c"
RevA(I) = "g"
'From C to G
Case "G"
RevA(I) = "C"
Case "g"
RevA(I) = "c"
'From G to C
Case "T"
RevA(I) = "A"
Case "t"
RevA(I) = "a"
'From T to A
Case Else
RevA(I) = "N"
'Rest is N
End Select
Next I
For I = 1 To N
Rev = Rev & RevA(I)
Next I
End Function

Short explanation for Tom :
DNA contains the information for cells
It is a double helix with 2 strings , molecules
The two strings contain the same information
They are redundant , one can be used to construct the other
In each string A only pairs with T and C only with G
But :
the Sense strand reads from left to right and
the anti Sense strand from right to left
so :

ACGTCCCTGAAATT <====Sense strand
TGCAGGGACTTTAA <====anti Sense strand

Finding the reverse complement means finding the other if one is known

hth
Gys





"Tom Ogilvy" wrote in message
...
As an example
Assume you had a reversed string like AAA

your code would convert it like this

AAA = 111 = UUU

If that is what you want, then Ok. If the problem is you would want 111 as
a result, then I think you need to go to an intermediate stage (two step
process)

AAA = MMM = 111

Where the middle stage would use unique identifiers so you wouldn't convert
any value after it was converted to a final value.

A to M, M to 1
C to N, N to 2
G to O, O to 3
U to P, P to 4
1 to Q, Q to U
2 to R, R to G
3 to S, S to C
4 to T, T to A

--
Regards,
Tom Ogilvy



"M H" wrote in message
...

I've written an excel function aim to change a RNA sequence to its
reverse complement (e.g. from "ACGUUGUA" to "UACAACGU") as:

Function ReverseComplement(Rcell As Range, Optional IsText As Boolean)

Dim i As Integer
Dim strReverseSeq As String
Dim strSenseSeq As String

strSenseSeq = Trim(Rcell)

For i = 1 To Len(strSenseSeq)
strReverseSeq = Mid(strSenseSeq, i, 1) & _ strReverseSeq
Next i

If IsText = False Then
ReverseComplement = CLng(strReverseSeq)
Else
ReverseComplement = strReverseSeq
End If

strSeqA1 = Replace(strReverseSeq, "A", "1")
strSeqC2 = Replace(strSeqA1, "C", "2")
strSeqG3 = Replace(strSeqC2, "G", "3")
strSeqT4 = Replace(strSeqG3, "U", "4")
strSeq1T = Replace(strSeqT4, "1", "U")
strSeq2G = Replace(strSeq1T, "2", "G")
strSeq3C = Replace(strSeq2G, "3", "C")
strSeq4A = Replace(strSeq3C, "4", "A")

End Function

The first half works fine, which reverse the sequence, but the second
part doesn't work, which cannot make the comoplements Please help for
debug. Much thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!