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)
相关文章推荐
- Codeforces Round #298 (Div. 2) D. Handshakes 二分
- Yii2-Redis使用小记 - Cache
- javaWeb web.xml 配置
- easysize的使用方法 (实现控件大小位置随界面变化而有相应的变化,这个变化可以自己设置)
- Container With Most Water
- 字符串長度計算
- clientHeight offsetHeight scrollHeight
- spring依赖注入
- string类find函数返回值判定
- Java栈与堆
- 远程服务器控制台部署JBOSS项目
- UVa 1629 - Cake slicing(记忆化搜索)
- Table 'barfoo_datacenter_config.parttemplates' doesn't exist------Mysql
- html+css学习笔记
- 【BZOJ 1146】【CTSC 2008】网络管理network
- zoj2987 Misspelling
- android 画虚线、实线,画圆角矩形,一半圆角
- 从用户态的open到内核驱动实现流程
- socket与http的区别
- 如何从wireshark中获取H264码流(原创)