您的位置:首页 > 其它

Complementing a Strand of DNA

2015-07-27 17:06 459 查看


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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: