Skip to content

Commit

Permalink
Last-minute changes to automation lesson
Browse files Browse the repository at this point in the history
  • Loading branch information
bmle committed Aug 24, 2023
1 parent afbeb3f commit e38040f
Show file tree
Hide file tree
Showing 4 changed files with 1,735 additions and 1,131 deletions.
26 changes: 7 additions & 19 deletions automation_python.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -479,27 +479,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"For errors we get without directly calling `raise`, both the class of `Error` and the message are predetermined. This is useful in some situations, but less so in others. Suppose you wrote a reverse complement function like the one below:"
"For errors we get without directly calling `raise`, both the class of `Error` and the message are predetermined. This is useful in some situations, but less so in others. Suppose you wrote a reverse complement function:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def reverse_complement(dna_sequence):\n",
" \"\"\"Reverses the complement of a dna sequence\"\"\"\n",
" complements = {\"T\":\"A\", \"A\":\"T\", \"C\":\"G\", \"G\":\"C\"}\n",
" reverse = dna_sequence[::-1]\n",
" result = \"\"\n",
" for letter in reverse:\n",
" result = result + complements[letter]\n",
" return(result)\n",
"\n",
"help(reverse_complement)\n",
"print(reverse_complement(\"CAAT\"))"
]
"source": []
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -804,14 +792,14 @@
"gapminder['region'] = gapminder['region'].astype(str)\n",
"\n",
"# Method 1 for formatting the 'region' column:\n",
"gapminder_copy['region'] = gapminder_copy['region'].str.lstrip() # Strip white space on left\n",
"gapminder_copy['region'] = gapminder_copy['region'].str.rstrip() # Strip white space on right\n",
"gapminder_copy['region'] = gapminder_copy['region'].str.lower() # Convert to lowercase\n",
"gapminder['region'] = gapminder['region'].str.lstrip() # Strip white space on left\n",
"gapminder['region'] = gapminder['region'].str.rstrip() # Strip white space on right\n",
"gapminder['region'] = gapminder['region'].str.lower() # Convert to lowercase\n",
"\n",
"# Method 2 for formatting the 'region' column:\n",
"gapminder_copy['region'] = gapminder['region'].str.lstrip().str.rstrip().str.lower() # Strip white space on left and right, and convert to lowercase\n",
"gapminder['region'] = gapminder['region'].str.lstrip().str.rstrip().str.lower() # Strip white space on left and right, and convert to lowercase\n",
"\n",
"print(gapminder_copy['region'])"
"print(gapminder['region'])"
]
},
{
Expand Down
13 changes: 7 additions & 6 deletions automation_python_instructor.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"For errors we get without directly calling `raise`, both the class of `Error` and the message are predetermined. This is useful in some situations, but less so in others. Suppose you wrote a reverse complement function like the one below:"
"For errors we get without directly calling `raise`, both the class of `Error` and the message are predetermined. This is useful in some situations, but less so in others. Suppose you wrote a reverse complement function:"
]
},
{
Expand All @@ -565,6 +565,7 @@
"metadata": {},
"outputs": [],
"source": [
"# live demo\n",
"def reverse_complement(dna_sequence):\n",
" \"\"\"Reverses the complement of a dna sequence\"\"\"\n",
" complements = {\"T\":\"A\", \"A\":\"T\", \"C\":\"G\", \"G\":\"C\"}\n",
Expand Down Expand Up @@ -975,14 +976,14 @@
"gapminder['region'] = gapminder['region'].astype(str)\n",
"\n",
"# Method 1 for formatting the 'region' column:\n",
"gapminder_copy['region'] = gapminder_copy['region'].str.lstrip() # Strip white space on left\n",
"gapminder_copy['region'] = gapminder_copy['region'].str.rstrip() # Strip white space on right\n",
"gapminder_copy['region'] = gapminder_copy['region'].str.lower() # Convert to lowercase\n",
"gapminder['region'] = gapminder['region'].str.lstrip() # Strip white space on left\n",
"gapminder['region'] = gapminder['region'].str.rstrip() # Strip white space on right\n",
"gapminder['region'] = gapminder['region'].str.lower() # Convert to lowercase\n",
"\n",
"# Method 2 for formatting the 'region' column:\n",
"gapminder_copy['region'] = gapminder['region'].str.lstrip().str.rstrip().str.lower() # Strip white space on left and right, and convert to lowercase\n",
"gapminder['region'] = gapminder['region'].str.lstrip().str.rstrip().str.lower() # Strip white space on left and right, and convert to lowercase\n",
"\n",
"print(gapminder_copy['region'])"
"print(gapminder['region'])"
]
},
{
Expand Down
Loading

0 comments on commit e38040f

Please sign in to comment.