A little genetics lesson
When you only have access to someone's visible traits or phenotype, a pedigree of their family history is often used to figure out the actual genetic information or, genotype of each family member.
When dealing with simple dominance as we will be, a simple pedigree chart will be enough to figure out the alleles of each person.
Each row here is a generation. Circles are female, males squares, horizontal lines are marriage, vertical lines children. Pretty simple. Black means recessive phenotype, white, dominant. Starting from the top, (assume the alleles are
a), we know person 2 has
aa, homozygous recessive because that is the only possible option for the recessive phenotype. Now even though person one could be either
AA to be dominant phenotype, because he has a recessive child, he must be
Aa, or heterozygous. You can do this for all the other people. In the event you don't have any information that enables you to figure out the second allele, it can be done like so:
- You will receive a pedigree chart in the form of a list of generations like
[GenI, GenII, etc.] in any sane format.
- Each generation will be a list of strings, each string representing a person.
- The people are made up of three parts - an ID, their phenotype, and their "connections".
- Their ID is a single printable ascii character that is unique in the entire tree other than
a. (No, there won't be more than 95 people in the chart).
- Their phenotype is one of
A being the dominant allele, and
a being recessive.
- Their connections are a sequence of ID's of other people that they have connections with.
- A connection in the same generation is marriage, in different generations is child and parent.
- The connections are repeated on both sides (i.e. the husband has say he is a husband of wife, and wife says she is husband of wife).
- You have to figure out the genotypes of everyone as much as possible.
- Return the same list, except instead of people, put their genotypes in the same position.
- The genotype has to be outputted in order so
Aa instead of
- A little leeway on the input format is fine.
- This is code-golf so shortest answer in bytes wins.
[["0A1234", "1a0234"], ["2A01", "3a01", "4A015678",
"5a4678"], ["6a45", "7A45","8A45"]] (The one above) ->
[["Aa", "aa"], ["Aa", "aa", "Aa", "aa"], ["aa", "Aa", "Aa"]]
[["0A12", "1A02"], ["2A301", "3a2"]] ->
[["A_", "A_"], ["A_", "aa"]]
- -30 bytes if you deal with incomplete and co-dominance also. On the detection of three phenotypes, apply incomplete/co dominance to your algorithm.