tracts.demography.parametrized_demography_sex_biased

Classes

ParametrizedDemographySexBiased([name, ...])

A class representing a demographic history with varying rates of male and female migration.

SexType(suffix, expression)

class tracts.demography.parametrized_demography_sex_biased.ParametrizedDemographySexBiased(name='', min_time=2, max_time=inf, allosome_label=None)

Bases: ParametrizedDemography

A class representing a demographic history with varying rates of male and female migration. Constructs a separate migration matrix for male and female individuals. Each entry represent the proportion of that sex that is replaced during that migration. The matrices are implemented as two subpopulations whose migrations have independent rate parameters but linked time parameters.

__init__(name='', min_time=2, max_time=inf, allosome_label=None)
add_continuous_migration(dest_population, source_population, rate_param, start_param, end_param)

Adds a continuous migration from source population A, parametrized by start_time, end_time, and magnitude.

add_dependent_parameter(param_name, expression, param_type=ParamType.UNTYPED, bounds=None)
add_founder_event(dest_population, source_populations, remainder_population, found_time, end_time=None)

Adds a founder event. A parametrized demography must have exactly one founder event. source_populations is a dict where each key is a population and each value is the name of the parameter defining the migration ratio of each population remainder_population is the source of the remaining migrants, such that the total migration ratio adds up to 1. found_time is the name of the parameter defining the time of migration.

Return type:

None

add_parameter(param_name, param_type=ParamType.UNTYPED, bounds=None)

Adds the given parameter name to the parameters of the model.

add_population(population_name)

Adds the given population name to the populations of the model.

add_pulse_migration(dest_population, source_population, rate_param, time_param)

Adds a pulse migration from source population A, parametrized by time and rate.

check_bounds(params)

Checks the bounds on parameters. Bounds should be absolute restrictions on possible parameter values, whereas constraints should be restrictions on parameter values relative to each other.

check_constraints(params)

Constraints take the form of a dict {'param_subset':Tuple[String], 'expression': lambda (param_subset)}. The violation score is the largest negative value from all the constraints.

events: dict[str:list[BaseMigrationEvent]]
execute_migration_events(migration_matrices, params)
finalize()
founder_events: dict[str, FounderEvent]
free_params: dict[str, Parameter]
get_founding_time(population)
get_index(time_param_name, population_name, params)

Returns the matrix index as a tuple from the position and time. Reduces repetitive code.

get_migration_matrices(params, solve_using_known_proportions=None)

Takes in a list of params equal to the length of free_params and returns a pg migration matrix for each population of interest where p is the number of incoming populations and g is the number of generations. If one of the parameters (time or migration) is incorrect, returns an empty matrix.

Return type:

dict[str, ndarray]

get_param_value(param_name, params)

Gets the correct value from the name of the parameter and the list of passed params. If param_name is a number instead, uses the number directly.

get_random_parameters()
get_violation_score(params)

Takes in a list of params equal to the length of free_params and returns a negative violation score if the resulting matrix would be or is invalid.

property has_been_fixed
insert_params(params, params_from_proportions)

Used for merging the parameters solved by the primary optimizer with the parameters found from the known ancestry proportions into a single list of parameters in the correct order for the model.

is_time_param()
list_parameters()
static load_from_YAML(source)

Creates an instance of ParametrizedDemographySexBiased from a YAML file.

Return type:

ParametrizedDemographySexBiased

logger = <Logger tracts.demography.base_parametrized_demography (WARNING)>
property parameter_bounds
property params_fixed_by_ancestry
static parse_proportions(ancestor_names, proportions)

Parses the ancestry proportions used in a founding event into a dict of parametrized source populations and a remainder population.

Return type:

tuple[dict[slice(<class ‘str’>, <class ‘str’>, None)], str]

proportions_from_matrices(migration_matrices)
proportions_from_matrices_return_keys()

This method returns the expected keys from self.proportions_from_matrices(). It is used by FixedProportionsHandler to validate that the fixed parameter will be solvable from the given data.

static proportions_from_matrix(migration_matrix)
set_up_fixed_ancestry_proportions(params_to_fix, proportions)
class tracts.demography.parametrized_demography_sex_biased.SexType(suffix, expression)

Bases: Enum

FEMALE = ('_female', <function SexType.male_female_sex_type_function.<locals>.<lambda>>)
MALE = ('_male', <function SexType.male_female_sex_type_function.<locals>.<lambda>>)
__init__(suffix, expression)
static male_female_sex_type_function(multiplier)

Returns a function f[multiplier] to compute the sex-specific migration rates. The float paramater refers to male (-1) or female (+1). Given a rate parameter and the accompanying sex bias, f[multiplier](rate, sex_bias) will output a function to compute the corresponding rate in a demography.

Return type:

Callable[[str, str], Callable[[BaseParametrizedDemography, list[float]], float]]