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. POJ-1062-昂贵的聘礼(枚举)

    链接:https://vjudge.net/problem/POJ-1062 题意: 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为 ...

  2. 洛谷 P4092 [HEOI2016/TJOI2016]树 || bzoj4551

    https://www.lydsy.com/JudgeOnline/problem.php?id=4551 https://www.luogu.org/problemnew/show/P4092 这当 ...

  3. 502的错误其实不是nginx的问题,要从后端找原因。php-cgi进程数不够用、php执行时间长、或者是php-cgi进程死掉,都会出现502错误。

    502的错误其实不是nginx的问题,要从后端找原因.php-cgi进程数不够用.php执行时间长.或者是php-cgi进程死掉,都会出现502错误.

  4. js onclick=‘save()’ 和 onclick='return save()'

    onclick="function()" 表示只会执行 function , 但是不会传回 function 中之回传值onclick = "return functio ...

  5. HTML <form> 标签的 enctype

    form的enctype有三种 application/x-www-form-urlencoded 在发送前编码所有字符(默认) multipart/form-data 不对字符编码. 在使用包含文件 ...

  6. chrome浏览器好用的一些插件

    1. Listen 1(听音乐) 2. The Great Suspender(定时释放chrome 打开的页面内存) 3. Similar Web(页面流量分析) 4. Advertising Te ...

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

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

  8. 判断后台service是否在运行

    public static boolean isServiceRunning(Context mContext,String className) { boolean isRunning = fals ...

  9. android 从contentView中删除view

    1. ((ViewGroup)view.getParent()).removeView(view) 2. ViewGroup rootView = (ViewGroup) this.findViewB ...

  10. linux服务器上的jenkins远程触发构建windows server 2012服务器上的jenkins任务

    本文来自:https://blog.csdn.net/huashao0602/article/details/53318295  非常感谢原博主,亲测可行,这是我做CI持续集成试过的第6套方案了! 背 ...