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

Exercise 18.1

Restriction enzymes are proteins that cut DNA at specific sites called cleavage sites. These sites are widely used for DNA modification and cloning. Interestingly, cleavage sites are palindromic.

A DNA palindrome is not quite the same as a word palindrome though. Remember, a word palindrome reads the same backward and forward, such as "level".

DNA is double stranded. The two strands are complementary, so an A on one strand pairs with a T on the other strand, and G pairs with C. So given one strand, say "AACCGGTT" we know that its complement will be "TTGGCCAA".

A DNA sequence is said to be palindromic if its reverse complement is the same as the DNA sequence. For example, the DNA sequence "ATGATCAT" is palindromic because its complement is "TACTAGTA", which, when reversed, is "ATGATCAT".

Write some code to test and print whether the following DNA sequence is palindromic.

  • Hint 1: You can reuse the code in Notebook 18 to construct a complementary sequence.

  • Hint 2: You need a conditional statement to test if the DNA sequence equals its reverse complement.

complement_table = { 'A':'T', 'C':'G', 'G':'C', 'T':'A'} dna_seq = 'ACAGGTACCTGT'
complement_seq = '' for base in dna_seq: complement_base = complement_table[base] complement_seq += complement_base if complement_seq[::-1] == dna_seq: print('DNA sequence is palindromic') else: print('DNA sequence is not palindromic')

Exercise 18.2

Modify your code so that it tests each of the DNA sequences in the following list.

  • Hint 1: You'll need a nested loop (see Notebook 13); the outer loop goes through the list one sequence at a time and the nested loop goes through the bases of each sequence.

  • Hint 2: The complement sequence string needs to be assigned the empty string on each iteration of the loop.

complement_table = { 'A':'T', 'C':'G', 'G':'C', 'T':'A'} dna_sequences = [ 'ACGTAATTACGT','ATGATATATCAT','ATTAGTACAAAG','GGACCCCGTTTA','AAAGATATCTTT' ]
for dna_seq in dna_sequences: complement_seq = '' for base in dna_seq: complement_base = complement_table[base] complement_seq += complement_base if complement_seq[::-1] == dna_seq: print('DNA sequence is palindromic') else: print('DNA sequence is not palindromic')

Exercise 18.3

The molecular masses of amino acids vary. The dictionary in the following code cell gives the molecular masses in Daltons (1 Dalton is 1.7x10-24 grams) of each of the amino acids represented by their letters.

Write a a program that calculates and prints the molecular mass of the peptide "FWGCYPT" to 5dp.

  • Hint: Have a variable to store the peptide's mass and initialise to 0. Loop through the peptide sequence incrementing the peptide's mass by looking up each amino acid's mass in the dictionary masses.

masses = { "A" : 71.03711, "C" : 103.00919, "D" : 115.02694, "E" : 129.04259, "F" : 147.06841, "G" : 57.02146, "H" : 137.05891, "I" : 113.08406, "K" : 128.09496, "L" : 113.08406, "M" : 131.04049, "N" : 114.04293, "P" : 97.05276, "Q" : 128.05858, "R" : 156.10111, "S" : 87.03203, "T" : 101.04768, "V" : 99.06841, "W" : 186.07931, "Y" : 163.06333}
peptide = "FWGCYPT" mass = 0 for aa in peptide: mass += masses[aa] print(f'mass of {peptide} is {mass:.5f} Daltons')
mass of FWGCYPT is 854.34214 Daltons