Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
December 1st, 2004, 12:58 PM
 gingernut82
Registered User

Join Date: Nov 2004
Posts: 2
Time spent in forums: < 1 sec
Reputation 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
December 1st, 2004, 02:35 PM
 SimonGreenhill
(retired)

Join Date: Dec 2003
Location: The Laboratory
Posts: 10,101
Time spent in forums: 3 Months 3 Weeks 6 h 8 m 52 sec
Reputation Power: 0
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
December 1st, 2004, 03:30 PM
 mawe
Contributing User

Join Date: Nov 2004
Posts: 394
Time spent in forums: 1 Day 10 h 6 m 47 sec
Reputation Power: 51
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
December 1st, 2004, 05:28 PM
 deltacoder
slightly insane code guru

Join Date: Jul 2004
Location: Indianapolis, IN
Posts: 871
Time spent in forums: 2 h 8 m 36 sec
Reputation Power: 17
you might try using the map() function - it applies a function to each element of a list.
__________________

deltacoder.com :: W3C Standards :: PHP.net :: Google

#5
December 2nd, 2004, 04:56 AM
 gingernut82
Registered User

Join Date: Nov 2004
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
 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

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > Complete beginner stuck!