Many of us have heard that there are four blood types: A, B, AB, and O, with the first two being more common. Without going into what blood type is for the moment, let's instead ask why it is that we end up with these four types at all?
Blood type is determined by genetics. You may be familiar with the concept of a Punnett Square to describe how genetric traits are passed on and expressed. Various traits (such as hair color, eye color, or presence of the sternalis muscle) are determined by genes which appear in your DNA. Each gene you possess is made up of two alleles - one inherited from your mother and the other from your father. It is the combination of these alleles which inform the gene how certain traits are expressed.
A classic example is with the pea plant, in which the color of the peapods are determined by a gene with two possible alleles:
G which is a dominant allele coding for green colorg which is a recessive allele coding for yellow colorSo for an individual receiving one random allele from each of their parents, there are four possible allele gene combinations:
Here there are two possible alleles that can be given from each parent, yielding 3 possible combinations for offspring genes.
Note that only 25% of the offspring possibilities result in yellow peapods.
Here we can see that G is a dominant because the pods will always be green whenever there is a G allele in the pair, and
likewise g is recessive because the pods are only yellow when no dominant allele is present. Also it should be made clear
that an individual has a 50% chance to pass on to their offspring either allele of the pair that they possess. And so two
peapods with genes G g and g g have an equal chance of creating each of the following outcomes for each of their offspring:
Here one parent with gene G g donates one allele, and the other parent with gene g g donates the other.
Note that now 50% of the offspring possibilities result in yellow peapods.
But, what about when there are multiple possible alleles present in the gene pool? Each individual can still only have 2 alleles
(because you always have exactly 2 biological parents), but what if there were 3 allele types available?
This is exactly the case with blood type, in which the alleles are:
IA, which is a dominant allele coding for A-antigen productionIB, which is a dominant allele coding for B-antigen productioni, which is a recessive allele coding for no antigen productionIn this system then, we can understand outcomes leading to the four possible blood types:
IA IA or IA i will produce A-antigen only, which is Blood Type AIB IB or IB i will produce B-antigen only, which is Blood Type BIA IB will produce both A-antigen and B-antigen, which is Blood Type ABi i will produce no antigen, which is Blood Type O
Now there are up to 3 possible alleles.
Understand that an individual can still have only two alleles, but now each allele may be one of 3 possible types.
It is also important to note that not all allele types are represented equally throughout a population. While each allele's frequency in the gene pool should stay relatively consistent (barring external factors or random drift), some alleles may appear much more frequently than others.
Let's say that John is a haematologist. He knows his blood type, and he also knows the relative percentages that each allele type is represented in the general population. John plans one day to get married and have children, and he imagines that one day he may even have grandchildren! He has know idea what the blood types of his future in-laws may be, but he wonders what the possibilities are that his grandchildren might have each blood type.
Input Data
First line is Q, the quantity of testcases.
Q lines will follow in the format pIA pIB pi J G, where
pIA, pIB, and pi correspond to the percentages that each allele IA, IB, and i are represented in the populationJ is John's blood typeG is John's grandchild's blood typeAnswer
Should consist of Q space-separated values, corresponding to the probability that John's grandchild may have blood type G, given his
other three grandparents will come from random members of the population.
Error should be less than 1e-6.
Example
input data:
4
0.345 0.456 0.199 B AB
0.321 0.432 0.247 A A
0.303 0.404 0.293 AB O
0.111 0.222 0.667 O AB
answer:
0.289624 0.377379 0.042925 0.024642