{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"# Conditionals"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"## Logical tests\n",
"\n",
"Create the following variables:\n",
"\n",
"```python\n",
"w = 10.2\n",
"x = 1.3\n",
"y = 2.8\n",
"z = 17.5\n",
"dna1 = 'attattaggaccaca'\n",
"dna2 = 'attattaggaacaca'\n",
"species1 = 'diplodocus'\n",
"species2 = 'tyrannosaurus'\n",
"```\n",
"\n",
"Use the variables to print whether or not the following statements are True or False:\n",
"1. w is greater than 10\n",
"1. w + x is less than 15\n",
"1. x is greater than y\n",
"1. 2 * x + 0.2 is equal to y\n",
"1. 2 * x + 0.2 is equal to y at precision of 4 decimals\n",
"1. dna1 is the same as dna2\n",
"1. dna1 is not the same as dna2\n",
"1. the number of occurrences of the base t is the same in dna1 and dna2\n",
"1. x times w is between 13.2 and 13.5\n",
"1. species2 comes before species1 alphabetically\n",
"1. w is greater than x, and y is greater than z\n",
"1. dna1 is longer than 5 bases, or z is less than w * x, or both\n",
"1. The combined length of the two dna sequences is greater than or equal to 30\n",
"1. (w + x + y) divided by the logarithm (base 10) of 100 is equal to 7.15\n",
"1. the GC content (which is always a percentage) of dna1 is not the same as the GC content of dna2\n",
"\n",
"Expected results:\n",
"```\n",
"True\n",
"True\n",
"False\n",
"True\n",
"True\n",
"False\n",
"True\n",
"True\n",
"True\n",
"False\n",
"False\n",
"True\n",
"True\n",
"False\n",
"True\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"## DNA or RNA\n",
"\n",
"### A. Classify as DNA or RNA\n",
"\n",
"The difference between a DNA and an RNA sequence is that RNA has the base Uracil (u or U) instead of the base Thymine (t or T). Using loops and conditional statments, print the type of each sequence of the following list as ‘DNA’, ‘RNA’, or ‘UNKNOWN’. \n",
"```python\n",
"sequences = [\n",
"'ttgaatgccttacaactgatcattacacaggcggcatgaagcaaaaatatactgtgaaccaat',\n",
"'gauuauuccccacaaagggagugggauuaggagcugcaucauuuacaagagcagaauguuuca',\n",
"'gaaagcaagaaaaggcaggcgaggaagggaagaagggggggaaacc',\n",
"'guuuccuacaguauuugaugagaaugagaguuuacuccuggaagauaauauuagaauguuuac',\n",
"'gauaaggaagaugaagacuuucaggaaucuaauaaaaugcacuccaugaauggauucauguau'\n",
"]\n",
"```\n",
"\n",
"Expected results:\n",
"```\n",
"Solution:\n",
"\tDNA\n",
"\tRNA\n",
"\tUNKNOWN\n",
"\tRNA\n",
"\tRNA\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true,
"scrolled": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"### B. Classify as DNA or RNA with a Function\n",
"Do the same as in A above using your own function named **seqType** that takes 1 sequence as input and returns its type as a string (‘DNA’, ‘RNA’, or ‘UNKNOWN’). "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"## Shurb carbon storage\n",
"\n",
"Dr. Granger is interested in studying the factors controlling the size and carbon storage of shrubs. This research is part of a larger area of research trying to understand carbon storage by plants. On four different sites she has conducted three different experiments. Each experiment applied a treatment to a shrub to observe effect on its dimensions (length, width and height). She wants to conduct a preliminary analysis of these data to include in a grant proposal and she would like you to conduct the analysis for her. Unfortunately, you do not receive the data as a table but as a list. The 5 first values represent the first experiment as **'site', 'experiment', 'length', 'width', and 'height'**. The 5 next values represent the second experiment similarly, and so on. \n",
"\n",
"experiments = [\n",
"1,1,2.2,1.3,9.6,1,2,2.1,2.2,7.6,1,3,2.7,1.5,2.2,2,1,3.0,4.5,1.5,\n",
"2,2,3.1,3.1,4.0,2,3,2.5,2.8,3.0,3,1,1.9,1.8,4.5,3,2,1.1,0.5,2.3,\n",
"3,3,3.5,2.0,7.5,4,1,2.9,2.7,3.2,4,2,4.5,4.8,6.5,4,3,1.2,1.8,2.7]\n",
"\n",
"### A. Preliminary analysis:\n",
"\n",
"1. Define a function **plantCategory** that takes as input the height of a plant (1 number) and that returns a string equal to **'tall'** if height > 5, **'medium'** if 2 <= height < 5, or **'short'** if height < 2\n",
"1. For testing, print the result of your function for height 1, 3 and 9. Then print an empty line\n",
"1. Copy the list above in your code\n",
"1. Write a conditional statement to perform the rest of the analysis only if the list contains 4\\*3\\*5 numbers as expected (4 sites, 3 experiments, 5 values each)\n",
"1. Using a **for loop, range() function and slices**, \"convert\" the list into a 2D list named **data**. The new 2D list **data** will contain sublists of 5 values for each experiment. \n",
"1. print the 2D list (1 experiment per line, tab-separated values) followed by an empty line\n",
"1. For each sublist in **data** print the experiment number and the category of plant (use your function) \n",
"\n",
"Expected results:\n",
"```\n",
"1 is small\n",
"3 is medium\n",
"9 is tall\n",
"\n",
"1\t1\t2.2\t1.3\t9.6\n",
"1\t2\t2.1\t2.2\t7.6\n",
"1\t3\t2.7\t1.5\t2.2\n",
"2\t1\t3.0\t4.5\t1.5\n",
"2\t2\t3.1\t3.1\t4.0\n",
"2\t3\t2.5\t2.8\t3.0\n",
"3\t1\t1.9\t1.8\t4.5\n",
"3\t2\t1.1\t0.5\t2.3\n",
"3\t3\t3.5\t2.0\t7.5\n",
"4\t1\t2.9\t2.7\t3.2\n",
"4\t2\t4.5\t4.8\t6.5\n",
"4\t3\t1.2\t1.8\t2.7\n",
"\n",
"1\ttall\n",
"2\ttall\n",
"3\tmedium\n",
"1\tsmall\n",
"2\tmedium\n",
"3\tmedium\n",
"1\tmedium\n",
"2\tmedium\n",
"3\ttall\n",
"1\tmedium\n",
"2\ttall\n",
"3\tmedium\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"### B. Amount of carbon\n",
"\n",
"* Let define the volume **v = Length \\* Width \\* Height**, and the amount of carbon **c = 1.8 + 2 \\* log(volume)**\n",
"* We are interested in 2 types of shrubs: **(1) tall shrubs with c>8.5, and (2) medium shrubs with c < 7**\n",
"* For each shrub of both types, print on a line its **site, experiment, category and c** (tab separated values)\n",
"\n",
"Expected results:\n",
"```\n",
"1\t2\ttall\t8.92\n",
"1\t3\tmedium\t6.17\n",
"3\t2\tmedium\t2.27\n",
"3\t3\ttall\t9.72\n",
"4\t2\ttall\t11.69\n",
"4\t3\tmedium\t5.33\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"### C. Analysis across sites\n",
"\n",
"* Determine the average carbon in a shrub for each of the different experiments and print those values to the screen.\n",
"\n",
"Expected results:\n",
"```\n",
"Experiment vs. average amount of carbon:\n",
"1\t7.94\n",
"3\t7.28\n",
"2\t7.99\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"# Sources\n",
"* https://docs.python.org/3.5/\n",
"* partly from www.programmingforbiologists.org"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}