#1
  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. #2
  3. (retired)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2003
    Location
    The Laboratory
    Posts
    10,101
    Rep 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.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep 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
  6. #4
  7. slightly insane code guru
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2004
    Location
    Indianapolis, IN
    Posts
    871
    Rep Power
    18
    you might try using the map() function - it applies a function to each element of a list.
  8. #5
  9. 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

IMN logo majestic logo threadwatch logo seochat tools logo