pyp_utils contains a set of procedures for creating and operating on PyPedal pedigrees. This includes routines for reordering and renumbering pedigrees, as well as for modifying pedigrees.
delete_id_map() checks to see if an ID map for the given filetag exists. If the file exists, it is deleted.
draw_pedigree() uses the pydot bindings to the graphviz library -- if they are available on your system -- to produce a directed graph of your pedigree with paths of inheritance as edges and animals as nodes. If there is more than one generation in the pedigree as determind by the "gen" attributes of the anumals in the pedigree, draw_pedigree() will use subgraphs to try and group animals in the same generation together in the drawing.
fast_reorder() renumbers a pedigree such that parents precede their offspring in the pedigree. In order to minimize overhead as much as is reasonably possible, a list of animal IDs that have already been seen is kept. Whenever a parent that is not in the seen list is encountered, the offspring of that parent is moved to the end of the pedigree. This should ensure that the pedigree is properly sorted such that all parents precede their offspring. myped is reordered in place. fast_reorder() uses dictionaries to renumber the pedigree based on paddedIDs.
id_map_new_to_old() takes an ID from a renumbered pedigree and an ID map, and returns the original ID number.
load_id_map() reads an ID map from the file generated by pyp_utils/renumber() into a dictionary. There is a VERY similar function, pyp_io/id_map_from_file(), that is deprecated because it is much more fragile that this procedure.
pedigree_range() takes a renumbered pedigree and removes all individuals with a renumbered ID > n. The reduced pedigree is returned. Assumes that the input pedigree is sorted on animal key in ascending order.
preprocess() processes a pedigree file, which includes reading the animals into a list of animal objects, forming lists of sires and dams, and checking for common errors.
renumber() takes a pedigree as input and renumbers it such that the oldest animal in the pedigree has an ID of '1' and the n-th animal has an ID of 'n'. If the pedigree is not ordered from oldest to youngest such that all offspring precede their offspring, the pedigree will be reordered. The renumbered pedigree is written to disc in 'asd' format and a map file that associates sequential IDs with original IDs is also written.
reorder() renumbers a pedigree such that parents precede their offspring in the pedigree. In order to minimize overhead as much as is reasonably possible, a list of animal IDs that have already been seen is kept. Whenever a parent that is not in the seen list is encountered, the offspring of that parent is moved to the end of the pedigree. This should ensure that the pedigree is properly sorted such that all parents precede their offspring. myped is reordered in place. reorder() is VERY slow, but I am pretty sure that it works correctly.
set_ancestor_flag() loops through a pedigree to build a dictionary of all of the parents in the pedigree. It then sets the ancestor flags for the parents. It assumes that the pedigree is reordered and renumbered. NOTE: set_ancestor_flag() expects a reordered and renumbered pedigree as input!
sort_dict_by_keys() returns a dictionary where the values in the dictionary in the order obtained by sorting the keys. Taken from the routine sortedDictValues3 in the "Python Cookbook", p. 39.
trim_pedigree_to_year() takes pedigrees and removes all individuals who were not born in birthyear 'year'.