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. html文本框和按钮这些点击时不显示边框的光晕

    直接在样式加:focus{outline:0;}这样子就可以了

  2. nopCommerce - asp.net开源商城

    nopcommerce官网 http://nopcommerce.codeplex.com/ nopCommerce is a open source e-commerce solution that ...

  3. asp.net网页跳转

    1.Response.Redirect("http://www.bcbbs.net",false);    目标页面和原页面可以在2个服务器上,可输入网址或相对路径.后面的bool ...

  4. SpringBoot 2.x (9):整合Mybatis注解实战

    SSM框架再熟悉不过了,不过以前通常是使用XML写SQL语句 这里用SpringBoot整合Mybatis并且使用注解进行开发 依赖: <!-- Mybatis --> <depen ...

  5. JVM垃圾回收机制一

    JVM内存分配与回收 JVM 分代 JVM把堆分为年轻代和老年代,年轻代又分为1个Eden区和2个Survivor区,Eden和Survivor的内存的大小比例是8:1:1. 为什么要分代? 很大的原 ...

  6. Objective-C Data Encapsulation

    All Objective-C programs are composed of the following two fundamental elements: Program statements ...

  7. 4G牌照影响

    与3G牌照发放整整讨论了10年不同,4G牌照发放在2009年3G规模建设4年后就进行了发放,也颇匹配于行业的加速度.那么,4G到底会在哪些方面.在何种程度上改变中国呢?其实,4G的影响可能没有那么大, ...

  8. 第14周翻译:SQL Server的阶梯安全级别2

    SQL Server的阶梯安全级别2:身份验证 源自:http://www.sqlservercentral.com/articles/Stairway+Series/109975/ 作者:Don K ...

  9. Python 学习日志9月19日

    9月19日 周二 今天是普通的一天,昨天也是普通的一天,刚才我差点忘记写日志,突然想起来有个事情没做,回来写. 今天早晨学习<Head First HTML and CSS>第十一章节“布 ...

  10. Python实现1-9数组形成的结果为100的所有运算式

    问题: 编写一个在1,2,…,9(顺序不能变)数字之间插入+或-或什么都不插入,使得计算结果总是100的程序,并输出所有的可能性.例如:1 + 2 + 34–5 + 67–8 + 9 = 100. f ...