def test_meta_validation(self): with self.assertRaisesRegex(ValueError, "position 1.*not.*BIOM"): meta((self.table1, self.not_a_table), (self.tree1, self.tree2), method='unweighted') with self.assertRaisesRegex(ValueError, "position 1.*not.*newick"): meta((self.table1, self.table2), (self.tree1, self.not_a_tree), method='unweighted')
def test_meta_unifrac_unbalanced(self): with self.assertRaisesRegex(ValueError, ("Number of trees and tables " "must be the same.")): meta(('a', ), ('a', 'b')) with self.assertRaisesRegex(ValueError, ("Number of trees and tables " "must be the same.")): meta(('a', 'b'), ('a', ))
def test_meta_unifrac_unbalanced(self): with self.assertRaisesRegex(ValueError, ("Number of trees and tables " "must be the same.")): meta((self.table1, ), (self.tree1, self.tree2), method='unweighted') with self.assertRaisesRegex(ValueError, ("Number of trees and tables " "must be the same.")): meta((self.table1, self.table2), (self.tree1, ), method='unweighted')
def test_meta_unifrac_unbalanced_weights(self): with self.assertRaisesRegex( ValueError, "Number of weights does not " "match number of trees and " "tables."): meta( (self.table1, self.table2), (self.tree1, self.tree2), weights=(1, 2, 3), )
def test_meta_validation(self): with self.assertRaisesRegex(ValueError, "Table does not appear to be a " "BIOM-Format v2.1"): meta((self.table1, self.not_a_table), (self.tree1, self.tree2), method='unweighted') with self.assertRaisesRegex(ValueError, "The phylogeny does not " "appear to be newick"): meta((self.table1, self.table2), (self.tree1, self.not_a_tree), method='unweighted')
def beta_phylogenetic_meta_passthrough( tables: BIOMV210Format, phylogenies: NewickFormat, metric: str, threads: int = 1, variance_adjusted: bool = False, alpha: float = None, bypass_tips: bool = False, weights: list = None, consolidation: str = 'skipping_missing_values' # noqa ) -> skbio.DistanceMatrix: # Ideally we remove this when we can support optional type-mapped params. if alpha is not None and metric != 'generalized_unifrac': raise ValueError("The alpha parameter is only allowed when the " "selected metric is 'generalized_unifrac'") metric_map = { 'unweighted_unifrac': 'unweighted', 'weighted_normalized_unifrac': 'weighted_normalized', 'weighted_unifrac': 'weighted_unnormalized', 'generalized_unifrac': 'generalized' } metric = metric_map[metric] return unifrac.meta(tuple([str(t) for t in tables]), tuple([str(p) for p in phylogenies]), weights=weights, threads=threads, consolidation=consolidation, method=metric, variance_adjusted=variance_adjusted, alpha=alpha, bypass_tips=bypass_tips)
def test_meta_unifrac(self): """meta_unifrac should give correct result on sample trees""" result = meta([self.table1, self.table2], [self.tree1, self.tree2], weights=[1, 1], consolidation='skipping-missing-values', method='unweighted') u1_distances = np.array([[0, 10/16., 8/13.], [10/16., 0, 8/17.], [8/13., 8/17., 0]]) u2_distances = np.array([[0, 11/14., 6/13.], [11/14., 0, 7/13.], [6/13., 7/13., 0]]) exp = (u1_distances + u2_distances) / 2 npt.assert_almost_equal(exp, result.data) self.assertEqual(tuple('ABC'), result.ids)
def test_meta_unifrac(self): """meta_unifrac should give correct result on sample trees""" t1 = self.get_data_path('t1.newick') t2 = self.get_data_path('t2.newick') e1 = self.get_data_path('e1.biom') e2 = self.get_data_path('e2.biom') result = meta([e1, e2], [t1, t2], weights=[1, 1], consolidation='skipping-missing-values', method='unweighted') u1_distances = np.array([[0, 10 / 16., 8 / 13.], [10 / 16., 0, 8 / 17.], [8 / 13., 8 / 17., 0]]) u2_distances = np.array([[0, 11 / 14., 6 / 13.], [11 / 14., 0, 7 / 13.], [6 / 13., 7 / 13., 0]]) exp = (u1_distances + u2_distances) / 2 npt.assert_almost_equal(exp, result.data) self.assertEqual(tuple('ABC'), result.ids)
def test_meta_unifrac_alpha_not_generalized(self): with self.assertRaisesRegex(ValueError, "The alpha parameter can"): meta(('a', ), ('b', ), method='generalized', alpha=1, consolidation='skipping_missing_matrices')
def test_meta_unifrac_bad_consolidation(self): with self.assertRaisesRegex(ValueError, "Consolidation \(foo\) unrecognized."): meta(('a', ), ('b', ), method='unweighted', consolidation='foo')
def test_meta_unifrac_bad_method(self): with self.assertRaisesRegex(ValueError, "Method \(bar\) " "unrecognized."): meta(('a', ), ('b', ), method='bar')
def test_meta_unifrac_no_method(self): with self.assertRaisesRegex(ValueError, "No method specified."): meta(('a', ), ('b', ))
def test_meta_unifrac_missing(self): with self.assertRaisesRegex(ValueError, "No trees specified."): meta(('a', ), tuple()) with self.assertRaisesRegex(ValueError, "No tables specified."): meta(tuple(), ('a', ))
def test_meta_unifrac_bad_method(self): with self.assertRaisesRegex(ValueError, r"Method \(bar\) " "unrecognized."): meta((self.table1, ), (self.tree1, ), method='bar')
def test_meta_unifrac_missing(self): with self.assertRaisesRegex(ValueError, "No trees specified."): meta((self.table1, ), tuple(), method='unweighted') with self.assertRaisesRegex(ValueError, "No tables specified."): meta(tuple(), (self.tree1, ), method='unweighted')