Filters
Filters extract structured views (trios, sib-pairs, etc.) from phenotype and pedigree histories, used by the statistics system.
Filters for extracting structured views from simulation history.
Filters produce FilteredViews (trios, sib-pairs, etc.) from phenotype and pedigree histories, used by statistics modules.
- class xftsim.filters.FilteredView[source]
Bases:
objectBase class for filtered data views produced by Filter.apply().
- class xftsim.filters.TrioView(offspring_phenotypes, mother_phenotypes, father_phenotypes, n_trios)[source]
Bases:
FilteredViewAligned trio data: offspring, mother, and father phenotypes.
All dicts map phenotype name -> (n_trios,) array.
- Parameters:
- class xftsim.filters.SibPairView(sib1_phenotypes, sib2_phenotypes, n_pairs, sib1_idx=None, sib2_idx=None)[source]
Bases:
FilteredViewSibling pair data: two aligned sets of sibling phenotypes.
All dicts map phenotype name -> (n_pairs,) array. sib1_idx and sib2_idx are the original sample indices.
- Parameters:
- class xftsim.filters.Filter[source]
Bases:
ABCAbstract base class for filters.
Filters extract structured views from simulation history.
- abstract apply(generation, phenotype_history, pedigree_history)[source]
Apply the filter to extract a view.
- Parameters:
generation (
int) – Current generation number.phenotype_history (
dict[int,PhenotypeArray]) – Generation -> phenotypes mapping.pedigree_history (
dict[int,PedigreeArray]) – Generation -> pedigree mapping.
- Return type:
- Returns:
FilteredVieworNone– The filtered view, or None if not applicable.- Parameters:
- class xftsim.filters.TrioFilter[source]
Bases:
FilterExtract complete trios (offspring + both parents) from adjacent generations.
At generation 0, returns None (no parents). At generation > 0, indexes parent phenotypes from gen-1 by pedigree indices.
- apply(generation, phenotype_history, pedigree_history)[source]
Apply the filter to extract a view.
- Parameters:
generation (
int) – Current generation number.phenotype_history (
dict[int,PhenotypeArray]) – Generation -> phenotypes mapping.pedigree_history (
dict[int,PedigreeArray]) – Generation -> pedigree mapping.
- Return type:
- Returns:
FilteredVieworNone– The filtered view, or None if not applicable.- Parameters:
generation (
int)phenotype_history (
dict[int,PhenotypeArray])pedigree_history (
dict[int,PedigreeArray])
- class xftsim.filters.SibPairFilter[source]
Bases:
FilterExtract sibling pairs (individuals sharing the same FID).
Groups offspring by FID and forms all unique within-family pairs.
- apply(generation, phenotype_history, pedigree_history)[source]
Apply the filter to extract a view.
- Parameters:
generation (
int) – Current generation number.phenotype_history (
dict[int,PhenotypeArray]) – Generation -> phenotypes mapping.pedigree_history (
dict[int,PedigreeArray]) – Generation -> pedigree mapping.
- Return type:
- Returns:
FilteredVieworNone– The filtered view, or None if not applicable.- Parameters:
generation (
int)phenotype_history (
dict[int,PhenotypeArray])pedigree_history (
dict[int,PedigreeArray])
Bases:
FilteredViewView of one individual per family (unrelated subsample).
Indices into the original sample array (one per family).
- Type:
np.ndarray
Subset of phenotypes for the selected individuals.
- Type:
PhenotypeArray
- Parameters:
indices (
ndarray)phenotypes (
PhenotypeArray)
-
phenotypes:
PhenotypeArray= None
Bases:
FilterSelect one individual per family (first occurrence per FID).
Produces an UnrelatedView with the first individual encountered for each unique FID value.
Apply the filter to extract a view.
- Parameters:
generation (
int) – Current generation number.phenotype_history (
dict[int,PhenotypeArray]) – Generation -> phenotypes mapping.pedigree_history (
dict[int,PedigreeArray]) – Generation -> pedigree mapping.
- Return type:
- Returns:
FilteredVieworNone– The filtered view, or None if not applicable.- Parameters:
generation (
int)phenotype_history (
dict[int,PhenotypeArray])pedigree_history (
dict[int,PedigreeArray])
- class xftsim.filters.AscertainedView(indices=<factory>, phenotypes=None, ascertainment_key='', threshold=0.0)[source]
Bases:
FilteredViewView of individuals passing an ascertainment threshold.
- indices
Indices into the original sample array.
- Type:
np.ndarray
- phenotypes
Subset of phenotypes for selected individuals.
- Type:
PhenotypeArray
- Parameters:
indices (
ndarray)phenotypes (
PhenotypeArray)ascertainment_key (
str)threshold (
float)
-
phenotypes:
PhenotypeArray= None
- class xftsim.filters.AscertainmentFilter(phenotype_key, quantile, tail='both')[source]
Bases:
FilterSelect individuals from the tails of a phenotype distribution.
- Parameters:
phenotype_key (
str) – Which phenotype to ascertain on (e.g. ‘Y’, ‘Y.G’).quantile (
float) – Proportion of the distribution to select. E.g. 0.1 selects the top 10%, bottom 10%, or both (depending ontail).tail (
str) – Which tail(s) to select: ‘upper’, ‘lower’, or ‘both’. - ‘upper’: individuals above the (1 - quantile) percentile - ‘lower’: individuals below the quantile percentile - ‘both’: individuals in either tail (union of upper and lower)
- Parameters:
- apply(generation, phenotype_history, pedigree_history)[source]
Apply the filter to extract a view.
- Parameters:
generation (
int) – Current generation number.phenotype_history (
dict[int,PhenotypeArray]) – Generation -> phenotypes mapping.pedigree_history (
dict[int,PedigreeArray]) – Generation -> pedigree mapping.
- Return type:
- Returns:
FilteredVieworNone– The filtered view, or None if not applicable.- Parameters:
generation (
int)phenotype_history (
dict[int,PhenotypeArray])pedigree_history (
dict[int,PedigreeArray])
- class xftsim.filters.SubsampleView(indices=<factory>, phenotypes=None, n_subsample=0)[source]
Bases:
FilteredViewView of a random subsample of individuals.
- indices
Indices into the original sample array.
- Type:
np.ndarray
- phenotypes
Subset of phenotypes for selected individuals.
- Type:
PhenotypeArray
- Parameters:
indices (
ndarray)phenotypes (
PhenotypeArray)n_subsample (
int)
-
phenotypes:
PhenotypeArray= None
- class xftsim.filters.SubsampleFilter(n=None, fraction=None, seed=None)[source]
Bases:
FilterRandomly subsample individuals.
Exactly one of
norfractionmust be provided.- Parameters:
- Parameters:
- apply(generation, phenotype_history, pedigree_history)[source]
Apply the filter to extract a view.
- Parameters:
generation (
int) – Current generation number.phenotype_history (
dict[int,PhenotypeArray]) – Generation -> phenotypes mapping.pedigree_history (
dict[int,PedigreeArray]) – Generation -> pedigree mapping.
- Return type:
- Returns:
FilteredVieworNone– The filtered view, or None if not applicable.- Parameters:
generation (
int)phenotype_history (
dict[int,PhenotypeArray])pedigree_history (
dict[int,PedigreeArray])