This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Computing The Reverse And Complement Of A Sequence With Pygr

Computing the reverse complement with the Pygr bioinformatics framework:

#
# Reverse complement example with pygr
#

from pygr.sequence import Sequence

# needs a separate function to reverse strings
def rev(it):
    "Reverses an interable and returns it as a string"
    return ''.join(reversed(it))

# original sequence as as string
seq = 'ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG'

# create a Sequence class  instance named bobo
dna = Sequence(seq,'bobo')

# sequence class' type and content
print type(dna)
print dna

# the -operator reverse complements the DNA, returns a new sequence
print -dna

# to reverse the DNA, reverse the input data
rdna = Sequence( rev(seq),'bobo')
print rdna

# to complement the DNA reverse complement, then reverse again
cseq = rev(str(-dna))
cdna = Sequence(cseq,'bobo')

print cdna

Produces the output:

<class 'pygr.sequence.Sequence'>
ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG
CTATCGGGCACCCTTTCAGCGGCCCATTACAATGGCCAT
GATAGCCCGTGGGAAAGTCGCCGGGTAATGTTACCGGTA
TACCGGTAACATTACCCGGCGACTTTCCCACGGGCTATC
python sequence

This post was not formulated in a question/answer format therefore will be closed.

This is not a question

0 answers

No answers yet.

Log in to answer this question.