arch

Below is an auto-generated summary of the xftsim.arch submodule API.

class xftsim.arch.AdditiveGeneticComponent(beta=None, metadata={}, component_name='addGenetic')

Bases: ArchitectureComponent

A genetic component with additive effects.

Parameters:
  • beta (xft.effect.AdditiveEffects, optional) – Additive effects, by default None.

  • metadata (Dict, optional) – Additional metadata, by default an empty dictionary.

effects

Additive effects.

Type:

xft.effect.AdditiveEffects

compute_component(haplotypes, phenotypes)

Compute the additive genetic component of the phenotype.

Parameters:
  • haplotypes (xr.DataArray) – Haplotypes to be used in the computation.

  • phenotypes (xr.DataArray) – Phenotypes to be modified.

property true_cov_beta

Compute the covariance matrix of the additive effects.

Returns:

ndarray – Covariance matrix of the additive effects.

property true_rho_beta

Compute the correlation coefficient matrix of the additive effects.

Returns:

ndarray – Correlation coefficient matrix of the additive effects.

class xftsim.arch.AdditiveNoiseComponent(variances=None, sds=None, means=None, phenotype_name=None, component_index=None, component_name='addNoise')

Bases: ArchitectureComponent

An independent Gaussian noise component.

Parameters:
  • variances (Iterable, optional) – Variances of the noise components, by default None.

  • sds (Iterable, optional) – Standard deviations of the noise components, by default None.

  • means (Iterable, optional) – Means of the noise components, by default set to zero.

  • phenotype_name (Iterable, optional) – Names of the phenotypes, by default None. Included for backwards compatability. Do not specify if providing component_index

  • component_index (xftsim.index.ComponentIndex, optional) – Alternatively, provide output component index

variances

Variances of the noise components.

Type:

ndarray

sds

Standard deviations of the noise components.

Type:

ndarray

compute_component(haplotypes, phenotypes)

Compute the noise component of the phenotype.

Parameters:
  • haplotypes (xr.DataArray) – Haplotypes, not used in the computation.

  • phenotypes (xr.DataArray) – Phenotypes to be modified.

class xftsim.arch.Architecture(components=None, metadata={}, depth=1, expand_components=False)

Bases: object

Class representing a phenogenetic architecure

Parameters:
  • components (Iterable, optional) – An iterable collection of ArchitectureComponent objects

  • metadata (Dict, optional) – A dictionary for holding metadata about the Architecture object

  • depth (int, optional) – The generational depth of the architecture, default to 1

  • expand_components (bool, optional) – A boolean flag indicating whether to expand the components, default to False

metadata

A dictionary for holding metadata about the Architecture object

Type:

Dict

components

An iterable collection of ArchitectureComponent objects

Type:

Iterable

depth

The depth of the architecture

Type:

int

expand_components

A boolean flag indicating whether to expand the components

Type:

bool

founder_initializations() List:

Get a list of the founder initialization of each component

merged_component_indexer() xft.index.ComponentIndex:

Get the merged component indexer

initialize_phenotype_array(haplotypes: xr.DataArray, control: dict = None) xr.DataArray:

Initialize a new phenotype array

initialize_founder_phenotype_array(haplotypes: xr.DataArray, control: dict = None) xr.DataArray:

Initialize a new founder phenotype array

compute_phenotypes(haplotypes: xr.DataArray = None, phenotypes: xr.DataArray = None, control: dict = None) None:

Compute phenotypes for the given haplotypes and phenotypes

check_dependencies()
compute_phenotypes(haplotypes=None, phenotypes=None, control=None)

Compute phenotypes.

Parameters:
  • haplotypes (xr.DataArray, optional) – Input haplotypes.

  • phenotypes (xr.DataArray, optional) – Input phenotypes.

  • control (dict, optional) – Dictionary containing control parameters.

property dependency_graph
property dependency_graph_edges
draw_dependency_graph(node_color='none', node_size=1200, font_size=5, margins=0.1, edge_color='#222222', arrowsize=6, number_edges=True, **kwargs)
property founder_initializations

Get a list of the founder initialization of each component

initialize_founder_phenotype_array(haplotypes, control=None)

Initialize a founder generation phenotype array from haplotypes under the specified architecture. In the absense of vertical transmission, this is equivalent to initialize_phenotype_array().

Parameters:
  • haplotypes (xr.DataArray) – Input haplotypes.

  • control (dict, optional) – Dictionary containing control parameters.

Returns:

xr.DataArray – Phenotype array with the merged component indexer and sample indexer.

initialize_phenotype_array(haplotypes, control=None)

Initialize a phenotype array from haplotypes under the specified architecture.

Parameters:
  • haplotypes (xr.DataArray) – Input haplotypes.

  • control (dict, optional) – Dictionary containing control parameters.

Returns:

xr.DataArray – Phenotype array with the merged component indexer and sample indexer.

property merged_component_indexer

Get the merged ComponentIndex indexer across all archtecure components

class xftsim.arch.ArchitectureComponent(compute_component=None, input_cindex=None, output_cindex=None, input_haplotypes=False, founder_initialization=None, component_name='generic')

Bases: object

Class representing a component of a genetic architecture.

Parameters:
  • compute_component (Callable, optional) – Function that accesses haplotypes and/or phenotypes and modifies phenotypes by reference, by default None.

  • input_cindex (xft.index.ComponentIndex, optional) – Index of the input component, by default None.

  • output_cindex (xft.index.ComponentIndex, optional) – Index of the output component, by default None.

  • input_haplotypes (bool or xft.index.HaploidVariantIndex, optional) – Boolean or HaploidVariantIndex indicating if input haplotypes are used, by default False.

  • founder_initialization (Callable, optional) – Function that initializes founder haplotypes for the component, by default None.

_compute_component

Function that accesses haplotypes and/or phenotypes and modifies phenotypes by reference.

Type:

Callable or None

input_haplotypes

Boolean or HaploidVariantIndex indicating if input haplotypes are used.

Type:

bool or xft.index.HaploidVariantIndex

input_cindex

Index of the input component.

Type:

xft.index.ComponentIndex

output_cindex

Index of the output component.

Type:

xft.index.ComponentIndex

founder_initialization

Function that initializes founder haplotypes for the component.

Type:

Callable or None

property component_name
compute_component(haplotypes=None, phenotypes=None)

Function that accesses haplotypes and/or phenotypes and modifies phenotypes by reference.

Parameters:
  • haplotypes (xr.DataArray, optional) – Haplotypes to be accessed, by default None.

  • phenotypes (xr.DataArray, optional) – Phenotypes to be accessed and modified, by default None.

static default_input_cindex(*args, **kwargs)

Static method to define the default input component index.

static default_output_cindex(*args, **kwargs)

Static method to define the default output component index.

property dependency_graph
property dependency_graph_edges
draw_dependency_graph(node_color='none', node_size=1500, arrowsize=7, font_size=6, margins=0.1, **kwargs)
property input_component_name
property input_phenotype_name
property input_vorigin_relative
property merged_phenotype_indexer
property output_component_name
property output_phenotype_name
property output_vorigin_relative
property phenotype_name
property vorigin_relative
class xftsim.arch.BinarizingTransformation(thresholds, input_cindex, output_cindex, component_name='binarize')

Bases: ArchitectureComponent

An architecture component that binarizes specified phenotypes based on specified thresholds under a liability-threshold model.

Attributes:

thresholdsIterable

A list or array of thresholds used for binarization.

input_cindexxft.index.ComponentIndex

The input component index.

output_cindexxft.index.ComponentIndex

The output component index.

phenotype_nameIterable

The name of the phenotype.

liability_componentstr

The liability component to be used. Default is ‘phenotype’.

vorigin_relativeIterable

The relative V origin. Default is [-1].

output_componentstr

The name of the output component. Default is ‘binary_phenotype’.

Methods:

construct_input_cindex(phenotype_name: Iterable,

liability_component: str = ‘phenotype’, vorigin_relative: Iterable = [-1],) -> xft.index.ComponentIndex

Constructs the input component index based on given phenotype names.

construct_output_cindex(phenotype_name: Iterable,

output_component: str = ‘binary_phenotype’, vorigin_relative: Iterable = [-1],) -> xft.index.ComponentIndex

Constructs the output component index based on given phenotype names.

construct_cindexes(phenotype_name: Iterable,

liability_component: str = ‘phenotype’, output_component: str = ‘binary_phenotype’, vorigin_relative: Iterable = [-1],) -> Tuple[xft.index.ComponentIndex, xft.index.ComponentIndex]

Constructs both the input and output component indexes based on given phenotype names.

compute_component(self,

haplotypes: xr.DataArray, phenotypes: xr.DataArray) -> None:

Computes the binary phenotype based on the given thresholds.

compute_component(haplotypes, phenotypes)

Computes the binarizing transformation.

Parameters:
  • haplotypes (xr.DataArray) – The haplotypes.

  • phenotypes (xr.DataArray) – The phenotypes.

static construct_cindexes(phenotype_name, liability_component='phenotype', output_component='binary_phenotype', vorigin_relative=[-1])

Constructs both input and output component indexes for the binarizing transformation.

Parameters:
  • phenotype_name (Iterable) – Names of the phenotypes.

  • liability_component (str, optional) – Name of the liability component. Default is “phenotype”.

  • output_component (str, optional) – Name of the output component. Default is “binary_phenotype”.

  • vorigin_relative (Iterable, optional) – v-origin relative. Default is [-1].

Returns:

Tuple[xft.index.ComponentIndex, xft.index.ComponentIndex] – The input and output component indexes.

static construct_input_cindex(phenotype_name, liability_component='phenotype', vorigin_relative=[-1])

Constructs the input component index for the binarizing transformation.

Parameters:
  • phenotype_name (Iterable) – Names of the phenotypes.

  • liability_component (str, optional) – Name of the liability component. Default is “phenotype”.

  • vorigin_relative (Iterable, optional) – v-origin relative. Default is [-1].

Returns:

xft.index.ComponentIndex – The input component index.

static construct_output_cindex(phenotype_name, output_component='binary_phenotype', vorigin_relative=[-1])

Constructs the output component index for the binarizing transformation.

Parameters:
  • phenotype_name (Iterable) – Names of the phenotypes.

  • output_component (str, optional) – Name of the output component. Default is “binary_phenotype”.

  • vorigin_relative (Iterable, optional) – v-origin relative. Default is [-1].

Returns:

xft.index.ComponentIndex – The output component index.

class xftsim.arch.ConstantFounderInitialization(component_index=None, constants=None)

Bases: FounderInitialization

Founder initialization that sets all haplotypes to constant values.

class xftsim.arch.CorrelatedNoiseComponent(vcov=None, means=None, phenotype_name=None, component_index=None, component_name='corrNoise')

Bases: ArchitectureComponent

Multivariate Gaussian noise component.

Parameters:
  • vcov (ndarray, optional) – variance covariance matrix

  • means (Iterable, optional) – Means of the noise components, by default set to zero.

  • phenotype_name (Iterable, optional) – Names of the phenotypes, by default None. Included for backwards compatability. Do not specify if providing component_index

  • component_index (xftsim.index.ComponentIndex, optional) – Alternatively, provide output component index

compute_component(haplotypes, phenotypes)

Compute the noise component of the phenotype.

Parameters:
  • haplotypes (xr.DataArray) – Haplotypes, not used in the computation.

  • phenotypes (xr.DataArray) – Phenotypes to be modified.

class xftsim.arch.FounderInitialization(component_index=None, initialize_component=None)

Bases: object

Base class for founder initialization.

initialize_component(phenotypes)

Initialize founder haplotypes for a single phenotype component.

Parameters:

phenotypes (xr.DataArray) – Phenotypes for a single phenotype component.

Raises:

Warning – If no initialization method is defined.

class xftsim.arch.GCTA_Architecture(h2, Rg=None, phenotype_name=None, variant_indexer=None, haplotypes=None)

Bases: Architecture

Additive genetic architecture object under GCTA infinitessimal model <CITE>

Under this genetic architecture, all variants are causal and standardized genetic variants / sqrt(m) have the user specified (possibly diagonal) genetic correlation matrix and variance equal to h2.

Parameters:
  • h2 (Iterable) – Vector of genetic variances or genetic variance/covariance matrix

  • Rg (numpy.ndarray) – Optional genetic correlation matrix

  • phenotype_name (Iterable) – Optional names of phenotypes

  • variant_indexer (xft.index.HaploidVariantIndex | xft.index.DiploidVariantIndex) – Variant indexer, will determine ploidy automatically Phenotype component indexer, defaults to xft.index.ComponentIndex.RangeIndex if not provided

  • haplotypes (xr.DataArray) – Alternatively, one can simply provide haplotypes instead of the variant indexer. Ignored if variant_indexer is supplied.

class xftsim.arch.GaussianFounderInitialization(component_index=None, variances=None, sds=None, means=None)

Bases: FounderInitialization

A class for initializing founder haplotypes by drawing iid samples from normal distributions with the specified means and standard deviations.

Parameters:
  • component_index (xft.index.ComponentIndex, optional) – A ComponentIndex object containing the indexing information of the components. If not provided, then the initialization will be null.

  • variances (Iterable, optional) – An iterable object of length k_total specifying the variances of the Gaussian distribution. Either variances or sds must be provided.

  • sds (Iterable, optional) – An iterable object of length k_total specifying the standard deviations of the Gaussian distribution. Either variances or sds must be provided.

  • means (Iterable, optional) – An iterable object of length k_total specifying the means of the Gaussian distribution. If not provided, then the means will be set to 0.

Raises:

AssertionError – If neither variances nor sds is provided or if the length of component_index does not match the length of sds.

sds

An array of standard deviations.

Type:

numpy.ndarray

means

An array of means.

Type:

numpy.ndarray

component_index

An object containing the indexing information of the components.

Type:

xft.index.ComponentIndex

class xftsim.arch.HorizontalComponent(input_cindex, output_cindex, coefficient_matrix=None, normalize=True, component_name='linHoriz')

Bases: LinearTransformationComponent

class xftsim.arch.InfinitessimalArchitecture

Bases: object

class xftsim.arch.LinearTransformationComponent(input_cindex=None, output_cindex=None, coefficient_matrix=None, normalize=True, founder_initialization=None, component_name='linear')

Bases: ArchitectureComponent

A linear transformation component. Maps input phenotypes to output phenotypes using linear map represented by coefficient_matrix.

Parameters:
  • input_cindex (xft.index.ComponentIndex, optional) – Input component index, by default None.

  • output_cindex (xft.index.ComponentIndex, optional) – Output component index, by default None.

  • coefficient_matrix (ndarray, optional) – Coefficient matrix, by default None.

  • normalize (bool, optional) – If True, normalize the input by subtracting the mean and dividing by the standard deviation, by default True.

  • founder_initialization (FounderInitialization, optional) – Founder initialization, by default None.

v_input_dimension

Input dimension.

Type:

int

v_output_dimension

Output dimension.

Type:

int

normalize

If True, normalize the input by subtracting the mean and dividing by the standard deviation.

Type:

bool

coefficient_matrix

Coefficient matrix.

Type:

ndarray

compute_component(haplotypes, phenotypes)

Compute the linear transformation component of the phenotype.

Parameters:
  • haplotypes (xr.DataArray) – Haplotypes, not used in the computation.

  • phenotypes (xr.DataArray) – Phenotypes to be modified.

property linear_transformation

Get the linear transformation matrix.

Returns:

pd.DataFrame – Linear transformation matrix.

class xftsim.arch.LinearVerticalComponent(input_cindex=None, output_cindex=None, coefficient_matrix=None, normalize=True, founder_variances=None, founder_initialization=None, component_name='linVert')

Bases: LinearTransformationComponent

A vertical transmission component. Requires a way to generate “transmitted” components in the founder generation.

Parameters:
  • input_cindex (xft.index.ComponentIndex, optional) – Input component index, by default None.

  • output_cindex (xft.index.ComponentIndex, optional) – Output component index, by default None.

  • coefficient_matrix (ndarray, optional) – Coefficient matrix, by default None.

  • normalize (bool, optional) – If True, normalize the input by subtracting the mean and dividing by the standard deviation, by default True.

  • founder_variances (Iterable, optional) – Variances of the founders, by default None.

  • founder_initialization (FounderInitialization, optional) – Founder initialization, by default None.

v_input_dimension

Input dimension.

Type:

int

v_output_dimension

Output dimension.

Type:

int

normalize

If True, normalize the input by subtracting the mean and dividing by the standard deviation.

Type:

bool

coefficient_matrix

Coefficient matrix.

Type:

ndarray

class xftsim.arch.ProductComponent(input_cindex, output_cindex, output_coef=1.0, coefficient_vector=None, mean_deviate=True, normalize=False)

Bases: ArchitectureComponent

Multiplies existing components

Parameters:
  • input_cindex (xft.index.ComponentIndex) – Index of components to multiply

  • output_cindex (xft.index.ComponentIndex) – Output component index

  • output_coef (float, options) – Coefficent to multiply output by, by default 1.0

  • coefficient_vector (ndarray, optional) – Coefficients to premultiply inputs by, by default all ones.

  • mean_deviate (bool, optional) – If True, mean deviate the inputs by subtracting the mean. Defaults to True.

  • normalize (bool, optional) – If True, normalize the inputs by subtracting the mean and dividing by the standard deviation prior to multiply. Defaults to False.

compute_component(haplotypes, phenotypes)

Compute the noise component of the phenotype.

Parameters:
  • haplotypes (xr.DataArray) – Haplotypes, not used in the computation.

  • phenotypes (xr.DataArray) – Phenotypes to be modified.

class xftsim.arch.SpikeSlabArchitecture

Bases: object

class xftsim.arch.SumAllTransformation(input_cindex, output_component_name='phenotype', output_comp_type='outcome', component_name='sumAll')

Bases: ArchitectureComponent

Sum all intermediate phenotype components to generate outcome phenotype components.

Parameters:

input_cindex (xft.index.ComponentIndex) – Input component index.

input_haplotypes

If True, haplotypes are input.

Type:

bool

input_cindex

Input component index.

Type:

xft.index.ComponentIndex

output_cindex

Output component index.

Type:

xft.index.ComponentIndex

founder_initialization

Founder initialization.

Type:

None

compute_component(haplotypes, phenotypes)

Compute the sum of the input components and assign them to the output component.

Parameters:

haplotypesxr.DataArray

Haplotypes.

phenotypesxr.DataArray

Phenotypes.

Returns:

None

static construct_input_cindex(phenotype_name, sum_components=['additiveGenetic', 'additiveNoise'], vorigin_relative=[-1])

Construct input component index.

Parameters:
  • phenotype_name (Iterable) – Phenotype name.

  • sum_components (Iterable, optional) – Components to sum, by default [‘additiveGenetic’, ‘additiveNoise’].

  • vorigin_relative (Iterable, optional) – Relative vorigins, by default [-1].

Returns:

xft.index.ComponentIndex – Component index.

class xftsim.arch.SumTransformation(input_cindex, output_cindex, component_name='sumTrans')

Bases: ArchitectureComponent

Sum components to generate phenotypes.

Parameters:
  • input_cindex (xft.index.ComponentIndex) – Input component index.

  • output_cindex (xft.index.ComponentIndex) – Output component index.

input_haplotypes

If True, haplotypes are input.

Type:

bool

input_cindex

Input component index.

Type:

xft.index.ComponentIndex

output_cindex

Output component index.

Type:

xft.index.ComponentIndex

founder_initialization

Founder initialization.

Type:

None

compute_component(haplotypes, phenotypes)

Compute the sum of the input components and assign them to the output component.

Parameters:

haplotypesxr.DataArray

Haplotypes.

phenotypesxr.DataArray

Phenotypes.

Returns:

None

static construct_cindexes(phenotype_name, sum_components=['additiveGenetic', 'additiveNoise'], vorigin_relative=[-1], output_component='phenotype', comp_type='outcome')

Construct input and output ComponentIndex objects for SumTransformation.

Parameters:

phenotype_nameIterable

Names of the phenotypes.

sum_componentsIterable, optional (default=[“additiveGenetic”, “additiveNoise”])

Names of the components to be summed.

vorigin_relativeIterable, optional (default=[-1])

Relative origin of the component with respect to the phenotype.

output_componentstr, optional (default=”phenotype”)

Name of the output component.

Returns:

Tuple[xft.index.ComponentIndex, xft.index.ComponentIndex]:

A tuple containing input and output ComponentIndex objects.

static construct_input_cindex(phenotype_name, sum_components=['additiveGenetic', 'additiveNoise'], vorigin_relative=[-1])

Construct input component index.

Parameters:
  • phenotype_name (Iterable) – Phenotype name.

  • sum_components (Iterable, optional) – Components to sum, by default [‘additiveGenetic’, ‘additiveNoise’].

  • vorigin_relative (Iterable, optional) – Relative vorigins, by default [-1].

Returns:

xft.index.ComponentIndex – Component index.

static construct_output_cindex(phenotype_name, sum_components=['additiveGenetic', 'additiveNoise'], vorigin_relative=[-1], comp_type='outcome', output_name='phenotype')

Construct output component index.

Parameters:
  • phenotype_name (Iterable) – Phenotype name.

  • sum_components (Iterable, optional) – Components to sum, by default [‘additiveGenetic’, ‘additiveNoise’].

  • vorigin_relative (Iterable, optional) – Relative vorigins, by default [-1].

  • output_name (str, optional) – Output name, by default ‘phenotype’.

Returns:

xft.index.ComponentIndex – Component index.

xftsim.arch.VerticalComponent

alias of LinearVerticalComponent

class xftsim.arch.ZeroFounderInitialization(component_index=None)

Bases: ConstantFounderInitialization

Founder initialization that sets all haplotypes to zero.