文章目录

  • 简介
  • biom工具安装
  • 文件格式
  • 小提示和常见问题
  • 快速使用Quick Start
  • 文件格式转换
  • biom文件添加样本分组和物种注释
  • BIOM表统计
  • Reference
  • 附录1. Python中交互操作biom的函数
    • 函数
  • 猜你喜欢
  • 写在后面

简介

http://biom-format.org/

BIOM格式是微生物组领域最常用的结果保存格式,优点是可将OTU或Feature表、样本属性、物种信息等多个表保存于同一个文件中,且格式统一,体积更小巧,目前被微生物组领域几乎所有主流软件所支持:

  • QIIME
  • MG-RAST
  • PICRUSt
  • Mothur
  • phyloseq
  • MEGAN
  • VAMPS
  • metagenomeSeq
  • Phinch
  • RDP Classifier
  • USEARCH
  • PhyloToAST
  • EBI Metagenomics
  • GCModeller
  • MetaPhlAn 2

BIOM格式于2012年Rob Knight首发于我国GigaScience杂志上,被引242次。

The Biological Observation Matrix (or BIOM, canonically pronounced biome) 是微生物组分析的核心数据类型。

我们主要了解以下三方面的内容:

  1. BIOM文件格式的定义;
  2. biom命令对文件格式的转换、添加元数据、总结等;
  3. 使用Python和R操作BIOM文件

biom工具安装

常用的biom操作工具是一个python包,可通过pip、conda等安装

# 安装依赖关系科学计算包
pip install numpy
# 安装biom包
pip install biom-format
# 安装biom2.0格式支持
pip install h5py
# 显示命令行
biom

更推荐,conda安装 python和r相应的操作包

相应bioconda包在 https://bioconda.github.io/recipes.html 查询名称和版本详细

# 安装Python包
conda install biom-format # 2.1.7
# 安装r的biom包
conda install r-biom
# 或安装r微生物组包,包括了r-biom
conda install bioconductor-microbiome

主要功能如下

sage: biom [OPTIONS] COMMAND [ARGS]...ptions:--version   版本Show the version and exit.-h, --help  帮助Show this message and exit.ommands:add-metadata       添加元数据 Add metadata to a BIOM table.convert            文本表格与biom互转 Convert to/from the BIOM table format.from-uc            转换uc为biom Create a BIOM table from a vsearch/uclust/usearch BIOM...head               跳过表头 Dump the first bit of a table.normalize-table    标准化 Normalize a BIOM table.show-install-info  提供安装信息 Provide information about the biom-format installation.subset-table       提取子集 Subset a BIOM table.summarize-table    统计摘要 Summarize sample or observation data in a BIOM table.table-ids          转储 Dump IDs in a table.validate-table     格式验证 Validate a BIOM-formatted file.

文件格式

http://biom-format.org/documentation/biom_format.html

BIOM目前分为1.0 JSON2.0 HDF5两个版本;

1.0 JSON是编程语言广泛支持的格式,类似于散列的键值对结果。会根据数据松散程度,选择不同的存储结构来节省空间。

2.0 HDF5是二进制格式,被许多程序语言支持,读取更高效和节约空间。

小提示和常见问题

BIOM的目的是存储和处理大、松散的表;储存研究主要信息为单个文件;格式在不同软件间通用。

下面是OTU表常用存储的两种样式

紧密OTU表 A dense representation of an OTU table:

OTU ID PC.354  PC.355  PC.356
OTU0   0   0   4
OTU1   6   0   0
OTU2   1   0   7
OTU3   0   0   3

松散OTU表 A sparse representation of an OTU table:

PC.354 OTU1 6
PC.354 OTU2 1
PC.356 OTU0 4
PC.356 OTU2 7
PC.356 OTU3 3

OTU表经常会有90%的0,甚至99%为0。其中BIOM 1.0支持松散、紧密两种格式;BIOM2.x仅支持松散格式。

封装核心研究数据(OTU表、样本信息和OTU物种注释)至单个文件

快速使用Quick Start

本节讲指在python中交互操作biom格式文件,我不常用,具体见附录1.

文件格式转换

convert命令可以将文本格式的表格与biom格式间自由转换。

  • 转换为制表符分隔的表格,方便在Excel等程序中查看;
  • 转换松散或紧密格式的biom(biom1.0只支持紧密dense格式)

制表符分隔的表格通常称为经典格式表格,BIOM格式称为biom表格。

转换经典表格为HDF5或JSON格式

biom convert -i table.txt -o table.from_txt_json.biom --table-type="OTU table" --to-json
biom convert -i table.txt -o table.from_txt_hdf5.biom --table-type="OTU table" --to-hdf5

转换biom为经典格式

biom convert -i table.biom -o table.from_biom.txt --to-tsv

转换biom为经典格式,并在最后列包括物种注释信息

biom convert -i table.biom -o table.from_biom_w_taxonomy.txt --to-tsv --header-key taxonomy

转换biom为经典格式,并在最后列包括物种注释信息,并改名为ConsensusLineage

此功能对于一些软件要求指定的列名有很有用。

biom convert -i table.biom -o table.from_biom_w_consensuslineage.txt --to-tsv --header-key taxonomy --output-metadata-id "ConsensusLineage"

带物种注释表格互转

biom convert -i table.biom -o table_tax.txt --to-tsv --header-key taxonomy
biom convert -i table_tax.txt -o new_table.biom --to-hdf5 --table-type="OTU table" --process-obs-metadata taxonomy
biom convert -i table_tax.txt -o new_table.biom --to-json --table-type="OTU table" --process-obs-metadata taxonomy

转换QIIME1.4早期表格为BIOM格式(不常用)

sed 's/Consensus Lineage/ConsensusLineage/' < otu_table.txt | sed 's/ConsensusLineage/taxonomy/' > otu_table.taxonomy.txt
biom convert -i otu_table.taxonomy.txt -o otu_table.from_txt.biom --table-type="OTU table" --process-obs-metadata taxonomy --to-hdf5

biom文件添加样本分组和物种注释

biom add-metadata -h # 显示帮助

Usage: biom add-metadata [OPTIONS]Add metadata to a BIOM table.Add sample and/or observation metadata to BIOM-formatted files. Seeexamples here: http://biom-format.org/documentation/adding_metadata.htmlExample usage:Add sample metadata to a BIOM table:$ biom add-metadata -i otu_table.biom -o table_with_sample_metadata.biom-m sample_metadata.txtOptions:-i, --input-fp FILE             输入文件The input BIOM table  [required]-o, --output-fp FILE            输出文件The output BIOM table  [required]-m, --sample-metadata-fp FILE   样本信息The sample metadata mapping file (will addsample metadata to the input BIOM table, ifprovided).--observation-metadata-fp FILE  OTU物种注释 The observation metadata mapping file (willadd observation metadata to the input BIOMtable, if provided).--sc-separated TEXT             元数据按分号分隔,如物种分类级 Comma-separated list of the metadata fieldsto split on semicolons. This is useful forhierarchical data such as taxonomy orfunctional categories.--sc-pipe-separated TEXT        元数据按竖线分隔,如lefse Comma-separated list of the metadata fieldsto split on semicolons and pipes ("|"). Thisis useful for hierarchical data such asfunctional categories with one-to-manymappings (e.g. x;y;z|x;y;w)).--int-fields TEXT                分号分隔的整数 Comma-separated list of the metadata fieldsto cast to integers. This is useful forinteger data such as "DaysSinceStart".--float-fields TEXT             分号分隔的符点数 Comma-separated list of the metadata fieldsto cast to floating point numbers. This isuseful for real number data such as "pH".--sample-header TEXT            指定样本属性列名 Comma-separated list of the sample metadatafield names. This is useful if a header lineis not provided with the metadata, if youwant to rename the fields, or if you want toinclude only the first n fields where n isthe number of entries provided here.--observation-header TEXT       OTU属性样名 Comma-separated list of the observationmetadata field names. This is useful if aheader line is not provided with themetadata, if you want to rename the fields,or if you want to include only the first nfields where n is the number of entriesprovided here.--output-as-json                输出JSON格式 Write the output file in JSON format.-h, --help                      帮助 Show this message and exit.

你的样本分组文件是这样格式的

head sample.txt

#SampleID       BarcodeSequence genotype
KO1     TAGCTT  KO
KO2     GGCTAC  KO
KO3     CGCGCG  KO

你的物种注释信息是这样的

head taxonomy.txt

#OTUID  taxonomy        confidence
OTU_325 k__Bacteria;p__Bacteroidetes;c__Flavobacteriia;o__Flavobacteriales;f__Cryomorphaceae;g__;s__    0.880
OTU_324 k__Bacteria;p__Chlorobi;c__SJA-28;o__;f__;g__;s__       1.000

添加样本分组信息

biom add-metadata -i table.biom -o table.w_smd.biom --sample-metadata-fp sample.txt

添加OTU注释

biom add-metadata -i table.biom -o table.w_omd.biom --observation-metadata-fp taxonomy.txt

添加样本和OTU注释

biom add-metadata -i table.biom -o table.w_md.biom --observation-metadata-fp taxonomy.txt --sample-metadata-fp sample.txt

同时添加行列信息
可以指定注释的列格式,如整数integers (–int-fields)、浮点小数 (–float-fields)、或物种层级注释并用分号分隔 (–sc-separated)

biom add-metadata -i table.biom -o table.w_md.biom --observation-metadata-fp taxonomy.txt --sample-metadata-fp sample.txt --sc-separated taxonomy --float-fields confidence

–observation-header和–sample-header可以重命名列名,

biom add-metadata -i min_sparse_otu_table.biom -o table.w_smd.biom --sample-metadata-fp sam_md.txt --sample-header SampleID,BarcodeSequence,DateOfBirthbiom add-metadata -i min_sparse_otu_table.biom -o table.w_omd.biom --observation-metadata-fp obs_md.txt --observation-header OTUID,taxonomy,confidence

可以指定名称的列读入

biom add-metadata -i min_sparse_otu_table.biom -o table.w_omd.biom --observation-metadata-fp obs_md.txt --observation-header OTUID,taxonomy --sc-separated taxonomy

BIOM表统计

biom summarize-table -h

统计每个样品

biom summarize-table -i table.w_md.biom -o table.w_md_summary.txt

示例结果如下:

Num samples: 27
Num observations: 975
Total count: 409647
Table density (fraction of non-zero values): 0.464Counts/sample summary:Min: 2352.0Max: 35955.0Median: 14851.000Mean: 15172.111Std. dev.: 10691.823Sample Metadata Categories: BarcodeSequence; genotypeObservation Metadata Categories: taxonomy; confidenceCounts/sample detail:
OE4: 2352.0
OE3: 2353.0
OE8: 3091.0
OE2: 3173.0

统计每个样本中的观察值数量unique observations per sample,即alpha多样性 richness

biom summarize-table -i table.w_md.biom --qualitative -o table.w_md_qual_summary.txt

结果如下:

Num samples: 27
Num observations: 975Observations/sample summary:Min: 222Max: 633Median: 486.000Mean: 452.704Std. dev.: 138.713Sample Metadata Categories: BarcodeSequence; genotypeObservation Metadata Categories: taxonomy; confidenceObservations/sample detail:
OE3: 222
OE4: 248
OE8: 261
OE1: 272
OE2: 278

Reference

The Biological Observation Matrix (BIOM) format or: how I learned to stop worrying and love the ome-ome.
Daniel McDonald, Jose C. Clemente, Justin Kuczynski, Jai Ram Rideout, Jesse Stombaugh, Doug Wendel, Andreas Wilke, Susan Huse, John Hufnagle, Folker Meyer, Rob Knight, and J. Gregory Caporaso.
GigaScience 2012, 1:7. doi:10.1186/2047-217X-1-7

http://biom-format.org/

附录1. Python中交互操作biom的函数

函数

Python中只要有biom包,可在Python交互的命令行中读取

load_table(f) 函数读取biom文件

读取并展示biom的内置数据

>>> from biom import example_table
>>> print(example_table)
# Constructed from biom file
#OTU ID S1  S2  S3
O1  0.0 1.0 2.0
O2  3.0 4.0 5.0

从文件读取biom文件

from biom import load_table
table = load_table('otutab.biom')

Table函数

Table(data, observation_ids, sample_ids[, …])

import numpy as np
from biom.table import Table
data = np.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']}]
table = Table(data, observ_ids, sample_ids, observ_metadata,
sample_metadata, table_id='Example Table')table # 表格信息print(table) # 输出表格print(table.ids()) # 显示样本名print(table.ids(axis='observation')) # 显示观测值名称print(table.nnz)  # 非零number of nonzero entries

我更喜欢命令行模型,对于Python中交互使用,更多代码详见 http://biom-format.org/documentation/table_objects.html

猜你喜欢

  • 10000+: 菌群分析
    宝宝与猫狗 提DNA发Nature 实验分析谁对结果影响大 Cell微生物专刊 肠道指挥大脑
  • 系列教程:微生物组入门 Biostar 微生物组 宏基因组
  • 专业技能:生信宝典 学术图表 高分文章 不可或缺的人
  • 一文读懂:宏基因组 寄生虫益处 进化树
  • 必备技能:提问 搜索 Endnote
  • 文献阅读 热心肠 SemanticScholar Geenmedical
  • 扩增子分析:图表解读 分析流程 统计绘图
  • 16S功能预测 PICRUSt FAPROTAX Bugbase Tax4Fun
  • 在线工具:16S预测培养基 生信绘图
  • 科研经验:云笔记 云协作 公众号
  • 编程模板: Shell R Perl
  • 生物科普: 肠道细菌 人体上的生命 生命大跃进 细胞暗战 人体奥秘

写在后面

为鼓励读者交流、快速解决科研困难,我们建立了“宏基因组”专业讨论群,目前己有国内外2600+ 一线科研人员加入。参与讨论,获得专业解答,欢迎分享此文至朋友圈,并扫码加主编好友带你入群,务必备注“姓名-单位-研究方向-职称/年级”。技术问题寻求帮助,首先阅读《如何优雅的提问》学习解决问题思路,仍末解决群内讨论,问题不私聊,帮助同行。

学习扩增子、宏基因组科研思路和分析实战,关注“宏基因组”

点击阅读原文,跳转最新文章目录阅读
https://mp.weixin.qq.com/s/5jQspEvH5_4Xmart22gjMA

BIOM:生物观测矩阵——微生物组数据通用数据格式相关推荐

  1. json txt格式转换器_BIOM:生物观测矩阵——微生物组数据通用数据格式

    简介 http://biom-format.org/ BIOM格式是微生物组领域最常用的结果保存格式,优点是可将OTU或Feature表.样本属性.物种信息等多个表保存于同一个文件中,且格式统一,体积 ...

  2. r语言怎么把txt数据变成一个Rdata格式_BIOM:生物观测矩阵——微生物组数据通用数据格式...

    简介 http://biom-format.org/ BIOM格式是微生物组领域最常用的结果保存格式,优点是可将OTU或Feature表.样本属性.物种信息等多个表保存于同一个文件中,且格式统一,体积 ...

  3. BIOM格式文件_微生物组数据通用数据格式

    生物观测矩阵(Biological Observation Matrix,BIOM)是微生物组数据通用数据格式(The Biological Observation Matrix (BIOM) for ...

  4. R包animalcules-一键式交互探索微生物组数据

    写在前面 这个包最优雅的地方在于交互式,所以学习的主要目的也就是交互式的实践.交互 图可以很好的探索数据,但一般不支持输出矢量图,不方便下游编辑和修改和用于发表.如果你找到了导出矢量图方法,请留言. ...

  5. Nature综述:Rob Knight带你分析微生物组数据(2020版)

    文章目录 微生物组分析最佳实践 导读 摘要Abstract 背景介绍Introduction 实验设计Experimental design 图1. 微生物组实验设计中的注意事项 知识点1. 优秀工作 ...

  6. Nature综述:Rob Knight带你分析微生物组数据

    微生物组分析最佳实践 Best practices for analysing microbiomes Impact Factor:34.648 https://doi.org/10.1038/s41 ...

  7. R语言统计分析微生物组数据(第三章3)

    3.4 微生物数据组成分析 早在1897年,皮尔逊就警告说,在器官测量中使用两个绝对测量值的比值,可能会形成"伪相关".自1920s以来,地质学的研究人员已经知道,使用标准的统计方 ...

  8. Brief Bioinform | 农科院深圳基因组所王怡雯组提出一种去除微生物组数据中批次效应的多元算法框架...

    PLSDA-batch:去除微生物组数据中批次效应的多元算法框架 PLSDA-batch: a multivariate framework to correct for batch effects ...

  9. NBT:Rob Knight团队发表微生物组数据降维新方法

    上下文感知的降维解卷积肠道微生物群落动态 Context-aware dimensionality reduction deconvolutes gut microbial community dyn ...

最新文章

  1. 应用丨AI和机器学习如何改变美国政府决策方式
  2. 程序猿工作效率的影响因素和管理者怎样推断
  3. PyQt5 技术篇 - 按钮隐藏并保留位置,pyqt5设置按钮的可见度,设置按钮透明度
  4. shell 打印追加_[转]shell 数组定义、使用和追加
  5. MySQL数据库select语句的使用方法
  6. java8 lambda表达式实现自定义用户组件,Don't Repeat Yourself
  7. hive分区用2个字段有何限制_[特性]Hive动态分区功能使用
  8. Connect to repo.maven.apache.org:443 [repo.maven.apache.org/151.101.24.215] failed: connect timed ou
  9. js截屏代码_服务端浏览器截屏
  10. Lesson5 一阶自治微分方程
  11. python代码-在哪里编写python代码
  12. CSS - Iconfont
  13. java毕设项目教务排课系统(附源码)
  14. Speed Gear(变速精灵XP) V6.0 - 免费版,破解版,绿色版
  15. 光流法+FAST特征点
  16. 如何解决(网页)粘贴数据到excel数据变换问题
  17. xlsxwriter去掉网格线_python 中 xlsxwriter 模块的使用
  18. [软件更新]vidalia 0.2.0.32
  19. 防风雨密封胶的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告
  20. 深入理解Magento第五章 – Magento资源配置

热门文章

  1. Matlab中图像函数大全 - [基础知识]
  2. Lock锁与synchronized锁的区别
  3. 2019寒假作业3 编程总结
  4. Acwing第 64 场周赛【未完结】
  5. 配置正确但是 Aria2 RPC 服务器错误解决方案 2023
  6. 判断能否构成三角形C++
  7. android biz,BizConf Video Pro
  8. solidworks三维建模竞赛练习题
  9. 关联分析python牛奶面包_Python数据分析基础ReadingDay13_关联分析Apriori
  10. Link2SD ,内存自定义映射软件,功能比较灵活。