<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://teaching.healthtech.dtu.dk:443/22101/index.php?action=history&amp;feed=atom&amp;title=Dictionaries</id>
	<title>Dictionaries - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://teaching.healthtech.dtu.dk:443/22101/index.php?action=history&amp;feed=atom&amp;title=Dictionaries"/>
	<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22101/index.php?title=Dictionaries&amp;action=history"/>
	<updated>2026-05-01T12:05:24Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22101/index.php?title=Dictionaries&amp;diff=87&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22101/index.php?title=Dictionaries&amp;diff=87&amp;oldid=prev"/>
		<updated>2024-11-26T08:08:37Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises to be handed in&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 10:08, 26 November 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l22&quot;&gt;Line 22:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 22:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises to be handed in ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises to be handed in ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Create a dictionary where the keys are codons and the value are the one-letter-code for the amino acids. The dictionary will function as a look-up table. You can find a [[codon list]] here.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Create a dictionary where the keys are codons and the value are the one-letter-code for the amino acids. The dictionary will function as a look-up table. You can find a [[codon list]] here&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;. You are meant to make the dict &quot;by hand&quot; as there is a structure lesson in that. If you feel like it you can in addition make a program that constructs the dict from a file&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Use the dictionary from the previous exercise in a program, that translates all the nucleotide fasta entries in &amp;#039;&amp;#039;dna7.fsa&amp;#039;&amp;#039; to amino acid sequence. Save the results in a file &amp;#039;&amp;#039;aa7.fsa&amp;#039;&amp;#039; in fasta format. Since the sequence is now consisting of amino acids add &amp;#039;Amino Acid Sequence&amp;#039; to each header. The STOP codon is NOT a part of the amino acid sequence. Think about what STOP means.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Use the dictionary from the previous exercise in a program, that translates all the nucleotide fasta entries in &amp;#039;&amp;#039;dna7.fsa&amp;#039;&amp;#039; to amino acid sequence. Save the results in a file &amp;#039;&amp;#039;aa7.fsa&amp;#039;&amp;#039; in fasta format. Since the sequence is now consisting of amino acids add &amp;#039;Amino Acid Sequence&amp;#039; to each header. The STOP codon is NOT a part of the amino acid sequence. Think about what STOP means.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# In the file &amp;#039;&amp;#039;ex5.acc&amp;#039;&amp;#039; are a lot of accession numbers, where some are duplicates. Earlier we just removed the duplicates, now we should count them. Make a program that reads the file once, and writes a file &amp;#039;&amp;#039;noorder5.acc&amp;#039;&amp;#039; with the unique accession numbers and the number of occurrences in the file. A line should look like this: &amp;quot;AC24677 2&amp;quot;, if this accession occurs twice in &amp;#039;&amp;#039;ex5.acc&amp;#039;&amp;#039;.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# In the file &amp;#039;&amp;#039;ex5.acc&amp;#039;&amp;#039; are a lot of accession numbers, where some are duplicates. Earlier we just removed the duplicates, now we should count them. Make a program that reads the file once, and writes a file &amp;#039;&amp;#039;noorder5.acc&amp;#039;&amp;#039; with the unique accession numbers and the number of occurrences in the file. A line should look like this: &amp;quot;AC24677 2&amp;quot;, if this accession occurs twice in &amp;#039;&amp;#039;ex5.acc&amp;#039;&amp;#039;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key c22101:diff:1.41:old-35:rev-87:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22101/index.php?title=Dictionaries&amp;diff=35&amp;oldid=prev</id>
		<title>WikiSysop: Created page with &quot;__NOTOC__ {| width=500  style=&quot;float:right; margin-left: 10px; margin-top: -56px;&quot; |Previous: Sets |Next: How to Python |} == Required course material for the lesson == Powerpoint: [https://teaching.healthtech.dtu.dk/material/22101/22101_13-Dicts.ppt Dictionaries]&lt;br&gt; Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=61d288cc-5f62-4027-a83e-af27012c27d2 Dictionaries]&lt;br&gt; Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=7b897492-bedb-4042-a4fc...&quot;</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22101/index.php?title=Dictionaries&amp;diff=35&amp;oldid=prev"/>
		<updated>2024-03-01T16:01:26Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__NOTOC__ {| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot; |Previous: &lt;a href=&quot;/22101/index.php/Sets&quot; title=&quot;Sets&quot;&gt;Sets&lt;/a&gt; |Next: &lt;a href=&quot;/22101/index.php/How_to_Python&quot; title=&quot;How to Python&quot;&gt;How to Python&lt;/a&gt; |} == Required course material for the lesson == Powerpoint: [https://teaching.healthtech.dtu.dk/material/22101/22101_13-Dicts.ppt Dictionaries]&amp;lt;br&amp;gt; Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=61d288cc-5f62-4027-a83e-af27012c27d2 Dictionaries]&amp;lt;br&amp;gt; Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=7b897492-bedb-4042-a4fc...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__NOTOC__&lt;br /&gt;
{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Sets]]&lt;br /&gt;
|Next: [[How to Python]]&lt;br /&gt;
|}&lt;br /&gt;
== Required course material for the lesson ==&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22101/22101_13-Dicts.ppt Dictionaries]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=61d288cc-5f62-4027-a83e-af27012c27d2 Dictionaries]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=7b897492-bedb-4042-a4fc-af27012c0a0b Tips and Tricks]&amp;lt;br&amp;gt;&lt;br /&gt;
Resource: [https://teaching.healthtech.dtu.dk/material/22101/clean_code.html Clean Code] Every time you read it, you will take something from it.&amp;lt;br&amp;gt;&lt;br /&gt;
Resource: [[Example code - Dicts]]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=276ecfa4-012e-47b4-b521-af27012b06d9 Live Coding]&lt;br /&gt;
&lt;br /&gt;
== Subjects covered ==&lt;br /&gt;
* Dictionaries, which are unordered tables of data.&lt;br /&gt;
* Functions relevant to dictionaries:&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;keys&amp;#039;&amp;#039;&amp;#039;, returns a list of keys in the dictionary,&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;values&amp;#039;&amp;#039;&amp;#039;, returns a list of values in the dictionary,&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;in&amp;#039;&amp;#039;&amp;#039;, determines if a key/value pair exist,&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;del&amp;#039;&amp;#039;&amp;#039;, which deletes a key/value pair,&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;items&amp;#039;&amp;#039;&amp;#039;, which iterates over all key/value pair in the dictionary.&lt;br /&gt;
&lt;br /&gt;
== Exercises to be handed in ==&lt;br /&gt;
# Create a dictionary where the keys are codons and the value are the one-letter-code for the amino acids. The dictionary will function as a look-up table. You can find a [[codon list]] here.&lt;br /&gt;
# Use the dictionary from the previous exercise in a program, that translates all the nucleotide fasta entries in &amp;#039;&amp;#039;dna7.fsa&amp;#039;&amp;#039; to amino acid sequence. Save the results in a file &amp;#039;&amp;#039;aa7.fsa&amp;#039;&amp;#039; in fasta format. Since the sequence is now consisting of amino acids add &amp;#039;Amino Acid Sequence&amp;#039; to each header. The STOP codon is NOT a part of the amino acid sequence. Think about what STOP means.&lt;br /&gt;
# In the file &amp;#039;&amp;#039;ex5.acc&amp;#039;&amp;#039; are a lot of accession numbers, where some are duplicates. Earlier we just removed the duplicates, now we should count them. Make a program that reads the file once, and writes a file &amp;#039;&amp;#039;noorder5.acc&amp;#039;&amp;#039; with the unique accession numbers and the number of occurrences in the file. A line should look like this: &amp;quot;AC24677 2&amp;quot;, if this accession occurs twice in &amp;#039;&amp;#039;ex5.acc&amp;#039;&amp;#039;.&lt;br /&gt;
# Improve the previous exercise by saving the accessions in order of occurrences with the top counts first in the file &amp;#039;&amp;#039;order5.acc&amp;#039;&amp;#039;.&lt;br /&gt;
# &amp;lt;font color=&amp;quot;#AA00FF&amp;quot;&amp;gt;In the tab-separated files &amp;#039;&amp;#039;slinger.txt&amp;#039;&amp;#039; and &amp;#039;&amp;#039;hoist.txt&amp;#039;&amp;#039; are two columns with an accession number and a numeric result; a probability between 0 and 1. The numbers are from running 2 different programs (slinger and hoist, if you are in doubt). You must combine these probabilities - basically taking the average of the two numbers - for each accession number and write the result in a file &amp;#039;&amp;#039;combined.txt&amp;#039;&amp;#039;. The file should look like the sources, i.e. tab-separated with accession in column 1 and number in column 2. Unfortunately, the two programs have not been run from the same set of accession numbers, so some of the results are only available in one of the input files. In such case you ignore/discard the data for that accession. Only save results in the output file when the accession is in both of the input files.&amp;lt;/font&amp;gt;&lt;br /&gt;
# Using above method gives you too little data. You try this time to combine your two input sets differently. If an accession is in both input files you use the average, if it is in only one, you just use the number straight in the output file. This is effectively making a union of the input instead of an intersection.&lt;br /&gt;
&lt;br /&gt;
== Exercises for extra practice ==&lt;br /&gt;
* Given a tab-separated file with 3 columns; StudentID, CourseNumber, Grade. Can you find a way to load the grades for a student in a retrievable manner into (some of) the python data structures learned so far? Retrievable means here that you can find the grades for a student if you know the studentID.&amp;lt;br&amp;gt;Explain your approach. Hint: It is not necessarily efficient.&lt;br /&gt;
* The &amp;#039;&amp;#039;geneA-E.txt&amp;#039;&amp;#039; files all have the same structure on each line; first number is a float between 0 and 1, second number is an integer. For all files (the combined data set) find the average of the float, given the integer and display in ascending order of the integer. You need to add all the floats for a given integer together and divide by the number of floats for the integer, then you have the average for the integer. To succeed at this, you must use two dicts where the integer is the key in both. The corresponding values are the sum of the floats (for that key) and the number of times the key has been encountered in the files.&lt;br /&gt;
* This exercise requires that you did the last two practice exercises in [[Simple Pattern Matching]]. In the &amp;#039;&amp;#039;data1-4.gb&amp;#039;&amp;#039; files count who many times the different codons in the coding sequence occurs. Display.&lt;br /&gt;
* This exercise builds on mandatory exercise 2. You must read the &amp;#039;&amp;#039;dna7.fsa&amp;#039;&amp;#039; file and translate the DNA sequences to protein sequence. Report the frequencies of the various amino acids for the entire file - all sequences (not individual sequences). That is - count how many there is of each amino acid (a total) in the translated sequences, compute the frequency of each (Number_of_this_amino_acid/Total_number_of_amino_acids) and print the results as &amp;quot;S   0.0123&amp;quot;, i.e. 4 digits after the dot.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
</feed>