Dictionary
A dictionary can be created by listing key-value pairs inside a curly braces.
We can access the value associated with a particular key.
Dictionaries are mutable.
Dictionary – Exercise
Make a dictionary nucleotides and assign A, T, G and C as the keys and corresponding nucleotide names as values.
Print the value assigned to key 'G' in the dictionary nucleotides.
Print the first item stored in nucleotides. ( Hint: DictName.values() )
Print all keys and values stored in nucleotides.
Ask the user to input a sequence and print the nucleotide names using nucleotides.
Adding to a Dictionary
You can add entries to Python dictionaries. Ask user to enter a new key and value for your virus dictionary.
Create two dictionaries containing information about viruses. Can you create a database (using lists) containing the 2 dictionaries? Print names of all viruses stored in our database.
Modifying a Dictionary
You can change the value of a key, e.g.: virus1['load'] = 2000
We can delete an entry using del function similar to lists, e.g.: del virus1['load']
Looping a Dictionary
You can loop through a dictionary using its keys.
Create a dictionary which has multiple Patient data.
Calculate the average virus load in HIV and HCV patients.
Challenge: DNA to Protein sequence
Translate the valid DNA sequences from seqs given in code below to protein sequences using the dictionary codon_table
Did you take the reading frames into account? Translate codon for each reading frame.
Start with the following bit of sexy code:
File "<ipython-input-25-38f8df452d0d>", line 14
seqs[index] = item.upper().replace('U','T') for index,item in enumerate(seqs)
^
SyntaxError: invalid syntax