def test_lca_subtree_simple_alias(self, mocked_print):
        testargs = [
            "phykit",
            "lca_subtree",
            f"{here.parent.parent.parent}/sample_files/tree_simple.tre",
            f"{here.parent.parent.parent}/sample_files/tree_simple_lca_subtree_list.txt",
        ]

        with patch.object(sys, "argv", testargs):
            Phykit()

        with open(f"{here.parent.parent}/expected/tree_simple.tre.subtree.tre",
                  "r") as expected_tree:
            expected_tree_content = expected_tree.read()

        with open(
                f"{here.parent.parent.parent}/sample_files/tree_simple.tre.subtree.tre",
                "r") as out_tree:
            out_tree_content = out_tree.read()

        assert expected_tree_content == out_tree_content
Beispiel #2
0
    def test_prune_keep_long(self, mocked_print):
        testargs = [
            "phykit", "prune",
            f"{here.parent.parent.parent}/sample_files/tree_simple.tre",
            f"{here.parent.parent.parent}/sample_files/tree_simple_prune_keep.txt",
            "--keep"
        ]

        with patch.object(sys, "argv", testargs):
            Phykit()

        with open(f"{here.parent.parent}/expected/tree_simple.pruned_keep.tre",
                  "r") as expected_tree:
            expected_tree_content = expected_tree.read()

        with open(
                f"{here.parent.parent.parent}/sample_files/tree_simple.tre.pruned",
                "r") as out_tree:
            out_tree_content = out_tree.read()

        assert expected_tree_content == out_tree_content
    def test_polytomy_test_incorrect_group_formatting(self, mocked_print):
        testargs = [
            "phykit",
            "polytomy_test",
            "-t",
            f"{here.parent.parent.parent}/sample_files/polyt_test_trees.txt",
            "-g",
            f"{here.parent.parent.parent}/sample_files/polyt_test_groups_three_tabs.txt",
        ]

        with patch.object(sys, "argv", testargs):
            with pytest.raises(SystemExit) as pytest_wrapped_e:
                Phykit()

        assert pytest_wrapped_e.type == SystemExit
        mocked_print.assert_has_calls([
            call("Please format the groups file (-g) as a four column tab-delimited file with column 1 being the name of the test"),
            call("col2: the tip names of one group (; separated)"),
            call("col3: the tip names of a second group (; separated)"),
            call("col4: the tip names of a third group (; separated)"),
            call("col5: the tip names of the outgroup taxa (; separated)"),
        ])
    def test_rename_fasta_entries_outputting(self, mocked_print):
        testargs = [
            "phykit", "rename_fasta_entries",
            f"{here.parent.parent.parent}/sample_files/simple.fa", "-i",
            f"{here.parent.parent.parent}/sample_files/simple_fasta_idmap.txt",
            "-o",
            f"{here.parent.parent.parent}/sample_files/simple_customized_output_name.fa"
        ]
        with patch.object(sys, "argv", testargs):
            Phykit()

        with open(
                f"{here.parent.parent}/expected/simple_customized_output_name.fa",
                "r") as expected_fa:
            expected_fa_content = expected_fa.read()

        with open(
                f"{here.parent.parent.parent}/sample_files/simple.fa.renamed.fa",
                "r") as out_renamed:
            out_renamed_content = out_renamed.read()

        assert expected_fa_content == out_renamed_content
    def test_dna_threader_alias1(self, mocked_print):
        expected_result_0 = dedent(""">1\nAAAGGG---""")
        expected_result_1 = dedent(""">2\nAAATTTGGG""")
        expected_result_2 = dedent(""">3\nAAATTTGGG""")
        expected_result_3 = dedent(""">4\nAAATTTGGG""")
        testargs = [
            "phykit",
            "p2n",
            "-p",
            f"{here.parent.parent.parent}/sample_files/test_alignment.prot.faa",
            "-n",
            f"{here.parent.parent.parent}/sample_files/test.nucl.fna",
        ]

        with patch.object(sys, "argv", testargs):
            Phykit()
        assert mocked_print.mock_calls == [
            call(expected_result_0),
            call(expected_result_1),
            call(expected_result_2),
            call(expected_result_3)
        ]
Beispiel #6
0
    def test_nni_custom_out(self, mocked_print):
        testargs = [
            "phykit", "nearest_neighbor_interchange",
            f"{here.parent.parent.parent}/sample_files/small_Aspergillus_tre_rooted.tree",
            "-o",
            f"{here.parent.parent.parent}/sample_files/nni_custom_out.tre"
        ]

        with patch.object(sys, "argv", testargs):
            Phykit()

        with open(
                f"{here.parent.parent}/expected/small_Aspergillus_tre_rooted.nni_moves.tre",
                "r") as expected_tree:
            expected_tree_content = expected_tree.read()

        with open(
                f"{here.parent.parent.parent}/sample_files/nni_custom_out.tre",
                "r") as out_tree:
            out_tree_content = out_tree.read()

        assert expected_tree_content == out_tree_content
Beispiel #7
0
    def test_rename_tree_tips_alias1(self, mocked_print):
        testargs = [
            "phykit",
            "rename_tips",
            f"{here.parent.parent.parent}/sample_files/tree_simple.tre",
            "-i",
            f"{here.parent.parent.parent}/sample_files/tree_simple_idmap.txt",
        ]

        with patch.object(sys, "argv", testargs):
            Phykit()

        with open(f"{here.parent.parent}/expected/tree_simple.tre.renamed.tre",
                  "r") as expected_tree:
            expected_tree_content = expected_tree.read()

        with open(
                f"{here.parent.parent.parent}/sample_files/tree_simple.tre.renamed.tre",
                "r") as out_tree:
            out_tree_content = out_tree.read()

        assert expected_tree_content == out_tree_content
    def test_branch_length_multiplier_alias(self, mocked_print):
        testargs = [
            "phykit",
            "blm",
            f"{here.parent.parent.parent}/sample_files/tree_simple.tre",
            "-f",
            "2",
        ]
        with patch.object(sys, "argv", testargs):
            Phykit()

        with open(
                f"{here.parent.parent}/expected/tree_simple.tre.factor_2.0.tre",
                "r") as expected_tree:
            expected_tree_content = expected_tree.read()

        with open(
                f"{here.parent.parent.parent}/sample_files/tree_simple.tre.factor_2.0.tre",
                "r") as out_tree:
            out_tree_content = out_tree.read()

        assert expected_tree_content == out_tree_content
    def test_pairwise_identity_verbose(self, mocked_print):
        testargs = [
            "phykit",
            "pairwise_identity",
            f"{here.parent.parent.parent}/sample_files/simple.fa",
            "-v",
        ]
        with patch.object(sys, "argv", testargs):
            Phykit()

        assert mocked_print.mock_calls == [
            call("1-2\t0.8333333333333334"),
            call("1-3\t0.5"),
            call("1-4\t0.16666666666666666"),
            call("1-5\t0.16666666666666666"),
            call("2-3\t0.6666666666666666"),
            call("2-4\t0.3333333333333333"),
            call("2-5\t0.3333333333333333"),
            call("3-4\t0.6666666666666666"),
            call("3-5\t0.5"),
            call("4-5\t0.5"),
        ]
    def test_collapse_branches2(self, mocked_print):
        testargs = [
            "phykit",
            "collapse_branches",
            f"{here.parent.parent.parent}/sample_files/small_Aspergillus_tree.tre",
            "-s",
            "90",
        ]
        with patch.object(sys, "argv", testargs):
            Phykit()

        with open(
                f"{here.parent.parent}/expected/small_Aspergillus_tree.tre.collapsed_90.0.tre",
                "r") as expected_tree:
            expected_tree_content = expected_tree.read()

        with open(
                f"{here.parent.parent.parent}/sample_files/small_Aspergillus_tree.tre.collapsed_90.0.tre",
                "r") as out_tree:
            out_tree_content = out_tree.read()

        assert expected_tree_content == out_tree_content
Beispiel #11
0
    def test_root_tree(self, mocked_print):
        testargs = [
            "phykit",
            "root_tree",
            f"{here.parent.parent.parent}/sample_files/tree_simple.tre",
            "-r",
            f"{here.parent.parent.parent}/sample_files/tree_simple.outgroup.txt",
        ]

        with patch.object(sys, "argv", testargs):
            Phykit()

        with open(f"{here.parent.parent}/expected/tree_simple.tre.rooted",
                  "r") as expected_tree:
            expected_tree_content = expected_tree.read()

        with open(
                f"{here.parent.parent.parent}/sample_files/tree_simple.tre.rooted",
                "r") as out_tree:
            out_tree_content = out_tree.read()

        assert expected_tree_content == out_tree_content
    def test_patristic_distances_verbose(self, mocked_print):
        testargs = [
            "phykit", "patristic_distances",
            f"{here.parent.parent.parent}/sample_files/tree_simple.tre", "-v"
        ]
        with patch.object(sys, "argv", testargs):
            Phykit()

        assert mocked_print.mock_calls == [
            call("raccoon-bear\t26.0"),
            call("raccoon-sea_lion\t43.4461"),
            call("raccoon-seal\t43.4521"),
            call("raccoon-monkey\t147.4653"),
            call("raccoon-cat\t93.7467"),
            call("raccoon-weasel\t44.8935"),
            call("raccoon-dog\t45.5071"),
            call("bear-sea_lion\t31.047"),
            call("bear-seal\t31.053"),
            call("bear-monkey\t135.0661"),
            call("bear-cat\t81.3475"),
            call("bear-weasel\t32.4944"),
            call("bear-dog\t33.108"),
            call("sea_lion-seal\t24.0"),
            call("sea_lion-monkey\t143.0726"),
            call("sea_lion-cat\t89.354"),
            call("sea_lion-weasel\t40.5009"),
            call("sea_lion-dog\t48.8621"),
            call("seal-monkey\t143.0786"),
            call("seal-cat\t89.36"),
            call("seal-weasel\t40.5069"),
            call("seal-dog\t48.8681"),
            call("monkey-cat\t148.0"),
            call("monkey-weasel\t140.3308"),
            call("monkey-dog\t152.8813"),
            call("cat-weasel\t86.6122"),
            call("cat-dog\t99.1627"),
            call("weasel-dog\t50.3095"),
        ]
    def test_dna_threader0(self, mocked_print):
        expected_result_0 = dedent(
            """>200_S38\natggctgacatcctcacgcagctccagacttgcctggatcagcttgcaacacaattctacgcaacacttggttatctcacaacataccacgacaatgcccccacaacaccaccacca------aatgtccccgacgcagcaccagccctagcaaagatcaccaagaactcatcatcaccgccagtcccagcagccatcgcaaataaagtggggggtgcagctgctgttgcgggcaatgca---tcacccccacaggcgcct---------cct---------------------------------------------caacaacccggagct---------gcgcca---gggagagcagtagaaggtgaagatcccaaccttcctcccgcgccagactcgcccagcacgtttgcaagccggcagcgggagcttgcgcgcgatctcattatcaaagaacagcagatcgagtaccttatctccgtgcttcccgggattggcgcctctgaggctgaacaagaaaccagaatccaggacctggagaccgagcttagagacgtcgagaaggagcgcgctgcgaaagtgcgggagttgaaaaagttgaggactcggttggaggatgttcttggcgctgtcgctgtgggtatccacggggatggttactctcaaaac---------"""
        )
        expected_result_1 = dedent(
            """>203_S40\natggctgacatcctcacgcagctccagacttgcctggatcagcttgcaacacaattctacgcaacacttggttatctcacaacataccacgacaatgcccccacaacaccaccacca------aatgtccccgacgcagcaccagccctagcaaagatcaccaagaactcatcatcaccaccagtcccagcagccatcgcaaataaagtggggggtgcagctgctgttgcgggcaatgca---tcacccccacaggcgcct---------cct---------------------------------------------caacaacccggagct---------gcgcca---gggagagcagtagaaggtgaagatcccaaccttcctcccgcgccagactcgcccagcacgtttgcaagccggcagcgggagcttgcgcgcgatctcattatcaaagaacagcagatcgagtaccttatctccgtgcttcccgggattggcgcctctgaggctgaacaagaaaccagaatccaggacctggagaccgagcttagagacgtcgagaaggagcgcgctgcgaaagtgcgggagttgaaaaagttgaggactcggttggaggatgttcttggcgctgtcgctgtgggtatccacggggatggttactctcaaaac---------"""
        )

        testargs = [
            "phykit",
            "thread_dna",
            "-p",
            f"{here.parent.parent.parent}/sample_files/EOG091N44MS.fa.mafft",
            "-n",
            f"{here.parent.parent.parent}/sample_files/EOG091N44MS.fa",
        ]

        with patch.object(sys, "argv", testargs):
            Phykit()
        assert mocked_print.mock_calls == [
            call(expected_result_0),
            call(expected_result_1),
        ]
Beispiel #14
0
 def test_saturation_verbose(self, mocked_print):
     expected_result = 0.8451
     testargs = [
         "phykit",
         "sat",
         "-t",
         f"{here.parent.parent.parent}/sample_files/12_YPR191W_Anc_7.548_codon_aln.fasta.clipkit.treefile",
         "-a",
         f"{here.parent.parent.parent}/sample_files/12_YPR191W_Anc_7.548_codon_aln.fasta.clipkit",
         "-v"
     ]
     with patch.object(sys, "argv", testargs):
         Phykit()
     assert mocked_print.mock_calls == [
         call("Kpol-Kpha\t0.6136\t0.6176"),
         call("Kpol-Snag\t0.5654\t0.7482"),
         call("Kpol-Suva\t0.5948\t0.6945"),
         call("Kpol-Skud\t0.5906\t0.7341"),
         call("Kpol-Smik\t0.6157\t0.7734"),
         call("Kpol-Scer\t0.6105\t0.7634"),
         call("Kpol-Kbla\t0.599\t0.7287"),
         call("Kpol-Kafr\t0.5696\t0.7509"),
         call("Kpol-Sdai\t0.5916\t0.7297"),
         call("Kpol-Scas\t0.5822\t0.7958"),
         call("Kpol-Cgla\t0.5979\t0.653"),
         call("Kpha-Snag\t0.5393\t0.8254"),
         call("Kpha-Suva\t0.5424\t0.7717"),
         call("Kpha-Skud\t0.5257\t0.8113"),
         call("Kpha-Smik\t0.5466\t0.8505"),
         call("Kpha-Scer\t0.5445\t0.8406"),
         call("Kpha-Kbla\t0.5435\t0.9228"),
         call("Kpha-Kafr\t0.5581\t0.945"),
         call("Kpha-Sdai\t0.5424\t0.9238"),
         call("Kpha-Scas\t0.5382\t0.9899"),
         call("Kpha-Cgla\t0.5738\t0.8472"),
         call("Snag-Suva\t0.5518\t0.7281"),
         call("Snag-Skud\t0.5508\t0.7678"),
         call("Snag-Smik\t0.5539\t0.807"),
         call("Snag-Scer\t0.555\t0.797"),
         call("Snag-Kbla\t0.5215\t1.0535"),
         call("Snag-Kafr\t0.5539\t1.0757"),
         call("Snag-Sdai\t0.5225\t1.0544"),
         call("Snag-Scas\t0.4984\t1.1206"),
         call("Snag-Cgla\t0.5131\t0.9778"),
         call("Suva-Skud\t0.8105\t0.229"),
         call("Suva-Smik\t0.7969\t0.2682"),
         call("Suva-Scer\t0.7958\t0.2583"),
         call("Suva-Kbla\t0.5361\t0.9997"),
         call("Suva-Kafr\t0.5162\t1.0219"),
         call("Suva-Sdai\t0.5309\t1.0007"),
         call("Suva-Scas\t0.5162\t1.0668"),
         call("Suva-Cgla\t0.5707\t0.9241"),
         call("Skud-Smik\t0.8199\t0.2171"),
         call("Skud-Scer\t0.8325\t0.2071"),
         call("Skud-Kbla\t0.5183\t1.0394"),
         call("Skud-Kafr\t0.5288\t1.0616"),
         call("Skud-Sdai\t0.5089\t1.0403"),
         call("Skud-Scas\t0.5005\t1.1065"),
         call("Skud-Cgla\t0.5602\t0.9637"),
         call("Smik-Scer\t0.8314\t0.1998"),
         call("Smik-Kbla\t0.5382\t1.0786"),
         call("Smik-Kafr\t0.5225\t1.1008"),
         call("Smik-Sdai\t0.534\t1.0796"),
         call("Smik-Scas\t0.5257\t1.1457"),
         call("Smik-Cgla\t0.5529\t1.003"),
         call("Scer-Kbla\t0.5372\t1.0686"),
         call("Scer-Kafr\t0.5162\t1.0908"),
         call("Scer-Sdai\t0.5298\t1.0696"),
         call("Scer-Scas\t0.5236\t1.1357"),
         call("Scer-Cgla\t0.5508\t0.993"),
         call("Kbla-Kafr\t0.5686\t0.67"),
         call("Kbla-Sdai\t0.5613\t0.8756"),
         call("Kbla-Scas\t0.5393\t0.9418"),
         call("Kbla-Cgla\t0.5508\t0.799"),
         call("Kafr-Sdai\t0.534\t0.8978"),
         call("Kafr-Scas\t0.5152\t0.964"),
         call("Kafr-Cgla\t0.555\t0.8212"),
         call("Sdai-Scas\t0.6356\t0.5357"),
         call("Sdai-Cgla\t0.5675\t0.7045"),
         call("Scas-Cgla\t0.5518\t0.7706"),
     ]
Beispiel #15
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Convenience wrapper for running phykit directly from source tree."""
import sys

from phykit.phykit import Phykit

if __name__ == "__main__":
    Phykit()