Skip to content

Commit

Permalink
Merge pull request #505 from GavinHuttley/develop
Browse files Browse the repository at this point in the history
BUG: hypothesis_result.select_models handles nested codon models, fixes #504
  • Loading branch information
GavinHuttley committed Jan 28, 2020
2 parents 312fff6 + 2ae695d commit 2bd3f68
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/cogent3/app/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,13 @@ def select_models(self, stat="aicc", threshold=0.05):
assert stat in ("aicc", "aic")
second_order = stat == "aicc"
results = []
for k, m in self.items():
val = m.lf.get_aic(second_order=second_order)
for m in self.values():
if isinstance(m.lf, dict):
# multiple lf's, e.g. split codon position analyses have 3
val = sum(lf.get_aic(second_order=second_order) for lf in m.lf.values())
else:
val = m.lf.get_aic(second_order=second_order)

results.append((val, m))
results.sort()
min_model = results.pop(0)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_app/test_evo.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,22 @@ def test_null_hyp_fail_error(self):
r = hyp(aln)
self.assertEqual(r.origin, "model")

def test_hyp_split_codon_select_models(self):
"""hypothesis_result identifies selects best model when split_codon"""
_data = {
"Human": "ATGCGGCTCGCGGAGGCCGCGCTCGCGGAG",
"Mouse": "ATGCCCGGCGCCAAGGCAGCGCTGGCGGAG",
"Opossum": "ATGCCAGTGAAAGTGGCGGCGGTGGCTGAG",
}
aln = make_aligned_seqs(data=_data, moltype="dna")
opt_args = dict(max_evaluations=10, limit_action="ignore")
m1 = evo_app.model("F81", split_codons=True, opt_args=opt_args)
m2 = evo_app.model("GTR", split_codons=True, opt_args=opt_args)
hyp = evo_app.hypothesis(m1, m2)
r = hyp(aln)
bm = r.select_models()
assert_allclose(bm[0].lnL, -85.00043312185628)

def test_alt_hyp_fail_error(self):
"""if alt fails NotCompleted.origin should be model"""
_data = {
Expand Down

0 comments on commit 2bd3f68

Please sign in to comment.