Skip to content

Commit

Permalink
[refine] add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshadfield committed Feb 11, 2025
1 parent 92d08b5 commit 701d6ee
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/functional/refine/cram/rooting-invalid.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Setup

$ source "$TESTDIR"/_setup.sh

Attempt to root on a strain which is not in the tree is an error
$ ${AUGUR} refine \
> --tree "$TESTDIR/../data/tree_raw.nwk" --metadata "$TESTDIR/../data/metadata.tsv" --alignment "$TESTDIR/../data/aligned.fasta" \
> --output-tree tree.nwk --output-node-data branch_lengths.json \
> --root not-in-tree > /dev/null
ERROR: Rooting with the provided strain name(s) failed.
This is probably because the following names supplied to '--root' were not found in the tree:
- 'not-in-tree'

[2]

Check that rooting on multiple (valid) sequences + '--remove-outgroup' is an error
$ ${AUGUR} refine \
> --tree "$TESTDIR/../data/tree_raw.nwk" --metadata "$TESTDIR/../data/metadata.tsv" --alignment "$TESTDIR/../data/aligned.fasta" \
> --output-tree tree.nwk --output-node-data branch_lengths.json \
> --root 'Colombia/2016/ZC204Se' 'VEN/UF_1/2016' --remove-outgroup > /dev/null
ERROR: --remove-outgroup is not valid when rooting on multiple strains
[2]
24 changes: 24 additions & 0 deletions tests/functional/refine/cram/rooting-outgroup.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Setup

$ source "$TESTDIR"/_setup.sh

Check that rooting on an outgroup strain actually works
$ ${AUGUR} refine \
> --tree "$TESTDIR/../data/tree_raw.nwk" --metadata "$TESTDIR/../data/metadata.tsv" --alignment "$TESTDIR/../data/aligned.fasta" \
> --output-tree tree1.nwk --output-node-data branch_lengths1.json \
> --root 'Colombia/2016/ZC204Se' > /dev/null

$ python3 "$TESTDIR/../report-root.py" tree1.nwk
Tree root has a single terminal child 'Colombia/2016/ZC204Se'

Check that rooting on an outgroup strain with '--remove-outgroup' does remove it
$ ${AUGUR} refine \
> --tree "$TESTDIR/../data/tree_raw.nwk" --metadata "$TESTDIR/../data/metadata.tsv" --alignment "$TESTDIR/../data/aligned.fasta" \
> --output-tree tree2.nwk --output-node-data branch_lengths2.json \
> --root 'Colombia/2016/ZC204Se' --remove-outgroup > /dev/null

$ grep 'Colombia/2016/ZC204Se' tree2.nwk
[1]

$ python3 "$TESTDIR/../report-root.py" tree2.nwk
No children of the root were terminal nodes
11 changes: 11 additions & 0 deletions tests/functional/refine/report-root.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import sys
from augur.utils import read_tree

T = read_tree(sys.argv[1])
root_child_tips = [c for c in T.root.clades if c.is_terminal()]
if len(root_child_tips)==0:
print("No children of the root were terminal nodes")
elif len(root_child_tips)>1:
print("Multiple children of the root were terminal nodes")
else:
print(f"Tree root has a single terminal child {root_child_tips[0].name!r}")

0 comments on commit 701d6ee

Please sign in to comment.