Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 8 - More on Strings and Special Methods - Programming Exercises - Page 265: 8.12

Answer

code

Work Step by Step

# 8.12 (Bioinformatics: find genes) 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 triplet TAG, TAA, or TGA. Furthermore, 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. def findGen(genome): found = False for i in range(len(genome)): startInd = str(genome).find("ATG") if startInd == -1: break endInd1, endInd2, endInd3 = \ str(genome).find("TAG"), str(genome).find("TAA"), str(genome).find("TGA") if endInd1 == -1: endInd1 = len(genome) * 2 if endInd2 == -1: endInd2 = len(genome) * 2 if endInd3 == -1: endInd3 = len(genome) * 2 endInd = min(endInd1, endInd2, endInd3) gen = str(genome)[startInd + 3:endInd] if len(gen) % 3 == 0: print(gen) found = True genome = genome[endInd + 3:len(genome)] if not found: print("No genes found") def main(): g = input("Enter a genome string: ") findGen(g) main()
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.