Lab Worksheet 9

Problem 1: Write a class NameSet that collects a unique set of names. Within the class, names should be stored in a list. NameSet should accept names in any format (upper case, lower case, etc.), but keep them capitalized.

Hint - when solving this question and the next question, these string functions may be useful: upper(), lower(), and capitalize().

In [1]:
class NameSet:
    
    def __init__(self):
        self.unique_list = []  # creates an empty list to keep unique names 

Problem 2: Write a class CountNuc that stores the counts of A's, C's, G's, and T's in a DNA sequence. Your class should be able to accept both upper and lower case DNA sequences. Nucleotide counts in CountNuc should be stored in a dictionary. Once your class has been written, confirm your class operates correctly on a test string "AGct". After that, determine the counts of A's, C's, G's, and T's in dna_string string given below, and print the counts.

In [2]:
class CountNuc:

    def __init__(self):
        self.nuc_dict = {}   # creates an empty dictionary to keep counts of nucleotides
In [3]:
# test the class `CountNuc` with small test string
test_dna_string = "AGct"

# determine the counts of A's, C's, G's and T's of this string:
dna_string = "ATCGAGCTataCCGATACAGGcTGGTATAAAAgatTC"