From 89030f8ea96b93a89638959336691eecfd28fa90 Mon Sep 17 00:00:00 2001 From: asetGem <amandine.perrin@pasteur.fr> Date: Mon, 9 Nov 2020 15:23:05 +0100 Subject: [PATCH] Default is iqtree2. if iqtree1, specify it --- PanACoTA/subcommands/tree.py | 30 +++++++++++++---------- PanACoTA/tree_module/iqtree_func.py | 32 ++++++++++++++++--------- test/test_unit/test_tree/test_iqtree.py | 11 +++++---- 3 files changed, 45 insertions(+), 28 deletions(-) diff --git a/PanACoTA/subcommands/tree.py b/PanACoTA/subcommands/tree.py index b0d24abe..d4a0a06e 100755 --- a/PanACoTA/subcommands/tree.py +++ b/PanACoTA/subcommands/tree.py @@ -116,18 +116,22 @@ def main(cmd, align, outdir, soft, model, threads, boot=False, write_boot=False, print("quicktree is not installed. 'PanACoTA tree' cannot run.") sys.exit(1) from PanACoTA.tree_module import quicktree_func as tree - elif soft == "iqtree": - if not utils.check_installed("iqtree"): # pragma: no cover - if not utils.check_installed("iqtree2"): - print("IQtree is not installed. 'PanACoTA tree' cannot run.") - sys.exit(1) - else: - soft == "iqtree2" - from PanACoTA.tree_module import iqtree_func as tree elif soft == "iqtree2": + # by default, iqtree2 (not iqtree). + # So, if user did not specify, it means iqtree2. But if 'iqtree2' command + # does not exist, use iqtree command instead. # test if iqtree2 is installed and in the path if not utils.check_installed("iqtree2"): # pragma: no cover - print("iqtree2 is not installed. 'PanACoTA tree' cannot run.") + if not utils.check_installed("iqtree"): + print("IQtree2 is not installed. 'PanACoTA tree' cannot run.") + sys.exit(1) + else: + soft == "iqtree" + from PanACoTA.tree_module import iqtree_func as tree + elif soft == "iqtree": + # user specifically asked for iqtree (version 1) + if not utils.check_installed("iqtree"): # pragma: no cover + print("IQtree is not installed. 'PanACoTA tree' cannot run.") sys.exit(1) from PanACoTA.tree_module import iqtree_func as tree @@ -179,11 +183,13 @@ def build_parser(parser): help=("Directory where tree results will be saved. ")) # Choose with which soft inferring phylogenetic tree - softparse = parser.add_argument_group('Choose soft to use (default is IQtree)') + softparse = parser.add_argument_group('Choose soft to use (default is IQtree2)') softs = ["fasttree", "fastme", "quicktree", "iqtree", "iqtree2"] - softparse.add_argument("-s", "--soft", dest="soft", choices=softs, default="iqtree", + softparse.add_argument("-s", "--soft", dest="soft", choices=softs, default="iqtree2", help=("Choose with which software you want to infer the " - "phylogenetic tree. Default is IQtree.")) + "phylogenetic tree. Default is IQtree2 " + "(versions 2.x of IQtree). If you want version 1.x of " + "IQtree, use '-s iqtree'")) optional = parser.add_argument_group('Optional arguments') optional.add_argument("-b", "--boot", dest="boot", type=int, diff --git a/PanACoTA/tree_module/iqtree_func.py b/PanACoTA/tree_module/iqtree_func.py index 980f0ab6..282d9ada 100644 --- a/PanACoTA/tree_module/iqtree_func.py +++ b/PanACoTA/tree_module/iqtree_func.py @@ -91,17 +91,27 @@ def run_tree(alignfile, boot, outdir, quiet, threads, **kwargs): mem_info = "" threadinfo = "" - # Get info on all options - if boot and soft=="iqtree": - bootinfo = f"-bb {boot}" - elif boot: - bootinfo = f"-B {boot}" - if write_boot and soft == "iqtree": - wb_info = "-wbt" - elif write_boot: - wb_info = "--boot-trees" + # Get info on all options (syntax changes according to IQtree version 1.x or 2.x) + if boot: + if soft=="iqtree": + bootinfo = f"-bb {boot}" + else: + bootinfo = f"-B {boot}" + if write_boot: + if soft == "iqtree": + wb_info = "-wbt" + else: + wb_info = "--boot-trees" if memory: - mem_info = f"-mem {memory}" + if soft=="iqtree": + mem_info = f"-mem {memory}" + else: + mem_info = f"--mem {memory}" + # IQtree is always run quietly, but syntax depends on version: + if soft=="iqtree": + qu = "-quiet" + else: + qu = "--quiet" # Get threads information if threads: if soft == "iqtree": @@ -125,7 +135,7 @@ def run_tree(alignfile, boot, outdir, quiet, threads, **kwargs): else: prefix = f"--prefix {treefile}" cmd = (f"{soft} -s {alignfile} {threadinfo} -m {model} {mem_info} {bootinfo} {wb_info} " - f"{seqtype} {prefix} -quiet {fast}") + f"{seqtype} {prefix} {qu} {fast}") logger.details("IQtree command: " + cmd) if quiet: fnull = open(os.devnull, 'w') diff --git a/test/test_unit/test_tree/test_iqtree.py b/test/test_unit/test_tree/test_iqtree.py index aec93da4..993c7920 100644 --- a/test/test_unit/test_tree/test_iqtree.py +++ b/test/test_unit/test_tree/test_iqtree.py @@ -99,7 +99,7 @@ def test_run_iqtree2_default(caplog): assert ("iqtree2 -s test/data/align/exp_files/exp_pers4genomes.grp.aln " "-T 1 -m GTR --seqtype DNA " "--prefix test/data/tree/generated_by_unit-tests/exp_pers4genomes.grp.aln.iqtree_tree " - "-quiet") in caplog.text + "--quiet") in caplog.text assert tutil.is_tree_lengths(treefile) assert not tutil.is_tree_bootstrap(treefile) @@ -183,7 +183,7 @@ def test_run_iqtree2_boot_write_boot(caplog): assert ("iqtree2 -s test/data/align/exp_files/exp_pers4genomes.grp.aln " "-T 1 -m GTR -B 1000 --boot-trees --seqtype DNA " "--prefix test/data/tree/generated_by_unit-tests/exp_pers4genomes.grp.aln.iqtree_tree " - "-quiet") in caplog.text + "--quiet") in caplog.text assert not tutil.is_tree_lengths(treefile) assert tutil.is_tree_bootstrap(treefile) @@ -236,9 +236,10 @@ def test_run_iqtree2_fast_mem_quiet(caplog): logs = os.path.join(GENEPATH, "exp_pers4genomes.grp.aln.iqtree_tree.log") assert os.path.isfile(logs) assert "Running IQtree..." in caplog.text - assert ("iqtree2 -s test/data/align/exp_files/exp_pers4genomes.grp.aln " - "-T 1 -m GTR -mem 4GB --seqtype DNA " + assert ("iqtree2 -s test/data/align/exp_files/exp_pers4genomes.grp.aln -T 1 " + "-m GTR --mem 4GB --seqtype DNA " "--prefix test/data/tree/generated_by_unit-tests/exp_pers4genomes.grp.aln.iqtree_tree " - "-quiet -fast") in caplog.text + "--quiet -fast") in caplog.text assert tutil.is_tree_lengths(treefile) assert not tutil.is_tree_bootstrap(treefile) + -- GitLab