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.
assign_offspring() assigns offspring to their parent(s)'s unknown sex offspring list (well, dictionary).
assign_sexes() assigns a sex to every animal in the pedigree using sire and daughter lists for improved accuracy.
delete_id_map() checks to see if an ID map for the given filetag exists. If the file exists, it is deleted.
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.
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.
pyp_datestamp() returns a datestamp, as a string, of the format YYYYMMDDHHMMSS.
pyp_nice_time() returns the current date and time formatted as, e.g., Wed Mar 30 10:26:31 2005.
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.
reverse_string() reverses the input string and returns the reversed version.
set_age() Computes ages for all animals in a pedigree based on the global BASE_DEMOGRAPHIC_YEAR defined in pyp_demog.py. If the by is unknown, the inferred generation is used. If the inferred generation is unknown, the age is set to -999.
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. set_ancestor_flag() expects a reordered and renumbered pedigree as input!
set_generation() Works through a pedigree to infer the generation to which an animal belongs based on founders belonging to generation 1. The igen assigned to an animal as the larger of sire.igen+1 and dam.igen+1. This routine assumes that myped is reordered and renumbered.
set_species() assigns a specie to every animal in the pedigree.
simple_histogram_dictionary() returns a dictionary containing a simple, text histogram. The input dictionary is assumed to contain keys which are distinct levels and values that are counts.
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.
sort_dict_by_values() returns a dictionary where the keys in the dictionary are sorted ascending value, first on value and then on key within value. The implementation was taken from John Hunter's contribution to a newsgroup thread: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/bbc259f8454e4d3f/cc686f4cd795feb4?q=python+%22sorted+dictionary%22=1=en#cc686f4cd795feb4
string_to_table_name() takes an arbitrary string and returns a string that is safe to use as an SQLite table name.
subpedigree() takes a NewPedigree object and list of animal IDs and returns a NewPedigree object containing only the animals in the animals list.
trim_pedigree_to_year() takes pedigrees and removes all individuals who were not born in birthyear 'year'.