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 seq in dna_sequences: if seq[:4] == 'TATA': print(seq) break

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 seq in dna_sequences: count = 0 for codon in stop_codons: if codon in seq: count += 1 if count == 1: print( f'{count} of the stop codons is in {seq}' ) else: print( f'{count} of the stop codons are in {seq}' )