Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
lesson 2 updated
  • Loading branch information
haeunhwangbo committed Jul 13, 2022
commit d647d00101e309d0539921bf5c34077219900dfc
189 changes: 69 additions & 120 deletions Lesson_2_Control_Structs/Lesson_2_Control_structs_student.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -651,63 +651,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"3. Use a different approach to add `'PTEN'` to `gene_list` and then replace `'PTEN'` with `'BRAF'`."
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [],
"source": [
"# Q3\n"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['EGFR', 'KRAS', 'MYC', 'RB', 'P53', 'PTEN']"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# add PTEN"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['EGFR', 'KRAS', 'MYC', 'RB', 'P53', 'BRAF']"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# replace PTEN with BRAF"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"4. Make a dictionary that describes the price of five medications. Name the dictionary `med_dict`\n",
"3. Make a dictionary that describes the price of five medications. Name the dictionary `med_dict`\n",
">* Lisinopril: \t23.07\n",
">* Gabapentin: 86.27\n",
">* Sildenafil: \t169.94 \n",
Expand All @@ -728,7 +672,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"5. Use `med_dict` to calculate how much it will cost if a patien tis treated with Lisinopril and Prednisone."
"4. Use `med_dict` to calculate how much it will cost if a patien tis treated with Lisinopril and Prednisone."
]
},
{
Expand Down Expand Up @@ -981,7 +925,9 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"tags": []
},
"source": [
"### Exercise Part 2"
]
Expand All @@ -990,111 +936,114 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The most exciting part about control flows is that they can be *nested* to make more complex algorithms. Let's go back to the dose-finding clinical trials. We have a list of doses that we want to test. `dose_list = [1, 2, 3, 5, 8, 13]`. We want to increase the dose until we hit the maximal tolerated dose (MTD). For simplicity, we will increase dose when there is less than two patients out of three patients with toxicity and stop otherwise. The last dose before at least two patients have toxicity is declared MTD. We will look into the future and assume that we know how many patients will have toxicity at each dose `tox_list = [0, 0, 1, 1, 2, 2]`. Show two approaches to find the MTD."
"Before going into exercise, we need to learn a handy operation `+=`."
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"dose_list = [1, 2, 3, 5, 8, 13]\n",
"tox_list = [0, 0, 1, 1, 2, 2]"
"a = 0\n",
"a = a + 1"
]
},
{
"cell_type": "code",
"execution_count": 14,
"cell_type": "markdown",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# approach 1"
"is equivalent to "
]
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5\n"
]
}
],
"outputs": [],
"source": [
"# approach 2"
"a = 0\n",
"a += 1"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "WQkaT4IqItdT"
},
"metadata": {},
"source": [
"### Libraries\n",
"A python library is a collection of functions and methods that allows you to perform many actions without writing your own code. \n",
"\n",
"In this course we will discuss a few libraries including pandas for storing and managing data and seaborn for plotting.\n",
"1. The most exciting part about control flows is that they can be *nested* to make more complex algorithms. Let's look at the complementary DNA sequences that we discussed in lesson 1. Solve this problem using `for` and `if`.\n",
"\n",
"Many libraries come installed with anaconda including both pandas and seaborn. However, these libraries are not imported when you open a jupyter notebook, so we have to tell python which libraries we would like to use.\n",
"\n",
"This is how you import the pandas library"
"> Create two new variables, comp_oligo1 and comp_oligo2, that are the complementary DNA sequences of oligo1 and oligo2 (hint: A <-> T and G <-> C)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "_4uRIZm3Lv-e"
},
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
"oligo1 = 'GCGCTCAAT'\n",
"oligo2 = 'TACTAGGCA'"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (<ipython-input-2-3a5720451dff>, line 3)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-2-3a5720451dff>\"\u001b[0;36m, line \u001b[0;32m3\u001b[0m\n\u001b[0;31m if nuc == #something\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"# backbone\n",
"comp_oligo1 = ''\n",
"for nuc in oligo1:\n",
" if nuc == #something:\n",
" comp_oligo1 += #something\n",
" ..."
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "avWOnU6NLznR"
},
"metadata": {},
"source": [
"We imported the `pandas` library and given it the alias `pd`. This way when we want to use pandas we only have to type `pd`. \n",
"\n",
"Let's do the same thing with the `numpy` package. We will want to give it the standard alias `np`. "
"2. Let's go back to the dose-finding clinical trials. We have a list of doses that we want to test. `dose_list = [1, 2, 3, 5, 8, 13]`. We want to increase the dose until we hit the maximal tolerated dose (MTD). For simplicity, we will increase dose when there is less than two patients out of three patients with toxicity and stop otherwise. The last dose before at least two patients have toxicity is declared MTD. We will look into the future and assume that we know how many patients will have toxicity at each dose `tox_list = [0, 0, 1, 1, 2, 2]`. Find the MTD using `while`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "7wpJB0pxMp6k"
},
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
"dose_list = [1, 2, 3, 5, 8, 13]\n",
"tox_list = [0, 0, 1, 1, 2, 2]"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
Expand Down
Loading