BIOM Table-codes
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的更多相关文章
- Java(JCo3)与SAP系统相互调用
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- [SAP ABAP开发技术总结]BAPI调用
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- python练习册 每天一个小程序 第0002题
1 #-*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目描述: 5 将 0001 题生成的 200 个激活码(或者优惠券)保存到 MySQL 关系型 ...
- 输入法词库解析(七)微软用户自定义短语.dat
详细代码:https://github.com/cxcn/dtool 前言 微软拼音和微软五笔通用的用户自定义短语 dat 格式. 解析 前 8 个字节标识文件格式 machxudp,微软五笔的 le ...
- System Error Codes
很明显,以下的文字来自微软MSDN 链接http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx M ...
- Windows Locale Codes - Sortable list(具体一个语言里还可具体细分,中国是2052,法国是1036)
Windows Locale Codes - Sortable list NOTE: Code page is an outdated method for character encoding, y ...
- [ZT]Language codes – MFC
Below is table with all MFC language codes. I think it can be sometimes very useful. First column c ...
- Table Properties [AX 2012]
Table Properties [AX 2012] 1 out of 2 rated this helpful - Rate this topic Updated: July 20, 2012 Ap ...
- Windows Sockets Error Codes
https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx Most Windows Sockets ...
随机推荐
- [題解](并查集)luogu_P2391 白雪皚皚
今天被老師留的作業搞死了,全是裸的水題,難題就那麼兩道我還沒寫......,狗屎 1.倒序處理,每個點至多會被更新一次 2.所以要做的就是快速找到下一個不同顏色的點, 3.然而不知道怎麼就 想到用并查 ...
- Linux —— 文件搜索命令
文件搜索命令(配置文件/etc/updatedb.conf) locate 文件名 搜索速度非常快 在后台数据库中按照文件名搜索 updatedb 更新数据库 只可以按照文件名搜索 whereis 命 ...
- Codeforces Round #532(Div. 2) C.NN and the Optical IIIusion
链接:https://codeforces.com/contest/1100/problem/C 题意: 一个圆球外面由其他圆球包裹,两两相连. 给出n,r. n为外面圆球数量,r为内部圆球半径. 求 ...
- 24 使用Maven 或 Gradle构建groovy
1 使用Maven 或 Gradle构建groovy 1.1 使用maven构建groovy pom.xml file. <dependencies> ... oth ...
- object-position和object-fit
今天在用video标签时发现改变video的宽和高,它里面播放内容由于比例的限制无法充满我设置的宽高,这时要是有类似background-size属性该是多好.网上一查果然找到了css3中的objec ...
- jupyter notebook dead kernel问题解决
背景: 我在刚安装好的tensorflow环境下启动jupyter notebook,无论是浏览器还是控制台,提示都是关于dead kernel.然后就查嘛,更新大发好. 但是我在控制台里按照其他人说 ...
- vue使用props动态传值给子组件里的函数用,每次更新,呼叫函数
父组件 <template> <div id="app"> <div>详情内容</div> <button v-on:clic ...
- TruncateTable数据库清理
原文引用 https://www.cnblogs.com/liangxiaoking/p/5958456.html 本地链接下载 https://files.cnblogs.com/files/she ...
- Redis的下载安装
Redis官网只提供了Linux版,MicroSoft自己搞了个Windows版,可在GitHub下载: https://github.com/microsoftarchive/redis/relea ...
- 解析C++普通局部变量与指针类型的对象变量的应用区别
首先我们先来了解一下MFC中的CPtrArray类,他可以说是CObject类型指针对象的集合.通过intAdd( CObject* newElement );注意参数是一个指针类型)可以向集合中添加 ...