我是一名生物学研究生,在过去的几个月里,我自学了非常有限的 python 来处理我拥有的一些数据。我不是在寻求家庭作业帮助,这是一个研究项目。
使用此代码,我打算获取一个称为序列的字符串的一部分,介于:找到“蛋白质翻译”的起始位点或ATG的第一次出现(生物术语是起始密码子),然后是TAA的第一次出现(终止密码子)。
然后,该函数translate_dna()
应该为字符串中的每三个字母交换字典值。变量 CDS 正确存在,但是对于,或者如果我的函数中的循环不起作用:(。有什么建议吗?输入文件的格式如下:
>gnl|GNOMON|230560476.m Model predicted by Gnomon on Homo sapiens unplaced genomic scaffold, alternate assembly HuRef DEGEN_1103279082069, whole genome shotgun sequence (NW_001841731.1)
CCCCAGTAGCTGGGATTACAGGTTATCCAAGGACATGGAAAAGCCAACACCATGGTAGCATTAATGAAAG
TTTACCAAGAGGAAGATGAAGCCTACCAGGAATTAGTTACCATGGCAACCATGTTTTTCCAGTACTTACT
GCAGCCATTTAGGGCTATGCGAGAAGTTGCAACTTTATGTAAGCTTGAT
>gnl|GNOMON|230560472.m Model predicted by Gnomon on Homo sapiens unplaced genomic scaffold, alternate assembly HuRef DEGEN_1103279082069, whole genome shotgun sequence (NW_001841731.1)
GCCGGCGTTTGACCGCGCTTGGGTGGCCTGGGACCCTGTGGGAGGCTTCCCCGGCGCCGAGAGCCCTGGC
TGACGGCTGATGGGGAGGAGCCGGCGGGCGGAGAAGGCCACGGGCTCCCCAGTACCCTCACCTGCGCGGG
ATCGCTGCGGGAAACCAGGGGGAGCTTCGGCAGGGCCTGCAGAGAGGACAAGCGAAGTTAAGAGCCTAGT
GTACTTGCCGCTGGGAGCTGGGCTAGGCCCCCAACCTTTGCCCTGAAGATGCTGGCAGAGCAGGATGTTG
TAACGGGAAATGTCAGAAATACTGCAAGCAAACTGAAAACAACCCATCCATGTAGGAAAGAATAACACGG
ACTACACACTATGAGGAAACCACAGGGGAGTTTCAGGCCAGTCAGCTTTTGATCTTCAACTTTATAACTT
TCACCTTAGGATATGACGAGCCCACCGGAGTTTCAAAAATGGTATCATTTTGTATCAGGCTTGTTTTTTA
CACTCTTGGTTTCTCACAGAGATAGGTGGTTTCTCCTTAAAATCGAACATTTATATGATGCATTTTACTG
TAGTTACTATCAGAAAAGTTAGTTTTCCCAAATTTAAGTTCACTCTGGGGTACTATAGCGTGAATGTAGT
TCATTCTGTTGAGCTAGTTGTTCATGTTAGTGTAGTTCACATATTTATCTGGAACTCAAAAATGAGGGGT
TGAGAGGGGAAGCTAAAATTCAAAACATGTCCAAATATATAATTTTAATATTTTACTTTATATTTAAAAT
AGAAAAGCAATTGATTCTAGAATTAGACTAATTGCTAGCATTGCTAGGATATATAAAATGAAGCTGAATG
TTTTAACTCTGGAATTTTTCTGAATAGTCTAAGAAATAAGGCTGAAGTGTATCACTTGCCTTAAGTTTAC
TTTTGCGTGTGTGTTTTAATTTTGTTCAGTGGGGCTTTCACTTAAAAAAAAAACCATAATATTATTACCT
GGATAAAAAATACAGCTGAAAGTAGATCACTTTATCTTTAAGCAGAAGGATGGAAATAGAAGAATTTTAA
GAATGTATTGGTTGAAAAACATCTATATTATTTTATTTTTATTTCTCTTCTTGTGGGAGTAAAATAATTT
CCAACCAAATCAGTCCACCTAGATTATACACTGTTCAGTTTGTTTTCTGCCCTGCAGCACAAGCAATAAC
CAGCAGAGACTGGAACCACAGCTGAGGCTCTGTAAATGAGTTGACTGCTAAGGACTTCATGGGGATATTA
ACCTGGGGCATTAAGAGAATCAACATGCTAAAGTACTTGGAGACAGCTCTGTAATGTTTTATGAGGTTTT
TTGTTTTTTTTTTTTGAGACAGAGTCTTGCACTGTCGCCCAGGCTGG
代码:
from sys import argv
script, filename = argv
def translate_dna(sequence):
codontable = {
'ATA':'I', 'ATC':'I', 'ATT':'I', 'ATG':'M',
'ACA':'T', 'ACC':'T', 'ACG':'T', 'ACT':'T',
'AAC':'N', 'AAT':'N', 'AAA':'K', 'AAG':'K',
'AGC':'S', 'AGT':'S', 'AGA':'R', 'AGG':'R',
'CTA':'L', 'CTC':'L', 'CTG':'L', 'CTT':'L',
'CCA':'P', 'CCC':'P', 'CCG':'P', 'CCT':'P',
'CAC':'H', 'CAT':'H', 'CAA':'Q', 'CAG':'Q',
'CGA':'R', 'CGC':'R', 'CGG':'R', 'CGT':'R',
'GTA':'V', 'GTC':'V', 'GTG':'V', 'GTT':'V',
'GCA':'A', 'GCC':'A', 'GCG':'A', 'GCT':'A',
'GAC':'D', 'GAT':'D', 'GAA':'E', 'GAG':'E',
'GGA':'G', 'GGC':'G', 'GGG':'G', 'GGT':'G',
'TCA':'S', 'TCC':'S', 'TCG':'S', 'TCT':'S',
'TTC':'F', 'TTT':'F', 'TTA':'L', 'TTG':'L',
'TAC':'Y', 'TAT':'Y', 'TAA':'_', 'TAG':'_',
'TGC':'C', 'TGT':'C', 'TGA':'_', 'TGG':'W',
}
proteinsequence = ''
start = sequence.find('ATG')
sequencestart = sequence[int(start):]
stop = sequencestart.find('TAA')
cds = str(sequencestart[:int(stop)+3])
for n in range(0,len(cds),3):
if cds[n:n+3] in codontable == True:
proteinsequence += codontable[cds[n:n+3]]
print proteinsequence
sequence = ''
header = ''
sequence = ''
for line in open(filename):
if line[0] == ">":
if header != '':
print header
translate_dna(sequence)
header = line.strip()
sequence = ''
else:
sequence += line.strip()
print header
translate_dna(sequence)