Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse complement DNA

I have this equation for reverse complementing DNA in python:

def complement(s): 
    basecomplement = {'A': 'T', 'C': 'G', 'G': 'C', 'T': 'A'} 
    letters = list(s) 
    letters = [basecomplement[base] for base in letters] 
    return ''.join(letters)
def revcom(s):
    complement(s[::-1])
print("ACGTAAA")
print(complement("ACGTAAA"[::-1]))
print(revcom("ACGTAAA"))

however the lines:

print(complement("ACGTAAA"[::-1]))
print(revcom("ACGTAAA"))

do not equal one another. only the top line gives an answer. the bottom just prints "NONE"

any help why this is?

like image 491
Michael Ridley Avatar asked Oct 24 '13 15:10

Michael Ridley


People also ask

What is reverse complement DNA?

Reverse Complement converts a DNA sequence into its reverse, complement, or reverse-complement counterpart. The entire IUPAC DNA alphabet is supported, and the case of each input sequence character is maintained. You may want to work with the reverse-complement of a sequence if it contains an ORF on the reverse strand.

Why do we need reverse complement DNA?

Reverse/Complement. Often we need to obtain the complementary strand of a DNA sequence. As DNA is antiparallel, we really need the reverse complement sequence to keep our 5' and 3' ends properly oriented. While this is easy to do manually with short sequences, for longer sequences computer programs are easier.

Is RNA the reverse complement of DNA?

The RNA goes in the reverse direction compared to the DNA, but its base pairs still match (e.g. G to C). The reverse complementary RNA for a positive strand DNA sequence will be identical to the corresponding negative strand DNA sequence.


1 Answers

You forgot the return statement in revcom. Try this:

def revcom(s):
    return complement(s[::-1])

If you don't explicitly return a value from a function in Python, then the function returns None.

like image 64
mdml Avatar answered Sep 30 '22 18:09

mdml