PyPedal::pyp_utils Namespace Reference


Functions

def set_ancestor_flag
def set_generation
def set_age
def set_species
def assign_sexes
def assign_offspring
def reorder
def fast_reorder
def renumber
def load_id_map
def delete_id_map
def trim_pedigree_to_year
def pedigree_range
def sort_dict_by_keys
def sort_dict_by_values
def simple_histogram_dictionary
def reverse_string
def pyp_nice_time
def string_to_table_name
def pyp_datestamp
def subpedigree
def founders_from_list


Function Documentation

def PyPedal::pyp_utils::assign_offspring (   pedobj  ) 

assign_offspring() assigns offspring to their parent(s)'s unknown sex offspring list (well, dictionary).

Parameters:
myped An instance of a NewPedigree object.
Returns:
0 for failure and 1 for success. integer
assign_offspring() assigns offspring to their parent(s)'s unknown sex offspring list
(well, dictionary).

Definition at line 267 of file pyp_utils.py.

def PyPedal::pyp_utils::assign_sexes (   pedobj  ) 

assign_sexes() assigns a sex to every animal in the pedigree using sire and daughter lists for improved accuracy.

Parameters:
pedobj A renumbered and reordered PyPedal pedigree object.
Returns:
0 for failure and 1 for success. integer
assign_sexes() assigns a sex to every animal in the pedigree using sire and daughter
lists for improved accuracy.

Definition at line 226 of file pyp_utils.py.

def PyPedal::pyp_utils::delete_id_map (   filetag = '_renumbered_'  ) 

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

Parameters:
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) integer
delete_id_map() checks to see if an ID map for the given filetag exists.  If the file
exists, it is deleted.

Definition at line 778 of file pyp_utils.py.

def PyPedal::pyp_utils::fast_reorder (   myped,
  filetag = '_new_reordered_',
  io = 'no',
  debug = 0 
)

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.

Parameters:
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).
debug Flag to indicate whether or not debugging messages are written to STDOUT.
Returns:
A reordered PyPedal pedigree. list
Renumber 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.  fast_reorder()
appears to be VERY fast, but I am not sure if it works correctly all of the time or
not.  Use this procedure at your own risk!

Definition at line 540 of file pyp_utils.py.

def PyPedal::pyp_utils::founders_from_list (   anlist,
  unkID 
)

founders_from_list() takes a list of NewAnimal objects and returns a list of animalIDs that represent founders in that pedigree (animals with an unknown sire and dam.

Parameters:
anlist A list of NewAnimal objects.
unkID The animalID assigned to unknown parents.
Returns:
A list of animalIDs of founders. list
founders_from_list() takes a list of NewAnimal objects and returns a
list of animalIDs that represent founders in that pedigree (animals
with an unknown sire and dam.

Definition at line 1052 of file pyp_utils.py.

def PyPedal::pyp_utils::load_id_map (   filetag = '_renumbered_'  ) 

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.

Parameters:
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 or an empty dictionary (on failure). 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.

Definition at line 740 of file pyp_utils.py.

def PyPedal::pyp_utils::pedigree_range (   pedobj,
  n 
)

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.

Parameters:
myped A PyPedal pedigree object.
n A renumbered animalID.
Returns:
A pedigree containing only animals born in the given birthyear of an ampty list (on failure). 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.

Definition at line 829 of file pyp_utils.py.

def PyPedal::pyp_utils::pyp_datestamp (  ) 

pyp_datestamp() returns a datestamp, as a string, of the format YYYYMMDDHHMMSS.

Parameters:
None 
Returns:
A 14-character string containing the datestamp. string
pyp_datestamp() returns a datestamp, as a string, of the format
YYYYMMDDHHMMSS.

Definition at line 988 of file pyp_utils.py.

def PyPedal::pyp_utils::pyp_nice_time (  ) 

pyp_nice_time() returns the current date and time formatted as, e.g., Wed Mar 30 10:26:31 2005.

Parameters:
None 
Returns:
A string containing the formatted date and time. string
pyp_nice_time() returns the current date and time formatted as, e.g.,
Wed Mar 30 10:26:31 2005.

Definition at line 952 of file pyp_utils.py.

def PyPedal::pyp_utils::renumber (   myped,
  filetag = '_renumbered_',
  io = 'no',
  outformat = '0',
  debug = 0,
  returnmap = 0,
  missingparent = 0,
  animaltype = 'new' 
)

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.

Parameters:
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 to write an asd pedigree (0) or a full pedigree (1).
returnmap Indicates whether or not an ID map, as well as the renumbered pedigree, should be returned. If nonzero, suppresses writing of ID maps to disc.
debug Flag to indicate whether or not progress messages are written to stdout.
missingparent Indicates the value used to indicate a missing parent.
animaltype Type of animal object used to populate pedigree
Returns:
A reordered PyPedal pedigree. 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.

Definition at line 611 of file pyp_utils.py.

def PyPedal::pyp_utils::reorder (   myped,
  filetag = '_reordered_',
  io = 'no',
  missingparent = 0,
  debug = 0,
  max_rounds = 100 
)

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.

Parameters:
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).
missingparent Indicates the value used to indicate a missing parent.
debug Toggles debugging messages on and off.
max_rounds Maximum times to iterate through a pedigree trying to reorder it.
Returns:
A reordered PyPedal pedigree. list
Renumber 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.

Definition at line 338 of file pyp_utils.py.

def PyPedal::pyp_utils::reverse_string (   mystring  ) 

reverse_string() reverses the input string and returns the reversed version.

Parameters:
mystring A non-empty Python string.
Returns:
The input string with the order of its characters reversed. string
reverse_string() reverses the input string and returns the reversed version.

Definition at line 930 of file pyp_utils.py.

def PyPedal::pyp_utils::set_age (   pedobj  ) 

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.

Parameters:
pedobj A PyPedal pedigree object.
Returns:
0 for failure and 1 for success. integer
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.

Definition at line 172 of file pyp_utils.py.

def PyPedal::pyp_utils::set_ancestor_flag (   pedobj  ) 

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!

Parameters:
pedobj A PyPedal NewPedigree object.
Returns:
0 for failure and 1 for success. 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.
set_ancestor_flag() expects a reordered and renumbered pedigree as input!

Definition at line 56 of file pyp_utils.py.

def PyPedal::pyp_utils::set_generation (   pedobj  ) 

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.

Parameters:
pedobj A PyPedal NewPedigree object.
Returns:
0 for failure and 1 for success. integer
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.

Definition at line 120 of file pyp_utils.py.

def PyPedal::pyp_utils::set_species (   pedobj,
  species = 'u' 
)

set_species() assigns a specie to every animal in the pedigree.

Parameters:
pedobj A PyPedal pedigree object.
species A PyPedal string.
Returns:
0 for failure and 1 for success. integer
set_species() assigns a specie to every animal in the pedigree.

Definition at line 202 of file pyp_utils.py.

def PyPedal::pyp_utils::simple_histogram_dictionary (   mydict,
  histchar = '*',
  histstep = 5 
)

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.

Parameters:
mydict A non-empty Python dictionary.
histchar The character used to draw the histogram (default is '*').
histstep Used to determine the number of bins (stars) in the diagram.
Returns:
A dictionary containing the histogram by level or an empty dictionary (on failure). dictionary
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.

Definition at line 899 of file pyp_utils.py.

def PyPedal::pyp_utils::sort_dict_by_keys (   mydict  ) 

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.

Parameters:
mydict A non-empty Python dictionary.
Returns:
The input dictionary with keys sorted in ascending order or an empty dictionary (on failure). 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.

Definition at line 853 of file pyp_utils.py.

def PyPedal::pyp_utils::sort_dict_by_values (   first,
  second 
)

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&rnum=1&hl=en#cc686f4cd795feb4

Parameters:
mydict A non-empty Python dictionary.
Returns:
A list of tuples sorted in ascending order. list
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&
rnum=1&hl=en#cc686f4cd795feb4

Definition at line 877 of file pyp_utils.py.

def PyPedal::pyp_utils::string_to_table_name (   instring  ) 

string_to_table_name() takes an arbitrary string and returns a string that is safe to use as an SQLite table name.

Parameters:
instring A string that will be converted to an SQLite-safe table name.
Returns:
A string that is safe to use as an SQLite table name. string
string_to_table_name() takes an arbitrary string and returns a string that
is safe to use as an SQLite table name.

Definition at line 968 of file pyp_utils.py.

def PyPedal::pyp_utils::subpedigree (   pedobj,
  anlist 
)

subpedigree() takes a NewPedigree object and list of animal IDs and returns a NewPedigree object containing only the animals in the animals list.

Parameters:
pedobj PyPedal pedigree object.
animals A list of animal IDs.
Returns:
An instance of a NewPedigree object. object
subpedigree() takes a NewPedigree object and list of animal
IDs and returns a NewPedigree object containing only the
animals in the animals list.

Definition at line 1007 of file pyp_utils.py.

def PyPedal::pyp_utils::trim_pedigree_to_year (   pedobj,
  year 
)

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

Parameters:
myped A PyPedal pedigree object.
year A birthyear.
Returns:
A pedigree containing only animals born in the given birthyear or an ampty list (on failure). list
trim_pedigree_to_year() takes pedigrees and removes all individuals who were not born
in birthyear 'year'.

Definition at line 798 of file pyp_utils.py.


Generated on Fri Mar 28 14:34:59 2008 for PyPedal by  doxygen 1.5.3