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. (洛谷P2512||bzoj1045) [HAOI2008]糖果传递 || 洛谷P4016 负载平衡问题 || UVA11300 Spreading the Wealth || (洛谷P3156||bzoj3293) [CQOI2011]分金币

    bzoj1045 洛谷P4016 洛谷P2512 bzoj3293 洛谷P3156 题解:https://www.luogu.org/blog/LittleRewriter/solution-p251 ...

  2. Java EE学习笔记(六)

    初识MyBatis 1.MyBatis的定义 1).MyBatis(前身是iBatis)是一个支持普通SQL查询.存储过程以及高级映射的持久层框架. 2).MyBatis框架也被称之为ORM(Obje ...

  3. java transient关键字作用,使用场景

    transient的作用及使用方法,官方解释为: Variables may be marked transient to indicate that they are not part of the ...

  4. php出现Warning: file_put_contents,failed to open stream

    Warning: file_put_contents(D:/wwwroot/jinxiongdi/web/temp/caches/f/index_40F756F0.php) [function.fil ...

  5. css与JS知识整理

    CSS知识 CSS选择器:基础中的核心,选择器指明了{}中“样式”作用的对象,也就是“样式”作用于网页中的哪些元素. CSS选择器类型:一共三大类. 基础选择器    属性选择器    组合选择器  ...

  6. Mybatis中的复合条件查询

    1.Map中根据字段名存儲: 定义接口:List<Student> selectByCondition1(Map<String,Object> map); 映射文件: < ...

  7. Java基础之入门介绍

    基础知识 1.JVM.JRE和JDK的区别:     JVM(Java Virtual Machine):java虚拟机,用于保证java的跨平台的特性.                   java ...

  8. Android线程池(转)

    .前言 转载请注明出处:http://blog.csdn.net/seu_calvin/article/details/52415337 使用线程池可以给我们带来很多好处,首先通过线程池中线程的重用, ...

  9. shell中使用ssh

    ssh服务是不能用非交互的方式传递密码,想不输入密码,直接ssh连接到服务器有两种方法,sshpass和expect sshpass # wget http://downloads.sourcefor ...

  10. 【数据库-Azure SQL Database】JDBC 如何连接 SQL Azure 数据库

    使用 JAVA 代码连接 Azure SQL Database 时产生了 SSL 错误,对于此问题大多数用户都是因为不知如何编写 JDBC 连接字符串而产生的,以下为相关示例代码,供您参考:   pa ...