Skip to content

Commit 7b1224a

Browse files
committed
Add clockpr option to specify prior on substitution rate
1 parent 910b9a2 commit 7b1224a

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

phylostan/generate_script.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,8 +1010,11 @@ def get_model(params):
10101010
if params.estimate_rate:
10111011
if params.clock == 'strict':
10121012
parameters_block.append('real <lower=0> rate;')
1013-
functions_block.append(ctmc_scale_prior())
1014-
model_priors.append('rate ~ ctmc_scale(blensUnscaled);')
1013+
if params.clockpr == 'ctmcscale':
1014+
functions_block.append(ctmc_scale_prior())
1015+
model_priors.append('rate ~ ctmc_scale(blensUnscaled);')
1016+
else:
1017+
model_priors.append('rate ~ exponential(1000);')
10151018
elif params.clock.endswith('mrf'):
10161019
transformed_parameters_declarations.append('real substrates[bcount];')
10171020
parameters_block.append('real deltas[2*S-3];')
@@ -1189,7 +1192,7 @@ def get_model(params):
11891192
raise ValueError('Supports JC69, HKY and GTR only.')
11901193

11911194
# Tree likelihood
1192-
model_block.append(likelihood(params.categories > 1 or params.invariant, params.clock is not None))
1195+
model_block.append(likelihood2(params.categories > 1 or params.invariant, params.clock is not None))
11931196

11941197
if params.clock is not None:
11951198
model_block.append(jacobian(params.heterochronous))

phylostan/phylostan.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ def create_build_parser(subprasers, prog, help):
8282
parser.add_argument('--clock', required=False,
8383
choices=['strict', 'ace', 'acln', 'acg', 'aoup', 'ucln', 'uced', 'gmrf', 'hsmrf'], default=None,
8484
help="""Type of clock""")
85+
parser.add_argument('--clockpr', default='ctmcscale',
86+
type=lambda x: distribution_type(x, ('exponential', 'ctmcscale')),
87+
help="""prior on substitution rate [default: %(default)s]""",
88+
)
8589
parser.add_argument('--estimate_rate', action='store_true', help="""Estimate substitution rate""")
8690
parser.add_argument('-c', '--coalescent', choices=['constant', 'skyride', 'skygrid'], default=None,
8791
help="""Type of coalescent (constant or skyride)""")
@@ -105,6 +109,22 @@ def create_compile_parser(subprasers, prog, help):
105109
return parser
106110

107111

112+
def distribution_type(arg, choices):
113+
"""Used by argparse for specifying distributions with optional
114+
parameters."""
115+
res = arg.split('(')
116+
if (isinstance(choices, tuple) and res[0] in choices) or res[0] == choices:
117+
return arg
118+
else:
119+
if isinstance(choices, tuple):
120+
message = "'" + "','".join(choices) + '"'
121+
else:
122+
message = "'" + choices + "'"
123+
raise argparse.ArgumentTypeError(
124+
'invalid choice (choose from a number or ' + message + ')'
125+
)
126+
127+
108128
def main():
109129
parser_epilog = """To get some information for each sub-command:\n
110130
phylostan build --help

0 commit comments

Comments
 (0)