def test_alpha(self): t = biom.Table(np.array([[0, 1, 3], [1, 1, 2]]), ['O1', 'O2'], ['S1', 'S2', 'S3']) actual = alpha(table=t, metric='observed_otus') # expected computed by hand expected = pd.Series({'S1': 1, 'S2': 2, 'S3': 2}, name='observed_otus') pdt.assert_series_equal(actual, expected)
def core_metrics(table: biom.Table, phylogeny: skbio.TreeNode, sampling_depth: int) -> (pd.Series, pd.Series, pd.Series, pd.Series, skbio.DistanceMatrix, skbio.DistanceMatrix, skbio.DistanceMatrix, skbio.DistanceMatrix, skbio.OrdinationResults, skbio.OrdinationResults, skbio.OrdinationResults, skbio.OrdinationResults): rarefied_table = rarefy(table=table, sampling_depth=sampling_depth) faith_pd_vector = alpha_phylogenetic( table=rarefied_table, phylogeny=phylogeny, metric='faith_pd') observed_otus_vector = alpha(table=rarefied_table, metric='observed_otus') shannon_vector = alpha(table=rarefied_table, metric='shannon') evenness_vector = alpha(table=rarefied_table, metric='pielou_e') unweighted_unifrac_distance_matrix = beta_phylogenetic( table=rarefied_table, phylogeny=phylogeny, metric='unweighted_unifrac') weighted_unifrac_distance_matrix = beta_phylogenetic( table=rarefied_table, phylogeny=phylogeny, metric='weighted_unifrac') jaccard_distance_matrix = beta(table=rarefied_table, metric='jaccard') bray_curtis_distance_matrix = beta( table=rarefied_table, metric='braycurtis') unweighted_unifrac_pcoa_results = pcoa( distance_matrix=unweighted_unifrac_distance_matrix) weighted_unifrac_pcoa_results = pcoa( distance_matrix=weighted_unifrac_distance_matrix) jaccard_pcoa_results = pcoa(distance_matrix=jaccard_distance_matrix) bray_curtis_pcoa_results = pcoa( distance_matrix=bray_curtis_distance_matrix) return ( faith_pd_vector, observed_otus_vector, shannon_vector, evenness_vector, unweighted_unifrac_distance_matrix, weighted_unifrac_distance_matrix, jaccard_distance_matrix, bray_curtis_distance_matrix, unweighted_unifrac_pcoa_results, weighted_unifrac_pcoa_results, jaccard_pcoa_results, bray_curtis_pcoa_results )
def test_alpha_empty_table(self): t = biom.Table(np.array([]), [], []) with self.assertRaisesRegex(ValueError, "empty"): alpha(table=t, metric='observed_otus')
def test_alpha_unknown_metric(self): t = biom.Table(np.array([[0, 1, 3], [1, 1, 2]]), ['O1', 'O2'], ['S1', 'S2', 'S3']) with self.assertRaises(ValueError): alpha(table=t, metric='not-a-metric')
def test_alpha_phylo_metric(self): t = biom.Table(np.array([[0, 1, 3], [1, 1, 2]]), ['O1', 'O2'], ['S1', 'S2', 'S3']) with self.assertRaises(ValueError): alpha(table=t, metric='faith_pd')
def test_alpha_unknown_metric(self): t = biom.Table(np.array([[0, 1, 3], [1, 1, 2]]), ['O1', 'O2'], ['S1', 'S2', 'S3']) with self.assertRaisesRegex(ValueError, 'Unknown metric'): alpha(table=t, metric='not-a-metric')