Models (models package)¶
Base class Model¶
-
class
gadma.models.model.
Model
(raise_excep=False)¶ Bases:
object
Abstract class of model. Contains variables of class
Variable
.- Parameters
raise_excep (bool) – if True then raises exception when something except
Variable
is added as variable.
-
add_variable
(variable)¶ Adds one variable to the model.
- Parameters
variable (
Variable
) – variable to add.
-
add_variables
(variables)¶ Adds several variables to the model.
- Parameters
variables (list) – variables to add.
-
fix_variable
(variable, value)¶
-
get_variable
(name)¶ Finds the variable of the model by its name.
- Parameters
name (str) – name of the model’s variable.
- Raises
ValueError – if there is no variable with that name.
-
string_repr
(values)¶ Returns string representation of variables and values.
- Parameters
values – Values of the variables in model.
-
unfix_if_fixed
(variable)¶
-
unfix_variable
(variable)¶
-
var2value
(values)¶ Returns dictionary {variable: value}.
- Parameters
values – List or dict {var_name: value} of values.
-
property
variables
¶
Combinations of variables¶
Base class VariablesCombination¶
-
class
gadma.models.variables_combinations.
VariablesCombination
¶ Bases:
gadma.models.model.Model
Base class for combination of variables.
Base class BinaryOperation¶
-
class
gadma.models.variables_combinations.
BinaryOperation
(arg1, arg2)¶ Bases:
gadma.models.variables_combinations.VariablesCombination
Combination of two variables.
- Parameters
arg1 (
gadma.Variable
or value.) – First argument.arg2 (
gadma.Variable
or value.) – Second argument.
- Raises
AssertError – if both arguments are not variables.
-
get_value
(values)¶ Returns value of the combination from variables values.
- Parameters
values (list of dict) – Values of the variables.
-
property
name
¶ Generates name from variables names like: self.arg1.name operation self.arg1.name
-
operation
(val1, val2)¶ Returns the result of binary operation from two values.
-
operation_str
()¶ Returns string representation of binary operation.
-
string_repr
(values)¶ Returns string representation of combination with defined values.
- Parameters
values (list of dict) – Values of the variables.
Classes of different binary operations¶
-
class
gadma.models.variables_combinations.
Addition
(arg1, arg2)¶ Bases:
gadma.models.variables_combinations.BinaryOperation
The sum of two variables.
-
operation
(val1, val2)¶ Returns the result of binary operation from two values.
-
operation_str
()¶ Returns string representation of binary operation.
-
-
class
gadma.models.variables_combinations.
Division
(arg1, arg2)¶ Bases:
gadma.models.variables_combinations.BinaryOperation
The division of one variable by another.
-
operation
(val1, val2)¶ Returns the result of binary operation from two values.
-
operation_str
()¶ Returns string representation of binary operation.
-
-
class
gadma.models.variables_combinations.
Multiplication
(arg1, arg2)¶ Bases:
gadma.models.variables_combinations.BinaryOperation
The multiplication of two variables.
-
operation
(val1, val2)¶ Returns the result of binary operation from two values.
-
operation_str
()¶ Returns string representation of binary operation.
-
-
class
gadma.models.variables_combinations.
Subtraction
(arg1, arg2)¶ Bases:
gadma.models.variables_combinations.BinaryOperation
The subtraction of two variables.
-
operation
(val1, val2)¶ Returns the result of binary operation from two values.
-
operation_str
()¶ Returns string representation of binary operation.
-
Events¶
-
class
gadma.models.event.
Epoch
(time_arg, init_size_args, size_args, mig_args=None, dyn_args=None, sel_args=None, dom_args=None)¶ Bases:
gadma.models.event.Event
Epoch for demographic model. All arguments could be both values and some variables. Additionally values could be combinations of the variables (see
gadma.models.VariablesCombinations
).- Parameters
time_arg (float or
gadma.TimeVariable
) – Time of the epoch.init_size_args (list of values and/or
gadma.PopulationSizeVariable
) – Sizes of populations at the beginning of the epoch.size_args (list of values and/or
gadma.PopulationSizeVariable
) – Sizes of populations at the end of the epoch.mig_args (2d list of values and/or
gadma.MigrationVariable
) – Migration rates between populations.dyn_args (list of values and/or
gadma.DynamicVariable
) – Dynamics of population size changes during the epoch.sel_args (list of values and/or
gadma.SelectionVariable
) – Selection rates for each population during the epoch.
-
as_custom_string
(values)¶ Returns string representation of the event.
-
get_vars_not_in_init_args
()¶
-
class
gadma.models.event.
Event
¶ Bases:
gadma.models.model.Model
Base class for some event.
-
as_custom_string
(values)¶ Returns string representation of the event.
-
-
class
gadma.models.event.
Split
(pop_to_div, size_args=None)¶ Bases:
gadma.models.event.Event
Class for split demographic event.
- Parameters
pop_to_div – Population index that splits.
size_args – Sizes of populations after split.
-
as_custom_string
(values)¶ Returns string representation of the event.
Demographic models¶
Base class DemographicModel¶
-
class
gadma.models.demographic_model.
DemographicModel
(gen_time=None, theta0=None, mu=None, linear_constrain=None)¶ Bases:
gadma.models.model.Model
Base class for demographic model.
- Parameters
gen_time (float) – Time of one generation.
theta0 (float) – Mutation flux (4 * mu * L, where L - length of sequence).
mu (float) – Mutation rate per base per generation.
linear_constrain (
gadma.optimizers.LinearConstrain
) – linear constrain on parameters.
-
as_custom_string
(values)¶ Returns string representation of the demographic model with parameters as a list with variables and their values.
- Parameters
values – Values of the demographic model.
-
get_number_of_parameters
(values)¶ Returns number of parameters of the model.
-
translate_units
(values, Nanc, Tg=1)¶ Translates values from genetic units to physical.
- Parameters
values – Values of parameters.
Nanc – Size of ancestral population.
Tg – Time per generation.
Class EpochDemographicModel¶
-
class
gadma.models.demographic_model.
EpochDemographicModel
(gen_time=None, theta0=None, mu=None, linear_constrain=None)¶ Bases:
gadma.models.demographic_model.DemographicModel
Class for demographic model of epoch type. This type is common for
dadi
andmoments
.See
gadma.models.DemographicModel
for constructor docs.-
add_epoch
(time_arg, size_args, mig_args=None, dyn_args=None, sel_args=None, dom_args=None)¶ Adds new epoch to the demographic model events.
- Parameters
time_arg – time of the epoch.
size_args – population sizes at the end of the epoch.
mig_args – migrations between populations during the epoch.
dyn_args – dynamics of the populations during the epoch.
sel_args – selection coefficients of the populations during the epoch.
dom_args – dominance coefficients.
- Note
all arguments could contain variables of
Variable
class as well as different constants/values includinggadma.models.BinaryOperation
instances.
-
add_split
(pop_to_div, size_args)¶ Adds new split to the demographic model events.
- Parameters
pop_to_div – population to divide.
size_args – population sizes of two subpopulations after the split.
-
as_custom_string
(values)¶ Returns string representation of the demographic model with parameters.
- Parameters
values – Values of the demographic model.
-
fix_dynamics
(values)¶ Makes all dynamics in events fixed.
- Parameters
values (list or dict) – Values of parameters to take for fixation.
-
fix_variable
(variable, value)¶ Fixes variable in the model to the value.
- Parameters
variable – Variable to fix.
value – Value of the variable to fix.
-
get_involved_for_split_time_vars
(n_split)¶ Returns list of ints and bias. If value > 0 then this variable is involved in sum of times for split.
It will return A, b: Ax + b = time of n_split split.
-
get_number_of_parameters
(values)¶ Returns number of parameters of the model. Be careful as this number could be different to the number of variables. According to the population size dynamics in values some variables could have no influence on the model and in this case they are not counted.
- Parameters
values (list or dict) – Values of the parameters. Dynamics makes the most sense.
-
number_of_populations
()¶ Returns number of populations in the model.
-
unfix_dynamics
()¶ Makes all dynamics in events unfixed.
-
unfix_variable
(variable)¶ Unfixes the variable of the model.
-
Class StructureDemographicModel¶
-
class
gadma.models.structure_demographic_model.
StructureDemographicModel
(initial_structure, final_structure, have_migs, have_sels, have_dyns, sym_migs, frac_split, gen_time=None, theta0=None, mu=None)¶ Bases:
gadma.models.demographic_model.EpochDemographicModel
Special class for demographic model created by structure.
- Parameters
initial_structure (list of ints) – List of ints with number of intervals in initial structure.
final_structure (list of ints) – List of ints with number of intervals in final structure.
have_migs (bool) – If True then model will have migrations.
have_sels (bool) – If True then model will have selection coefficients.
have_dyns (bool) – If True then model will create dynamics of size change different to Sudden change.
sym_migs (bool) – If True then migrations will be symetric.
frac_split (bool) – If True then populations split in some proportion. If False then newly formed population has size as an independent variable.
-
from_structure
(structure)¶ Creates new model from given structure. It is base constructor of the model.
- Parameters
structure (list of ints) – Structure of the model.
-
get_structure
()¶ Returns current structure of the model.
-
increase_structure
(new_structure=None, X=None)¶ Increase structure of the model. Raises ValueError if structure is equal or greater than final_structure.
- Parameters
new_structure – New structure for the model. Should be greater by 1 in one element. E.g. structure is (1,2), then new structure could be either (2,2) or (1,3). If None random available element is chosen to increase.
X – list of values to transform as values of new model.
- Note
Function is specific for
gadma.models.StructureDemographicModel
. It probably will not work for any other class.
-
transform_values_from_other_model
(model, x)¶
Class CustomDemographicModel¶
-
class
gadma.models.custom_demographic_model.
CustomDemographicModel
(function, variables, gen_time=None, theta0=None, mu=None)¶ Bases:
gadma.models.demographic_model.DemographicModel
Demographic model that was defined by the user in some file. Engines should be able to deal with such kind of models.
- Parameters
function – function that creates the demographic model or something like that.
variables – Variables of the function. I.e. model parameters.
gen_time – Time of one generation.
theta0 – Mutation flux. See
gadma.models.DemographicModel
for more information.mu – Mutation rate. See
gadma.models.DemographicModel
for more information.