HereditaryStratigraphicColumn

class HereditaryStratigraphicColumn

Genetic annotation to enable phylogenetic inference.

Primary end-user facing interface for hstrat library. Should be bundled with digital genomes and propagated via the CloneDescendant method when passing those genomes from parent to offspring. Provides basis for phylogenetic analysis of distributed digital evolution populations.

Naming conventions are derived by analogy to Geological “Stratigraphy” (i.e., <https://en.wikipedia.org/wiki/Stratigraphy>). The “hereditary stratigraphy” system provided by this software works by associating an identifier, referred to as a “stratum,” with each elapsed generation along a line of descent. This allows two “columns” to be aligned to detect the generation of their most recent common ancestor: strata before the MRCA will be identical and strata after will differ.

Stratum retention policy and stratum differentia bit width can be configured to tune the time and space complexity of the column, trading-off with uncertainty induced on estimates of phylogenetic distance back to the most common recent ancestor of two columns.

Arbitrary user-defined data can be associated with strata by optional argument to the CloneDescendant method. (Note that a first stratum is deposited during column initialization, so an optional annotation argument may also be provided then.)

__init__(stratum_retention_policy: Any = perfect_resolution_algo.Policy(policy_spec=perfect_resolution_algo.PolicySpec()), *, always_store_rank_in_stratum: bool = True, stratum_differentia_bit_width: int = 64, initial_stratum_annotation: Any | None = None, stratum_ordered_store: Callable[[...], HereditaryStratumOrderedStoreBase] | Tuple[HereditaryStratumOrderedStoreBase, int] | None = None, stratum_ordered_store_factory: Callable[[...], HereditaryStratumOrderedStoreBase] | Tuple[HereditaryStratumOrderedStoreBase, int] | None = None)[source]

Initialize column to track a new line of descent.

Deposits a first stratum, so GetNumStrataDeposited() will return 1 after initialization even though the user has not yet called DepositStratum().

Parameters

stratum_retention_policyany

Policy struct that implements stratum retention policy by specifying the set of strata ranks that should be pruned from a hereditary stratigraphic column when the nth stratum is deposited.

always_store_rank_in_stratumbool, optional

Should the deposition rank be stored as a data member of generated strata, even if not strictly necessary?

stratum_differentia_bit_widthint, optional

The bit width of the generated differentia. Default 64, allowing for 2^64 distinct values.

initial_stratum_annotation: any, optional

Optional object to store as an annotation. Allows arbitrary user- provided to be associated with the first stratum deposition in the line of descent.

stratum_ordered_store: callable or tuple of store and count, optional

One of: * callable to generate a container that implements the necessary interface to store strata within the column; can be configured for performance reasons, but has no semantic effect. * instance of one aforementioned container along with a deposition count * None, in which case a default-initialized container will be used

stratum_ordered_store_factory: deprecated, alias of stratum_ordered_store.

Notes

If no condemner or predicate functor specifying a stratum retention policy is provided, the perfect resolution policy where all strata are retained is used.

Methods

CalcMinImplausibleSpuriousConsecutiveDifferentiaCollisions(significance_level: float) int[source]

Determine amount of evidence required to indicate shared ancestry.

Calculates how many differentia collisions are required to reject the null hypothesis that columns do not share common ancestry at those ranks at significance level significance_level.

Deprecated since version 1.6.0: Use calc_min_implausible_spurious_differentia_collisions_between

CalcProbabilityDifferentiaCollision() float[source]

How likely are differentia collisions?

Calculates the probability of two randomly-differentiated differentia being identical by coincidence.

Deprecated since version 1.6.0: Use calc_probability_differentia_collision_between

Clone() HereditaryStratigraphicColumn[source]

Create an independent copy of the column.

Contains identical data but may be freely altered without affecting data within this column.

CloneDescendant(stratum_annotation: Any | None = None) HereditaryStratigraphicColumn[source]

Return a cloned column that has had an additional stratum deposited.

Does not alter self.

Parameters

stratum_annotation: any, optional

Optional object to store as an annotation. Allows arbitrary user- provided to be associated with this stratum deposition in the line of descent.

CloneNthDescendant(num_stratum_depositions: int) HereditaryStratigraphicColumn[source]

Return a cloned column that has had n additional strata deposited.

Does not alter self.

Parameters

num_stratum_depositions: int

How many generations should clone column be descended?

DepositStrata(num_stratum_depositions: int) None[source]

Elapse n generations.

Parameters

num_stratum_depositions: int

How many generations to elapse?

DepositStratum(annotation: Any | None = None) None[source]

Elapse a generation.

Parameters

annotation: any, optional

Optional object to store as an annotation. Allows arbitrary user- provided to be associated with this stratum deposition in the line of descent.

GetColumnIndexOfRank(rank: int) int | None[source]

Map generation of deposition to column position.

What is the index position within retained strata of the stratum deposited at rank r? Returns None if no stratum with rank r is present within the store.

GetNumDiscardedStrata() int[source]

How many deposited strata have been discarded?

Determined by number of generations elapsed and the configured column retention policy.

GetNumStrataDeposited() int[source]

How many strata have been depostited on the column?

Note that a first stratum is deposited on the column during initialization.

GetNumStrataRetained() int[source]

How many strata are currently stored within the column?

May be fewer than the number of strata deposited if strata have been discarded as part of the configured stratum retention policy.

GetRankAtColumnIndex(index: int) int[source]

Map column position to generation of deposition.

What is the deposition rank of the stratum positioned at index i among retained strata? Index order is from most ancient (index 0) to most recent.

GetStratumAtColumnIndex(index: int) HereditaryStratum[source]

Get the stratum positioned at index i among retained strata.

Index order is from most ancient (index 0) to most recent.

GetStratumAtRank(rank: int) HereditaryStratum | None[source]

Get the stratum deposited at generation g.

Returns None if stratum with rank g is not retained.

GetStratumDifferentiaBitWidth() int[source]

How many bits wide are the differentia of strata?

HasAnyAnnotations() bool[source]

Do any retained strata have annotations?

HasDiscardedStrata() bool[source]

Have any deposited strata been discarded?

IterRankDifferentiaZip(copyable: bool = False) Iterator[Tuple[int, int]][source]

Iterate over ranks of retained strata and their differentia.

If copyable, return an iterator that can be copied to produce a new fully-independent iterator at the same position.

Equivalent to zip(col.IterRetainedRanks(), col.IterRetainedDifferentia()), but may be more efficient.

IterRetainedDifferentia() Iterator[int][source]

Iterate over differentia of strata stored in the column.

Differentia yielded from most ancient to most recent.

IterRetainedRanks() Iterator[int][source]

Iterate over deposition ranks of strata stored in the column.

The store may be altered during iteration without iterator invalidation, although subsequent updates will not be reflected in the iterator.

IterRetainedStrata() Iterator[HereditaryStratum][source]

Iterate over strata stored in the column. Strata yielded from most ancient to most recent.

__init__(stratum_retention_policy: Any = perfect_resolution_algo.Policy(policy_spec=perfect_resolution_algo.PolicySpec()), *, always_store_rank_in_stratum: bool = True, stratum_differentia_bit_width: int = 64, initial_stratum_annotation: Any | None = None, stratum_ordered_store: Callable[[...], HereditaryStratumOrderedStoreBase] | Tuple[HereditaryStratumOrderedStoreBase, int] | None = None, stratum_ordered_store_factory: Callable[[...], HereditaryStratumOrderedStoreBase] | Tuple[HereditaryStratumOrderedStoreBase, int] | None = None)[source]

Initialize column to track a new line of descent.

Deposits a first stratum, so GetNumStrataDeposited() will return 1 after initialization even though the user has not yet called DepositStratum().

Parameters

stratum_retention_policyany

Policy struct that implements stratum retention policy by specifying the set of strata ranks that should be pruned from a hereditary stratigraphic column when the nth stratum is deposited.

always_store_rank_in_stratumbool, optional

Should the deposition rank be stored as a data member of generated strata, even if not strictly necessary?

stratum_differentia_bit_widthint, optional

The bit width of the generated differentia. Default 64, allowing for 2^64 distinct values.

initial_stratum_annotation: any, optional

Optional object to store as an annotation. Allows arbitrary user- provided to be associated with the first stratum deposition in the line of descent.

stratum_ordered_store: callable or tuple of store and count, optional

One of: * callable to generate a container that implements the necessary interface to store strata within the column; can be configured for performance reasons, but has no semantic effect. * instance of one aforementioned container along with a deposition count * None, in which case a default-initialized container will be used

stratum_ordered_store_factory: deprecated, alias of stratum_ordered_store.

Notes

If no condemner or predicate functor specifying a stratum retention policy is provided, the perfect resolution policy where all strata are retained is used.