The pyp_utils Module

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.

Module Contents

delete_id_map(filetag='_renumbered_') ⇒ integer [#]

delete_id_map() checks to see if an ID map for the given filetag exists. If the file exists, it is deleted.

filetag
A descriptor prepended to output file names that is used to determine name of the file to delete.
Returns:
A flag indicating whether or not the file was successfully deleted (0|1)

draw_pedigree(myped, gfilename='pedigree', gtitle='My_Pedigree', gformat='jpg') ⇒ integer [#]

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.

myped
A PyPedal pedigree object.
gfilename
The name of the file to which the pedigree should be drawn
gtitle
The title of the graph.
Returns:
A 1 for success and a 0 for failure.

fast_reorder(myped, filetag='_new_reordered_', io='no') ⇒ list [#]

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.

myped
A PyPedal pedigree object.
filetag
A descriptor prepended to output file names.
io
Indicates whether or not to write the reordered pedigree to a file (yes|no).
Returns:
A reordered PyPedal pedigree.

id_map_new_to_old(id_map, new_id) ⇒ integer [#]

id_map_new_to_old() takes an ID from a renumbered pedigree and an ID map, and returns the original ID number.

id_map
A dictionary mapping renumbered animalIDs to original animalIDs.
new_id
A renumbered animalID.
Returns:
A dictionary whose keys are renumbered IDs and whose values are original IDs.

load_id_map(filetag='_renumbered_') ⇒ dictionary [#]

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.

filetag
A descriptor prepended to output file names that is used to determine the input file name.
Returns:
A dictionary whose keys are renumbered IDs and whose values are original IDs.

pedigree_range(myped, n) ⇒ list [#]

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.

myped
A PyPedal pedigree object.
n
A renumbered animalID.
Returns:
A pedigree containing only animals born in the given birthyear.

preprocess(inputfile, sepchar=',', debug=0) ⇒ list [#]

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.

inputfile
Name of the file from which the pedigree is to be read,
sepchar
Indicates which character is used to separate entries in the pedigree file (default is CSV).
debug
Flag to indicate whether or not progress messages are written to stdout.
Returns:
A list of Animal() objects; this is what PyPedal calls a pedigree.

renumber(myped, filetag='_renumbered_', io='no', outformat='0', debug=0) ⇒ list [#]

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.

myped
A PyPedal pedigree object.
filetag
A descriptor prepended to output file names.
io
Indicates whether or not to write the renumbered pedigree to a file (yes|no).
outformat
Flag to indicate whether or not ro write an asd pedigree (0) or a full pedigree (1).
debug
Flag to indicate whether or not progress messages are written to stdout.
Returns:
A reordered PyPedal pedigree.

reorder(myped, filetag='_reordered_', io='no') ⇒ list [#]

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.

myped
A PyPedal pedigree object.
filetag
A descriptor prepended to output file names.
io
Indicates whether or not to write the reordered pedigree to a file (yes|no).
Returns:
A reordered PyPedal pedigree.

set_ancestor_flag(myped, filetag='_ancestor_', io='no') ⇒ integer [#]

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!

myped
A PyPedal pedigree object.
filetag
A descriptor prepended to output file names.
io
Indicates whether or not to write an ancestor list to a file..
Returns:
0 for failure and 1 for success.

sort_dict_by_keys(mydict) ⇒ dictionary [#]

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.

mydict
A non-empty Python dictionary.
Returns:
The input dictionary with keys sorted in ascending order.

trim_pedigree_to_year(myped, year) ⇒ list [#]

trim_pedigree_to_year() takes pedigrees and removes all individuals who were not born in birthyear 'year'.

myped
A PyPedal pedigree object.
year
A birthyear.
Returns:
A pedigree containing only animals born in the given birthyear.