Skip to content

Commit

Permalink
Add fixed ancestral size for structure model
Browse files Browse the repository at this point in the history
  • Loading branch information
noscode committed May 30, 2024
1 parent f4c22c5 commit 6bc50ca
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
26 changes: 26 additions & 0 deletions gadma/cli/settings_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,14 @@ def get_model(self):
)
constrain = self.get_linear_constrain_for_model(model)
model.linear_constrain = constrain
if self.fixed_ancestral_size:
if self.ancestral_size_as_parameter is not None:
ValueError(
"Option `Fixed ancestral size` is set, please set "
"`Ancestral size as parameter` to True"
)
model.fix_variable(model.Nanc_size, self.fixed_ancestral_size)
model.Nanc_size = self.fixed_ancestral_size
return model
elif ((self.custom_filename is not None or
self.model_func is not None) and
Expand Down Expand Up @@ -1787,6 +1795,24 @@ def is_valid(self):
"`Lower bound of second split` should be less than `Upper"
" bound of first split`"
)
if self.fixed_ancestral_size is not None:
# check that mu and L are given
if self.sequence_length is None:
raise ValueError(
"`Sequence length` should be specified in order to use "
"fixed ancestral size."
)
if self.mutation_rate is None:
raise ValueError(
"`Mutation rate` should be specified in order to use "
"fixed ancestral size."
)
if not self.ancestral_size_as_parameter:
self.ancestral_size_as_parameter = True
warnings.warn(
"Option `Ancestral sizea as parameter` is set to True, "
"as fixed ancestral population size is used."
)

def print_citations(self):
"""
Expand Down
4 changes: 4 additions & 0 deletions gadma/models/demographic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ def fix_variable(self, variable, value):
:param variable: Variable to fix.
:param value: Value of the variable to fix.
"""
# check for ancestral population size
if variable == self.Nanc_size:
super(DemographicModel, self).fix_variable(variable, value)
return
for event in self.events:
if variable in event.variables:
event.fix_variable(variable, value)
Expand Down

0 comments on commit 6bc50ca

Please sign in to comment.