Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
10327 views
ubuntu2004
Kernel: Python 3 (system-wide)

Exercise 13.1

Loop through the following DNA sequences. Stop when you find the first sequence starting with "TATA" and print that sequence.

  • Hint 1: break out of the loop.

  • Hint 2: Use string slicing to access the first four bases of each DNA sequence.

dna_sequences = ['TATCATGGTATAGGATGAT', 'CTATAGCCTATATATTAGGA', 'TATATCGCTAGGGTATAGGGTT', 'TATGAGGATTAGA', 'TATAGACTAGGAT'] for i in dna_sequences: if i[0:4] == 'TATA': print(i) break
TATATCGCTAGGGTATAGGGTT

Exercise 13.2

Count how many of the three stop codons "TAA", "TAG" and "TGA" occur in each of the following DNA sequences in the list dna_sequences. Ignore multiple occurrences of the same stop codon in a DNA sequence.

  • Hint: You will need a nested loop: An outer loop to go through the sequences and a nested loop to go through the stop codons.

dna_sequences = ['TATCATGGTATAGGATGAT', 'CTATAGCCTATATATTAGGA', 'TATATCGCTAGGGTATAGGGTT', 'TATGAGGATTAGA', 'TATAGACTAGGAT'] stop_codons = ['TAA', 'TAG', 'TGA'] for dna_seq in dna_sequences: count = 0 for codons in stop_codons: if codons in dna_seq: print(f'{codons} is present') count += 1 else: print(f'{codons} not present') print(f'{count} stop codons are present in {dna_seq}') print()
TAA not present TAG is present TGA is present 2 stop codons are present in TATCATGGTATAGGATGAT TAA not present TAG is present TGA not present 1 stop codons are present in CTATAGCCTATATATTAGGA TAA not present TAG is present TGA not present 1 stop codons are present in TATATCGCTAGGGTATAGGGTT TAA not present TAG is present TGA is present 2 stop codons are present in TATGAGGATTAGA TAA not present TAG is present TGA not present 1 stop codons are present in TATAGACTAGGAT