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')

# use add_metadata. This is ADD, NOT CONSTRUCT!

#table.add_metadata(sample_metadata, axis='sample')

# 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).

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

# filter with a function

filter_f = lambda values, id_, md: md['environment'] == 'A'

env_a = normed.filter(filter_f, axis='sample', inplace=False)

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

# divide by 'environment'

part_f = lambda id_, md: md['environment']
env_tables = table.partition(part_f, axis='sample')

# make a sum
for partition, env_table in env_tables:

print(partition, env_table.sum('sample'))

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

# add-metadata

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

biom convert -i table.biom -o table.from_biom_w_consensuslineage.txt --to-tsv --header-key taxonomy --output-metadata-id "ConsensusLineage"

# 1. convert .biom to .txt

# special header-key

biom convert -i otu_table.biom -o otu_table.txt --to-tsv --header-key taxonomy

# 2. fix in excel

# 3. convert back

biom convert -i otu_table.txt -o new_otu_table.biom --to-hdf5 --table-type="OTU table" --process-obs-metadata taxonomy

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

biom summarize-table -i INPUT.biom --qualitative -o OUTPUT.txt

BIOM Table-codes的更多相关文章

  1. Java(JCo3)与SAP系统相互调用

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  2. [SAP ABAP开发技术总结]BAPI调用

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  3. python练习册 每天一个小程序 第0002题

    1 #-*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目描述: 5 将 0001 题生成的 200 个激活码(或者优惠券)保存到 MySQL 关系型 ...

  4. 输入法词库解析(七)微软用户自定义短语.dat

    详细代码:https://github.com/cxcn/dtool 前言 微软拼音和微软五笔通用的用户自定义短语 dat 格式. 解析 前 8 个字节标识文件格式 machxudp,微软五笔的 le ...

  5. System Error Codes

    很明显,以下的文字来自微软MSDN 链接http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx M ...

  6. Windows Locale Codes - Sortable list(具体一个语言里还可具体细分,中国是2052,法国是1036)

    Windows Locale Codes - Sortable list NOTE: Code page is an outdated method for character encoding, y ...

  7. [ZT]Language codes – MFC

    Below is table with all MFC language codes. I think it can be sometimes very useful.  First column c ...

  8. Table Properties [AX 2012]

    Table Properties [AX 2012] 1 out of 2 rated this helpful - Rate this topic Updated: July 20, 2012 Ap ...

  9. Windows Sockets Error Codes

    https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx Most Windows Sockets ...

随机推荐

  1. Day2课后作业:购物车简单版

    PRODUCT_LIST = [ ['iphone7',6500], ['macbook',12000], ['pythonbook',66], ['bike',999], ['coffee',31] ...

  2. [JLOI2016]圆的异或并

    Description 在平面直角坐标系中给定N个圆.已知这些圆两两没有交点,即两圆的关系只存在相离和包含.求这些圆的异或面积并.异或面积并为:当一片区域在奇数个圆内则计算其面积,当一片区域在偶数个圆 ...

  3. [JSOI2009]密码

    Description Input Output Sample Input 10 2 hello world Sample Output 2 helloworld worldhello HINT 一看 ...

  4. UVA11988:悲剧文本(模拟链表)

    You’re typing a long text with a broken keyboard. Well it’s not so badly broken. The only problem wi ...

  5. sftp 常用命令 以及 以及与 scp 的比较

    1.scp 不能容忍网络闪断,因此一旦出现网络闪断,那么scp 命令就会异常退出 sftp 可以容忍网络闪断,而且具备断电续传,因此sftp 适用于网络更慢的环境, 2. sftp 是一个交互式文件传 ...

  6. jquery offsetParent()源码解读

    offsetParent: function() { return this.map(function() { var offsetParent = this.offsetParent || docE ...

  7. CI模板中如何引入模板

    <?php $this->load->view('index/head.html') ?>

  8. zTree树插件动态加载

    需求: 由于项目中家谱图数据量超大,而一般加载方式是通过,页面加载时 zTree.init方法进行数据加载,将所有数据一次性加载到页面中.而在项目中家谱级别又非常广而深,成千上万级,因此一次加载,完全 ...

  9. jQuery3.2.1 和2.0和 1区别

    1. 移除旧的IE工作区新的最终版最主要的目标是更加快速,更加时尚,因此,那些支持早于IE9版本的相关技术与工作区都被移除了.这意味着如果你想要或者需要支持IE6-8,你必须用回1.12版本,因为甚至 ...

  10. ES-windos环搭建-ik中文分词器

    ik下载 打开Github官网,搜索elasticsearch-analysis-ik,单击medcl/elasticsearch-analysis-ik.或者直接点击 在readme.md文件中,下 ...