Пример #1
0
    def test_consistency_unrooted(self):
        """Test consistency of taxa with a taxa that is only monophyletic in unrooted tree"""

        seed_con = 'f__Lachnospiraceae; g__Bacteroides; s__'
        nl.determine_rank_order(seed_con)
        tipname_map = {'a': ['f__Lachnospiraceae', 'g__Bacteroides', 's__Bacteroides pectinophilus'],
                       'b': ['f__Lachnospiraceae', 'g__Bacteroides', 's__Bacteroides pectinophilus'],
                       'c': ['f__Lachnospiraceae', 'g__Bacteroides', 's__Bacteroides pectinophilus'],
                       'd': ['f__Lachnospiraceae', 'g__Bacteroides', 's__Bacteroides acidifaciens'],
                       'e': ['f__Lachnospiraceae', 'g__Bacteroides', 's__Bacteroides acidifaciens']}

        tree = nl.load_tree(StringIO(u'((a,b),(c,(d,e)));'), tipname_map)

        counts = nl.collect_names_at_ranks_counts(tree)
        nl.decorate_ntips_rank(tree)
        nl.decorate_name_counts(tree)

        # determine taxonomic consistency of rooted tree
        #expected_consistency_index
        c = Consistency(counts, len(nl.RANK_ORDER))
        consistency_index = c.calculate(tree, rooted=True)

        self.assertAlmostEqual(consistency_index[0]['f__Lachnospiraceae'], 1.0)
        self.assertAlmostEqual(consistency_index[1]['g__Bacteroides'], 1.0)
        self.assertAlmostEqual(consistency_index[2]['s__Bacteroides pectinophilus'], 0.66666666)
        self.assertAlmostEqual(consistency_index[2]['s__Bacteroides acidifaciens'], 1.0)

        #determine consistency of unrooted tree
        consistency_index = c.calculate(tree, rooted=False)

        self.assertAlmostEqual(consistency_index[0]['f__Lachnospiraceae'], 1.0)
        self.assertAlmostEqual(consistency_index[1]['g__Bacteroides'], 1.0)
        self.assertAlmostEqual(consistency_index[2]['s__Bacteroides pectinophilus'], 1.0)
        self.assertAlmostEqual(consistency_index[2]['s__Bacteroides acidifaciens'], 1.0)
Пример #2
0
    def test_consistency_missing(self):
        """Test consistency of taxa in tree with missing taxa"""

        seed_con = 'f__Lachnospiraceae; g__Bacteroides; s__'
        nl.determine_rank_order(seed_con)
        tipname_map = {'a': ['f__Lachnospiraceae', 'g__Bacteroides', None],
                       'c': ['f__Lachnospiraceae', 'g__Bacteroides', 's__Bacteroides pectinophilus'],
                       'b': ['f__Lachnospiraceae', 'g__Bacteroides', None], 'e': [None, None, None],
                       'd': ['f__Lachnospiraceae', 'g__Bacteroides', 's__Bacteroides pectinophilus'],
                       'g': [None, None, None], 'f': ['f__Lachnospiraceae', 'g__Lachnospira', None],
                       'h': ['f__Lachnospiraceae', 'g__Lachnospira', 's__Bacteroides pectinophilus']}
        tree = nl.load_tree(StringIO(u'(((a,b),(c,d)),((e,f),(g,h)));'), tipname_map)

        counts = nl.collect_names_at_ranks_counts(tree)
        nl.decorate_ntips_rank(tree)
        nl.decorate_name_counts(tree)

        # determine taxonomic consistency of rooted tree
        #expected_consistency_index
        c = Consistency(counts, len(nl.RANK_ORDER))
        consistency_index = c.calculate(tree, rooted=True)

        self.assertAlmostEqual(consistency_index[0]['f__Lachnospiraceae'], 1.0)
        self.assertAlmostEqual(consistency_index[1]['g__Bacteroides'], 1.0)
        self.assertAlmostEqual(consistency_index[1]['g__Lachnospira'], 1.0)
        self.assertAlmostEqual(consistency_index[2]['s__Bacteroides pectinophilus'], 1.0)

        #determine consistency of unrooted tree
        consistency_index = c.calculate(tree, rooted=False)

        self.assertAlmostEqual(consistency_index[0]['f__Lachnospiraceae'], 1.0)
        self.assertAlmostEqual(consistency_index[1]['g__Bacteroides'], 1.0)
        self.assertAlmostEqual(consistency_index[1]['g__Lachnospira'], 1.0)
        self.assertAlmostEqual(consistency_index[2]['s__Bacteroides pectinophilus'], 1.0)
Пример #3
0
    def test_consistency_unrooted(self):
        """Test consistency of taxa with a taxa that is only monophyletic in unrooted tree"""

        seed_con = 'f__Lachnospiraceae; g__Bacteroides; s__'
        nl.determine_rank_order(seed_con)
        tipname_map = {
            'a': [
                'f__Lachnospiraceae', 'g__Bacteroides',
                's__Bacteroides pectinophilus'
            ],
            'b': [
                'f__Lachnospiraceae', 'g__Bacteroides',
                's__Bacteroides pectinophilus'
            ],
            'c': [
                'f__Lachnospiraceae', 'g__Bacteroides',
                's__Bacteroides pectinophilus'
            ],
            'd': [
                'f__Lachnospiraceae', 'g__Bacteroides',
                's__Bacteroides acidifaciens'
            ],
            'e': [
                'f__Lachnospiraceae', 'g__Bacteroides',
                's__Bacteroides acidifaciens'
            ]
        }

        tree = nl.load_tree('((a,b),(c,(d,e)));', tipname_map)

        counts = nl.collect_names_at_ranks_counts(tree)
        nl.decorate_ntips_rank(tree)
        nl.decorate_name_counts(tree)

        # determine taxonomic consistency of rooted tree
        #expected_consistency_index
        c = Consistency(counts, len(nl.RANK_ORDER))
        consistency_index = c.calculate(tree, rooted=True)

        self.assertAlmostEqual(consistency_index[0]['f__Lachnospiraceae'], 1.0)
        self.assertAlmostEqual(consistency_index[1]['g__Bacteroides'], 1.0)
        self.assertAlmostEqual(
            consistency_index[2]['s__Bacteroides pectinophilus'], 0.66666666)
        self.assertAlmostEqual(
            consistency_index[2]['s__Bacteroides acidifaciens'], 1.0)

        #determine consistency of unrooted tree
        consistency_index = c.calculate(tree, rooted=False)

        self.assertAlmostEqual(consistency_index[0]['f__Lachnospiraceae'], 1.0)
        self.assertAlmostEqual(consistency_index[1]['g__Bacteroides'], 1.0)
        self.assertAlmostEqual(
            consistency_index[2]['s__Bacteroides pectinophilus'], 1.0)
        self.assertAlmostEqual(
            consistency_index[2]['s__Bacteroides acidifaciens'], 1.0)
Пример #4
0
    def test_consistency_missing(self):
        """Test consistency of taxa in tree with missing taxa"""

        seed_con = 'f__Lachnospiraceae; g__Bacteroides; s__'
        nl.determine_rank_order(seed_con)
        tipname_map = {
            'a': ['f__Lachnospiraceae', 'g__Bacteroides', None],
            'c': [
                'f__Lachnospiraceae', 'g__Bacteroides',
                's__Bacteroides pectinophilus'
            ],
            'b': ['f__Lachnospiraceae', 'g__Bacteroides', None],
            'e': [None, None, None],
            'd': [
                'f__Lachnospiraceae', 'g__Bacteroides',
                's__Bacteroides pectinophilus'
            ],
            'g': [None, None, None],
            'f': ['f__Lachnospiraceae', 'g__Lachnospira', None],
            'h': [
                'f__Lachnospiraceae', 'g__Lachnospira',
                's__Bacteroides pectinophilus'
            ]
        }
        tree = nl.load_tree('(((a,b),(c,d)),((e,f),(g,h)));', tipname_map)

        counts = nl.collect_names_at_ranks_counts(tree)
        nl.decorate_ntips_rank(tree)
        nl.decorate_name_counts(tree)

        # determine taxonomic consistency of rooted tree
        #expected_consistency_index
        c = Consistency(counts, len(nl.RANK_ORDER))
        consistency_index = c.calculate(tree, rooted=True)

        self.assertAlmostEqual(consistency_index[0]['f__Lachnospiraceae'], 1.0)
        self.assertAlmostEqual(consistency_index[1]['g__Bacteroides'], 1.0)
        self.assertAlmostEqual(consistency_index[1]['g__Lachnospira'], 1.0)
        self.assertAlmostEqual(
            consistency_index[2]['s__Bacteroides pectinophilus'], 1.0)

        #determine consistency of unrooted tree
        consistency_index = c.calculate(tree, rooted=False)

        self.assertAlmostEqual(consistency_index[0]['f__Lachnospiraceae'], 1.0)
        self.assertAlmostEqual(consistency_index[1]['g__Bacteroides'], 1.0)
        self.assertAlmostEqual(consistency_index[1]['g__Lachnospira'], 1.0)
        self.assertAlmostEqual(
            consistency_index[2]['s__Bacteroides pectinophilus'], 1.0)
Пример #5
0
    def test_decorate_ntips_rank(self):
        """correctly decorate the tree with the NumTipsRank param"""
        input = "(((a,b)c,(d,e,f)g)h,(i,j)k)l;"
        tree = TreeNode.from_newick(input)
        tips = dict([(tip.name, tip) for tip in tree.tips()])
        tips['a'].Consensus = [1, 2, 3, 4, 5, 6, 7]
        tips['b'].Consensus = [None, None, None, 5, None, None, None]
        tips['d'].Consensus = [1, 2, 3, 4, 5, 6, 8]
        tips['e'].Consensus = [None, None, None, None, None, None, None]
        tips['f'].Consensus = [1, 2, 3, 4, 5, 6, 8]
        tips['i'].Consensus = [1, 2, 3, 4, 5, 6, 8]
        tips['j'].Consensus = [1, 2, 3, 4, 5, 6, 8]
        decorate_ntips_rank(tree)

        self.assertEqual(tree.NumTipsRank[0], 5)
        self.assertEqual(tree.NumTipsRank[1], 5)
        self.assertEqual(tree.NumTipsRank[2], 5)
        self.assertEqual(tree.NumTipsRank[3], 6)
        self.assertEqual(tree.NumTipsRank[4], 5)
        self.assertEqual(tree.NumTipsRank[5], 5)
        self.assertEqual(tree.NumTipsRank[6], 5)
Пример #6
0
    def test_decorate_ntips_rank(self):
        """correctly decorate the tree with the NumTipsRank param"""
        data = StringIO(u"(((a,b)c,(d,e,f)g)h,(i,j)k)l;")
        tree = TreeNode.read(data)
        tips = dict([(tip.name, tip) for tip in tree.tips()])
        tips['a'].Consensus = [1, 2, 3, 4, 5, 6, 7]
        tips['b'].Consensus = [None, None, None, 5, None, None, None]
        tips['d'].Consensus = [1, 2, 3, 4, 5, 6, 8]
        tips['e'].Consensus = [None, None, None, None, None, None, None]
        tips['f'].Consensus = [1, 2, 3, 4, 5, 6, 8]
        tips['i'].Consensus = [1, 2, 3, 4, 5, 6, 8]
        tips['j'].Consensus = [1, 2, 3, 4, 5, 6, 8]
        decorate_ntips_rank(tree)

        self.assertEqual(tree.NumTipsRank[0], 5)
        self.assertEqual(tree.NumTipsRank[1], 5)
        self.assertEqual(tree.NumTipsRank[2], 5)
        self.assertEqual(tree.NumTipsRank[3], 6)
        self.assertEqual(tree.NumTipsRank[4], 5)
        self.assertEqual(tree.NumTipsRank[5], 5)
        self.assertEqual(tree.NumTipsRank[6], 5)