def observed_features(table: biom.Table) -> pd.Series: presence_absence_table = table.pa(inplace=False) counts = presence_absence_table.matrix_data.toarray().astype(int).T sample_ids = presence_absence_table.ids(axis='sample') result = skbio.diversity.alpha_diversity(metric='observed_otus', counts=counts, ids=sample_ids) result.name = 'observed_features' return result
def faith_pd(table: biom.Table, phylogeny: skbio.TreeNode) -> pd.Series: presence_absence_table = table.pa() counts = presence_absence_table.matrix_data.toarray().astype(int).T sample_ids = presence_absence_table.ids(axis='sample') feature_ids = presence_absence_table.ids(axis='observation') try: result = skbio.diversity.alpha_diversity(metric='faith_pd', counts=counts, ids=sample_ids, otu_ids=feature_ids, tree=phylogeny) except skbio.tree.MissingNodeError as e: message = str(e).replace('otu_ids', 'feature_ids') message = message.replace('tree', 'phylogeny') raise skbio.tree.MissingNodeError(message) result.name = 'faith_pd' return result
def presence_absence(table: biom.Table) -> biom.Table: """ Convert feature table in-place to presence/absence data """ table.pa(inplace=True) return table