<?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=Classes</id>
	<title>Classes - 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=Classes"/>
	<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/22113/index.php?title=Classes&amp;action=history"/>
	<updated>2026-04-09T02:52:28Z</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=Classes&amp;diff=119&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/22113/index.php?title=Classes&amp;diff=119&amp;oldid=prev"/>
		<updated>2025-03-17T17:24:50Z</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 19:24, 17 March 2025&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-l20&quot;&gt;Line 20:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 20:&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;# Add a method &amp;#039;&amp;#039;&amp;#039;verify(alphabet,[start[,end]])&amp;#039;&amp;#039;&amp;#039;, which verifies sequence entries according to an alphabet. It works in a way similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; for the range of what should be verified. The method returns True if all entries in the range are verified (belonging to the alphabet), False otherwise.&amp;lt;br&amp;gt;The alphabet could be a DNA alphabet (ATCG), a protein alphabet or something derived from those. You should put your alphabets into class variables, as they are common for all instances, and not subject to change.&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;# Add a method &amp;#039;&amp;#039;&amp;#039;verify(alphabet,[start[,end]])&amp;#039;&amp;#039;&amp;#039;, which verifies sequence entries according to an alphabet. It works in a way similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; for the range of what should be verified. The method returns True if all entries in the range are verified (belonging to the alphabet), False otherwise.&amp;lt;br&amp;gt;The alphabet could be a DNA alphabet (ATCG), a protein alphabet or something derived from those. You should put your alphabets into class variables, as they are common for all instances, and not subject to change.&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;# Add a method &amp;#039;&amp;#039;&amp;#039;discard(alphabet,[start[,end]])&amp;#039;&amp;#039;&amp;#039;, which discards sequence entries and corresponding headers if they do not match the given alphabet. It works in a way similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; for the range of what should be verified.&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;# Add a method &amp;#039;&amp;#039;&amp;#039;discard(alphabet,[start[,end]])&amp;#039;&amp;#039;&amp;#039;, which discards sequence entries and corresponding headers if they do not match the given alphabet. It works in a way similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; for the range of what should be verified.&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;# Add iteration and length evaluation to the &#039;&#039;&#039;Fasta&#039;&#039;&#039; class using magic methods. Do this so you can write code like &amp;lt;div style=&quot;font-family:&#039;Courier New&#039;&quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;The function &#039;&#039;&#039;len&#039;&#039; returns the number of sequences.&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;# Add iteration and length evaluation &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;(__len__ magic method) &lt;/ins&gt;to the &#039;&#039;&#039;Fasta&#039;&#039;&#039; class using magic methods. Do this so you can write code like &amp;lt;div style=&quot;font-family:&#039;Courier New&#039;&quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;The function &#039;&#039;&#039;len&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&lt;/ins&gt;&#039;&#039; returns the number of sequences.&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;# Add the methods &amp;#039;&amp;#039;&amp;#039;deletethis()&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insertthis(header, sequence)&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;verifythis(alphabet)&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;discardthis(alphabet)&amp;#039;&amp;#039;&amp;#039; to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class. The methods should only work when &amp;#039;&amp;#039;iterating over an instance at the current item&amp;#039;&amp;#039;, i.e. they work when you are iterating over the fasta sequences on the &amp;#039;&amp;#039;current&amp;#039;&amp;#039; sequence and header, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&amp;quot;DNA&amp;quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;continue&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible, maybe by changing the way your iteration works in the previous exercise.&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;# Add the methods &amp;#039;&amp;#039;&amp;#039;deletethis()&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insertthis(header, sequence)&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;verifythis(alphabet)&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;discardthis(alphabet)&amp;#039;&amp;#039;&amp;#039; to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class. The methods should only work when &amp;#039;&amp;#039;iterating over an instance at the current item&amp;#039;&amp;#039;, i.e. they work when you are iterating over the fasta sequences on the &amp;#039;&amp;#039;current&amp;#039;&amp;#039; sequence and header, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&amp;quot;DNA&amp;quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;continue&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible, maybe by changing the way your iteration works in the previous exercise.&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;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 for extra practice ==&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 for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key c22113:diff:1.41:old-118:rev-119:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/22113/index.php?title=Classes&amp;diff=118&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/22113/index.php?title=Classes&amp;diff=118&amp;oldid=prev"/>
		<updated>2025-03-17T17:22:56Z</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 19:22, 17 March 2025&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-l20&quot;&gt;Line 20:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 20:&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;# Add a method &amp;#039;&amp;#039;&amp;#039;verify(alphabet,[start[,end]])&amp;#039;&amp;#039;&amp;#039;, which verifies sequence entries according to an alphabet. It works in a way similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; for the range of what should be verified. The method returns True if all entries in the range are verified (belonging to the alphabet), False otherwise.&amp;lt;br&amp;gt;The alphabet could be a DNA alphabet (ATCG), a protein alphabet or something derived from those. You should put your alphabets into class variables, as they are common for all instances, and not subject to change.&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;# Add a method &amp;#039;&amp;#039;&amp;#039;verify(alphabet,[start[,end]])&amp;#039;&amp;#039;&amp;#039;, which verifies sequence entries according to an alphabet. It works in a way similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; for the range of what should be verified. The method returns True if all entries in the range are verified (belonging to the alphabet), False otherwise.&amp;lt;br&amp;gt;The alphabet could be a DNA alphabet (ATCG), a protein alphabet or something derived from those. You should put your alphabets into class variables, as they are common for all instances, and not subject to change.&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;# Add a method &amp;#039;&amp;#039;&amp;#039;discard(alphabet,[start[,end]])&amp;#039;&amp;#039;&amp;#039;, which discards sequence entries and corresponding headers if they do not match the given alphabet. It works in a way similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; for the range of what should be verified.&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;# Add a method &amp;#039;&amp;#039;&amp;#039;discard(alphabet,[start[,end]])&amp;#039;&amp;#039;&amp;#039;, which discards sequence entries and corresponding headers if they do not match the given alphabet. It works in a way similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; for the range of what should be verified.&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;# Add iteration and length evaluation to the &#039;&#039;&#039;Fasta&#039;&#039;&#039; class using magic methods. Do this so you can write code like &amp;lt;div style=&quot;font-family:&#039;Courier New&#039;&quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;The &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;method &lt;/del&gt;&#039;&#039;&#039;len&#039;&#039; returns the number of sequences.&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;# Add iteration and length evaluation to the &#039;&#039;&#039;Fasta&#039;&#039;&#039; class using magic methods. Do this so you can write code like &amp;lt;div style=&quot;font-family:&#039;Courier New&#039;&quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;The &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;function &lt;/ins&gt;&#039;&#039;&#039;len&#039;&#039; returns the number of sequences.&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;# Add the methods &amp;#039;&amp;#039;&amp;#039;deletethis()&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insertthis(header, sequence)&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;verifythis(alphabet)&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;discardthis(alphabet)&amp;#039;&amp;#039;&amp;#039; to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class. The methods should only work when &amp;#039;&amp;#039;iterating over an instance at the current item&amp;#039;&amp;#039;, i.e. they work when you are iterating over the fasta sequences on the &amp;#039;&amp;#039;current&amp;#039;&amp;#039; sequence and header, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&amp;quot;DNA&amp;quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;continue&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible, maybe by changing the way your iteration works in the previous exercise.&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;# Add the methods &amp;#039;&amp;#039;&amp;#039;deletethis()&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insertthis(header, sequence)&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;verifythis(alphabet)&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;discardthis(alphabet)&amp;#039;&amp;#039;&amp;#039; to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class. The methods should only work when &amp;#039;&amp;#039;iterating over an instance at the current item&amp;#039;&amp;#039;, i.e. they work when you are iterating over the fasta sequences on the &amp;#039;&amp;#039;current&amp;#039;&amp;#039; sequence and header, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&amp;quot;DNA&amp;quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;continue&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible, maybe by changing the way your iteration works in the previous exercise.&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;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 for extra practice ==&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 for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/22113/index.php?title=Classes&amp;diff=117&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/22113/index.php?title=Classes&amp;diff=117&amp;oldid=prev"/>
		<updated>2025-03-17T17:20:44Z</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 19:20, 17 March 2025&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-l20&quot;&gt;Line 20:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 20:&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;# Add a method &amp;#039;&amp;#039;&amp;#039;verify(alphabet,[start[,end]])&amp;#039;&amp;#039;&amp;#039;, which verifies sequence entries according to an alphabet. It works in a way similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; for the range of what should be verified. The method returns True if all entries in the range are verified (belonging to the alphabet), False otherwise.&amp;lt;br&amp;gt;The alphabet could be a DNA alphabet (ATCG), a protein alphabet or something derived from those. You should put your alphabets into class variables, as they are common for all instances, and not subject to change.&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;# Add a method &amp;#039;&amp;#039;&amp;#039;verify(alphabet,[start[,end]])&amp;#039;&amp;#039;&amp;#039;, which verifies sequence entries according to an alphabet. It works in a way similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; for the range of what should be verified. The method returns True if all entries in the range are verified (belonging to the alphabet), False otherwise.&amp;lt;br&amp;gt;The alphabet could be a DNA alphabet (ATCG), a protein alphabet or something derived from those. You should put your alphabets into class variables, as they are common for all instances, and not subject to change.&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;# Add a method &amp;#039;&amp;#039;&amp;#039;discard(alphabet,[start[,end]])&amp;#039;&amp;#039;&amp;#039;, which discards sequence entries and corresponding headers if they do not match the given alphabet. It works in a way similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; for the range of what should be verified.&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;# Add a method &amp;#039;&amp;#039;&amp;#039;discard(alphabet,[start[,end]])&amp;#039;&amp;#039;&amp;#039;, which discards sequence entries and corresponding headers if they do not match the given alphabet. It works in a way similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; for the range of what should be verified.&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;# Add iteration and length evaluation to the &#039;&#039;&#039;Fasta&#039;&#039;&#039; class using magic methods. Do this so you can write code like &amp;lt;div style=&quot;font-family:&#039;Courier New&#039;&quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;&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;# Add iteration and length evaluation to the &#039;&#039;&#039;Fasta&#039;&#039;&#039; class using magic methods. Do this so you can write code like &amp;lt;div style=&quot;font-family:&#039;Courier New&#039;&quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;The method &#039;&#039;&#039;len&#039;&#039; returns the number of sequences.&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;# Add the methods &amp;#039;&amp;#039;&amp;#039;deletethis()&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insertthis(header, sequence)&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;verifythis(alphabet)&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;discardthis(alphabet)&amp;#039;&amp;#039;&amp;#039; to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class. The methods should only work when &amp;#039;&amp;#039;iterating over an instance at the current item&amp;#039;&amp;#039;, i.e. they work when you are iterating over the fasta sequences on the &amp;#039;&amp;#039;current&amp;#039;&amp;#039; sequence and header, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&amp;quot;DNA&amp;quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;continue&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible, maybe by changing the way your iteration works in the previous exercise.&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;# Add the methods &amp;#039;&amp;#039;&amp;#039;deletethis()&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insertthis(header, sequence)&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;verifythis(alphabet)&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;discardthis(alphabet)&amp;#039;&amp;#039;&amp;#039; to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class. The methods should only work when &amp;#039;&amp;#039;iterating over an instance at the current item&amp;#039;&amp;#039;, i.e. they work when you are iterating over the fasta sequences on the &amp;#039;&amp;#039;current&amp;#039;&amp;#039; sequence and header, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&amp;quot;DNA&amp;quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;continue&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible, maybe by changing the way your iteration works in the previous exercise.&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;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 for extra practice ==&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 for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key c22113:diff:1.41:old-116:rev-117:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/22113/index.php?title=Classes&amp;diff=116&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/22113/index.php?title=Classes&amp;diff=116&amp;oldid=prev"/>
		<updated>2025-03-17T17:17:38Z</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 19:17, 17 March 2025&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-l18&quot;&gt;Line 18:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 18:&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;# Modify the &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; method, so it works similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039;. If called with no arguments like &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; it returns 2 lists with all headers and sequences. If called with one argument like &amp;#039;&amp;#039;&amp;#039;content(start)&amp;#039;&amp;#039;&amp;#039; it returns the header and sequence at position &amp;#039;&amp;#039;start&amp;#039;&amp;#039;. If called with two arguments, it returns the headers and sequences from position &amp;#039;&amp;#039;start&amp;#039;&amp;#039; up to but not including position &amp;#039;&amp;#039;end&amp;#039;&amp;#039; as two lists. Be careful that you return a copy of the lists and not the lists themselves as then the headers and sequences in the instance can be modified unintended outside the instance.&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;# Modify the &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; method, so it works similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039;. If called with no arguments like &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; it returns 2 lists with all headers and sequences. If called with one argument like &amp;#039;&amp;#039;&amp;#039;content(start)&amp;#039;&amp;#039;&amp;#039; it returns the header and sequence at position &amp;#039;&amp;#039;start&amp;#039;&amp;#039;. If called with two arguments, it returns the headers and sequences from position &amp;#039;&amp;#039;start&amp;#039;&amp;#039; up to but not including position &amp;#039;&amp;#039;end&amp;#039;&amp;#039; as two lists. Be careful that you return a copy of the lists and not the lists themselves as then the headers and sequences in the instance can be modified unintended outside the instance.&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;# Add a method &amp;#039;&amp;#039;&amp;#039;insert(header,sequence[,position])&amp;#039;&amp;#039;&amp;#039;, which adds header and sequence to the instance lists. &amp;#039;&amp;#039;header&amp;#039;&amp;#039; and &amp;#039;&amp;#039;sequence&amp;#039;&amp;#039; can either be simple strings (single header and sequence) or lists of headers and sequences. If &amp;#039;&amp;#039;position&amp;#039;&amp;#039; is not given, then the addition takes place at the end of the existing headers/sequences. If &amp;#039;&amp;#039;position&amp;#039;&amp;#039; is given then insertion takes places at that position.&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;# Add a method &amp;#039;&amp;#039;&amp;#039;insert(header,sequence[,position])&amp;#039;&amp;#039;&amp;#039;, which adds header and sequence to the instance lists. &amp;#039;&amp;#039;header&amp;#039;&amp;#039; and &amp;#039;&amp;#039;sequence&amp;#039;&amp;#039; can either be simple strings (single header and sequence) or lists of headers and sequences. If &amp;#039;&amp;#039;position&amp;#039;&amp;#039; is not given, then the addition takes place at the end of the existing headers/sequences. If &amp;#039;&amp;#039;position&amp;#039;&amp;#039; is given then insertion takes places at that position.&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;# Add a method &#039;&#039;&#039;verify(alphabet,[start[,end]])&#039;&#039;&#039;, which verifies sequence entries according to an alphabet. It works in a way similar to &#039;&#039;&#039;delete()&#039;&#039;&#039; and &#039;&#039;&#039;content()&#039;&#039;&#039; for the range of what should be verified. The method returns True if all entries in the range are verified, False otherwise.&amp;lt;br&amp;gt;The alphabet could be a DNA alphabet (ATCG), a protein alphabet or something derived from those. You should put your alphabets into class variables, as they are common for all instances, and not subject to change.&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;# Add a method &#039;&#039;&#039;verify(alphabet,[start[,end]])&#039;&#039;&#039;, which verifies sequence entries according to an alphabet. It works in a way similar to &#039;&#039;&#039;delete()&#039;&#039;&#039; and &#039;&#039;&#039;content()&#039;&#039;&#039; for the range of what should be verified. The method returns True if all entries in the range are verified &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;(belonging to the alphabet)&lt;/ins&gt;, False otherwise.&amp;lt;br&amp;gt;The alphabet could be a DNA alphabet (ATCG), a protein alphabet or something derived from those. You should put your alphabets into class variables, as they are common for all instances, and not subject to change.&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;# Add a method &amp;#039;&amp;#039;&amp;#039;discard(alphabet,[start[,end]])&amp;#039;&amp;#039;&amp;#039;, which discards sequence entries and corresponding headers if they do not match the given alphabet. It works in a way similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; for the range of what should be verified.&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;# Add a method &amp;#039;&amp;#039;&amp;#039;discard(alphabet,[start[,end]])&amp;#039;&amp;#039;&amp;#039;, which discards sequence entries and corresponding headers if they do not match the given alphabet. It works in a way similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; for the range of what should be verified.&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;# Add iteration and length evaluation to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class using magic methods. Do this so you can write code like &amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;&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;# Add iteration and length evaluation to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class using magic methods. Do this so you can write code like &amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/22113/index.php?title=Classes&amp;diff=115&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/22113/index.php?title=Classes&amp;diff=115&amp;oldid=prev"/>
		<updated>2025-03-17T17:15:59Z</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 19:15, 17 March 2025&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-l21&quot;&gt;Line 21:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 21:&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;# Add a method &amp;#039;&amp;#039;&amp;#039;discard(alphabet,[start[,end]])&amp;#039;&amp;#039;&amp;#039;, which discards sequence entries and corresponding headers if they do not match the given alphabet. It works in a way similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; for the range of what should be verified.&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;# Add a method &amp;#039;&amp;#039;&amp;#039;discard(alphabet,[start[,end]])&amp;#039;&amp;#039;&amp;#039;, which discards sequence entries and corresponding headers if they do not match the given alphabet. It works in a way similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; for the range of what should be verified.&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;# Add iteration and length evaluation to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class using magic methods. Do this so you can write code like &amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;&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;# Add iteration and length evaluation to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class using magic methods. Do this so you can write code like &amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;&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;# Add the methods &#039;&#039;&#039;deletethis()&#039;&#039;&#039;, &#039;&#039;&#039;insertthis(header, sequence)&#039;&#039;&#039;, &#039;&#039;&#039;verifythis(alphabet)&#039;&#039;&#039; and &#039;&#039;&#039;discardthis(alphabet)&#039;&#039;&#039; to the &#039;&#039;&#039;Fasta&#039;&#039;&#039; class. The methods should only work when &#039;&#039;iterating over an instance at the current item&#039;&#039;, i.e. they work when you are iterating over the fasta sequences on the &#039;&#039;current&#039;&#039; sequence and header, like this:&amp;lt;div style=&quot;font-family:&#039;Courier New&#039;&quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&quot;DNA&quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;continue&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with sequence &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;and header&lt;/del&gt;&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible, maybe by changing the way your iteration works in the previous exercise.&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;# Add the methods &#039;&#039;&#039;deletethis()&#039;&#039;&#039;, &#039;&#039;&#039;insertthis(header, sequence)&#039;&#039;&#039;, &#039;&#039;&#039;verifythis(alphabet)&#039;&#039;&#039; and &#039;&#039;&#039;discardthis(alphabet)&#039;&#039;&#039; to the &#039;&#039;&#039;Fasta&#039;&#039;&#039; class. The methods should only work when &#039;&#039;iterating over an instance at the current item&#039;&#039;, i.e. they work when you are iterating over the fasta sequences on the &#039;&#039;current&#039;&#039; sequence and header, like this:&amp;lt;div style=&quot;font-family:&#039;Courier New&#039;&quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&quot;DNA&quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;continue&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;header and &lt;/ins&gt;sequence&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible, maybe by changing the way your iteration works in the previous exercise.&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;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 for extra practice ==&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 for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/22113/index.php?title=Classes&amp;diff=114&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/22113/index.php?title=Classes&amp;diff=114&amp;oldid=prev"/>
		<updated>2025-03-17T17:13:18Z</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 19:13, 17 March 2025&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-l19&quot;&gt;Line 19:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 19:&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;# Add a method &amp;#039;&amp;#039;&amp;#039;insert(header,sequence[,position])&amp;#039;&amp;#039;&amp;#039;, which adds header and sequence to the instance lists. &amp;#039;&amp;#039;header&amp;#039;&amp;#039; and &amp;#039;&amp;#039;sequence&amp;#039;&amp;#039; can either be simple strings (single header and sequence) or lists of headers and sequences. If &amp;#039;&amp;#039;position&amp;#039;&amp;#039; is not given, then the addition takes place at the end of the existing headers/sequences. If &amp;#039;&amp;#039;position&amp;#039;&amp;#039; is given then insertion takes places at that position.&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;# Add a method &amp;#039;&amp;#039;&amp;#039;insert(header,sequence[,position])&amp;#039;&amp;#039;&amp;#039;, which adds header and sequence to the instance lists. &amp;#039;&amp;#039;header&amp;#039;&amp;#039; and &amp;#039;&amp;#039;sequence&amp;#039;&amp;#039; can either be simple strings (single header and sequence) or lists of headers and sequences. If &amp;#039;&amp;#039;position&amp;#039;&amp;#039; is not given, then the addition takes place at the end of the existing headers/sequences. If &amp;#039;&amp;#039;position&amp;#039;&amp;#039; is given then insertion takes places at that position.&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;# Add a method &amp;#039;&amp;#039;&amp;#039;verify(alphabet,[start[,end]])&amp;#039;&amp;#039;&amp;#039;, which verifies sequence entries according to an alphabet. It works in a way similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; for the range of what should be verified. The method returns True if all entries in the range are verified, False otherwise.&amp;lt;br&amp;gt;The alphabet could be a DNA alphabet (ATCG), a protein alphabet or something derived from those. You should put your alphabets into class variables, as they are common for all instances, and not subject to change.&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;# Add a method &amp;#039;&amp;#039;&amp;#039;verify(alphabet,[start[,end]])&amp;#039;&amp;#039;&amp;#039;, which verifies sequence entries according to an alphabet. It works in a way similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; for the range of what should be verified. The method returns True if all entries in the range are verified, False otherwise.&amp;lt;br&amp;gt;The alphabet could be a DNA alphabet (ATCG), a protein alphabet or something derived from those. You should put your alphabets into class variables, as they are common for all instances, and not subject to change.&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;# Add a method &#039;&#039;&#039;discard(alphabet,[start[,end]])&#039;&#039;&#039;, which discards sequence entries and corresponding headers &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;according to an &lt;/del&gt;alphabet. It works in a way similar to &#039;&#039;&#039;delete()&#039;&#039;&#039; and &#039;&#039;&#039;content()&#039;&#039;&#039; for the range of what should be verified.&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;# Add a method &#039;&#039;&#039;discard(alphabet,[start[,end]])&#039;&#039;&#039;, which discards sequence entries and corresponding headers &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;if they do not match the given &lt;/ins&gt;alphabet. It works in a way similar to &#039;&#039;&#039;delete()&#039;&#039;&#039; and &#039;&#039;&#039;content()&#039;&#039;&#039; for the range of what should be verified.&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;# Add iteration and length evaluation to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class using magic methods. Do this so you can write code like &amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;&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;# Add iteration and length evaluation to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class using magic methods. Do this so you can write code like &amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;&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;# Add the methods &#039;&#039;&#039;deletethis()&#039;&#039;&#039;, &#039;&#039;&#039;insertthis(header, sequence)&#039;&#039;&#039;, &#039;&#039;&#039;verifythis(alphabet)&#039;&#039;&#039; and &#039;&#039;&#039;discardthis(alphabet)&#039;&#039;&#039; to the &#039;&#039;&#039;Fasta&#039;&#039;&#039; class. The &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;tricky part is that these &lt;/del&gt;methods should only work when &#039;&#039;iterating over an instance at the current item&#039;&#039;, like this:&amp;lt;div style=&quot;font-family:&#039;Courier New&#039;&quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&quot;DNA&quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible, maybe by changing the way your iteration works in the previous exercise.&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;# Add the methods &#039;&#039;&#039;deletethis()&#039;&#039;&#039;, &#039;&#039;&#039;insertthis(header, sequence)&#039;&#039;&#039;, &#039;&#039;&#039;verifythis(alphabet)&#039;&#039;&#039; and &#039;&#039;&#039;discardthis(alphabet)&#039;&#039;&#039; to the &#039;&#039;&#039;Fasta&#039;&#039;&#039; class. The methods should only work when &#039;&#039;iterating over an instance at the current item&#039;&#039;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;, i.e. they work when you are iterating over the fasta sequences on the &#039;&#039;current&#039;&#039; sequence and header&lt;/ins&gt;, like this:&amp;lt;div style=&quot;font-family:&#039;Courier New&#039;&quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&quot;DNA&quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;continue&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with sequence and header&lt;/ins&gt;&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible, maybe by changing the way your iteration works in the previous exercise.&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;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 for extra practice ==&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 for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key c22113:diff:1.41:old-34:rev-114:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/22113/index.php?title=Classes&amp;diff=34&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: Comprehension, Generators, Functions and Methods |Next: Unit test |} == Required course material for the lesson == Powerpoint: [https://teaching.healthtech.dtu.dk/material/22113/22113_07-Classes.ppt Classes]&lt;br&gt; Resource: Example code - Classes&lt;br&gt;  == Subjects covered == Classes&lt;br&gt; Object Oriented Programming  == Exercises to be handed in == The ex...&quot;</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/22113/index.php?title=Classes&amp;diff=34&amp;oldid=prev"/>
		<updated>2024-03-06T14:01:45Z</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/Comprehension,_Generators,_Functions_and_Methods&quot; title=&quot;Comprehension, Generators, Functions and Methods&quot;&gt;Comprehension, Generators, Functions and Methods&lt;/a&gt; |Next: &lt;a href=&quot;/22113/index.php/Unit_test&quot; title=&quot;Unit test&quot;&gt;Unit test&lt;/a&gt; |} == Required course material for the lesson == Powerpoint: [https://teaching.healthtech.dtu.dk/material/22113/22113_07-Classes.ppt Classes]&amp;lt;br&amp;gt; Resource: &lt;a href=&quot;/22113/index.php/Example_code_-_Classes&quot; title=&quot;Example code - Classes&quot;&gt;Example code - Classes&lt;/a&gt;&amp;lt;br&amp;gt;  == Subjects covered == Classes&amp;lt;br&amp;gt; Object Oriented Programming  == Exercises to be handed in == The ex...&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: [[Comprehension, Generators, Functions and Methods]]&lt;br /&gt;
|Next: [[Unit test]]&lt;br /&gt;
|}&lt;br /&gt;
== Required course material for the lesson ==&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22113/22113_07-Classes.ppt Classes]&amp;lt;br&amp;gt;&lt;br /&gt;
Resource: [[Example code - Classes]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Subjects covered ==&lt;br /&gt;
Classes&amp;lt;br&amp;gt;&lt;br /&gt;
Object Oriented Programming&lt;br /&gt;
&lt;br /&gt;
== Exercises to be handed in ==&lt;br /&gt;
The exercises will be about the making of a class. A the exercises goes on the class can do more and more. Remember to add code outside the class, which test the new methods you make as you make them. The class methods need some decent input control and you need to think about what is required. Notice how versatile the class becomes, as you progress through the exercises.&lt;br /&gt;
# Create a class called &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039;. The purpose of the class is to do various kinds of manipulation of fasta files and sequences. Start with adding 3 class methods:&amp;lt;br&amp;gt;&amp;#039;&amp;#039;&amp;#039;load(filename)&amp;#039;&amp;#039;&amp;#039;, which gets a file name/path and loads the fasta file into internal instance lists with header and sequence.&amp;lt;br&amp;gt;&amp;#039;&amp;#039;&amp;#039;save(filename)&amp;#039;&amp;#039;&amp;#039;, which writes the internal instance header/sequence lists into a fasta file.&amp;lt;br&amp;gt;&amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039;, which returns two lists; the headers and the sequences.&amp;lt;br&amp;gt;You can likely reuse part of your functions in exercise 3 and 4 from [[Making Functions]].&amp;lt;br&amp;gt;Example use of the Fasta class:&amp;lt;br&amp;gt;&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;myfasta = Fasta()&amp;lt;br&amp;gt;myfasta.load(&amp;quot;dna7.fsa&amp;quot;)&amp;lt;br&amp;gt;print(myfasta.content())&amp;lt;br&amp;gt;myfasta.save(&amp;quot;newfile.fsa&amp;quot;)&amp;lt;/div&amp;gt;&lt;br /&gt;
# Add a method &amp;#039;&amp;#039;&amp;#039;delete([start[,end]])&amp;#039;&amp;#039;&amp;#039;, which deletes entries in the headers and sequences. If called with no arguments like &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039; it deletes all headers/sequences. If called with one argument like &amp;#039;&amp;#039;&amp;#039;delete(start)&amp;#039;&amp;#039;&amp;#039; it deletes the header and sequence at position &amp;#039;&amp;#039;start&amp;#039;&amp;#039;. If called with two arguments, it deletes headers and sequences from position &amp;#039;&amp;#039;start&amp;#039;&amp;#039; up to but not including position &amp;#039;&amp;#039;end&amp;#039;&amp;#039;. &amp;#039;&amp;#039;start&amp;#039;&amp;#039; and &amp;#039;&amp;#039;end&amp;#039;&amp;#039; can also be negative numbers, and in such case we count from the end of the lists, just like it works in normal list manipulations.&lt;br /&gt;
# Modify the &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; method, so it works similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039;. If called with no arguments like &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; it returns 2 lists with all headers and sequences. If called with one argument like &amp;#039;&amp;#039;&amp;#039;content(start)&amp;#039;&amp;#039;&amp;#039; it returns the header and sequence at position &amp;#039;&amp;#039;start&amp;#039;&amp;#039;. If called with two arguments, it returns the headers and sequences from position &amp;#039;&amp;#039;start&amp;#039;&amp;#039; up to but not including position &amp;#039;&amp;#039;end&amp;#039;&amp;#039; as two lists. Be careful that you return a copy of the lists and not the lists themselves as then the headers and sequences in the instance can be modified unintended outside the instance.&lt;br /&gt;
# Add a method &amp;#039;&amp;#039;&amp;#039;insert(header,sequence[,position])&amp;#039;&amp;#039;&amp;#039;, which adds header and sequence to the instance lists. &amp;#039;&amp;#039;header&amp;#039;&amp;#039; and &amp;#039;&amp;#039;sequence&amp;#039;&amp;#039; can either be simple strings (single header and sequence) or lists of headers and sequences. If &amp;#039;&amp;#039;position&amp;#039;&amp;#039; is not given, then the addition takes place at the end of the existing headers/sequences. If &amp;#039;&amp;#039;position&amp;#039;&amp;#039; is given then insertion takes places at that position.&lt;br /&gt;
# Add a method &amp;#039;&amp;#039;&amp;#039;verify(alphabet,[start[,end]])&amp;#039;&amp;#039;&amp;#039;, which verifies sequence entries according to an alphabet. It works in a way similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; for the range of what should be verified. The method returns True if all entries in the range are verified, False otherwise.&amp;lt;br&amp;gt;The alphabet could be a DNA alphabet (ATCG), a protein alphabet or something derived from those. You should put your alphabets into class variables, as they are common for all instances, and not subject to change.&lt;br /&gt;
# Add a method &amp;#039;&amp;#039;&amp;#039;discard(alphabet,[start[,end]])&amp;#039;&amp;#039;&amp;#039;, which discards sequence entries and corresponding headers according to an alphabet. It works in a way similar to &amp;#039;&amp;#039;&amp;#039;delete()&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;content()&amp;#039;&amp;#039;&amp;#039; for the range of what should be verified.&lt;br /&gt;
# Add iteration and length evaluation to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class using magic methods. Do this so you can write code like &amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;&lt;br /&gt;
# Add the methods &amp;#039;&amp;#039;&amp;#039;deletethis()&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insertthis(header, sequence)&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;verifythis(alphabet)&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;discardthis(alphabet)&amp;#039;&amp;#039;&amp;#039; to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class. The tricky part is that these methods should only work when &amp;#039;&amp;#039;iterating over an instance at the current item&amp;#039;&amp;#039;, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&amp;quot;DNA&amp;quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible, maybe by changing the way your iteration works in the previous exercise.&lt;br /&gt;
&lt;br /&gt;
== Exercises for extra practice ==&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
</feed>