Thread: Complete beginner stuck!

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2004
Posts
2
Rep Power
0

Complete beginner stuck!

Hi,

I only started using Python a couple of weeks ago, so I'm struggling.
I have a DNA sequence in a string. I've converted it to a list and reversed it, but now cant figure out how to generate the complementary sequence. Help !

Thanks,
Gingernut82
2. Hi, I'd try something like this
PHP Code:
``` complementary_sequence = [] # set up empty list for base in sequence: # go through each base     if base == 'A': complementary_sequence.append('T')    elif base == 'T': complementary_sequence.append('A')    elif base == 'C': complementary_sequence.append('G')    elif base == 'G': complementary_sequence.append('C')  ```
There are more efficient ways to do this, but this should get you started.
3. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2004
Posts
394
Rep Power
55
Hi!

Maybe something like this:
Code:
```def complement(seq):
basecomplement = {'A':'T','C':'G','T':'A','G':'C'}
return [basecomplement[base] for base in seq]

s = ['A','T','G','C']
print complement(s)```
Hope this helps.

mawe
4. you might try using the map() function - it applies a function to each element of a list.
5. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2004
Posts
2
Rep Power
0
Originally Posted by SimonGreenhill
Hi, I'd try something like this
PHP Code:
``` complementary_sequence = [] # set up empty list for base in sequence: # go through each base     if base == 'A': complementary_sequence.append('T')    elif base == 'T': complementary_sequence.append('A')    elif base == 'C': complementary_sequence.append('G')    elif base == 'G': complementary_sequence.append('C')  ```
There are more efficient ways to do this, but this should get you started.
Ok, thanks alot Simon,
Gingernut