Когда я пытаюсь запустить этот код, он никогда не заканчивается, и я думаю, что он где-то застрял, но я не слишком уверен, так как я новичок в python.
import re
codon = []
rcodon = []
dataset = "ggtcagaaaaagccctctccatgtctactcacgatacatccctgaaaaccactgaggaagtggcttttcagatcatcttgctttgccagtttggggttgggacttttgccaatgtatttctctttgtctataatttctctccaatctcgactggttctaaacagaggcccagacaagtgattttaagacacatggctgtggccaatgccttaactctcttcctcactatatttccaaacaacatgatga"
startcodon=0
n=0
print ("DNA sequence: ", dataset)
def find_codon(codon, string, start):
i = start + 3
while i < len(string):
i = string.find(codon, i) # find the next substring
if (i - start) % 3 == 0: # check that it's a multiple of 3 after start
return i
return None
while(n < 1):
startcodon=dataset.find("atg", startcodon)
#locate stop codons
taacodon=find_codon("taa", dataset, startcodon)
tagcodon=find_codon("tag", dataset, startcodon)
tgacodon=find_codon("tga", dataset, startcodon)
stopcodon = min(taacodon, tagcodon, tgacodon)
codon.append(dataset[startcodon:stopcodon+3])
if(startcodon > len(dataset) or startcodon < 0):
n = 2;
startcodon=stopcodon
#reverse the string and swap the letters
n=0;
while(n < len(codon)):
rcodon.append (codon[n][len(codon[n])::-1])
#replace a with u
rcodon[n] = re.sub('a', "u", rcodon[n])
#replace t with a
rcodon[n] = re.sub('t', "a", rcodon[n])
#replace c with x
rcodon[n] = re.sub('c', "x", rcodon[n])
#replace g with c
rcodon[n] = re.sub('g', "c", rcodon[n])
#replace x with g
rcodon[n] = re.sub('x', "g", rcodon[n])
print("DNA sequence: ", codon[n] ,'\n', "RNA sequence:", rcodon[n])
n=n+1
answer = 0
print("Total Sequences: ", len(codon)-3)
while (int(answer) >=0):
#str = "Please enter an integer from 0 to " + str(len(dataset)) + " or -1 to quit: "
answer = int(input("Please enter a sequence you would like to see or -1 to quit: "))
if(int(answer) >= 0):
print("DNA sequence: ", codon[int(answer)] ,'\n', "RNA sequence:", rcodon[int(answer)])
Любой совет будет полезен ,
Это проект о транскрипции ДНК БЕЗ био python Цель: создать программу, которая может найти «atg» в последовательности ДНК, а затем найти последовательность остановок (tga, taa или tag) при подсчете троек от начального atg.
edit: я хочу, чтобы программа выдала мне последовательности между atg и стоп-кодоном, как мой оригинальный код. Мой оригинальный код, однако, не рассматривал возможность перехода на 3 от атга, чтобы найти правильную последовательность остановок.
мой оригинальный код:
import re
codon = []
rcodon = []
dataset = "ggtcagaaaaagccctctccatgtctactcacgatacatccctgaaaaccactgaggaagtggcttttcagatcatcttgctttgccagtttggggttgggacttttgccaatgtatttctctttgtctataatttctctccaatctcgactggttctaaacagaggcccagacaagtgattttaagacacatggctgtggccaatgccttaactctcttcctcactatatttccaaacaacatgatga"
startcodon=0
n=0
while(n < 1):
startcodon=dataset.find("atg", startcodon, len(dataset)-startcodon)
#locate stop codons
taacodon=dataset.find("taa", startcodon+3, len(dataset)-startcodon)
tagcodon=dataset.find("tag", startcodon+3, len(dataset)-startcodon)
tgacodon=dataset.find("tga", startcodon+3, len(dataset)-startcodon)
if(taacodon<tagcodon):
if(taacodon<tgacodon):
stopcodon=taacodon
#print("taacodon", startcodon)
else:
stopcodon=tgacodon
#print("tGacodon", startcodon)
elif(tgacodon>tagcodon):
stopcodon=tagcodon
#print("taGcodon", startcodon)
else:
stopcodon=tgacodon
#print("tGacodon", startcodon)
#to add sequences to an array
codon.append(dataset[startcodon:stopcodon+3])
if(startcodon > len(dataset) or startcodon < 0):
n = 2;
startcodon=stopcodon
#reverse the string and swap the letters
n=0;
while(n < len(codon)):
rcodon.append (codon[n][len(codon[n])::-1])
#replace a with u
rcodon[n] = re.sub('a', "u", rcodon[n])
#replace t with a
rcodon[n] = re.sub('t', "a", rcodon[n])
#replace c with x
rcodon[n] = re.sub('c', "x", rcodon[n])
#replace g with c
rcodon[n] = re.sub('g', "c", rcodon[n])
#replace x with g
rcodon[n] = re.sub('x', "g", rcodon[n])
print("DNA sequence: ", codon[n] ,'\n', "RNA sequence:", rcodon[n])
n=n+1
answer = 0
print("Total Sequences: ", len(codon)-3)
while (int(answer) >= 0):
#str = "Please enter an integer from 0 to " + str(len(dataset)) + " or -1 to quit: "
answer = int(input("Please enter an sequence you would like to see or -1 to quit: "))
if(int(answer) >= 0):
print("DNA sequence: ", codon[int(answer)] ,'\n', "RNA sequence:", rcodon[int(answer)])