def test_validate_otu_ids_and_tree(self): # basic valid input t = TreeNode.read( io.StringIO('(((((OTU1:0.5,OTU2:0.5):0.5,OTU3:1.0):1.0):0.0,(OTU4:' '0.75,OTU5:0.75):1.25):0.0)root;')) counts = [1, 1, 1] otu_ids = ['OTU1', 'OTU2', 'OTU3'] self.assertTrue(_validate_otu_ids_and_tree(counts, otu_ids, t) is None) # all tips observed t = TreeNode.read( io.StringIO('(((((OTU1:0.5,OTU2:0.5):0.5,OTU3:1.0):1.0):0.0,(OTU4:' '0.75,OTU5:0.75):1.25):0.0)root;')) counts = [1, 1, 1, 1, 1] otu_ids = ['OTU1', 'OTU2', 'OTU3', 'OTU4', 'OTU5'] self.assertTrue(_validate_otu_ids_and_tree(counts, otu_ids, t) is None) # no tips observed t = TreeNode.read( io.StringIO('(((((OTU1:0.5,OTU2:0.5):0.5,OTU3:1.0):1.0):0.0,(OTU4:' '0.75,OTU5:0.75):1.25):0.0)root;')) counts = [] otu_ids = [] self.assertTrue(_validate_otu_ids_and_tree(counts, otu_ids, t) is None) # all counts zero t = TreeNode.read( io.StringIO('(((((OTU1:0.5,OTU2:0.5):0.5,OTU3:1.0):1.0):0.0,(OTU4:' '0.75,OTU5:0.75):1.25):0.0)root;')) counts = [0, 0, 0, 0, 0] otu_ids = ['OTU1', 'OTU2', 'OTU3', 'OTU4', 'OTU5'] self.assertTrue(_validate_otu_ids_and_tree(counts, otu_ids, t) is None)
def _setup_multiple_unifrac(counts, otu_ids, tree, validate): if validate: _validate_otu_ids_and_tree(counts[0], otu_ids, tree) counts_by_node, tree_index, branch_lengths = _vectorize_counts_and_tree(counts, otu_ids, tree) return counts_by_node, tree_index, branch_lengths
def test_validate_otu_ids_and_tree(self): # basic valid input t = TreeNode.read( StringIO(u"(((((OTU1:0.5,OTU2:0.5):0.5,OTU3:1.0):1.0):0.0,(OTU4:" u"0.75,OTU5:0.75):1.25):0.0)root;") ) counts = [1, 1, 1] otu_ids = ["OTU1", "OTU2", "OTU3"] self.assertTrue(_validate_otu_ids_and_tree(counts, otu_ids, t) is None) # all tips observed t = TreeNode.read( StringIO(u"(((((OTU1:0.5,OTU2:0.5):0.5,OTU3:1.0):1.0):0.0,(OTU4:" u"0.75,OTU5:0.75):1.25):0.0)root;") ) counts = [1, 1, 1, 1, 1] otu_ids = ["OTU1", "OTU2", "OTU3", "OTU4", "OTU5"] self.assertTrue(_validate_otu_ids_and_tree(counts, otu_ids, t) is None) # no tips observed t = TreeNode.read( StringIO(u"(((((OTU1:0.5,OTU2:0.5):0.5,OTU3:1.0):1.0):0.0,(OTU4:" u"0.75,OTU5:0.75):1.25):0.0)root;") ) counts = [] otu_ids = [] self.assertTrue(_validate_otu_ids_and_tree(counts, otu_ids, t) is None) # all counts zero t = TreeNode.read( StringIO(u"(((((OTU1:0.5,OTU2:0.5):0.5,OTU3:1.0):1.0):0.0,(OTU4:" u"0.75,OTU5:0.75):1.25):0.0)root;") ) counts = [0, 0, 0, 0, 0] otu_ids = ["OTU1", "OTU2", "OTU3", "OTU4", "OTU5"] self.assertTrue(_validate_otu_ids_and_tree(counts, otu_ids, t) is None)
def _setup_multiple_unifrac(counts, otu_ids, tree, validate): if validate: _validate_otu_ids_and_tree(counts[0], otu_ids, tree) counts_by_node, tree_index, branch_lengths = \ _vectorize_counts_and_tree(counts, otu_ids, tree) return counts_by_node, tree_index, branch_lengths
def _setup_faith_pd(counts, otu_ids, tree, validate, single_sample): if validate: if single_sample: # only validate count if operating in single sample mode, they # will have already been validated otherwise counts = _validate_counts_vector(counts) _validate_otu_ids_and_tree(counts, otu_ids, tree) else: _validate_otu_ids_and_tree(counts[0], otu_ids, tree) counts_by_node, tree_index, branch_lengths = _vectorize_counts_and_tree(counts, otu_ids, tree) return counts_by_node, branch_lengths
def _setup_faith_pd(counts, otu_ids, tree, validate, single_sample): if validate: if single_sample: # only validate count if operating in single sample mode, they # will have already been validated otherwise counts = _validate_counts_vector(counts) _validate_otu_ids_and_tree(counts, otu_ids, tree) else: _validate_otu_ids_and_tree(counts[0], otu_ids, tree) counts_by_node, tree_index, branch_lengths = \ _vectorize_counts_and_tree(counts, otu_ids, tree) return counts_by_node, branch_lengths
def test_validate_otu_ids_and_tree(self): # basic valid input t = TreeNode.read( io.StringIO( '(((((OTU1:0.5,OTU2:0.5):0.5,OTU3:1.0):1.0):0.0,(OTU4:' '0.75,OTU5:0.75):1.25):0.0)root;')) counts = [1, 1, 1] otu_ids = ['OTU1', 'OTU2', 'OTU3'] self.assertTrue(_validate_otu_ids_and_tree(counts, otu_ids, t) is None) # all tips observed t = TreeNode.read( io.StringIO( '(((((OTU1:0.5,OTU2:0.5):0.5,OTU3:1.0):1.0):0.0,(OTU4:' '0.75,OTU5:0.75):1.25):0.0)root;')) counts = [1, 1, 1, 1, 1] otu_ids = ['OTU1', 'OTU2', 'OTU3', 'OTU4', 'OTU5'] self.assertTrue(_validate_otu_ids_and_tree(counts, otu_ids, t) is None) # no tips observed t = TreeNode.read( io.StringIO( '(((((OTU1:0.5,OTU2:0.5):0.5,OTU3:1.0):1.0):0.0,(OTU4:' '0.75,OTU5:0.75):1.25):0.0)root;')) counts = [] otu_ids = [] self.assertTrue(_validate_otu_ids_and_tree(counts, otu_ids, t) is None) # all counts zero t = TreeNode.read( io.StringIO( '(((((OTU1:0.5,OTU2:0.5):0.5,OTU3:1.0):1.0):0.0,(OTU4:' '0.75,OTU5:0.75):1.25):0.0)root;')) counts = [0, 0, 0, 0, 0] otu_ids = ['OTU1', 'OTU2', 'OTU3', 'OTU4', 'OTU5'] self.assertTrue(_validate_otu_ids_and_tree(counts, otu_ids, t) is None)
def _validate(u_counts, v_counts, otu_ids, tree): _validate_counts_matrix([u_counts, v_counts], suppress_cast=True) _validate_otu_ids_and_tree(counts=u_counts, otu_ids=otu_ids, tree=tree)