Skip to content

Commit

Permalink
Add clockpr option to specify prior on substitution rate
Browse files Browse the repository at this point in the history
  • Loading branch information
4ment committed Apr 22, 2022
1 parent 910b9a2 commit 18389c6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
7 changes: 5 additions & 2 deletions phylostan/generate_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,8 +1010,11 @@ def get_model(params):
if params.estimate_rate:
if params.clock == 'strict':
parameters_block.append('real <lower=0> rate;')
functions_block.append(ctmc_scale_prior())
model_priors.append('rate ~ ctmc_scale(blensUnscaled);')
if params.clockpr == 'ctmcscale':
functions_block.append(ctmc_scale_prior())
model_priors.append('rate ~ ctmc_scale(blensUnscaled);')
else:
model_priors.append('rate ~ exponential(1000);')
elif params.clock.endswith('mrf'):
transformed_parameters_declarations.append('real substrates[bcount];')
parameters_block.append('real deltas[2*S-3];')
Expand Down
20 changes: 20 additions & 0 deletions phylostan/phylostan.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ def create_build_parser(subprasers, prog, help):
parser.add_argument('--clock', required=False,
choices=['strict', 'ace', 'acln', 'acg', 'aoup', 'ucln', 'uced', 'gmrf', 'hsmrf'], default=None,
help="""Type of clock""")
parser.add_argument('--clockpr', default='ctmcscale',
type=lambda x: distribution_type(x, ('exponential', 'ctmcscale')),
help="""prior on substitution rate [default: %(default)s]""",
)
parser.add_argument('--estimate_rate', action='store_true', help="""Estimate substitution rate""")
parser.add_argument('-c', '--coalescent', choices=['constant', 'skyride', 'skygrid'], default=None,
help="""Type of coalescent (constant or skyride)""")
Expand All @@ -105,6 +109,22 @@ def create_compile_parser(subprasers, prog, help):
return parser


def distribution_type(arg, choices):
"""Used by argparse for specifying distributions with optional
parameters."""
res = arg.split('(')
if (isinstance(choices, tuple) and res[0] in choices) or res[0] == choices:
return arg
else:
if isinstance(choices, tuple):
message = "'" + "','".join(choices) + '"'
else:
message = "'" + choices + "'"
raise argparse.ArgumentTypeError(
'invalid choice (choose from a number or ' + message + ')'
)


def main():
parser_epilog = """To get some information for each sub-command:\n
phylostan build --help
Expand Down

0 comments on commit 18389c6

Please sign in to comment.