Complementing a Strand of DNA

来源:互联网 发布:ebsco数据库怎么用 编辑:程序博客网 时间:2024/06/09 06:34

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  is the string  formed by reversing the symbols of , then taking the complement of each symbol (e.g., the reverse complement of "GTCA" is "TGAC").

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

Return: The reverse complement  of .

Sample Dataset

AAAACCCGGT

Sample Output

ACCGGGTTTT 

翻译,用了一个hash表来弄,比if,switch什么的好用。
file=open('rosalind_revc.txt','r');seq=file.read();print(seq)leng=len(seq);tran={'A':'T','T':'A','C':'G','G':'C'};trna=[];for i in range(0,leng):trna.append(tran[seq[leng-1-i]]);trna_convert=''.join(trna);f=open('out3.txt','w')f.write(trna_convert)f.close
注意:每次用下载的txt都会出现keyerror,是因为我不是按行读取的,直接把文件全部读入,文件最后提行了。多了个\n
list还要先定义,write的时候不能直接是list,不知道怎么写,就把list转成str了,trna_convert=''.join(trna)



0 0
原创粉丝点击