An example that computes the reverse complement of a sequence with BioPython
#
# Reverse complement example with BioPython
#
from Bio.Seq import Seq
# a separate function to reverse strings (or other iterables)
def rev(it):
"Reverses an interable and returns it as a string"
return ''.join(reversed(it))
# create a Seq class instance
dna = Seq("ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG")
# original DNA
print type(dna)
print dna
# reverse complement DNA, returns a new sequence
print dna.reverse_complement()
# currently there is no direct way to just reverse a sequence
# we need to do a little extra work
rseq = rev(str(dna))
rdna = Seq(rseq)
# reversed sequence
print rdna
# to complement DNA, returns a new sequence
print dna.complement()
Produces the following output:
<class 'Bio.Seq.Seq'>
ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG
CTATCGGGCACCCTTTCAGCGGCCCATTACAATGGCCAT
GATAGCCCGTGGGAAAGTCGCCGGGTAATGTTACCGGTA
TACCGGTAACATTACCCGGCGACTTTCCCACGGGCTATC
This is obviously not a question. It should therefore be labeled as 'community wiki' :)
Another tip: you can transform a Seq class instance into a string with the str() function.