利用python求一段DNA序列的互补序列
代码如下:
1 complement = {'A':'T','G':'C','C':'G','T':'A'} 2 rev_seq = '' 3 with open(r'D:\Rosalind\haha.txt','w+') as f1: 4 with open(r'D:\Rosalind\rosalind_revc.txt','r') as f: 5 dna_seq = f.read() 6 dna_seq = list(dna_seq.strip()) 7 for i in dna_seq: 8 rev_seq += complement[i] 9 10 rev_seq = rev_seq[::-1] 11 12 13 print (rev_seq,file = f1)
这是将从一个txt文件中导入序列,然后将互补后的结果输出到另外一个文件中。
如果一个段序列不长,直接中python交互式界面完成感觉更方便
先定义的一个字典: complement = {'C': 'G', 'G': 'C', 'T': 'A', 'A': 'T'}
然后 for i in list(seq):
rev_dna += complement[i]
rev_dna = rev_dna[::-1]
print (rev_dna)
直接得到互补后的结果。