Here's my solution to the problem[1]:

[1] http://shootout.alioth.debian.org/benchmark.php?test=revcomp

import sys
import string

basetable = string.maketrans('ACBDGHKMNSRUTWVYacbdghkmnsrutwvy',
                             'TGVHCDMKNSYAAWBRTGVHCDMKNSYAAWBR')
def revcomp(seqlines, linelength=60, basetable=basetable):
    seq = ''.join(seqlines)
    complement = seq.translate(basetable)
    revcomplement = complement[::-1]
    for i in xrange(0, len(revcomplement), linelength):
        print revcomplement[i:i+linelength]

def main():
    seqlines = []
    for line in sys.stdin:
        if line.startswith('>') or line.startswith(';'):
            if seqlines:
                revcomp(seqlines)
            sys.stdout.write(line)
            seqlines = []
        else:
            seqlines.append(line.strip())
    revcomp(seqlines)

if __name__ == '__main__':
    main()

--
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to