码迷,mamicode.com
首页 > 其他好文 > 详细

BIOM Table-codes

时间:2017-02-10 18:18:47      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:top   npm   fst   tts   crc   lua   ahci   san   nap   

import numpy

from biom.table import Table

============================================================================================================

# 10*4 matrix, [0, 39]

data = 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 = [{‘environment‘: ‘A‘}, {‘environment‘: ‘B‘},

{‘environment‘: ‘A‘}, {‘environment‘: ‘B‘}]

observ_metadata = [{‘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 = 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).

 

============================================================================================================

============================================================================================================

BIOM Table-codes

标签:top   npm   fst   tts   crc   lua   ahci   san   nap   

原文地址:http://www.cnblogs.com/pxy7896/p/6386892.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!