<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://teaching.healthtech.dtu.dk/22113/index.php?action=history&amp;feed=atom&amp;title=Making_Functions</id>
	<title>Making Functions - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://teaching.healthtech.dtu.dk/22113/index.php?action=history&amp;feed=atom&amp;title=Making_Functions"/>
	<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/22113/index.php?title=Making_Functions&amp;action=history"/>
	<updated>2026-05-15T21:44:37Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/22113/index.php?title=Making_Functions&amp;diff=26&amp;oldid=prev</id>
		<title>WikiSysop: Created page with &quot;__NOTOC__ {| width=500  style=&quot;font-size: 10px; float:right; margin-left: 10px; margin-top: -56px;&quot; |Previous: Regular Expressions |Next: Advanced Data Structures and New Data Types |} == Required course material for the lesson == Powerpoint: [https://teaching.healthtech.dtu.dk/material/22113/22113_04-Functions.ppt Making functions]&lt;br&gt; Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=f509116f-48e5-445b-bf6e-af27012ba23f Functions in Python] Monday&lt;br&gt;...&quot;</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/22113/index.php?title=Making_Functions&amp;diff=26&amp;oldid=prev"/>
		<updated>2024-03-06T13:39:27Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__NOTOC__ {| width=500  style=&amp;quot;font-size: 10px; float:right; margin-left: 10px; margin-top: -56px;&amp;quot; |Previous: &lt;a href=&quot;/22113/index.php/Regular_Expressions&quot; title=&quot;Regular Expressions&quot;&gt;Regular Expressions&lt;/a&gt; |Next: &lt;a href=&quot;/22113/index.php/Advanced_Data_Structures_and_New_Data_Types&quot; title=&quot;Advanced Data Structures and New Data Types&quot;&gt;Advanced Data Structures and New Data Types&lt;/a&gt; |} == Required course material for the lesson == Powerpoint: [https://teaching.healthtech.dtu.dk/material/22113/22113_04-Functions.ppt Making functions]&amp;lt;br&amp;gt; Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=f509116f-48e5-445b-bf6e-af27012ba23f Functions in Python] Monday&amp;lt;br&amp;gt;...&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;font-size: 10px; float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Regular Expressions]]&lt;br /&gt;
|Next: [[Advanced Data Structures and New Data Types]]&lt;br /&gt;
|}&lt;br /&gt;
== Required course material for the lesson ==&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22113/22113_04-Functions.ppt Making functions]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=f509116f-48e5-445b-bf6e-af27012ba23f Functions in Python] Monday&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=21e9d4d0-2ba5-465c-9939-af27012b7a7e Examples and identifying data types] Monday&amp;lt;br&amp;gt;&lt;br /&gt;
Resource: [[Example code - Functions]]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=e7b18282-7fb8-4c25-bd69-af27012adf7b Live Coding]&lt;br /&gt;
&lt;br /&gt;
== Subjects covered ==&lt;br /&gt;
* Functions: a function is both a way of hiding complexity and a way of reusing code.&lt;br /&gt;
* Scope of variables.&lt;br /&gt;
&lt;br /&gt;
== Exercises to be handed in ==&lt;br /&gt;
# Make a function, that returns the relevant one-letter designation for the correct amino acid, when you give it a codon (3 bases). You can find a [[codon list]] here. If something invalid is given as input to the function, raise an exception. Maybe make a dict with codons. You should also have a bit of code apart from the function so you can test it.&lt;br /&gt;
# Make a function that calculates the factorial. Add some input control to the function to make sure you get positive integers, when you ask for a number. Consider if you want to raise an exception if the function gets invalid data or you want to halt the program.&lt;br /&gt;
# Make a function &amp;#039;&amp;#039;&amp;#039;fastaread(filename)&amp;#039;&amp;#039;&amp;#039; which takes a filename as a parameter and returns 2 lists, first list is the headers, second list is the sequences (as single strings without whitespace). Add appropriate error handling to the function. You can test your function on the file &amp;#039;&amp;#039;dna7.fsa&amp;#039;&amp;#039;.&lt;br /&gt;
# Make a function &amp;#039;&amp;#039;&amp;#039;fastawrite(filename, headers, sequences)&amp;#039;&amp;#039;&amp;#039; which takes a filename, a list of headers and a corresponding list of sequences as parameters and writes the fasta file. Add appropriate error handling to the function. You can test your function on the file &amp;#039;&amp;#039;dna7.fsa&amp;#039;&amp;#039;.&lt;br /&gt;
# Make a function that take a DNA sequence (string) as parameter and return the complement strand (reverse complement). Make the function generic and portable, i.e. not dependent on any external factors. Together with the functions you made in exercise 3 &amp;amp; 4, read the fasta entries in file &amp;#039;&amp;#039;dna7.fsa&amp;#039;&amp;#039; and write the complement strands in the new file &amp;#039;&amp;#039;revdna7.fsa&amp;#039;&amp;#039;. Add &amp;#039;Complement strand&amp;#039; to each header.&lt;br /&gt;
# Make a function that calculates the GC-content of a DNA sequence. It takes a DNA (string) as parameter and returns the GC percentage. Make the function generic and portable, i.e. not dependent on any external factors. Together with the functions you made in exercise 3 &amp;amp; 4, read the fasta entries in file &amp;#039;&amp;#039;dna7.fsa&amp;#039;&amp;#039; and write only the sequences which has a GC-content percentage over 50% in the new file &amp;#039;&amp;#039;dna7GC.fsa&amp;#039;&amp;#039;.&lt;br /&gt;
# &amp;lt;font color=&amp;quot;#AA00FF&amp;quot;&amp;gt;Make a function that calculates the standard deviation (1.8355) of a list of numbers.  Use it on the numbers in &amp;#039;&amp;#039;ex1.dat&amp;#039;&amp;#039;. You can either do the two-pass algorithm (looking at all the numbers twice) which is clear from the formula or the one-pass algorithm.&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;[[File:StandardDeviation.gif]]&lt;br /&gt;
# Make a function that returns the unique elements of a list as a list. Try it on the accession numbers in &amp;#039;&amp;#039;ex5.acc&amp;#039;&amp;#039;, which contains 6461 unique accessions, but also make your own file with simple numbers.&lt;br /&gt;
# Make a function &amp;#039;&amp;#039;&amp;#039;fibonacci(no1, no2, count)&amp;#039;&amp;#039;&amp;#039; which calculates the first &amp;#039;&amp;#039;&amp;#039;count&amp;#039;&amp;#039;&amp;#039; [https://en.wikipedia.org/wiki/Fibonacci_number fibonacci numbers] based on &amp;#039;&amp;#039;&amp;#039;no1&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;no2&amp;#039;&amp;#039;&amp;#039; and returns them in a list. The next number in a fibonacci sequence is the sum of the two previous numbers. Test it with printing the resulting list (one number per line) from fibonacci(0,1,20).&lt;br /&gt;
# The [https://en.wikipedia.org/wiki/Hamming_distance Hamming distance] is the distance between two strings of &amp;#039;&amp;#039;&amp;#039;equal&amp;#039;&amp;#039;&amp;#039; length. Make a function which takes two strings as arguments and calculates the distance between them. Add error handling.&lt;br /&gt;
&lt;br /&gt;
== Exercises for extra practice ==&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
</feed>