本文整理汇总了Python中biom.table.Table.sum方法的典型用法代码示例。如果您正苦于以下问题:Python Table.sum方法的具体用法?Python Table.sum怎么用?Python Table.sum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类biom.table.Table
的用法示例。
在下文中一共展示了Table.sum方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: filter_BIOM_by_per_sample_read_prop
# 需要导入模块: from biom.table import Table [as 别名]
# 或者: from biom.table.Table import sum [as 别名]
def filter_BIOM_by_per_sample_read_prop(BIOM, min_prop=0.01):
"""
Filter OTU table by mininimum reads per sample
"""
import numpy as np
from biom.table import Table
print "\nFiltering at level: %s %%\n" %(min_prop*100)
# print "input table:\n"
# print BIOM
# print "\n"
sample_ids = BIOM.ids(axis='sample')
observation_ids = BIOM.ids(axis='observation')
data_to_biom = []
sample_metadata = BIOM.metadata(axis='sample')
observation_metadata = BIOM.metadata(axis='observation')
sums = BIOM.sum(axis='sample')
for OTU in observation_ids:
orig=BIOM.data(OTU, axis='observation')
for i in range(len(orig)):
if not int(orig[i]) == 0:
if not int(orig[i]) >= sums[i]*min_prop:
orig[i] = '0.0'
data_to_biom.append(orig)
data = np.asarray(data_to_biom)
#construct adjusted table
table = Table(data, observation_ids, sample_ids, table_id='OTU table', sample_metadata=sample_metadata, observation_metadata=observation_metadata)
#Filter OTUs with sum = '0'
to_exclude = []
observation_sums = table.sum(axis='observation')
for i in range(len(observation_sums)):
if int(observation_sums[i]) == 0:
to_exclude.append(observation_ids[i])
print "Removing %i OTUs for lack of support\n" %len(to_exclude)
table.filter(to_exclude, invert=True, axis='observation',inplace=True)
# print table
return table