In python!
Objective:
students will be able to
1.access string elements by index operator
2.search for simple pattern in strings
Specification:
Biologists use a sequence of letters A, C, T, and G to model a genome. A gene is a substring of a genome that starts after a triplet ATG and ends before a trilet TAG, TAA, or TGA. The length of a gene string is a multiple of 3 and the gene does not contain any of the triplets ATG, TAG, TAA, and TGA. Write a program that prompts the user to enter a genome and displays all genes in the genome. If no gene is found in the input sequence, the program displays "No gene is found". Here are the sample runs:
Enter a genome string: TTATGTTTTAAGGATGGGGCGTTAGTT [ENTER]
TTT
GGGCGT
Enter a genome string: TGTGTGTATAT [ENTER]
No gene is found
Program:
Sample output:
RUN1:
RUN2:
Code to copy:
#define main method
def main():
#prompt the user to enter genome string
print("Enter a genome string: ")
string=input();
#declare all the required variables
i=0
found=0
start=-1
#find the length of the string
num=len(string)
for i in range(num-2):
#find the substring
of genome string
triplet=string[i:i+3]
#compare the
substring with following strings
if triplet=="ATG":
start=i+3
elif triplet=="TAG" or
triplet=="TAA" or triplet=="TGA" and start!=-1:
gene=string[start:i]
if len(gene)%3==0:
found=1
#print the substring
print(gene)
start=-1
#check if there is no gene string
if found==0:
print("no gene is
found")
main()
In python! Objective: students will be able to 1.access string elements by index operator 2.search for...