首页 > 代码库 > BIOM Table-codes
BIOM Table-codes
import numpy
from biom.table import Table
============================================================================================================
# 10*4 matrix, [0, 39]
data = http://www.mamicode.com/numpy.arange(40).reshape(10, 4)
sample_ids = [‘S%d‘ % i for i in range(4)]
observ_ids = [‘O%d‘ % i for i in range(10)]
sample_metadata = http://www.mamicode.com/[{‘environment‘: ‘A‘}, {‘environment‘: ‘B‘},
{‘environment‘: ‘A‘}, {‘environment‘: ‘B‘}]
observ_metadata = http://www.mamicode.com/[{‘taxonomy‘: [‘Bacteria‘, ‘Firmicutes‘]},
{‘taxonomy‘: [‘Bacteria‘, ‘Firmicutes‘]},
{‘taxonomy‘: [‘Bacteria‘, ‘Proteobacteria‘]},
{‘taxonomy‘: [‘Bacteria‘, ‘Proteobacteria‘]},
{‘taxonomy‘: [‘Bacteria‘, ‘Proteobacteria‘]},
{‘taxonomy‘: [‘Bacteria‘, ‘Bacteroidetes‘]},
{‘taxonomy‘: [‘Bacteria‘, ‘Bacteroidetes‘]},
{‘taxonomy‘: [‘Bacteria‘, ‘Firmicutes‘]},
{‘taxonomy‘: [‘Bacteria‘, ‘Firmicutes‘]},
{‘taxonomy‘: [‘Bacteria‘, ‘Firmicutes‘]}]
# construct table
table = Table(data, observ_ids, sample_ids, observ_metadata, sample_metadata, table_id=‘myTestTable‘)
# print info of table
table
print(table)
#
print column names
print(table.ids())
print(table.ids(axis=‘sample‘))
# print row names
print(table.ids(axis=‘observation‘))
# print number of non-zero entries. Now it’s 39.
print(table.nnz)
============================================================================================================
data = http://www.mamicode.com/numpy.asarray([[2, 0], [6, 1]])
table = Table(data, [‘O1‘, ‘O2‘], [‘S1‘, ‘S2‘])
# normalize by ‘sample’(column)
new_table = table.norm(inplace=False)
#
normalize by row
new_table = table.norm(axis=‘observation‘, inplace=False)
# if inplace=True, table will change too. Now it stay unchanged. If set table1 = table before norm, and change table1 now, then table will change, too(shallow copy).
============================================================================================================
============================================================================================================
<style>p { margin-bottom: 0.25cm; line-height: 120% } a:link { }</style>BIOM Table-codes