Problem

In DNA strings, symbols 'A' and 'T' are complements of each other, as are 'C' and 'G'.

The reverse complement of a DNA string ss is the string scsc formed by reversing the symbols of ss, then taking the complement of each symbol (e.g., the reverse complement of "GTCA" is "TGAC").

Given: A DNA string ss of length at most 1000 bp.

Return: The reverse complement scsc of ss.

Sample Dataset

AAAACCCGGT

Sample Output

ACCGGGTTTT
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 08 20:33:16 2016

@author: hyl
“”” alt_map = {'ins':'0'} complement = {'A': 'T', 'C': 'G', 'G': 'C', 'T': 'A'} def reverse_complement(seq): for k,v in alt_map.iteritems(): seq = seq.replace(k,v) bases = list(seq) bases = reversed([complement.get(base,base) for base in bases]) bases = ''.join(bases) for k,v in alt_map.iteritems(): bases = bases.replace(v,k) print bases if __name__ == "__main__": fh= open ("C:\\Users\\hyl\\Desktop\\rosalind_revc.txt") seq ='' for line in fh.readlines(): seq += line reverse_complement(seq)

 

posted on 2016-12-13 17:09  Google-boy  阅读(427)  评论(0编辑  收藏  举报