-
Notifications
You must be signed in to change notification settings - Fork 8
Mendel's Genetics #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
danielle-pinto
wants to merge
3
commits into
2026-01-27-hamming-distance
Choose a base branch
from
2026-01-30-iprb
base: 2026-01-27-hamming-distance
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+71
−0
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,71 @@ | ||||||
| # Mendel's First Law | ||||||
|
|
||||||
| 🤔 [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. | ||||||
|
|
||||||
| 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. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or "having the recessive phenotype". |
||||||
|
|
||||||
| 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 | ||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Semantic line breaks please - it makes editing and diffs much nicer.
One way to help remember is to turn off automatic line breaks in your text editor.