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 ...
随机推荐
- 归档-对模型数组对象(存储到本地的plist文件)也数组里存放的是模型
一.模型文件 (1)JLMainViewsModel.h文件 必须遵循 NSCoding协议 @interface JLMainViewsModel : NSObject<NSCopying,N ...
- python 基础(五) 迭代器与生成器
迭代器和生成器 迭代器 iterator (1) 迭代对象: 可以直接作用于for循环的 称为可迭代对象(iterable)可以通过 isinstance 判断是否属于可迭代对象 可以直接作用于for ...
- JS面向对象方法(二) 面向对象方法实现橱窗式图面预览以及放大功能
效果图: HTML结构如下: <div id="preview"> <div id="mediumDiv"> <img id=& ...
- c#学习系列之字段(静态,常量,只读)
C#静态变量使用 static 修饰符进行声明,在类被实例化时创建,通过类进行访问不带有 static 修饰符声明的变量称做非静态变量.static变量在对象被实例化时创建,通过对象进行访问一个类的所 ...
- RS485的自动发送与布线
布线http://blog.sina.com.cn/s/blog_729a492301019owo.html 自动收发电路:485注意控制端电平问题(3.3/5V)
- setTimeout的核心原理和巧用
你所不了解的setTimeout 发表于 2015年11月23日 by 愚人码头 被浏览 14,756 次 分享到: 0 小编推荐:掘金是一个高质量的技术社区,从 ECMAScript 6 到 Vue ...
- 初始Mybatis,好累,自己感觉自己快坚持不了了
Mybatis1.持久化 持久化,就是内存数据和硬盘数据状态的转换 2.ORM思想Object Relation Mapping 对象关系映射 3.MyBatis入门案例 3.1导入jar包 依赖 & ...
- 第六章 设计程序架构 之 设计实现WebSocket策略
1. 概述 传统网页的通信方式是请求-响应模式,每次请求-响应都是新的连接.连接的建立和断开也是需要消耗资源的. WebSocket是基于TCP协议,实现单个连接上的双向通信. 本章内容包括: 异步读 ...
- 记AccessibilityService使用(转)
转自 :http://www.jianshu.com/p/ba298b8d5a6e 一.AccessibilityService的使用 首先先写一个类去继承AccessibilityService p ...
- 【extjs6学习笔记】0.2 准备:类库结构