我正在使用 Python 和正则表达式来查找ORF
(开放阅读框)。
查找子字符串 仅由以下字母ATGC
(无空格或换行符)组成的字符串:
以 开头ATG
,以TAG
or结尾TAA
,TGA
并且应该考虑从第一个字符开始的顺序,然后是第二个字符,然后是第三个字符:
Seq= "CCTCAGCGAGGACAGCAAGGGACTAGCCAGGAGGGAGAACAGAAACTCCAGAACATCTTGGAAATAGCTCCCAGAAAAGC
AAGCAGCCAACCAGGCAGGTTCTGTCCCTTTCACTCACTGGCCCAAGGCGCCACATCTCCCTCCAGAAAAGACACCATGA
GCACAGAAAGCATGATCCGCGACGTGGAACTGGCAGAAGAGGCACTCCCCCAAAAGATGGGGGGCTTCCAGAACTCCAGG
CGGTGCCTATGTCTCAGCCTCTTCTCATTCCTGCTTGTGGCAGGGGCCACCACGCTCTTCTGTCTACTGAACTTCGGGGT
GATCGGTCCCCAAAGGGATGAGAAGTTCCCAAATGGCCTCCCTCTCATCAGTTCTATGGCCCAGACCCTCACACTCAGAT
CATCTTCTCAAAATTCGAGTGACAAGCCTGTAGCCCACGTCGTAGCAAACCACCAAGTGGAGGAGCAGCTGGAGTGGCTG
AGCCAGCGCGCCAACGCCCTCCTGGCCAACGGCATGGATCTCAAAGACAACCAACTAGTGGTGCCAGCCGATGGGTTGTA
CCTTGTCTACTCCCAGGTTCTCTTCAAGGGACAAGGCTGCCCCGACTACGTGCTCCTCACCCACACCGTCAGCCGATTTG
CTATCTCATACCAGGAGAAAGTCAACCTCCTCTCTGCCGTCAAGAGCCCCTGCCCCAAGGACACCCCTGAGGGGGCTGAG
CTCAAACCCTGGTATGAGCCCATATACCTGGGAGGAGTCTTCCAGCTGGAGAAGGGGGACCAACTCAGCGCTGAGGTCAA
TCTGCCCAAGTACTTAGACTTTGCGGAGTCCGGGCAGGTCTACTTTGGAGTCATTGCTCTGTGAAGGGAATGGGTGTTCA
TCCATTCTCTACCCAGCCCCCACTCTGACCCCTTTACTCTGACCCCTTTATTGTCTACTCCTCAGAGCCCCCAGTCTGTA
TCCTTCTAACTTAGAAAGGGGATTATGGCTCAGGGTCCAACTCTGTGCTCAGAGCTTTCAACAACTACTCAGAAACACAA
GATGCTGGGACAGTGACCTGGACTGTGGGCCTCTCATGCACCACCATCAAGGACTCAAATGGGCTTTCCGAATTCACTGG
AGCCTCGAATGTCCATTCCTGAGTTCTGCAAAGGGAGAGTGGTCAGGTTGCCTCTGTCTCAGAATGAGGCTGGATAAGAT
CTCAGGCCTTCCTACCTTCAGACCTTTCCAGATTCTTCCCTGAGGTGCAATGCACAGCCTTCCTCACAGAGCCAGCCCCC
CTCTATTTATATTTGCACTTATTATTTATTATTTATTTATTATTTATTTATTTGCTTATGAATGTATTTATTTGGAAGGC
CGGGGTGTCCTGGAGGACCCAGTGTGGGAAGCTGTCTTCAGACAGACATGTTTTCTGTGAAAACGGAGCTGAGCTGTCCC
CACCTGGCCTCTCTACCTTGTTGCCTCCTCTTTTGCTTATGTTTAAAACAAAATATTTATCTAACCCAATTGTCTTAATA
ACGCTGATTTGGTGACCAGGCTGTCGCTACATCACTGAACCTCTGCTCCCCACGGGAGCCGTGACTGTAATCGCCCTACG
GGTCATTGAGAGAAATAA"
我试过的:
# finding the stop codon here
def stop_codon(seq_0):
for i in range(0,len(seq_0),3):
if (seq_0[i:i+3]== "TAA" and i%3==0) or (seq_0[i:i+3]== "TAG" and i%3==0) or (seq_0[i:i+3]== "TGA" and i%3==0) :
a =i+3
break
else:
a = None
# finding the start codon here
startcodon_find =[m.start() for m in re.finditer('ATG', seq_0)]
我怎样才能找到一种方法来检查起始密码子,然后找到第一个终止密码子。随后找到下一个起始密码子和下一个终止密码子。
我希望将其运行三帧。如前所述,三帧将序列的第一个、第二个和第三个字符作为开始。
此外,序列需要分成 3 的小部分。它应该是这样的:
ATG TTT AAA ACA AAA TAT TTA TCT AAC CCA ATT GTC TTA ATA ACG CTG ATT TGA
任何帮助将不胜感激。
我的最终答案:
def orf_find(st0):
seq_0=""
for i in range(0,len(st0),3):
if len(st0[i:i+3])==3:
seq_0 = seq_0 + st0[i:i+3]+ " "
ms_1 =[m.start() for m in re.finditer('ATG', seq_0)]
ms_2 =[m.start() for m in re.finditer('(TAA)|(TAG)|(TGA)', seq_0)]
def get_next(arr,value):
for a in arr:
if a > value:
return a
return -1
codons = []
start_codon=ms_1[0]
while (True):
stop_codon = get_next(ms_2,start_codon)
if stop_codon == -1:
break
codons.append((start_codon,stop_codon))
start_codon = get_next(ms_1,stop_codon)
if start_codon==-1:
break
max_val = 0
selected_tupple = ()
for i in codons:
k=i[1]-i[0]
if k > max_val:
max_val = k
selected_tupple = i
print "selected tupple is ", selected_tupple
final_seq=seq_0[selected_tupple[0]:selected_tupple[1]+3]
print final_seq
print "The longest orf length is " + str(max_val)
output_file = open('Longorf.txt','w')
output_file.write(str(orf_find(st0)))
output_file.close()
上面的 write 函数不能帮助我将内容写入文本文件。我进去的都是NONE..为什么会出现这个错误..有人可以帮忙吗?