本文整理汇总了Python中biom.Table.filter方法的典型用法代码示例。如果您正苦于以下问题:Python Table.filter方法的具体用法?Python Table.filter怎么用?Python Table.filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类biom.Table
的用法示例。
在下文中一共展示了Table.filter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: filter_table
# 需要导入模块: from biom import Table [as 别名]
# 或者: from biom.Table import filter [as 别名]
def filter_table(table: biom.Table, tree: skbio.TreeNode) -> biom.Table:
""" Filter table to remove feature ids that are not tip ids in tree
"""
tip_ids = set([t.name for t in tree.tips()])
feature_ids = set(table.ids(axis='observation'))
# ids_to_keep can only include ids that are in table
ids_to_keep = tip_ids & feature_ids
table.filter(ids_to_keep, axis='observation', inplace=True)
return table
示例2: generate_per_sample_biom
# 需要导入模块: from biom import Table [as 别名]
# 或者: from biom.Table import filter [as 别名]
def generate_per_sample_biom(biom_file, limit):
"""Generate per-sample BIOM files
Parameters
----------
biom_file : str
A filepath to a BIOM table
limit : int or None
Limit the number of tables to load
Returns
-------
str
The sample ID
str
The table in BIOM Format v1.0
str
The table in the classic OTU table format
"""
table = load_table(biom_file)
obs_ids = table.ids(axis='observation')
obs_md = table.metadata(axis='observation')
if limit is None:
limit = np.inf
count = 0
for v, sample, _ in table.iter():
if count >= limit:
break
single_sample = Table(v[:, np.newaxis], obs_ids, [sample], obs_md)
single_sample.filter(lambda v_, i, md: v_ > 0, axis='observation')
biomv1 = single_sample.to_json('AG')
biomtxt = single_sample.to_tsv(
header_key='taxonomy',
header_value='taxonomy',
metadata_formatter=lambda x: '; '.join(x))
yield (sample, biomv1, biomtxt)
count += 1