CS 170 Lab 7: DNA Strings

This is a lab exercise that involves using loops and strings.

  1. For once there is no file to start with for this lab. You are going to write functions that work with DNA strings. Recall from class that a DNA string consists of a sequence of characters from the set ['A', 'C', 'G', 'T']. The file dna.py from class manipulates DNA strings in various ways.

  2. Write a function called is_dna(seq) that returns True if seq is a string containing only characters from the DNA set and False otherwise. Your function should do no input and no printing.

  3. Write a function called transcription(seq) that takes a DNA sequence as input and returns an RNA transcription. An RNA transcription is the same as the original sequence, except that every T (thymine) in the DNA sequence is replaced with U (uracil). Do this by accumulating a new string as we saw yesterday. Your function should do no input or printing. It should return the newly constructed transcription string.

  4. Write a function called countbases(dna) that counts the number of appearances of each of the four bases in a given string of DNA (not RNA). This function should print its results in a readable way, labeling all four nucleotides and their count.

  5. Your main() function should ask the user for a DNA sequence. If what the user enters is a valid DNA sequence (as determined by your is_dna function) you should print out the transcription of that sequence, then print out the base counts, with both of these calculated using the above functions.

  6. When your program is working properly you should upload it. Make sure your file has your name and Lab 07 prominently displayed on it.