Skip to content

Commit 00b9774

Browse files
fix(tree): check for all synonyms of conflicting default args (#1547)
IQtree2 has multiple synonyms for default args We were only checking for one of the synonyms. This PR fixes that. It also uses the currently preferred name for all IQtree options, where "preferred" is defined as the name shown in `iqtree2 -h` List of changes: `-nt` -> `-T` `--ntmax` -> `--threads-max` `-czb` -> `--polytomy` List of synonyms: `-ntmax`==`--threads-max` `-s`==`--aln`==`--msa` `-m`==`--model`
1 parent 2e993df commit 00b9774

File tree

5 files changed

+46
-16
lines changed

5 files changed

+46
-16
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
* ancestral, translate: Add `--skip-validation` as an alias to `--validation-mode=skip`. [#1656][] (@victorlin)
88
* clades: Allow customizing the validation of input node data JSON files with `--validation-mode` and `--skip-validation`. [#1656][] (@victorlin)
9+
* tree: When using iqtree, check for all synonyms of default args when detecting potential conflicts, e.g. `--threads-max` is equivalent to `-ntmax`. Previously, we were only checking for the latter. Also use new, preferred IQtree2 option names (e.g. `--polytomy` instead of `-czb` etc.). [#1547][] (@corneliusroemer)
910

1011
### Bug Fixes
1112

1213
* index: Previously specifying a directory that does not exist in the path to `--output` would result in an incorrect error stating that the input file does not exist. It now shows the correct path responsible for the error. [#1644][] (@victorlin)
1314
* curate format-dates: Update help docs and improve failure messages to show use of `--expected-date-formats`. [#1653][] (@joverlee521)
1415

1516
[#1644]: https://github.com/nextstrain/augur/issues/1644
17+
[#1547]: https://github.com/nextstrain/augur/pull/1547
1618
[#1653]: https://github.com/nextstrain/augur/pull/1653
1719
[#1656]: https://github.com/nextstrain/augur/pull/1656
1820

augur/tree.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@
2828
# For compat with older versions of iqtree, we avoid the newish -fast
2929
# option alias and instead spell out its component parts:
3030
#
31-
# -ninit 2
31+
# --ninit 2
3232
# -n 2
33-
# -me 0.05
33+
# --epsilon 0.05
3434
#
3535
# This may need to be updated in the future if we want to stay in lock-step
3636
# with -fast, although there's probably no particular reason we have to.
3737
# Refer to the handling of -fast in utils/tools.cpp:
3838
# https://github.com/Cibiv/IQ-TREE/blob/44753aba/utils/tools.cpp#L2926-L2936
39-
# Increasing threads (nt) can cause IQtree to run longer, hence use AUTO by default
40-
# Auto makes IQtree chose the optimal number of threads
41-
# Redo prevents IQtree errors when a run was aborted and restarted
42-
"iqtree": "-ninit 2 -n 2 -me 0.05 -nt AUTO -redo",
39+
# Increasing threads (-T) can cause IQtree to run longer, hence use AUTO by default
40+
# -T AUTO makes IQtree chose the optimal number of threads
41+
# --redo prevents IQtree errors when a run was aborted and restarted
42+
"iqtree": "--ninit 2 -n 2 --epsilon 0.05 -T AUTO --redo",
4343
}
4444

4545
# IQ-TREE only; see usage below
@@ -71,12 +71,12 @@ def check_conflicting_args(tree_builder_args, defaults):
7171
7272
Examples
7373
--------
74-
>>> defaults = ("-ntmax", "-m", "-s")
75-
>>> check_conflicting_args("-czb -n 2", defaults)
76-
>>> check_conflicting_args("-czb -ntmax 2", defaults)
74+
>>> defaults = ("--threads-max", "-m", "-s")
75+
>>> check_conflicting_args("--polytomy -n 2", defaults)
76+
>>> check_conflicting_args("--polytomy --threads-max 2", defaults)
7777
Traceback (most recent call last):
7878
...
79-
augur.tree.ConflictingArgumentsException: The following tree builder arguments conflict with hardcoded defaults. Remove these arguments and try again: -ntmax
79+
augur.tree.ConflictingArgumentsException: The following tree builder arguments conflict with hardcoded defaults. Remove these arguments and try again: --threads-max
8080
8181
"""
8282
# Parse tree builder argument string into a list of shell arguments. This
@@ -261,13 +261,27 @@ def random_string(n):
261261
ofile.write(tmp_line)
262262

263263
# Check tree builder arguments for conflicts with hardcoded defaults.
264-
check_conflicting_args(tree_builder_args, ("-ntmax", "-s", "-m"))
264+
check_conflicting_args(tree_builder_args, (
265+
# -ntmax/--threads-max are synonyms
266+
# see https://github.com/iqtree/iqtree2/blob/74da454bbd98d6ecb8cb955975a50de59785fbde/utils/tools.cpp#L4882-L4883
267+
"-ntmax",
268+
"--threads-max",
269+
# -s/--aln/--msa are synonyms
270+
# see https://github.com/iqtree/iqtree2/blob/74da454bbd98d6ecb8cb955975a50de59785fbde/utils/tools.cpp#L2370-L2371
271+
"-s",
272+
"--aln",
273+
"--msa",
274+
# --model/-m are synonyms
275+
# see https://github.com/iqtree/iqtree2/blob/74da454bbd98d6ecb8cb955975a50de59785fbde/utils/tools.cpp#L3232-L3233
276+
"-m",
277+
"--model",
278+
))
265279

266280
if substitution_model.lower() != "auto":
267-
call = [iqtree, "-ntmax", str(nthreads), "-s", shquote(tmp_aln_file),
281+
call = [iqtree, "--threads-max", str(nthreads), "-s", shquote(tmp_aln_file),
268282
"-m", shquote(substitution_model), tree_builder_args, ">", shquote(log_file)]
269283
else:
270-
call = [iqtree, "-ntmax", str(nthreads), "-s", shquote(tmp_aln_file), tree_builder_args, ">", shquote(log_file)]
284+
call = [iqtree, "--threads-max", str(nthreads), "-s", shquote(tmp_aln_file), tree_builder_args, ">", shquote(log_file)]
271285

272286
cmd = " ".join(call)
273287

@@ -425,7 +439,7 @@ def register_parser(parent_subparsers):
425439
parser.add_argument('--vcf-reference', type=str, help='fasta file of the sequence the VCF was mapped to')
426440
parser.add_argument('--exclude-sites', type=str, help='file name of one-based sites to exclude for raw tree building (BED format in .bed files, second column in tab-delimited files, or one position per line)')
427441
parser.add_argument('--tree-builder-args', type=str, help=f"""arguments to pass to the tree builder either augmenting or overriding the default arguments (except for input alignment path, number of threads, and substitution model).
428-
Use the assignment operator (e.g., --tree-builder-args="-czb" for IQ-TREE) to avoid unexpected errors.
442+
Use the assignment operator (e.g., --tree-builder-args="--polytomy" for IQ-TREE) to avoid unexpected errors.
429443
FastTree defaults: "{DEFAULT_ARGS['fasttree']}".
430444
RAxML defaults: "{DEFAULT_ARGS['raxml']}".
431445
IQ-TREE defaults: "{DEFAULT_ARGS['iqtree']}".
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Setup
2+
3+
$ source "$TESTDIR"/_setup.sh
4+
5+
Build a tree with conflicting default arguments.
6+
Expect error message.
7+
8+
$ ${AUGUR} tree \
9+
> --method iqtree \
10+
> --alignment "$TESTDIR/../data/aligned.fasta" \
11+
> --tree-builder-args="--threads-max 1 --msa $TESTDIR/../data/aligned.fasta" \
12+
> --output "tree_raw.nwk"
13+
ERROR: The following tree builder arguments conflict with hardcoded defaults. Remove these arguments and try again: --threads-max, --msa
14+
[1]

tests/functional/tree/cram/iqtree-extend-args.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ Build a tree, augmenting existing default arguments with custom arguments.
77
$ ${AUGUR} tree \
88
> --method iqtree \
99
> --alignment "$TESTDIR/../data/aligned.fasta" \
10-
> --tree-builder-args="-czb" \
10+
> --tree-builder-args="--polytomy" \
1111
> --output tree_raw.nwk > /dev/null

tests/functional/tree/cram/iqtree-override-args.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ Since the following custom arguments are incompatible with the default IQ-TREE a
88
$ ${AUGUR} tree \
99
> --method iqtree \
1010
> --alignment "$TESTDIR/../data/full_aligned.fasta" \
11-
> --tree-builder-args="-czb -bb 1000 -bnni" \
11+
> --tree-builder-args="--polytomy -bb 1000 -bnni" \
1212
> --override-default-args \
1313
> --output tree_raw.nwk > /dev/null

0 commit comments

Comments
 (0)