5.4 Relatives

PyPedal provides a number of tools for extracting information about relatives from a pedigree. Examples include: obtaining lists of the ancestors of an animal, getting lists of ancestors shared in common by a pair of animals, listing the descendants of an individual, the calculation of the additive genetic relationship between a given pair of animals, and the creation of ``subpedigrees'' containing only specified animals.

It is easy to obtain a list of an animal's relatives using pyp_metrics.related_animals():

list_a = pyp_metrics.related_animals(example.pedigree[6].animalID,example)
list_b = pyp_metrics.related_animals(example.pedigree[13].animalID,example)
produces a list of each animal's relatives:
[5, 1, 2]
[14, 5, 1, 2, 6, 3, 4]
pyp_metrics.common_ancestors() is used to get a list of the common ancestors of two animals, say animals "5" and "14" (remember that this pedigree is renumbered, and that Python lists are indexed from 0, so we need to offset the animal IDs by 1 to get the correct animal IDs).
list_r = pyp_metrics.common_ancestors(example.pedigree[4].animalID,example.pedigree[13].ani
malID,example)
print list_r
Results are returned as lists:
[1, 2, 5]
If you've already obtained ancestor lists for a given pair of animals in which you're interested you can also obtain a list of common ancestors using Python sets, which avoids performing calcualtions more than needed:
>>> set_a = set(list_a)
>>> set_b = set(list_b)
>>> set_c = set_a.intersection(set_b)
>>> set_c
set([1, 2, 5])
>>> list_c = list(set_c)
>>> list_c
[1, 2, 5]
A list of descendants can be obtained by calling pyp_metrics.descendants(), which returns a dictionary:
>>> pyp_metrics.descendants(5,example,{})
{7: 7, 8: 8, 9: 9, 10: 10, 11: 11, 12: 12, 13: 13, 14: 14}
However, it is improtant to note that you will not get the answer you expect unless you have either set the option "set_offspring = 1" or called pyp_utils.assign_offspring() after loading the pedigree. There is also a convenience function, pyp_metrics.founder_descendants(), for handling the special case of obtaining descendants of all of the founders in the pedigree:
>>> pyp_metrics.founder_descendants(example)
{1: {5: 5, 7: 7, 8: 8, 9: 9, 10: 10, 11: 11, 12: 12, 13: 13, 14: 14},
 2: {5: 5, 7: 7, 8: 8, 9: 9, 10: 10, 11: 11, 12: 12, 13: 13, 14: 14},
 3: {6: 6, 7: 7, 8: 8, 9: 9, 10: 10, 11: 11, 12: 12, 13: 13, 14: 14},
 4: {6: 6, 7: 7, 8: 8, 9: 9, 10: 10, 11: 11, 12: 12, 13: 13, 14: 14}}
See About this document... for information on suggesting changes.