From 0ba1396f709fd60f9696706fcc1b8b3fcb84ed19 Mon Sep 17 00:00:00 2001 From: Danielle Pinto Date: Fri, 30 Jan 2026 15:15:01 -0500 Subject: [PATCH 01/10] initial commit --- docs/src/rosalind/07-iprb.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 docs/src/rosalind/07-iprb.md diff --git a/docs/src/rosalind/07-iprb.md b/docs/src/rosalind/07-iprb.md new file mode 100644 index 0000000..d98034e --- /dev/null +++ b/docs/src/rosalind/07-iprb.md @@ -0,0 +1,17 @@ +# Counting Point Mutations + +🤔 [Problem link](https://rosalind.info/problems/iprb/) + +!!! warning "The Problem" + + Probability is the mathematical study of randomly occurring phenomena. We will model such a phenomenon with a random variable, which is simply a variable that can take a number of different distinct outcomes depending on the result of an underlying random process. + + For example, say that we have a bag containing 3 red balls and 2 blue balls. If we let X represent the random variable corresponding to the color of a drawn ball, then the probability of each of the two outcomes is given by Pr(X=red)=35 and Pr(X=blue)=25. + + Random variables can be combined to yield new random variables. Returning to the ball example, let Y model the color of a second ball drawn from the bag (without replacing the first ball). The probability of Y being red depends on whether the first ball was red or blue. To represent all outcomes of X and Y, we therefore use a probability tree diagram. This branching diagram represents all possible individual probabilities for X and Y, with outcomes at the endpoints ("leaves") of the tree. The probability of any outcome is given by the product of probabilities along the path from the beginning of the tree. + + An event is simply a collection of outcomes. Because outcomes are distinct, the probability of an event can be written as the sum of the probabilities of its constituent outcomes. For our colored ball example, let A be the event "Y is blue." Pr(A) is equal to the sum of the probabilities of two different outcomes: Pr(X=blue and Y=blue)+Pr(X=red and Y=blue), or 310+110=25. + + Given: Three positive integers k, m, and n, representing a population containing k+m+n organisms: k individuals are homozygous dominant for a factor, m are heterozygous, and n are homozygous recessive. + + Return: The probability that two randomly selected mating organisms will produce an individual possessing a dominant allele (and thus displaying the dominant phenotype). Assume that any two organisms can mate. \ No newline at end of file From 7e03286f2c51645565c7c4273421076caefcf4d3 Mon Sep 17 00:00:00 2001 From: Danielle Pinto Date: Fri, 30 Jan 2026 16:23:28 -0500 Subject: [PATCH 02/10] rough draft of first solution --- docs/src/rosalind/07-iprb.md | 56 +++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/docs/src/rosalind/07-iprb.md b/docs/src/rosalind/07-iprb.md index d98034e..0597e01 100644 --- a/docs/src/rosalind/07-iprb.md +++ b/docs/src/rosalind/07-iprb.md @@ -14,4 +14,58 @@ Given: Three positive integers k, m, and n, representing a population containing k+m+n organisms: k individuals are homozygous dominant for a factor, m are heterozygous, and n are homozygous recessive. - Return: The probability that two randomly selected mating organisms will produce an individual possessing a dominant allele (and thus displaying the dominant phenotype). Assume that any two organisms can mate. \ No newline at end of file + Return: The probability that two randomly selected mating organisms will produce an individual possessing a dominant allele (and thus displaying the dominant phenotype). Assume that any two organisms can mate. + +There are two main ways we can solve this problem: deriving an algorithm or simulation. + +### Deriving an Algorithm + +Using the information above, we can derive an algorithm using the variables k, m, and n that will calculate the probability of a progeny possessing a dominant allele. We could either calculate the probability of a progeny having a dominant allele, but in this case, it is easier to calculate the likelihood of a progeny having a recessive allele. This is a relatively rarer event, and the calculation will be straightforward. We just have to subtract this probability from 1 to get the overall likelihood of having a progeny with a dominant trait. + +To demonstrate how to derive this algorithm, we can use H and h to signify dominant and recessive alleles. + +Out of all the possible combinations, we will only get a progeny with a recessive trait in three situations: Hh x Hh, Hh x hh, and hh x hh. For all of these situations, we must calculate the probability of these mating combinations occuring (based on k, m, and n), as well as the probability of these events leading to a progeny with a recessive trait. + +To calculate this, we must the probability of picking the first mating pair and then the second mating pair. + +For the combination Hh x Hh, this is $\frac{m}{(k+m+n)}$ multiplied by $\frac{(m-1)}{(k+m+n-1)}$. Selecting the second Hh individual is equal to the number of Hh individuals left after 1 was already picked (m-1) divided by the total individuals left in the population (k+m+n-1). + +A similar calculation is performed for the rest of the combinations. However, it is important to note that the probability of selecting Hh x hh as a mating pair is $\frac{2*m*n}{(k+m+n)(k+m+n-1)}$, as there are two ways to choose this combination. Hh x hh can be selected, as well as hh x Hh. Order matters! + +| Probability of combination occuring | Hh x Hh | Hh x hh | hh x hh | +| --- |---|---|---| +| | $\frac{m(m-1)}{(k+m+n)(k+m+n-1)}$ | $\frac{2*m*n}{(k+m+n)(k+m+n-1)}$| $\frac{n(n-1)}{(k+m+n)(k+m+n-1)}$| + + + +The probability of these combinations leading to a recessive trait can be calculated using Punnet Squares. + +| Probability of recessive trait | Hh x Hh | Hh x hh | hh x hh | +| --- |---|---|---| +| | 0.25 | 0.50 | 1 | + +Now, we just have to sum the multiply the probability of each combination occuring by the probability of this combination leading to a recessive trait. This leads to the following formula: + +Pr(recessive trait) = +$\frac{m(m-1)}{(k+m+n)(k+m+n-1)}$ x 0.25 + $\frac{m*n}{(k+m+n)(k+m+n-1)}$ + $\frac{n(n-1)}{(k+m+n)(k+m+n-1)}$ + +Therefore, the probability of selecting an individual with a *dominant* trait is 1 - Pr(recessive trait). + +Now that we've derived this formula, let's turn this into code! + +```julia +function mendel(k,m,n) + + total = (k+m+n)*(k+m+n-1) + return 1-( + (0.25*m*(m-1))/total + + m*n/total + + n*(n-1)/total) +end + +mendel(2,2,2) +``` + + + +### Simulation Method \ No newline at end of file From 7e0b97b0f2128b1adb097c5abe22df97bab967ed Mon Sep 17 00:00:00 2001 From: Danielle Pinto Date: Sat, 31 Jan 2026 10:06:03 -0500 Subject: [PATCH 03/10] fix problem name --- docs/src/rosalind/07-iprb.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/rosalind/07-iprb.md b/docs/src/rosalind/07-iprb.md index 0597e01..e6ebc78 100644 --- a/docs/src/rosalind/07-iprb.md +++ b/docs/src/rosalind/07-iprb.md @@ -1,4 +1,4 @@ -# Counting Point Mutations +# Mendel's First Law 🤔 [Problem link](https://rosalind.info/problems/iprb/) From a21c022cb001835964b16eb99197eef03557bd70 Mon Sep 17 00:00:00 2001 From: Danielle Pinto Date: Tue, 3 Feb 2026 14:33:06 -0500 Subject: [PATCH 04/10] adding semantic line breaks --- docs/src/rosalind/07-iprb.md | 97 ++++++++++++++++++++++++++++++------ 1 file changed, 81 insertions(+), 16 deletions(-) diff --git a/docs/src/rosalind/07-iprb.md b/docs/src/rosalind/07-iprb.md index e6ebc78..598b065 100644 --- a/docs/src/rosalind/07-iprb.md +++ b/docs/src/rosalind/07-iprb.md @@ -4,39 +4,98 @@ !!! warning "The Problem" - Probability is the mathematical study of randomly occurring phenomena. We will model such a phenomenon with a random variable, which is simply a variable that can take a number of different distinct outcomes depending on the result of an underlying random process. + Probability is the mathematical study of randomly occurring phenomena. + + We will model such a phenomenon with a random variable, + + which is simply a variable that can take a number of different distinct outcomes + + depending on the result of an underlying random process. + + For example, say that we have a bag containing 3 red balls and 2 blue balls. + + If we let X represent the random variable corresponding to the color of a drawn ball, + + then the probability of each of the two outcomes is given by Pr(X=red)=35 and Pr(X=blue)=25. + + Random variables can be combined to yield new random variables. + + Returning to the ball example, let Y model the color of a second ball drawn from the bag (without replacing the first ball). + + The probability of Y being red depends on whether the first ball was red or blue. + + To represent all outcomes of X and Y, we therefore use a probability tree diagram. + + This branching diagram represents all possible individual probabilities for X and Y, + + with outcomes at the endpoints ("leaves") of the tree. + + The probability of any outcome is given by the product of probabilities along the path from the beginning of the tree. + + An event is simply a collection of outcomes. + + Because outcomes are distinct, the probability of an event can be written as the sum of the probabilities of its constituent outcomes. + + For our colored ball example, let A be the event "Y is blue." + + Pr(A) is equal to the sum of the probabilities of two different outcomes: + + Pr(X=blue and Y=blue)+Pr(X=red and Y=blue), or 310+110=25. + + Given: Three positive integers k, m, and n, + + representing a population containing k+m+n organisms: + + k individuals are homozygous dominant for a factor, m are heterozygous, and n are homozygous recessive. + + Return: The probability that two randomly selected mating organisms will produce an individual possessing a dominant allele (and thus displaying the dominant phenotype). + + Assume that any two organisms can mate. - For example, say that we have a bag containing 3 red balls and 2 blue balls. If we let X represent the random variable corresponding to the color of a drawn ball, then the probability of each of the two outcomes is given by Pr(X=red)=35 and Pr(X=blue)=25. +There are two main ways we can solve this problem: deriving an algorithm or simulation. - Random variables can be combined to yield new random variables. Returning to the ball example, let Y model the color of a second ball drawn from the bag (without replacing the first ball). The probability of Y being red depends on whether the first ball was red or blue. To represent all outcomes of X and Y, we therefore use a probability tree diagram. This branching diagram represents all possible individual probabilities for X and Y, with outcomes at the endpoints ("leaves") of the tree. The probability of any outcome is given by the product of probabilities along the path from the beginning of the tree. +### Deriving an Algorithm - An event is simply a collection of outcomes. Because outcomes are distinct, the probability of an event can be written as the sum of the probabilities of its constituent outcomes. For our colored ball example, let A be the event "Y is blue." Pr(A) is equal to the sum of the probabilities of two different outcomes: Pr(X=blue and Y=blue)+Pr(X=red and Y=blue), or 310+110=25. +Using the information above, we can derive an algorithm using the variables k, m, and n that will calculate the probability of a progeny possessing a dominant allele. - Given: Three positive integers k, m, and n, representing a population containing k+m+n organisms: k individuals are homozygous dominant for a factor, m are heterozygous, and n are homozygous recessive. +We could calculate the probability of a progeny having a dominant allele, - Return: The probability that two randomly selected mating organisms will produce an individual possessing a dominant allele (and thus displaying the dominant phenotype). Assume that any two organisms can mate. +but in this case, it is easier to calculate the likelihood of a progeny having a recessive allele. -There are two main ways we can solve this problem: deriving an algorithm or simulation. + This is a relatively rarer event, and the calculation will be straightforward. + + We just have to subtract this probability from 1 to get the overall likelihood of having a progeny with a dominant trait. -### Deriving an Algorithm +To demonstrate how to derive this algorithm, we can use H and h to signify dominant and recessive alleles, respectively. + +Out of all the possible combinations, we will only get a progeny with a recessive trait in three situations: Hh x Hh, Hh x hh, and hh x hh. + +For all of these situations, we must calculate the probability of these mating combinations occuring (based on k, m, and n), -Using the information above, we can derive an algorithm using the variables k, m, and n that will calculate the probability of a progeny possessing a dominant allele. We could either calculate the probability of a progeny having a dominant allele, but in this case, it is easier to calculate the likelihood of a progeny having a recessive allele. This is a relatively rarer event, and the calculation will be straightforward. We just have to subtract this probability from 1 to get the overall likelihood of having a progeny with a dominant trait. +as well as the probability of these events leading to a progeny with a recessive trait. -To demonstrate how to derive this algorithm, we can use H and h to signify dominant and recessive alleles. +To calculate this, we must calculate the probability of picking the first mating pair and then the second mating pair. -Out of all the possible combinations, we will only get a progeny with a recessive trait in three situations: Hh x Hh, Hh x hh, and hh x hh. For all of these situations, we must calculate the probability of these mating combinations occuring (based on k, m, and n), as well as the probability of these events leading to a progeny with a recessive trait. +For the combination Hh x Hh, this is $\frac{m}{(k+m+n)}$ multiplied by $\frac{(m-1)}{(k+m+n-1)}$. -To calculate this, we must the probability of picking the first mating pair and then the second mating pair. + Selecting the second Hh individual is equal to the number of Hh individuals left after 1 was already picked (m-1), + + divided by the total individuals left in the population (k+m+n-1). -For the combination Hh x Hh, this is $\frac{m}{(k+m+n)}$ multiplied by $\frac{(m-1)}{(k+m+n-1)}$. Selecting the second Hh individual is equal to the number of Hh individuals left after 1 was already picked (m-1) divided by the total individuals left in the population (k+m+n-1). +A similar calculation is performed for the rest of the combinations. -A similar calculation is performed for the rest of the combinations. However, it is important to note that the probability of selecting Hh x hh as a mating pair is $\frac{2*m*n}{(k+m+n)(k+m+n-1)}$, as there are two ways to choose this combination. Hh x hh can be selected, as well as hh x Hh. Order matters! +However, it is important to note that the probability of selecting Hh x hh as a mating pair is $\frac{2*m*n}{(k+m+n)(k+m+n-1)}$, + + as there are two ways to choose this combination. + +Hh x hh can be selected, as well as hh x Hh. Order matters! | Probability of combination occuring | Hh x Hh | Hh x hh | hh x hh | | --- |---|---|---| | | $\frac{m(m-1)}{(k+m+n)(k+m+n-1)}$ | $\frac{2*m*n}{(k+m+n)(k+m+n-1)}$| $\frac{n(n-1)}{(k+m+n)(k+m+n-1)}$| - +
+
The probability of these combinations leading to a recessive trait can be calculated using Punnet Squares. @@ -44,7 +103,13 @@ The probability of these combinations leading to a recessive trait can be calcul | --- |---|---|---| | | 0.25 | 0.50 | 1 | -Now, we just have to sum the multiply the probability of each combination occuring by the probability of this combination leading to a recessive trait. This leads to the following formula: +
+
+ + +Now, we just have to sum the multiply the probability of each combination occuring by the probability of this combination leading to a recessive trait. + +This leads to the following formula: Pr(recessive trait) = $\frac{m(m-1)}{(k+m+n)(k+m+n-1)}$ x 0.25 + $\frac{m*n}{(k+m+n)(k+m+n-1)}$ + $\frac{n(n-1)}{(k+m+n)(k+m+n-1)}$ From 5872398554ad0e6575361bedebccdcec2130c2b5 Mon Sep 17 00:00:00 2001 From: Danielle Pinto Date: Wed, 4 Feb 2026 11:50:46 -0500 Subject: [PATCH 05/10] add note about downsides of algorithm approach --- docs/src/rosalind/07-iprb.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/src/rosalind/07-iprb.md b/docs/src/rosalind/07-iprb.md index 598b065..617aeec 100644 --- a/docs/src/rosalind/07-iprb.md +++ b/docs/src/rosalind/07-iprb.md @@ -60,7 +60,7 @@ Using the information above, we can derive an algorithm using the variables k, m We could calculate the probability of a progeny having a dominant allele, -but in this case, it is easier to calculate the likelihood of a progeny having a recessive allele. +but in this case, it is easier to calculate the likelihood of a progeny having the recessive phenotype. This is a relatively rarer event, and the calculation will be straightforward. @@ -131,6 +131,24 @@ end mendel(2,2,2) ``` +Deriving and using this algorithm is a clean solution. +However, it is also narrowly tailored to a specific problem. + +What happens if we want to solve a more complicated problem or if there are additional requirements tacked on? + +For example, what if we wanted to solve a question like "What's the probability of a heterozygous offspring?" + +We would need to derive another alogorithm for this similar, yet slightly different problem. + +Algorithms work in certain cases, but also don't scale up if we add another trait. + +Another approach would be to use a statistics based solution. + +For instance, we can use a simulation that can broadly calculate the likelihood of a given offspring based on a set of given probabilities. + +This solution is generic and can be used to ask more types of questions. + +
### Simulation Method \ No newline at end of file From c8b908b6d81b97229bde261473e6e77a7f3c189e Mon Sep 17 00:00:00 2001 From: Danielle Pinto Date: Thu, 5 Feb 2026 21:39:11 -0500 Subject: [PATCH 06/10] add statistical approach --- docs/src/rosalind/07-iprb.md | 98 +++++++++++++++++++++++++++++++----- 1 file changed, 86 insertions(+), 12 deletions(-) diff --git a/docs/src/rosalind/07-iprb.md b/docs/src/rosalind/07-iprb.md index 617aeec..6e1f3c9 100644 --- a/docs/src/rosalind/07-iprb.md +++ b/docs/src/rosalind/07-iprb.md @@ -42,7 +42,11 @@ Pr(X=blue and Y=blue)+Pr(X=red and Y=blue), or 310+110=25. - Given: Three positive integers k, m, and n, + + + Given: + + Three positive integers k, m, and n, representing a population containing k+m+n organisms: @@ -52,7 +56,7 @@ Assume that any two organisms can mate. -There are two main ways we can solve this problem: deriving an algorithm or simulation. +We will show two ways we can solve this problem: deriving an algorithm or using a statistical weighted probability approach. ### Deriving an Algorithm @@ -62,7 +66,7 @@ We could calculate the probability of a progeny having a dominant allele, but in this case, it is easier to calculate the likelihood of a progeny having the recessive phenotype. - This is a relatively rarer event, and the calculation will be straightforward. + This is a relatively rarer event, and the calculation will be less complicated. We just have to subtract this probability from 1 to get the overall likelihood of having a progeny with a dominant trait. @@ -74,7 +78,7 @@ For all of these situations, we must calculate the probability of these mating c as well as the probability of these events leading to a progeny with a recessive trait. -To calculate this, we must calculate the probability of picking the first mating pair and then the second mating pair. +First, we must calculate the probability of picking the first and second mate. For the combination Hh x Hh, this is $\frac{m}{(k+m+n)}$ multiplied by $\frac{(m-1)}{(k+m+n-1)}$. @@ -84,11 +88,11 @@ For the combination Hh x Hh, this is $\frac{m}{(k+m+n)}$ multiplied by $\frac{(m A similar calculation is performed for the rest of the combinations. -However, it is important to note that the probability of selecting Hh x hh as a mating pair is $\frac{2*m*n}{(k+m+n)(k+m+n-1)}$, +It is important to note that the probability of selecting Hh x hh as a mating pair is $\frac{2*m*n}{(k+m+n)(k+m+n-1)}$, as there are two ways to choose this combination. -Hh x hh can be selected, as well as hh x Hh. Order matters! +Hh x hh can be selected (where Hh is picked first), as well as hh x Hh. Order matters! | Probability of combination occuring | Hh x Hh | Hh x hh | hh x hh | | --- |---|---|---| @@ -107,7 +111,7 @@ The probability of these combinations leading to a recessive trait can be calcul
-Now, we just have to sum the multiply the probability of each combination occuring by the probability of this combination leading to a recessive trait. +Now, we just have to sum the probability of each combination occuring by the probability of this combination leading to a recessive trait. This leads to the following formula: @@ -121,7 +125,8 @@ Now that we've derived this formula, let's turn this into code! ```julia function mendel(k,m,n) - total = (k+m+n)*(k+m+n-1) + # denominator of the above fractions describing probability of different matches + total = (k+m+n)*(k+m+n-1) return 1-( (0.25*m*(m-1))/total + m*n/total + @@ -131,7 +136,7 @@ end mendel(2,2,2) ``` -Deriving and using this algorithm is a clean solution. +Deriving and using this algorithm works. However, it is also narrowly tailored to a specific problem. @@ -141,9 +146,9 @@ For example, what if we wanted to solve a question like "What's the probability We would need to derive another alogorithm for this similar, yet slightly different problem. -Algorithms work in certain cases, but also don't scale up if we add another trait. +Algorithms work in certain cases, but also don't scale up if we add more constraints. -Another approach would be to use a statistics based solution. +Another approach would be to use a statistics-based solution. For instance, we can use a simulation that can broadly calculate the likelihood of a given offspring based on a set of given probabilities. @@ -151,4 +156,73 @@ This solution is generic and can be used to ask more types of questions.
-### Simulation Method \ No newline at end of file +### Simulation Method + +For this method, we will make a fake population that follows the given parameters k, m, and n. + +Specifically, we can make a vector of 1's, 2's, and 3's, representing the HH, Hh, and hh phenotypes, respectively. + +In this vector, there will be k 1's, m 2's, and n 3's. + +Next, we'll make another vector that stores the probabilities of there being a dominant phenotype given the parental genotypes. + +This is calculated using Punnett Squares. + +For example, if HH mates with either [HH, Hh, hh], the probability of a dominant phenotype is 100%, leading to a vector [1, 1, 1]. + +Now that these vectors have been created, we can begin the simulation. + +First, we will sample from the population to approximate the ratio of dominant phenotypes. + +For each iteration, we will randomly pick two mates from the population. + +For example, 2 (Hh) and 3 (hh) is picked. + +This will lead to a probability of a dominant allele = 0.5. + +All of the probabilities will be accumulated throughout all of the simulations. + +At the end of the simulation, we can divide the sum of the probabilites by the total number of simulations. + +This will get us the approximated number of individuals with a dominant phenotype. + +This method is unlikely to return exactly the same answer as the algorithm approach. + +Sampling is random, so we will get slightly different results each time we run the simulation (unless we set a seed). + +However, both methods will be very similar. + +The standard error for the estimate decreases as the number of simulations gets very large. + +The larger the number of iterations, the more likely that the final approximation will be similar both between simulations, as well as to the answer from the algorithm. + +It is important to keep in mind that both the algorithm and statistical sampling approaches only provide approximations, as there will definetely be some unaccounted variation in a true biological population! + +```julia +using StatsBase + +function mendel_sim(k, m, n; iterations=100000) + # Genotypes: 1=HH, 2=Hh, 3=hh + population = [fill(1, k); fill(2, m); fill(3, n)] + + # Probability of dominant offspring given parent genotypes + # Index: offspring_prob[parent1, parent2] + offspring_prob = [ + 1.0 1.0 1.0; # HH × (HH, Hh, hh) + 1.0 0.75 0.5; # Hh × (HH, Hh, hh) + 1.0 0.5 0.0 # hh × (HH, Hh, hh) + ] + + dominant_count = 0 + dominant_count = sum( + offspring_prob[sample(population, 2; replace=false)...] + for i in 1:iterations + ) + + return dominant_count / iterations +end + +mendel_sim(2, 2, 2) +``` + +In this case, both solutions return a value close to 0.783. \ No newline at end of file From 04887e485f120f9d87922182248b294c8581e78c Mon Sep 17 00:00:00 2001 From: Danielle Pinto Date: Fri, 6 Feb 2026 12:14:34 -0500 Subject: [PATCH 07/10] implement Kevin's minor changes --- docs/src/rosalind/07-iprb.md | 41 ++++++------------------------------ 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/docs/src/rosalind/07-iprb.md b/docs/src/rosalind/07-iprb.md index 6e1f3c9..3f6b58f 100644 --- a/docs/src/rosalind/07-iprb.md +++ b/docs/src/rosalind/07-iprb.md @@ -5,41 +5,28 @@ !!! warning "The Problem" Probability is the mathematical study of randomly occurring phenomena. - We will model such a phenomenon with a random variable, - which is simply a variable that can take a number of different distinct outcomes - depending on the result of an underlying random process. For example, say that we have a bag containing 3 red balls and 2 blue balls. - If we let X represent the random variable corresponding to the color of a drawn ball, - then the probability of each of the two outcomes is given by Pr(X=red)=35 and Pr(X=blue)=25. Random variables can be combined to yield new random variables. - Returning to the ball example, let Y model the color of a second ball drawn from the bag (without replacing the first ball). - The probability of Y being red depends on whether the first ball was red or blue. - + To represent all outcomes of X and Y, we therefore use a probability tree diagram. - This branching diagram represents all possible individual probabilities for X and Y, - with outcomes at the endpoints ("leaves") of the tree. - The probability of any outcome is given by the product of probabilities along the path from the beginning of the tree. An event is simply a collection of outcomes. - Because outcomes are distinct, the probability of an event can be written as the sum of the probabilities of its constituent outcomes. - + For our colored ball example, let A be the event "Y is blue." - Pr(A) is equal to the sum of the probabilities of two different outcomes: - Pr(X=blue and Y=blue)+Pr(X=red and Y=blue), or 310+110=25. @@ -47,9 +34,7 @@ Given: Three positive integers k, m, and n, - representing a population containing k+m+n organisms: - k individuals are homozygous dominant for a factor, m are heterozygous, and n are homozygous recessive. Return: The probability that two randomly selected mating organisms will produce an individual possessing a dominant allele (and thus displaying the dominant phenotype). @@ -63,35 +48,24 @@ We will show two ways we can solve this problem: deriving an algorithm or using Using the information above, we can derive an algorithm using the variables k, m, and n that will calculate the probability of a progeny possessing a dominant allele. We could calculate the probability of a progeny having a dominant allele, - but in this case, it is easier to calculate the likelihood of a progeny having the recessive phenotype. - - This is a relatively rarer event, and the calculation will be less complicated. - - We just have to subtract this probability from 1 to get the overall likelihood of having a progeny with a dominant trait. +This is a relatively rarer event, and the calculation will be less complicated. +We just have to subtract this probability from 1 to get the overall likelihood of having a progeny with a dominant trait. To demonstrate how to derive this algorithm, we can use H and h to signify dominant and recessive alleles, respectively. - Out of all the possible combinations, we will only get a progeny with a recessive trait in three situations: Hh x Hh, Hh x hh, and hh x hh. - For all of these situations, we must calculate the probability of these mating combinations occuring (based on k, m, and n), - as well as the probability of these events leading to a progeny with a recessive trait. First, we must calculate the probability of picking the first and second mate. - For the combination Hh x Hh, this is $\frac{m}{(k+m+n)}$ multiplied by $\frac{(m-1)}{(k+m+n-1)}$. - Selecting the second Hh individual is equal to the number of Hh individuals left after 1 was already picked (m-1), - - divided by the total individuals left in the population (k+m+n-1). - +Selecting the second Hh individual is equal to the number of Hh individuals left after 1 was already picked (m-1), +divided by the total individuals left in the population (k+m+n-1). A similar calculation is performed for the rest of the combinations. It is important to note that the probability of selecting Hh x hh as a mating pair is $\frac{2*m*n}{(k+m+n)(k+m+n-1)}$, - - as there are two ways to choose this combination. - +as there are two ways to choose this combination. Hh x hh can be selected (where Hh is picked first), as well as hh x Hh. Order matters! | Probability of combination occuring | Hh x Hh | Hh x hh | hh x hh | @@ -154,7 +128,6 @@ For instance, we can use a simulation that can broadly calculate the likelihood This solution is generic and can be used to ask more types of questions. -
### Simulation Method From 8e1d7e25f0fcc7f49afe4e6326b356b46ba8af56 Mon Sep 17 00:00:00 2001 From: Danielle Pinto Date: Fri, 6 Feb 2026 13:22:25 -0500 Subject: [PATCH 08/10] fix typos --- docs/src/rosalind/07-iprb.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/src/rosalind/07-iprb.md b/docs/src/rosalind/07-iprb.md index 3f6b58f..88b8b9c 100644 --- a/docs/src/rosalind/07-iprb.md +++ b/docs/src/rosalind/07-iprb.md @@ -54,8 +54,8 @@ We just have to subtract this probability from 1 to get the overall likelihood o To demonstrate how to derive this algorithm, we can use H and h to signify dominant and recessive alleles, respectively. Out of all the possible combinations, we will only get a progeny with a recessive trait in three situations: Hh x Hh, Hh x hh, and hh x hh. -For all of these situations, we must calculate the probability of these mating combinations occuring (based on k, m, and n), -as well as the probability of these events leading to a progeny with a recessive trait. +For all of these situations, we must calculate the probability of these mating combinations occurring (based on k, m, and n), +as well as the probability of these events leading to a progeny with a recessive trait. First, we must calculate the probability of picking the first and second mate. For the combination Hh x Hh, this is $\frac{m}{(k+m+n)}$ multiplied by $\frac{(m-1)}{(k+m+n-1)}$. @@ -68,7 +68,7 @@ It is important to note that the probability of selecting Hh x hh as a mating pa as there are two ways to choose this combination. Hh x hh can be selected (where Hh is picked first), as well as hh x Hh. Order matters! -| Probability of combination occuring | Hh x Hh | Hh x hh | hh x hh | +| Probability of combination occurring | Hh x Hh | Hh x hh | hh x hh | | --- |---|---|---| | | $\frac{m(m-1)}{(k+m+n)(k+m+n-1)}$ | $\frac{2*m*n}{(k+m+n)(k+m+n-1)}$| $\frac{n(n-1)}{(k+m+n)(k+m+n-1)}$| @@ -85,7 +85,7 @@ The probability of these combinations leading to a recessive trait can be calcul
-Now, we just have to sum the probability of each combination occuring by the probability of this combination leading to a recessive trait. +Now, we just have to sum the probability of each combination occurring by the probability of this combination leading to a recessive trait. This leads to the following formula: @@ -118,7 +118,7 @@ What happens if we want to solve a more complicated problem or if there are addi For example, what if we wanted to solve a question like "What's the probability of a heterozygous offspring?" -We would need to derive another alogorithm for this similar, yet slightly different problem. +We would need to derive another algorithm for this similar, yet slightly different problem. Algorithms work in certain cases, but also don't scale up if we add more constraints. @@ -133,7 +133,7 @@ This solution is generic and can be used to ask more types of questions. For this method, we will make a fake population that follows the given parameters k, m, and n. -Specifically, we can make a vector of 1's, 2's, and 3's, representing the HH, Hh, and hh phenotypes, respectively. +Specifically, we can make a vector of 1's, 2's, and 3's, representing the HH, Hh, and hh genotypes, respectively. In this vector, there will be k 1's, m 2's, and n 3's. @@ -155,7 +155,7 @@ This will lead to a probability of a dominant allele = 0.5. All of the probabilities will be accumulated throughout all of the simulations. -At the end of the simulation, we can divide the sum of the probabilites by the total number of simulations. +At the end of the simulation, we can divide the sum of the probabilities by the total number of simulations. This will get us the approximated number of individuals with a dominant phenotype. @@ -169,7 +169,7 @@ The standard error for the estimate decreases as the number of simulations gets The larger the number of iterations, the more likely that the final approximation will be similar both between simulations, as well as to the answer from the algorithm. -It is important to keep in mind that both the algorithm and statistical sampling approaches only provide approximations, as there will definetely be some unaccounted variation in a true biological population! +It is important to keep in mind that both the algorithm and statistical sampling approaches only provide approximations, as there will definitely be some unaccounted variation in a true biological population! ```julia using StatsBase From af56621ad9603521109f7a177f763ffa40a4b1bf Mon Sep 17 00:00:00 2001 From: Danielle Pinto Date: Tue, 10 Feb 2026 21:15:02 -0500 Subject: [PATCH 09/10] make edits according to Kevin's suggestions --- docs/src/rosalind/07-iprb.md | 42 ++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/docs/src/rosalind/07-iprb.md b/docs/src/rosalind/07-iprb.md index 88b8b9c..fe0b945 100644 --- a/docs/src/rosalind/07-iprb.md +++ b/docs/src/rosalind/07-iprb.md @@ -174,28 +174,42 @@ It is important to keep in mind that both the algorithm and statistical sampling ```julia using StatsBase -function mendel_sim(k, m, n; iterations=100000) - # Genotypes: 1=HH, 2=Hh, 3=hh - population = [fill(1, k); fill(2, m); fill(3, n)] +# Probability of dominant offspring given parent genotypes +# Index: offspring_prob[parent1, parent2] +# Genotypes: 1=HH, 2=Hh, 3=hh - # Probability of dominant offspring given parent genotypes - # Index: offspring_prob[parent1, parent2] - offspring_prob = [ +ex_offspring_prob = [ 1.0 1.0 1.0; # HH × (HH, Hh, hh) 1.0 0.75 0.5; # Hh × (HH, Hh, hh) 1.0 0.5 0.0 # hh × (HH, Hh, hh) ] - dominant_count = 0 - dominant_count = sum( - offspring_prob[sample(population, 2; replace=false)...] - for i in 1:iterations - ) +function mendel_sim(k, m, n, offspring_prob; iterations=100000) + # Genotypes: 1=HH, 2=Hh, 3=hh + population = [fill(1, k); fill(2, m); fill(3, n)] + + total_pop = k+m+n + wts = [k/total_pop, m/total_pop, n/total_pop] + + # samples two mates from the vector [1,2,3] with probability weights given by wts - return dominant_count / iterations + # then sum the probability of each offspring having a dominant phenotype + # sum across all simulations + sum(1:iterations) do _ + (i,j) = sample([1,2,3], weights(wts), 2) + offspring_prob[i,j] + end / iterations end -mendel_sim(2, 2, 2) +mendel_sim(2, 2, 2, ex_offspring_prob) ``` -In this case, both solutions return a value close to 0.783. \ No newline at end of file +In the function above, the user provides the parameter `offspring_prob`. +If the user wanted to answer a slightly different question with different probability weights, +all that would be needed is a different input vector. +This allows the user to solve a wider variety of questions. + +However, this function does assume that there are only 3 phenotypes, which limits the situations it can be applied towards. + +This solution returns a value closer to 0.75, +while the first one returns a value close to 0.783. From 7a10364ead244da4f68fb1a571e41b427558e7ed Mon Sep 17 00:00:00 2001 From: Danielle Pinto Date: Tue, 10 Feb 2026 21:29:13 -0500 Subject: [PATCH 10/10] add Project.toml back --- docs/Project.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/Project.toml b/docs/Project.toml index 459adf0..7b835f1 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -10,3 +10,6 @@ FormatSpecimens = "3372ea36-2a1a-11e9-3eb7-996970b6ffbd" JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899" LiveServer = "16fef848-5104-11e9-1b77-fb7a48bbb589" XAM = "d759349c-bcba-11e9-07c2-5b90f8f05f7c" + +[compat] +DocumenterVitepress = "=0.2.7"