PyPop.Homozygosity#

Computing homozygosity statistics on genotype or allele counts.

Classes#

Homozygosity

Calculate homozygosity statistics.

HomozygosityEWSlatkinExact

Compute homozygosity using the Ewens-Watterson-Slatkin "exact test".

HomozygosityEWSlatkinExactPairwise

Compute pairwise homozygosity using the Ewens-Watterson-Slatkin.

Functions#

getObservedHomozygosityFromAlleleData(alleleData)

Get homozygosity from allele data.

Module Contents#

class Homozygosity(alleleData, rootPath='.', debug=0)#

Calculate homozygosity statistics.

Given allele count data for a given locus, calculates the observed homozygosity and returns the approximate expected homozygosity statistics taken from previous simulation runs.

Parameters:
  • alleleData (list) – list of allele counts

  • rootPath (str) – path to the root of the directory where the pre-calculated expected homozygosity statistics can be found.

  • debug (int) – flag to switch debugging on

getObservedHomozygosity()#

Calculate and return observed homozygosity.

Available even if expected stats cannot be calculated.

Returns:

observed homozygosity

Return type:

float

canGenerateExpectedStats()#

Can expected homozygosity stats be calculated?

Returns 1 if expected homozygosity statistics can be calculated. Should be called before attempting to get any expected homozygosity statistics.

Returns:

1 if can be calculated, otherwise 0

Return type:

int

getPValueRange()#

Gets lower and upper bounds for p-value.

Only meaningful if canGenerateExpectedStats() returns true.

Returns:

(lower, upper) bounds.

Return type:

tuple

getCount()#

Number of runs used to calculate statistics.

Only meaningful if canGenerateExpectedStats() returns 1.

Returns:

number of runs

Return type:

int

getExpectedHomozygosity()#

Gets mean of expected homozygosity.

This is the estimate of the expected homozygosity. Only meaningful if canGenerateExpectedStats() returns true.

Returns:

mean of expected homozygosity

Return type:

float

getVarExpectedHomozygosity()#

Gets variance of expected homozygosity.

This is the estimate of the variance expected homozygosity. Only meaningful if canGenerateExpectedStats() returns true.

Returns:

variance of expected homozygosity

Return type:

float

getNormDevHomozygosity()#

Gets normalized deviate of homozygosity.

Only meaningful if canGenerateExpectedStats() returns true.

Returns:

normalized deviate of homozygosity

Return type:

float

serializeHomozygosityTo(stream)#

Serialize homozygosity to a stream.

Parameters:

stream (XMLOutputStream) – stream to save to

class HomozygosityEWSlatkinExact(alleleData=None, numReplicates=10000, debug=0)#

Bases: Homozygosity

Inheritance diagram of PyPop.Homozygosity.HomozygosityEWSlatkinExact

Compute homozygosity using the Ewens-Watterson-Slatkin “exact test”.

Parameters:
  • alleleData (list) – list of allele counts

  • numReplicates (int) – number or replicates for simulation.

  • debug (int) – flag to switch debugging on

doCalcs(alleleData)#

Run the computations.

Parameters:

alleleData (list) – list of allele counts

getHomozygosity()#

Get the homozygosity statistics.

Returns:

tuple consisting of:
  • theta

  • prob_ewens

  • prob_homozygosity

  • mean_homozygosity

  • obsv_homozygosity

  • var_homozygosity

Return type:

tuple

serializeHomozygosityTo(stream)#

Serialize homozygosity to a stream.

Parameters:

stream (XMLOutputStream) – stream to save to

returnBulkHomozygosityStats(alleleCountDict=None, binningMethod=None)#

Get bulk homozygosity statistics for multiple allele counts.

This function is designed to work with the PyPop.RandomBinning submodule.

Parameters:
  • alleleCountDict (dict) – dictionary of lists of allele counts

  • binningMethod (str) – record the binning method used

Returns:

dictionary of statistics

Return type:

dict

class HomozygosityEWSlatkinExactPairwise(matrix=None, numReplicates=10000, untypedAllele='****', debug=0)#

Compute pairwise homozygosity using the Ewens-Watterson-Slatkin.

Parameters:
  • matrix (StringMatrix) – matrix with multiple loci columns for pairwise comparison

  • numReplicates (int, optional) – number or replicates for simulation.

  • untypedAllele (str, optional) – untyped allele

  • debug (int, optional) – flag to switch debugging on

serializeTo(stream)#

Serialize to a stream.

Parameters:

stream (XMLOutputStream) – stream to save to

getObservedHomozygosityFromAlleleData(alleleData)#

Get homozygosity from allele data.

Parameters:

alleleData (list) – list of allele counts

Returns:

observed homozygosity

Return type:

float