def testLengthenEdge(self): tree = create_tree_from_id2par(_bogus_id2par, ['hp', 'g', 'h']) self.assertEqual(tree.find_node('hp')._id, 'hp') li = tree.leaf_ids li.sort() self.assertEqual(li, ['g', 'h']) tree.do_full_check_of_invariants(self, id2par=_bogus_id2par)
def create_pruned_and_taxonomy_for_tip_ott_ids(tree_proxy, ott): '''returns a pair of trees: the first is that is a pruned version of tree_proxy created by pruning any leaf that has no ott_id and every internal that does not have any descendant with an ott_id. Nodes of out-degree 1 are suppressed as part of the TreeWithPathsInEdges-style. the second is the OTT induced tree for these ott_ids ''' # create and id2par that has ott IDs only at the tips (we are # ignoring mappings at internal nodes. # OTT IDs are integers, and the nodeIDs are strings - so we should not get clashes. #TODO consider prefix scheme ott_ids = [] ottId2OtuPar = {} for node in tree_proxy: if node.is_leaf: ott_id = node.ott_id if ott_id is not None: ott_ids.append(ott_id) assert isinstance(ott_id, int) parent_id = node.parent._id ottId2OtuPar[ott_id] = parent_id else: assert is_str_type(node._id) edge = node.edge if edge is not None: parent_id = node.parent._id ottId2OtuPar[node._id] = parent_id else: ottId2OtuPar[node._id] = None pruned_phylo = create_tree_from_id2par(ottId2OtuPar, ott_ids) taxo_tree = ott.induced_tree(ott_ids) return pruned_phylo, taxo_tree
def testCherry(self): tree = create_tree_from_id2par(_bogus_id2par, ['h', 'p']) self.assertTrue(tree._root._id == 'hp') self.assertEqual(len(tree.leaves), 2) i = tree.postorder_node_iter() self.assertTrue(next(i)._id in ['h', 'p']) self.assertTrue(next(i)._id in ['h', 'p']) self.assertEqual(next(i)._id, 'hp') self.assertRaises(StopIteration, next, i) self.assertRaises(ValueError, create_tree_from_id2par, _bogus_id2par, ['h', 'bogus_tip']) tree.do_full_check_of_invariants(self, id2par=_bogus_id2par)
def testFullExample(self): tips = ['h', 'p', 'g', 'Po', 'Hy', 'Sy', 'Ho', 'No'] tree = create_tree_from_id2par(_bogus_id2par, tips) tree.do_full_check_of_invariants(self, id2par=_bogus_id2par)
def testEmpty(self): # not sure whether we should return an empty tree, None, or raise an exception... self.assertEqual(None, create_tree_from_id2par(_bogus_id2par, []))
def testSingleton(self): tree = create_tree_from_id2par(_bogus_id2par, ['h']) self.assertEqual(tree.find_node('h')._id, 'h') tree.do_full_check_of_invariants(self, id2par=_bogus_id2par)
def induced_tree(self, ott_id_list, create_monotypic_nodes=False): # self._debug_anc_spikes(ott_id_list) return create_tree_from_id2par( self.ott_id2par_ott_id, ott_id_list, create_monotypic_nodes=create_monotypic_nodes)
def induced_tree(self, ott_id_list): return create_tree_from_id2par(self.ott_id2par_ott_id, ott_id_list)
def induced_tree(self, ott_id_list, create_monotypic_nodes=False): # self._debug_anc_spikes(ott_id_list) return create_tree_from_id2par(self.ott_id2par_ott_id, ott_id_list, create_monotypic_nodes=create_monotypic_nodes)