{ "metadata": { "name": "", "signature": "sha256:3ef5efb280bb4814d481ef4782f790913f5c6c4145576aa1a43292b02f58c907" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "1. Manipulating Probability Expressions (5 Points)\n", "====\n", "\n", "Simplfiy the following expression and write in words the probability law or definition being used to go from the left-hand-side to the right-hand-side. There should be no intermediate steps. See example question. **Answer the following questions in Markdown**.\n", "\n", "$\\DeclareMathOperator{\\P}{P}$\n", "$\\DeclareMathOperator{\\E}{E}$\n", "\n", "1. $$\\sum_{\\mathcal{X}}\\P(x|y) = $$\n", "\n", "2. $$\\sum_{\\mathcal{Y}}\\P(x|y)P(y) = $$\n", "\n", "4. $$\\sum_{\\mathcal{Y}}\\P(x,y) = $$\n", "\n", "5. $$\\frac{\\P(x,y)}{\\P(y)} = $$\n", "\n", "6. If $y$ and $x$ are independent: $$\\P(x|y) = $$\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "####Answers\n", "**1.1** $\\sum_{\\mathcal{X}}\\P(x|y) = 1$, due the the Law of Total Probability.\n", "\n", "**1.2** $\\sum_{\\mathcal{Y}}\\P(x|y)\\P(y) = \\P(x)$. Marginalization of conditional\n", "\n", "**1.3** $\\sum_{\\mathcal{Y}}\\P(x,y) = \\P(x)$. Definition of marginal\n", "\n", "**1.4** $\\frac{\\P(x,y)}{\\P(y)} = \\P(x|y)$. Definition of conditional\n", "\n", "**1.5** $\\P(x|y) = \\P(x)$. Definition of independence\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "2. Utilizing Probability Expressions (7 Points)\n", "====\n", "\n", "Using the path example from HW 1, answer the following questions symbolically. Recall that the sample space is pathways and see HW 1 Key for the list of paths. Given that:\n", "\n", "* Random variable $X$ is the length of the path\n", "* Random variable $Y$ is the end-point of the path\n", "* Random variable $Z$ is if the path has the $A$ node in it\n", "----\n", "\n", "1. $P(X=2)$\n", "2. $P(X=2 \\,|\\, Y = A)$\n", "3. $P(X = 2, \\,Y = D)$\n", "4. $P(X = 3 \\,|\\, Z)$\n", "5. $P(~Z \\,|\\, Y = C,\\, X = 3)$\n", "6. $P(Y = A, Z)$\n", "6. Which pair of random variables are independent? Why or why not?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##Answers\n", "**2.1** $$n=6,\\: Q=18,\\: \\P=\\frac{1}{3}$$\n", "\n", "**2.2** $$n=1,\\: Q=4,\\: \\P=\\frac{1}{4}$$\n", "\n", "**2.3** $$n=2,\\: Q=18,\\: \\P=\\frac{1}{9}$$\n", "\n", "**2.4** $$n=5,\\: Q=11,\\: P=\\frac{5}{11}$$\n", "\n", "**2.5** $$n=1,\\: Q=2,\\: P=\\frac{1}{2}$$\n", "\n", "**2.6** $$n = 4\\,\\: Q=18,\\: \\P = \\frac{4}{18}$$\n", "\n", "**2.7** \n", "\n", "$\\P(X = 2) = \\frac{1}{3} \\neq \\P(X = 2\\, | \\, Y = A) \\Rightarrow$ $X$ and $Y$ are not independent.\n", "\n", "$\\P(Z | Y = A) = 1 \\neq \\P(Z) \\Rightarrow$ $Z$ and $Y$ are not independent.\n", "\n", "By the transitive property $X$ and $Z$ are not independent.\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "3. Ebola Vaccine (10 Points)\n", "====\n", "Ebola virus disease (EVD) cases have been recently observed in many\n", "countries due to an ongoing West African epidemic. EVD is particularly\n", "dangerous due to its high fatality rate: about 50%. The standard clinical\n", "diagnosis technique which detects viral RNA or human antibodies\n", "requires 5 hours. You have developed a new blood test that is 95%\n", "accurate and only requires 2 minutes. Good job. Accuracy here means if\n", "the patient has EVD, your test says they have EVD 95% of the\n", "time. Similarly, if the patient doesn't have EVD, your test says they\n", "do not have EVD 95% of the time. **Answer these questions first symbolically then in Python**\n", "\n", "1. [5] To test your EVD screening method, you visit a country where only 1% of the population has EVD and randomly test people on the street. Assuming that the probability someone has EVD is 1%, if your method returns a positive, what is the actual probability the person has EVD? *Hint: You cannot compute the conditional which the question asks for directly. Look at your notes for how to rearrange conditionals.*\n", "\n", "2. [2] Your EVD screening method has passed preliminary clinical trials. Good job. Now, to reduce false positives you need to decide how many times you repeat the screening method before treating a patient for EVD. For there to be a 99.9% probability the patient has EVD, how many screenings must you do? Assume the screenings are conditionally independent and that you only consider someone to be EVD positve after $n$ positve trials. *Hint: See the useful equation below, which holds if $X$ and $Y$ are independent, but not $X$/$Z$ nor $Y$/$Z$ (thus $X/Y$ are conditionally independent). This is true, for example, if you have multiple independent trials which are conditioned on something*\n", "$$P(X,Y,Z) = P(X,Y|Z)P(Z) = P(X | Y,Z) P(Y | Z) P(Z) = $$\n", "$$P(X | Z) P(Y | Z) P(Z)$$ *Also, due to conditional independence $P(X,Y) \\neq P(X) P(Y)$, but $\\sum_Z P(X | Z) P(Y | Z) P(Z) = P(X,Y)$ is true using the equation above*\n", "\n", "3. [2] A patient was tested for EVD, tested positive, then was tested again and that test was negative. Per the protocol above, the patient was released. The local news picked up the story and the general public believes that passing and failing a test indicates there was a 50/50 chance the patient had EVD. There is panic and protestors outside hospitals. What is the actual probability the patient had EVD? *Note: There is actually a balance between question 2 and 3 that we will revisit in a later homework.*\n", "\n", "4. [1] Is the assumption that repeat screenings are independent valid? To put another way, if we see a false positive or false negative on the first trial are we equally likely to see one on the second trial? Why or why not?\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Answer to question 3.1\n", "\n", "$\\P(A=0)=0.99$ - probability that one does not have EVD\n", "\n", "$\\P(A=1)=0.01$ - probability that one has EVD\n", "\n", "$\\P(B=0)$ - probability that the test is negative\n", "\n", "$\\P(B=1)$ -probability that the test is positive\n", "\n", "$\\P(B=1|A=1)=0.95$ - probability that the test is positive given that a person has EVD\n", "\n", "$\\P(B=0|A=0)=0.95$ - probability that the test is negative given that a person does not EVD\n", "\n", "$\\P(A=1|B=1)=?$ - probability that a person has EVD, given the test is positive\n", "\n", "$\\P(B=1)=\\sum_{\\mathcal{A}}\\P(B=1|A)P(A)=P(A=1)P(B=1|A=1)+P(A=0)P(B=1|A=0)=0.01\\times0.95+0.99\\times(1-0.95)$\n", "\n", "$$\\P(A=1|B=1)=\\frac{\\P(B=1|A=1)\\P(A=1)}{\\P(B=1)}$$\n" ] }, { "cell_type": "code", "collapsed": false, "input": [ "marginal_evd = 0.01 #p of having EVD\n", "\n", "cond_positive = 0.95 # p of having positive test given one has EVD\n", "cond_negative = 0.95 # p of having negative test given one does not have EVD\n", "\n", "marginal_positive = marginal_evd * cond_positive + (1 - cond_positive)*(1-marginal_evd) # marginal probability of having positive test \n", "\n", "cond_evd=cond_positive * marginal_evd / marginal_positive # p of having EVD given the test is positive\n", "\n", "print 'The probability that the test is positive is equal to {:.4} and if the test is positive, the probability that a person has EVD is {:.4}'.format(marginal_positive,cond_evd)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The probability that the test is positive is equal to 0.059 and if the test is positive, the probability that a person has EVD is 0.161\n" ] } ], "prompt_number": 1 }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Answer to question 3.2\n", "\n", "$P(A=1|Z)$- the probabilty that one has EVD given that the test is positive after $n$ trials\n", "\n", "\n", "$P(A=0|Z) > 0.999$\n", "\n", "\n", "$$P(A=1|Z)=\\frac{P(A=1,Z)}{P(Z)}=\\frac{P(Z|A=1)P(A=1)}{P(Z)}=\\frac{(P(B=1|A=1))^{n}P(A=1)}{(P(B=1|A=0))^{n}P(A=0)+P(B=1|A=1)^{n}P(A=1)}$$\n" ] }, { "cell_type": "code", "collapsed": false, "input": [ "n=4 # try different number of trials until 'cond_evd_z' is less than 0.001\n", "\n", "#The probability of having EVD given Z has occurred\n", "cond_evd_z=cond_positive**n * marginal_evd / ( (1 - cond_negative)**n * (1 - marginal_evd) + cond_positive**n * marginal_evd) \n", "\n", "print 'Since {:.4} is greater than 0.999, the number of trials needed is {}.' .format(cond_evd_z, n)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Since 0.9992 is greater than 0.999, the number of trials needed is 4.\n" ] } ], "prompt_number": 2 }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Answer to Question 3.3\n", "$P(B=0|A=1)- $ probability of having negative test given one has EVD \n", "\n", "$P(A=1|B=0)=\\frac{P(B=0|A=1)(P(B=1|A=1))P(A=1)}{(P(B=1))P(B=0)} $ probability of having EVD given the test is negative\n", "\n", "$P(A=0)=0.99 - $ probability that one does not have EVD\n", "\n", "$P(A=1)=0.01 - $ probability that one has EVD\n", "\n", "$P(B=0)=1-P(B=1)=1-0.059=0.941- $ probability that the test is negative\n", "\n", "$$P(A=1|B_0 = 1, B_1 = 0) = \\frac{P(B_0 = 1| A = 1) P(B_1 = 0| A = 1) P(A = 1)}{P(B_0 = 1 | A = 1) P(B_1 = 0 | A = 1) P(A = 1) + P(B_0 = 1 | A = 0) P(B_1 = 0 | A = 0) P(A = 0)}$$" ] }, { "cell_type": "code", "collapsed": false, "input": [ "cond_evd_event = cond_positive * (1 - cond_positive) * marginal_evd / (cond_positive * (1 - cond_positive) * marginal_evd + (1 - cond_negative) * cond_negative * (1 - marginal_evd))\n", "\n", "print 'The probability the patient has EVD is {:.5}'.format(cond_evd_event)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The probability the patient has EVD is 0.01\n" ] } ], "prompt_number": 3 }, { "cell_type": "markdown", "metadata": {}, "source": [ "4. Python Math and Boolean (7 Points)\n", "====\n", "**Answer the following problems in Python using booleans**\n", "\n", "1. Is $2^{16}$ greater than $10^4$?\n", "\n", "2. Using the `frexp` function, show how the floating point number $0.1$ is represented and rebuild the number from its pieces. Use base 10\n", "\n", "2. is $0.1 + 0.2$ exactly equal to $(1.0 + 2.0) / 10.0$ with floats? Why not?\n", "\n", "2. When creating permutations from a combination of elements where you can use each element once, the number of permutations is $n!$. For example, if you have three letters and you can use each letter only once, the number of permutations is $3\\times 2 \\times 1$. How many ways can a deck of cards be shuffled? Are there more stars in the universe ($10^{23}$) or deck shuffling permutations? \n", "\n", "3. The next cell contains a joint probability mass function for $x$ and $y$. $x$ is the first number and $y$ is the second. You may access elements like this: `P[0,2]`. `P[0,2]` is the probability that $x=0$ and $y=2$. Demonstrate that the two random variables are not independent.\n", "\n", "4. Calculate the marginal $\\P(x=2)$, where $x$ is the first index using the next cell's joint probability mass function.\n", "\n", "5. Calculate the conditional $\\P(x=2 | y = 1)$, where $x$ is the first index using the next cell's joint probability mass function.\n" ] }, { "cell_type": "code", "collapsed": false, "input": [ "#This is loading the data for question 3.5 through 3.8. \n", "#Execute this cell and use new cells below. Do not answer in this cell!\n", "\n", "import numpy as np\n", "P = np.zeros( (3,3) )\n", "P[0,0] = 1. / 9\n", "P[0,1] = 1. / 9\n", "P[0,2] = 0.\n", "P[1,0] = 1. / 3\n", "P[1,1] = 0\n", "P[1,2] = 1. / 6\n", "P[2,0] = 1. / 9\n", "P[2,1] = 1. / 18\n", "P[2,2] = 1. / 9" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 3 }, { "cell_type": "code", "collapsed": false, "input": [ "#Example of how to calculate P(x = 0)\n", "px0 = P[0,0] + P[0,1] + P[0,2]\n", "print px0" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "0.222222222222\n" ] } ], "prompt_number": 4 }, { "cell_type": "markdown", "metadata": {}, "source": [ "####Answer below this cell\n", "----" ] }, { "cell_type": "code", "collapsed": false, "input": [ "#Question 4.1\n", "print 2**16 > 10**4" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "True\n" ] } ], "prompt_number": 32 }, { "cell_type": "code", "collapsed": false, "input": [ "#Question 4.2\n", "from math import frexp\n", "m,e=frexp(.1)\n", "print '{:4}*2^({:})={}' .format(m,int(e), m * 2**e)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ " 0.8*2^(-3)=0.1\n" ] } ], "prompt_number": 48 }, { "cell_type": "code", "collapsed": false, "input": [ "#Question 4.3\n", "print 'It is', 0.1+0.2==(1.0+2.0)/10, 'that they are equal'\n", "print 'They are not equal because there are no exact representation for either number in base 2 mantissa/exponent format'\n", "print '0.1 + 0.2 is {:.20}'.format(0.1+0.2)\n", "print '(1.0 + 2.0) / 10 is {:.20}'.format((1.0 + 2.0) / 10 )\n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "It is False that they are equal\n", "They are not equal because there are no exact representation for either number in base 2 mantissa/exponent format\n", "0.1 + 0.2 is 0.30000000000000004441\n", "(1.0 + 2.0) / 10 is 0.2999999999999999889\n" ] } ], "prompt_number": 27 }, { "cell_type": "code", "collapsed": false, "input": [ "#Question 4.4\n", "from math import factorial \n", "\n", "factor=factorial(42)\n", "print 'It is', factor>10**23, 'that there are more deck permutations than stars in the universe'" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "It is True that there are more deck permutations than stars in the universe\n" ] } ], "prompt_number": 26 }, { "cell_type": "code", "collapsed": false, "input": [ "#Question 4.5\n", "print P[1,1], (P[1,1]+P[1,0]+P[1,2])*(P[0,1]+P[1,1]+P[2,1])\n", "print 'Since these are not equal, P(X=1, Y=1) != P(X=1) P(Y=1), which violates independence'" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "0.0 0.0833333333333\n", "Since these are not equal, P(X=1, Y=1) != P(X=1) P(Y=1), which violates independence\n" ] } ], "prompt_number": 31 }, { "cell_type": "code", "collapsed": false, "input": [ "#Question 4.6\n", "print P[2,0]+P[2,1]+P[2,2]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "0.277777777778\n" ] } ], "prompt_number": 33 }, { "cell_type": "code", "collapsed": false, "input": [ "#Question 4.7\n", "P[2,1]/(P[0,1]+P[1,1]+P[2,1])" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 34, "text": [ "0.33333333333333331" ] } ], "prompt_number": 34 }, { "cell_type": "markdown", "metadata": {}, "source": [ "5. Probability of sum of two dice (6 Points)\n", "====\n", "Using Python, Markdown, and equations, describe a random variable for the sum of two dice when rolled and create a Python cell where a user may enter the sum and your cell prints the probability of that sample. For the Python portion, see the cell below for an example of the python program and [see here](http://nbviewer.ipython.org/github/ipython/ipython/blob/2.x/examples/Notebook/Trapezoid%20Rule.ipynb) for an example of how your answer should look (yours should be much shorter though). *Hint: There is a simple equation for the probability. Try writing out a few terms, like P(2), P(3), P(7), P(11), to derive the equation*\n", "\n", "Rubric: [3] explaination/equation, [3] for the python program." ] }, { "cell_type": "code", "collapsed": false, "input": [ "roll = 3 #Enter the value of a single die roll here\n", "P = 1 / 6. #State space is 6, uniform, and each roll has a single permutation.\n", "print 'The probability of rolling a', roll, 'is', P" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The probability of rolling a 3 is 0.166666666667\n" ] } ], "prompt_number": 11 }, { "cell_type": "markdown", "metadata": {}, "source": [ "The sum of two dice - Answer\n", "====\n", "\n", "Consider a random variable, $D$, which represents the sum of two fair dice being rolled. Different $D$ values have different permutation numbers. For example $D=7$ has 6 permutations. The sample space is 36 and the permutation number changes based on the distance from the maximum at $D=7$ so that $n/Q$, the probability, can be modeled as:\n", "\n", "$$P(D=x) = \\frac{6 - |x - 7|}{36} $$\n", "\n", "The program below computes the probability of $D$ given an input." ] }, { "cell_type": "code", "collapsed": false, "input": [ "dsum = 4 #The sum\n", "print 'The probability of two dice summing to', dsum, 'after a roll is', (6. - abs(dsum - 7)) / 36 #equation defined above." ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The probability of two dice summing to 4 after a roll is 0.0833333333333\n" ] } ], "prompt_number": 37 }, { "cell_type": "markdown", "metadata": {}, "source": [ "6. Sequence probability (15 points)\n", "====\n", "\n", "Proteins are made up of amino acids in a polymer chain. The list of amino acids in that chain is called a protein sequence. There are 20 amino acids and thus 20 possibilities at each sequence position. By comparing sequences of proteins from different species, we can predict the evolutionary history of proteins and organisms based on sequence similarity. Furthermore, by seeing which parts of a protein sequence do not change, we can predict which specific amino acids are related to the function of a protein. In this problem, we will build two models of a protein representing two possible evolutionary histories. Model 1 will have important amino acids at positions 23, 24 and 25. Model 2 will have important amino acids at positions 24, 25 and 99. Although we will not do this now, we can use these two models to assign sequences to different lineages. \n", "\n", "Your task is to create two Python cells, similar to Problem 4, which output the probability of a sample entered at the top. $s$, the amino acid identity and $i$, the position, are entered at the top and your program should determine the probability of seeing that amino acid at that specific position. If the position is important (23,24,25), in model 1 the probability of amino acids V, A, I, and L is equal and four times the probability of each other amino acids, which have equal probabilities. In model 2, if the position is 24 or 25, the same rule applies. If the position is 99 in model 2, the probability of D and E is equal and one hundred times the probability of each other amino acids, which again have equal probability. If a position is unimportant, all amino acids have equal probability. *Hint: Combine these algebraic statements ALONG with the normalization condition to get a probability mass function*\n", "\n", "Your answer should be two Markdown and two Python cells. The Markdown should contain a mathematical description of the two models with equations. The Python should be well-documented, contain conditionals, have an $s$ and $i$ variable at the top for a user to enter the values and it should print out a clear message repeating the $s$, $i$ variable along with the probability.\n", "\n", "Rubric: [5] covnerting text into probability equations, [1] variable assignment, [2] for conditionals, [4] probabilities, [2] string formatting, [1] correct answer" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Answer to Question 6\n", "\n", "$\\newcommand{\\Pa}[1]{\\textrm{P}\\left(\\textrm{#1}\\right)}$\n", "\n", "$s$-aa aminoacid identity\n", "\n", "$i$-position\n", "\n", "\n", "####Model 1\n", "\n", "\n", "**position is important: 23, 24, 25**\n", " \n", "let $x=$ probability of finding AA other than V,L,I and A\n", "\n", "$$\\Pa{V} = \\Pa{A} = \\Pa{I} = \\Pa{L} = 4 \\Pa{not V,L,I,A} = 4x$$\n", "\n", "$$\\Pa{V} + \\Pa{A} + \\Pa{I} + \\Pa{L} + 4 \\Pa{not V,L,I,A} = 1$$\n", "\n", "$$4x+4x+4x+4x+(20-4)x=1$$\n", "\n", "$$x=\\frac{1}{32}$$\n", "\n", "so the probability of the important amino acids is $4/32$\n", "\n", "**If position is unimportant:**\n", "\n", "$\\Pr(\\cdot)$ is constant\n", "\n", "$$\\Pr(\\cdot)=\\frac{1}{20}$$\n" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "# Model 1\n", "position= 24 # position of the amino acid\n", "identity= 'L' # The identity of the amino acid\n", "probability=0.05 #probability of amino acids when position is not important.\n", "\n", "if position==23 or position==24 or position==25: # position of 23, 24 and 25\n", " if identity=='L' or identity=='A' or identity=='I' or identity=='V': # identity of A, V, L , I\n", " probability=4.0/32\n", " else:\n", " probability=1.0/32\n", "print 'The probability of finding amino acid {} at position {} is {:.4}' .format(identity,position,probability) \n", "\n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The probability of finding amino acid L at position 24 is 0.125\n" ] } ], "prompt_number": 1 }, { "cell_type": "markdown", "metadata": {}, "source": [ "####Model 2\n", "**If position is 24 or 25:** Same as Model 1\n", "\n", "**If position is 99:**\n", "\n", "Let $z$ be the probability for unimportant amino acids. Then:\n", "\n", "$$\\Pa{E} = \\Pa{D} = 100 \\Pa{not E,D} = 100z$$\n", "\n", "$$\\Pa{E} + \\Pa{D} + (20-2) \\Pa{not E,D} = 1$$\n", "\n", "$$100z+100z+(20-2)z=1$$\n", "\n", "$$z=\\frac{1}{218}$$\n", "\n", "**If position is unimportant:**\n", "Same as Model 1" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "#Model 2\n", "position= 99 # position of the amino acid\n", "identity= 'L' # The identity of the amino acid\n", "probability=0.05 #probability of amino acids when position is not important.\n", "\n", "if position==24 or position==25: # position of 24 and 25\n", " if identity=='L' or identity=='A' or identity=='I' or identity=='V': # identity of A, V, L , I\n", " probability=4.0/32\n", " else:\n", " probability=1.0/32\n", "if position == 99:\n", " if identity == 'D' or identity == 'E':\n", " probability = 100 * 1. / 218\n", " else:\n", " probability = 1. / 218\n", "print 'The probability of finding amino acid {} at position {} is {:.4}' .format(identity,position,probability) \n", "\n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The probability of finding amino acid L at position 99 is 0.004587\n" ] } ], "prompt_number": 44 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }