Skip to content

Commit

Permalink
adding solutions to lecture 8 notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
magdalenarussell committed Oct 25, 2023
1 parent 6226a49 commit 4226942
Showing 1 changed file with 86 additions and 45 deletions.
131 changes: 86 additions & 45 deletions lectures/lecture08/lecture08.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@
},
{
"cell_type": "code",
"execution_count": 87,
"execution_count": 134,
"metadata": {},
"outputs": [],
"source": [
"# functions can take inputs, called \"arguments\" or \"parameters\"\n",
"def greet(name):\n",
" print('Nice to meet you,', name)"
" return('Nice to meet you,', name)"
]
},
{
"cell_type": "code",
"execution_count": 88,
"execution_count": 132,
"metadata": {},
"outputs": [
{
Expand All @@ -69,31 +69,23 @@
},
{
"cell_type": "code",
"execution_count": 89,
"execution_count": 135,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Nice to meet you, Maggie\n"
]
}
],
"outputs": [],
"source": [
"s = greet(\"Maggie\")"
]
},
{
"cell_type": "code",
"execution_count": 90,
"execution_count": 136,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"None\n"
"('Nice to meet you,', 'Maggie')\n"
]
}
],
Expand All @@ -111,7 +103,7 @@
},
{
"cell_type": "code",
"execution_count": 91,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -130,7 +122,7 @@
},
{
"cell_type": "code",
"execution_count": 92,
"execution_count": 137,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -158,7 +150,7 @@
},
{
"cell_type": "code",
"execution_count": 93,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -184,7 +176,7 @@
},
{
"cell_type": "code",
"execution_count": 94,
"execution_count": 138,
"metadata": {},
"outputs": [
{
Expand All @@ -193,7 +185,7 @@
"'GTCGNANTCNGCTACAGT'"
]
},
"execution_count": 94,
"execution_count": 138,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -206,7 +198,7 @@
},
{
"cell_type": "code",
"execution_count": 95,
"execution_count": 139,
"metadata": {},
"outputs": [
{
Expand All @@ -215,7 +207,7 @@
"'GTCG-A-TC-GCTACAGT'"
]
},
"execution_count": 95,
"execution_count": 139,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -234,7 +226,7 @@
},
{
"cell_type": "code",
"execution_count": 96,
"execution_count": 140,
"metadata": {},
"outputs": [
{
Expand All @@ -257,7 +249,7 @@
},
{
"cell_type": "code",
"execution_count": 97,
"execution_count": 141,
"metadata": {},
"outputs": [
{
Expand All @@ -280,7 +272,7 @@
},
{
"cell_type": "code",
"execution_count": 98,
"execution_count": 142,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -329,7 +321,7 @@
},
{
"cell_type": "code",
"execution_count": 99,
"execution_count": 143,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -350,26 +342,60 @@
" is observed in the sequence.\n",
" \n",
" \"\"\"\n",
" counter = {}\n",
" \n",
" return None"
" if case == 'upper':\n",
" seq = seq.upper()\n",
" elif case == 'lower':\n",
" seq = seq.lower()\n",
"\n",
" for i in seq:\n",
" if i in counter:\n",
" counter[i] += 1\n",
" else: \n",
" counter[i] = 1\n",
" \n",
" return counter"
]
},
{
"cell_type": "code",
"execution_count": 100,
"execution_count": 147,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"{'A': 2, 'T': 2, 'X': 2, 'G': 2, 'C': 1}"
]
},
"execution_count": 147,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"count_bases('AATCGGCT')"
"count_bases('AATXXGGCT')"
]
},
{
"cell_type": "code",
"execution_count": 101,
"execution_count": 146,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"{'a': 2, 't': 3, 'g': 2, 'c': 1}"
]
},
"execution_count": 146,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"count_bases('aatTGGcT')"
"count_bases('aatTGGcT', case = \"lower\")"
]
},
{
Expand Down Expand Up @@ -426,7 +452,7 @@
},
{
"cell_type": "code",
"execution_count": 102,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -443,7 +469,7 @@
},
{
"cell_type": "code",
"execution_count": 103,
"execution_count": 148,
"metadata": {},
"outputs": [
{
Expand All @@ -452,7 +478,7 @@
"<re.Match object; span=(13, 17), match='1994'>"
]
},
"execution_count": 103,
"execution_count": 148,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -477,7 +503,7 @@
},
{
"cell_type": "code",
"execution_count": 104,
"execution_count": 149,
"metadata": {},
"outputs": [
{
Expand All @@ -490,13 +516,13 @@
],
"source": [
"# compile a named re for the year\n",
"named_yearmatch = re.compile('\\/(?P<year>\\d{4})')\n",
"named_yearmatch = re.compile('\\/(?P<YEAR>\\d{4})')\n",
"\n",
"# search for the search pattern in the string\n",
"named_search = named_yearmatch.search(strain)\n",
"\n",
"# isolate named pattern\n",
"year = named_search.group('year')\n",
"year = named_search.group('YEAR')\n",
"\n",
"print(year)\n"
]
Expand Down Expand Up @@ -527,11 +553,26 @@
},
{
"cell_type": "code",
"execution_count": 105,
"execution_count": 152,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'H3N2'"
]
},
"execution_count": 152,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# write your code here..."
"subtype_pattern = re.compile(\"\\((?P<subtype>[A-Z]\\d+[A-Z]\\d+)\\)\")\n",
"\n",
"subtype_search = subtype_pattern.search(strain)\n",
"\n",
"subtype_search.group('subtype')"
]
},
{
Expand All @@ -556,7 +597,7 @@
},
{
"cell_type": "code",
"execution_count": 106,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -586,7 +627,7 @@
},
{
"cell_type": "code",
"execution_count": 107,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -632,7 +673,7 @@
},
{
"cell_type": "code",
"execution_count": 108,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down

0 comments on commit 4226942

Please sign in to comment.