예제 #1
0
def iqtree_ultrafast_bootstrap(
        alignment: AlignedDNAFASTAFormat,
        seed: int = _iqtree_defaults['seed'],
        n_cores: int = _iqtree_defaults['n_cores'],
        n_cores_max: int = _iqtree_defaults['n_cores_max'],
        n_runs: int = _iqtree_defaults['n_runs'],
        substitution_model: str = _iqtree_defaults['substitution_model'],
        bootstrap_replicates: int = _iqtree_defaults['bootstrap_replicates'],
        n_init_pars_trees: int = _iqtree_defaults['n_init_pars_trees'],
        n_top_init_trees: int = _iqtree_defaults['n_top_init_trees'],
        n_best_retain_trees: int = _iqtree_defaults['n_best_retain_trees'],
        stop_iter: int = _iqtree_defaults['stop_iter'],
        perturb_nni_strength: float = _iqtree_defaults['perturb_nni_strength'],
        spr_radius: int = _iqtree_defaults['spr_radius'],
        n_max_ufboot_iter: int = _iqtree_defaults['n_max_ufboot_iter'],
        n_ufboot_steps: int = _iqtree_defaults['n_ufboot_steps'],
        min_cor_ufboot: float = _iqtree_defaults['min_cor_ufboot'],
        ep_break_ufboot: float = _iqtree_defaults['ep_break_ufboot'],
        allnni: bool = _iqtree_defaults['allnni'],
        alrt: int = _iqtree_defaults['alrt'],
        abayes: bool = _iqtree_defaults['abayes'],
        lbp: int = _iqtree_defaults['lbp'],
        bnni: bool = _iqtree_defaults['bnni'],
        safe: bool = _iqtree_defaults['safe']) -> NewickFormat:
    # NOTE: the IQ-TREE commands `-n` (called as `n_iter` in the `iqtree`
    # method) and `-fast` are not compatable with ultrafast_bootstrap `-bb`.
    result = NewickFormat()

    with tempfile.TemporaryDirectory() as temp_dir:
        run_prefix = os.path.join(temp_dir, 'q2iqtreeufboot')
        cmd = _build_iqtree_ufbs_command(
            alignment,
            seed=seed,
            n_cores=n_cores,
            n_cores_max=n_cores_max,
            n_runs=n_runs,
            substitution_model=substitution_model,
            bootstrap_replicates=bootstrap_replicates,
            run_prefix=run_prefix,
            n_init_pars_trees=n_init_pars_trees,
            n_top_init_trees=n_top_init_trees,
            n_best_retain_trees=n_best_retain_trees,
            stop_iter=stop_iter,
            perturb_nni_strength=perturb_nni_strength,
            spr_radius=spr_radius,
            n_max_ufboot_iter=n_max_ufboot_iter,
            n_ufboot_steps=n_ufboot_steps,
            min_cor_ufboot=min_cor_ufboot,
            ep_break_ufboot=ep_break_ufboot,
            allnni=allnni,
            alrt=alrt,
            abayes=abayes,
            lbp=lbp,
            bnni=bnni,
            safe=safe)
        run_command(cmd)
        tree_tmp_fp = os.path.join(temp_dir, '%s.treefile' % run_prefix)
        os.rename(tree_tmp_fp, str(result))

    return result
예제 #2
0
    def test_run_rapid_bs_not_verbose(self):
        input_fp = self.get_data_path('aligned-dna-sequences-3.fasta')
        input_sequences = AlignedDNAFASTAFormat(input_fp, mode='r')
        aligned_fp = str(input_sequences)

        with tempfile.TemporaryDirectory() as temp_dir:
            cmd = ['raxmlHPC',
                   '-m', 'GTRGAMMA',
                   '-p', '1723',
                   '-s', aligned_fp,
                   '-w', temp_dir,
                   '-n', 'q2',
                   '-f', 'a',
                   '-x', '9834',
                   '-N', '10']

            with redirected_stdio(stderr=os.devnull):
                run_command(cmd, verbose=False)

            obs_tree_fp = os.path.join(temp_dir, 'RAxML_bipartitions.q2')
            obs_tree = skbio.TreeNode.read(str(obs_tree_fp),
                                           convert_underscores=False)
        # load the resulting tree and test that it has the right number of
        # tips and the right tip ids
        tips = list(obs_tree.tips())
        tip_names = [t.name for t in tips]
        self.assertEqual(set(tip_names),
                         set(['GCA001510755', 'GCA001045515',
                              'GCA000454205', 'GCA000473545',
                              'GCA000196255', 'GCA000686145',
                              'GCA001950115', 'GCA001971985',
                              'GCA900007555']))
예제 #3
0
    def test_run_rapid_bs_not_verbose(self):
        input_fp = self.get_data_path('aligned-dna-sequences-3.fasta')
        input_sequences = AlignedDNAFASTAFormat(input_fp, mode='r')
        aligned_fp = str(input_sequences)

        with tempfile.TemporaryDirectory() as temp_dir:
            cmd = ['raxmlHPC',
                   '-m', 'GTRGAMMA',
                   '-p', '1723',
                   '-s', aligned_fp,
                   '-w', temp_dir,
                   '-n', 'q2',
                   '-f', 'a',
                   '-x', '9834',
                   '-N', '10']

            with redirected_stdio(stderr=os.devnull):
                run_command(cmd, verbose=False)

            obs_tree_fp = os.path.join(temp_dir, 'RAxML_bipartitions.q2')
            obs_tree = skbio.TreeNode.read(str(obs_tree_fp),
                                           convert_underscores=False)
        # load the resulting tree and test that it has the right number of
        # tips and the right tip ids
        tips = list(obs_tree.tips())
        tip_names = [t.name for t in tips]
        self.assertEqual(set(tip_names),
                         set(['GCA001510755', 'GCA001045515',
                              'GCA000454205', 'GCA000473545',
                              'GCA000196255', 'GCA002142615',
                              'GCA000686145', 'GCA001950115',
                              'GCA001971985', 'GCA900007555']))
예제 #4
0
    def test_run_ultrafast_bs_not_verbose(self):
        input_fp = self.get_data_path('aligned-dna-sequences-3.fasta')
        input_sequences = AlignedDNAFASTAFormat(input_fp, mode='r')
        aligned_fp = str(input_sequences)

        with tempfile.TemporaryDirectory() as temp_dir:
            run_prefix = os.path.join(temp_dir, 'q2iqtreeufboot')
            cmd = [
                'iqtree', '-m', 'HKY', '-seed', '1723', '-bb', '1000', '-s',
                aligned_fp, '-pre', run_prefix, '-nt', '2'
            ]

            with redirected_stdio(stderr=os.devnull):
                run_command(cmd, verbose=False)
            obs_tree_fp = run_prefix + '.treefile'
            obs_tree = skbio.TreeNode.read(str(obs_tree_fp),
                                           convert_underscores=False)
        # load the resulting tree and test that it has the right number of
        # tips and the right tip ids
        tips = list(obs_tree.tips())
        tip_names = [t.name for t in tips]
        self.assertEqual(
            set(tip_names),
            set([
                'GCA001510755', 'GCA001045515', 'GCA000454205', 'GCA000473545',
                'GCA000196255', 'GCA002142615', 'GCA000686145', 'GCA001950115',
                'GCA001971985', 'GCA900007555'
            ]))
예제 #5
0
    def test_run_ultrafast_bs_not_verbose(self):
        input_fp = self.get_data_path('aligned-dna-sequences-3.fasta')
        input_sequences = AlignedDNAFASTAFormat(input_fp, mode='r')
        aligned_fp = str(input_sequences)

        with tempfile.TemporaryDirectory() as temp_dir:
            run_prefix = os.path.join(temp_dir, 'q2iqtreeufboot')
            cmd = ['iqtree',
                   '-m', 'HKY',
                   '-seed', '1723',
                   '-bb', '1000',
                   '-s', aligned_fp,
                   '-pre', run_prefix,
                   '-nt', '2']

            with redirected_stdio(stderr=os.devnull):
                run_command(cmd, verbose=False)
            obs_tree_fp = run_prefix + '.treefile'
            obs_tree = skbio.TreeNode.read(str(obs_tree_fp),
                                           convert_underscores=False)
        # load the resulting tree and test that it has the right number of
        # tips and the right tip ids
        tips = list(obs_tree.tips())
        tip_names = [t.name for t in tips]
        self.assertEqual(set(tip_names),
                         set(['GCA001510755', 'GCA001045515',
                              'GCA000454205', 'GCA000473545',
                              'GCA000196255', 'GCA002142615',
                              'GCA000686145', 'GCA001950115',
                              'GCA001971985', 'GCA900007555']))
예제 #6
0
def iqtree_ultrafast_bootstrap(
    alignment: AlignedDNAFASTAFormat,
    seed: int = _iqtree_defaults['seed'],
    n_cores: int = _iqtree_defaults['n_cores'],
    n_runs: int = _iqtree_defaults['n_runs'],
    substitution_model: str = _iqtree_defaults['substitution_model'],
    bootstrap_replicates: int = _iqtree_defaults['bootstrap_replicates'],
    n_init_pars_trees: int = _iqtree_defaults['n_init_pars_trees'],
    n_top_init_trees: int = _iqtree_defaults['n_top_init_trees'],
    n_best_retain_trees: int = _iqtree_defaults['n_best_retain_trees'],
    stop_iter: int = _iqtree_defaults['stop_iter'],
    perturb_nni_strength: float = _iqtree_defaults['perturb_nni_strength'],
    spr_radius: int = _iqtree_defaults['spr_radius'],
    n_max_ufboot_iter: int = _iqtree_defaults['n_max_ufboot_iter'],
    n_ufboot_steps: int = _iqtree_defaults['n_ufboot_steps'],
    min_cor_ufboot: float = _iqtree_defaults['min_cor_ufboot'],
    ep_break_ufboot: float = _iqtree_defaults['ep_break_ufboot'],
    allnni: bool = _iqtree_defaults['allnni'],
    alrt: int = _iqtree_defaults['alrt'],
    abayes: bool = _iqtree_defaults['abayes'],
    lbp: int = _iqtree_defaults['lbp'],
    bnni: bool = _iqtree_defaults['bnni'],
    safe: bool = _iqtree_defaults['safe']
                                ) -> NewickFormat:
    # NOTE: the IQ-TREE commands `-n` (called as `n_iter` in the `iqtree`
    # method) and `-fast` are not compatable with ultrafast_bootstrap `-bb`.
    result = NewickFormat()

    with tempfile.TemporaryDirectory() as temp_dir:
        run_prefix = os.path.join(temp_dir, 'q2iqtreeufboot')
        cmd = _build_iqtree_ufbs_command(
                    alignment,
                    seed=seed,
                    n_cores=n_cores,
                    n_runs=n_runs,
                    substitution_model=substitution_model,
                    bootstrap_replicates=bootstrap_replicates,
                    run_prefix=run_prefix,
                    n_init_pars_trees=n_init_pars_trees,
                    n_top_init_trees=n_top_init_trees,
                    n_best_retain_trees=n_best_retain_trees,
                    stop_iter=stop_iter,
                    perturb_nni_strength=perturb_nni_strength,
                    spr_radius=spr_radius,
                    n_max_ufboot_iter=n_max_ufboot_iter,
                    n_ufboot_steps=n_ufboot_steps,
                    min_cor_ufboot=min_cor_ufboot,
                    ep_break_ufboot=ep_break_ufboot,
                    allnni=allnni,
                    alrt=alrt,
                    abayes=abayes,
                    lbp=lbp,
                    bnni=bnni,
                    safe=safe)
        run_command(cmd)
        tree_tmp_fp = os.path.join(temp_dir, '%s.treefile' % run_prefix)
        os.rename(tree_tmp_fp, str(result))

    return result
예제 #7
0
def iqtree(
    alignment: AlignedDNAFASTAFormat,
    seed: int = _iqtree_defaults['seed'],
    n_cores: int = _iqtree_defaults['n_cores'],
    n_cores_max: int = _iqtree_defaults['n_cores_max'],
    n_runs: int = _iqtree_defaults['n_runs'],
    substitution_model: str = _iqtree_defaults['substitution_model'],
    n_init_pars_trees: int = _iqtree_defaults['n_init_pars_trees'],
    n_top_init_trees: int = _iqtree_defaults['n_top_init_trees'],
    n_best_retain_trees: int = _iqtree_defaults['n_best_retain_trees'],
    n_iter: int = _iqtree_defaults['n_iter'],
    stop_iter: int = _iqtree_defaults['stop_iter'],
    perturb_nni_strength: float = _iqtree_defaults['perturb_nni_strength'],
    spr_radius: int = _iqtree_defaults['spr_radius'],
    allnni: bool = _iqtree_defaults['allnni'],
    fast: bool = _iqtree_defaults['fast'],
    alrt: int = _iqtree_defaults['alrt'],
    abayes: bool = _iqtree_defaults['abayes'],
    lbp: int = _iqtree_defaults['lbp'],
    safe: bool = _iqtree_defaults['safe'],
) -> NewickFormat:
    result = NewickFormat()

    with tempfile.TemporaryDirectory() as temp_dir:
        run_prefix = os.path.join(temp_dir, 'q2iqtree')
        cmd = _build_iqtree_command(alignment,
                                    seed=seed,
                                    n_cores=n_cores,
                                    n_cores_max=n_cores_max,
                                    n_runs=n_runs,
                                    substitution_model=substitution_model,
                                    run_prefix=run_prefix,
                                    n_init_pars_trees=n_init_pars_trees,
                                    n_top_init_trees=n_top_init_trees,
                                    n_best_retain_trees=n_best_retain_trees,
                                    n_iter=n_iter,
                                    stop_iter=stop_iter,
                                    perturb_nni_strength=perturb_nni_strength,
                                    spr_radius=spr_radius,
                                    allnni=allnni,
                                    fast=fast,
                                    alrt=alrt,
                                    abayes=abayes,
                                    lbp=lbp,
                                    safe=safe)
        run_command(cmd)

        tree_tmp_fp = os.path.join(temp_dir, '%s.treefile' % run_prefix)
        os.rename(tree_tmp_fp, str(result))

    return result
예제 #8
0
def iqtree(
    alignment: AlignedDNAFASTAFormat,
    seed: int = _iqtree_defaults['seed'],
    n_cores: int = _iqtree_defaults['n_cores'],
    n_runs: int = _iqtree_defaults['n_runs'],
    substitution_model: str = _iqtree_defaults['substitution_model'],
    n_init_pars_trees: int = _iqtree_defaults['n_init_pars_trees'],
    n_top_init_trees: int = _iqtree_defaults['n_top_init_trees'],
    n_best_retain_trees: int = _iqtree_defaults['n_best_retain_trees'],
    n_iter: int = _iqtree_defaults['n_iter'],
    stop_iter: int = _iqtree_defaults['stop_iter'],
    perturb_nni_strength: float = _iqtree_defaults['perturb_nni_strength'],
    spr_radius: int = _iqtree_defaults['spr_radius'],
    allnni: bool = _iqtree_defaults['allnni'],
    fast: bool = _iqtree_defaults['fast'],
    alrt: int = _iqtree_defaults['alrt'],
    abayes: bool = _iqtree_defaults['abayes'],
    lbp: int = _iqtree_defaults['lbp'],
    safe: bool = _iqtree_defaults['safe'],
            ) -> NewickFormat:
    result = NewickFormat()

    with tempfile.TemporaryDirectory() as temp_dir:
        run_prefix = os.path.join(temp_dir, 'q2iqtree')
        cmd = _build_iqtree_command(alignment,
                                    seed=seed,
                                    n_cores=n_cores,
                                    n_runs=n_runs,
                                    substitution_model=substitution_model,
                                    run_prefix=run_prefix,
                                    n_init_pars_trees=n_init_pars_trees,
                                    n_top_init_trees=n_top_init_trees,
                                    n_best_retain_trees=n_best_retain_trees,
                                    n_iter=n_iter,
                                    stop_iter=stop_iter,
                                    perturb_nni_strength=perturb_nni_strength,
                                    spr_radius=spr_radius,
                                    allnni=allnni,
                                    fast=fast,
                                    alrt=alrt,
                                    abayes=abayes,
                                    lbp=lbp,
                                    safe=safe)
        run_command(cmd)

        tree_tmp_fp = os.path.join(temp_dir, '%s.treefile' % run_prefix)
        os.rename(tree_tmp_fp, str(result))

    return result