The pyp_newclasses Module

pyp_newclasses contains the new class structure that will be a part of PyPedal 2.0.0Final. It includes a master class to which most of the computational routines will be bound as methods, a NewAnimal() class, and a PedigreeMetadata() class.

Module Contents

LightAnimal(locations, data, mykw) (class) [#]

The LightAnimal() class holds animals records read from a pedigree file.

For more information about this class, see The LightAnimal Class.

loadPedigree(options='', optionsfile='pypedal.ini', pedsource='file', pedgraph=0) ⇒ PyPedal pedigree object [#]

loadPedigree() wraps pedigree creation and loading into a one-step process. If the user passes both a dictionary and a filename, the dictionary will be used instead of the filename unless the dictionary is empty.

options
Dictionary of pedigree options.
optionsfile
File from which pedigree options should be read.
pedsource
Source of the pedigree ('file'|'graph'|'graphfile'|'db').
pedgraph
XDiGraph from which to load the pedigree.
Returns:
An instance of a NewPedigree object on success, a 0 on failure.

NewAMatrix(kw) (class) [#]

NewAMatrix provides an instance of a numerator relationship matrix as a Numarray array of floats with some convenience methods.

For more information about this class, see The NewAMatrix Class.

NewAnimal(locations, data, mykw) (class) [#]

The NewAnimal() class is holds animals records read from a pedigree file.

For more information about this class, see The NewAnimal Class.

NewPedigree(kw={}, kwfile='pypedal.ini') (class) [#]

The NewPedigree class is the main data structure for PyP 2.0.0Final.

For more information about this class, see The NewPedigree Class.

PedigreeMetadata(myped, kw) (class) [#]

The PedigreeMetadata() class stores metadata about pedigrees.

For more information about this class, see The PedigreeMetadata Class.

PyPedalError (class) [#]

PyPedalError is the base class for exceptions in PyPedal.

For more information about this class, see The PyPedalError Class.

PyPedalPedigreeInputFileNameError() (class) [#]

PyPedalPedigreeInputFileNameError is raised when a simulated pedigree is not requested and a pedigree file name is not provided.

For more information about this class, see The PyPedalPedigreeInputFileNameError Class.

SimAnimal(animalID, sireID=0, damID=0, sex='u', gen=0) (class) [#]

The SimAnimal() class is a placeholder used for simulating animals.

For more information about this class, see The SimAnimal Class.

tail_recursive(func) (class) [#]

tail_recursive is a tail recursion decorator that eliminates tail calls for recursive functions.

For more information about this class, see The tail_recursive Class.

The LightAnimal Class

LightAnimal(locations, data, mykw) (class) [#]

The LightAnimal() class holds animals records read from a pedigree file. It is a much simpler object than the NewAnimal() object and is intended for use with the graph theoretic routines in pyp_network. The only attributes of these objects are: animal ID, sire ID, dam ID, original ID, birth year, and sex.

__init__(locations, data, mykw) ⇒ object [#]

__init__() initializes a LightAnimal() object.

locations
A dictionary containing the locations of variables in the input line.
data
The line of input read from the pedigree file.
Returns:
An instance of a LightAnimal() object populated with data

dictme() [#]

dictme() returns a summary of the data stored in the NewAnimal() object as a dictionary.

self
Reference to the current NewAnimal() object

pad_id() ⇒ integer [#]

pad_id() takes an Animal ID, pads it to fifteen digits, and prepends the birthyear (or 1950 if the birth year is unknown). The order of elements is: birthyear, animalID, count of zeros, zeros.

self
Reference to the current LightAnimal() object
Returns:
A padded ID number that is supposed to be unique across animals

printme() [#]

printme() prints a summary of the data stored in the LightAnimal() object.

self
Reference to the current LightAnimal() object

string_to_int(idstring, mymaxint=9223372036854775807) [#]

string_to_int() takes an Animal/Sire/Dam ID as a string and returns a hash.

stringme() [#]

stringme() returns a summary of the data stored in the LightAnimal() object as a string.

self
Reference to the current LightAnimal() object

trap() [#]

trap() checks for common errors in LightAnimal() objects

self
Reference to the current LightAnimal() object

The NewAMatrix Class

NewAMatrix(kw) (class) [#]

NewAMatrix provides an instance of a numerator relationship matrix as a Numarray array of floats with some convenience methods. The idea here is to provide a wrapper around a NRM so that it is easier to work with. For large pedigrees it can take a long time to compute the elements of A, so there is real value in providing an easy way to save and retrieve a NRM once it has been formed.

__init__(kw) ⇒ object [#]

__init__() initializes a NewAMatrix object.

self
Reference to the current NewAMatrix() object
kw
A dictionary of options.
Returns:
An instance of a NewAMatrix() object

form_a_matrix(pedigree) ⇒ integer [#]

form_a_matrix() calls pyp_nrm/fast_a_matrix() or pyp_nrm/fast_a_matrix_r() to form a NRM from a pedigree.

pedigree
The pedigree used to form the NRM.
Returns:
A NRM on success, 0 on failure.

info() ⇒ None [#]

info() uses the info() method of Numarray arrays to dump some information about the NRM. This is of use predominantly for debugging.

None
Returns:
None

load(nrm_filename) ⇒ integer [#]

load() uses the Numarray Array Function "fromfile()" to load an array from a binary file. If the load is successful, self.nrm contains the matrix.

nrm_filename
The file from which the matrix should be read.
Returns:
A load status indicator (0: failed, 1: success).

printme() ⇒ None [#]

printme() prints the NRM to the screen.

None
Returns:
None

save(nrm_filename, nrm_format='') ⇒ integer [#]

save() uses the Numarray method "tofile()" to save an array to a binary file.

nrm_filename
The file to which the matrix should be written.
Returns:
A save status indicator (0: failed, 1: success).

The NewAnimal Class

NewAnimal(locations, data, mykw) (class) [#]

The NewAnimal() class is holds animals records read from a pedigree file.

__init__(locations, data, mykw) ⇒ object [#]

__init__() initializes a NewAnimal() object.

locations
A dictionary containing the locations of variables in the input line.
data
The line of input read from the pedigree file.
Returns:
An instance of a NewAnimal() object populated with data

dictme() [#]

dictme() returns a summary of the data stored in the NewAnimal() object as a dictionary.

self
Reference to the current NewAnimal() object

pad_id() ⇒ integer [#]

pad_id() takes an Animal ID, pads it to fifteen digits, and prepends the birthyear (or 1950 if the birth year is unknown). The order of elements is: birthyear, animalID, count of zeros, zeros.

self
Reference to the current NewAnimal() object
Returns:
A padded ID number that is supposed to be unique across animals

printme() [#]

printme() prints a summary of the data stored in the NewAnimal() object.

self
Reference to the current NewAnimal() object

string_to_int(idstring, mymaxint=9223372036854775807) [#]

string_to_int() takes an Animal/Sire/Dam ID as a string and returns a hash.

stringme() [#]

stringme() returns a summary of the data stored in the NewAnimal() object as a string.

self
Reference to the current NewAnimal() object

trap() [#]

trap() checks for common errors in NewAnimal() objects

self
Reference to the current NewAnimal() object

The NewPedigree Class

NewPedigree(kw={}, kwfile='pypedal.ini') (class) [#]

The NewPedigree class is the main data structure for PyP 2.0.0Final.

__init__(kw={}, kwfile='pypedal.ini') ⇒ object [#]

__init__() initializes a NewPedigree object.

self
Reference to the current NewPedigree() object
kw
A dictionary of options.
kwfile
An optionsl configuration file name
Returns:
An instance of a NewPedigree() object

addanimal(animalID, sireID, damID) ⇒ integer [#]

addanimal() adds a new animal of class NewAnimal to the pedigree.

Returns:
1 on success, 0 on failure

delanimal(animalID) ⇒ integer [#]

delanimal() deletes an animal from the pedigree. Note that this method DOES not update the metadata attached to the pedigree and should only be used if that is not important. As of 04/10/2006 delanimal() is intended for use by pyp_metrics/mating_coi() rather than directly by users.

animalID
ID of the animal to be deleted
Returns:
1 on success, 0 on failure

fromgraph(pedgraph) ⇒ None [#]

fromgraph() loads the animals to populate the pedigree from an XDiGraph object.

pedgraph
Returns:
None

load(pedsource='file', pedgraph=0) ⇒ None [#]

load() wraps several processes useful for loading and preparing a pedigree for use in an analysis, including reading the animals into a list of animal objects, forming lists of sires and dams, checking for common errors, setting ancestor flags, and renumbering the pedigree.

pedsource
Source of the pedigree ('file'|'graph'|'graphfile'|'db').
pedgraph
XDiGraph from which to load the pedigree.
Returns:
None

preprocess() ⇒ None [#]

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.

None
Returns:
None

printoptions() ⇒ None [#]

printoptions() prints the contents of the options dictionary.

None
Returns:
None

renumber() ⇒ None [#]

renumber() updates the ID map after a pedigree has been renumbered so that all references are to renumbered rather than original IDs.

None
Returns:
None

save(filename='', outformat='o', idformat='o') ⇒ integer [#]

save() writes a PyPedal pedigree to a user-specified file. The saved pedigree includes all fields recognized by PyPedal, not just the original fields read from the input pedigree file.

filename
The file to which the pedigree should be written.
outformat
The format in which the pedigree should be written: 'o' for original (as read) and 'l' for long version (all available variables).
idformat
Write 'o' (original) or 'r' (renumbered) animal, sire, and dam IDs.
Returns:
A save status indicator (0: failed, 1: success)

simulate() ⇒ None [#]

simulate() simulates an arbitrary pedigree of size n with g generations starting from n_s base sires and n_d base dams. This method is based on the concepts and algorithms in the Pedigree::sample method from Matvec 1.1a. The arguments are read from the pedigree object's options dictionary.

None
Returns:
None

updateidmap() ⇒ None [#]

updateidmap() updates the ID map after a pedigree has been renumbered so that all references are to renumbered rather than original IDs.

None
Returns:
None

The PedigreeMetadata Class

PedigreeMetadata(myped, kw) (class) [#]

The PedigreeMetadata() class stores metadata about pedigrees. Hopefully this will help improve performance in some procedures, as well as provide some useful summary data.

__init__(myped, kw) ⇒ object [#]

__init__() initializes a PedigreeMetadata object.

self
Reference to the current Pedigree() object
myped
A PyPedal pedigree.
kw
A dictionary of options.
Returns:
An instance of a Pedigree() object populated with data

fileme() [#]

fileme() writes the metada stored in the Pedigree() object to disc.

self
Reference to the current Pedigree() object

nud() ⇒ integer-and-list [#]

nud() returns the number of unique dams in the pedigree along with a list of the dams

self
Reference to the current Pedigree() object
Returns:
The number of unique dams in the pedigree and a list of those dams

nuf() ⇒ integer-and-list [#]

nuf() returns the number of unique founders in the pedigree along with a list of the founders

self
Reference to the current Pedigree() object
Returns:
The number of unique founders in the pedigree and a list of those founders

nug() ⇒ integer-and-list [#]

nug() returns the number of unique generations in the pedigree along with a list of the generations

self
Reference to the current Pedigree() object
Returns:
The number of unique generations in the pedigree and a list of those generations

nuherds() ⇒ integer-and-list [#]

nuherds() returns the number of unique herds in the pedigree along with a list of the herds.

self
Reference to the current Pedigree() object
Returns:
The number of unique herds in the pedigree and a list of those herds

nus() ⇒ integer-and-list [#]

nus() returns the number of unique sires in the pedigree along with a list of the sires

self
Reference to the current Pedigree() object
Returns:
The number of unique sires in the pedigree and a list of those sires

nuy() ⇒ integer-and-list [#]

nuy() returns the number of unique birthyears in the pedigree along with a list of the birthyears

self
Reference to the current Pedigree() object
Returns:
The number of unique birthyears in the pedigree and a list of those birthyears

printme() [#]

printme() prints a summary of the metadata stored in the Pedigree() object.

self
Reference to the current Pedigree() object

stringme() [#]

stringme() returns a summary of the metadata stored in the pedigree as a string.

self
Reference to the current Pedigree() object

The PyPedalError Class

PyPedalError (class) [#]

PyPedalError is the base class for exceptions in PyPedal. The exceptions are based on the examples from "An Introduction to Python" by Guido van Rossum and Fred L. Drake,Jr. (http://www.network-theory.co.uk/docs/pytut/tut_64.html).

The PyPedalPedigreeInputFileNameError Class

PyPedalPedigreeInputFileNameError() (class) [#]

PyPedalPedigreeInputFileNameError is raised when a simulated pedigree is not requested and a pedigree file name is not provided.

The SimAnimal Class

SimAnimal(animalID, sireID=0, damID=0, sex='u', gen=0) (class) [#]

The SimAnimal() class is a placeholder used for simulating animals.

__init__(animalID, sireID=0, damID=0, sex='u', gen=0) ⇒ object [#]

__init__() initializes a SimAnimal() object.

animalID
Animal's ID.
sireID
Sire's ID.
damID
Dam's ID.
sex
Sex of animal.
Returns:
An instance of a SimAnimal() object populated with data

printme() ⇒ None [#]

printme() prints a summary of the data stored in a SimAnimal() object.

self
Reference to the current object
Returns:
None

stringme() ⇒ None [#]

stringme() returns the data stored in a SimAnimal() object as a string.

self
Reference to the current NewAnimal() object
Returns:
None

The tail_recursive Class

tail_recursive(func) (class) [#]

tail_recursive is a tail recursion decorator that eliminates tail calls for recursive functions. It was taken from the Python Cookbook entry "New Tail Recursion Decorator" submitted by Kay Schlueh. This version was provided by Michele Simionato on 2006/05/15. The URL is: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691.