2019 1/24 lineageコマンドのミス修正
2019 7/5 ツイート追記
2019 7/9 タイトル修正、ツイート追記
2020 4/29 ツイート追記
2020 9/7 説明修正、タイトル変更
2020 9/8 インストール追記
2021 4/16 論文引用
NCBI taxonomy databaseは、公共のシーケンスデータベースに含まれるすべての生物の分類(以後taxonomy)および命名法をまとめたものである(NCBI、2018)。taxonomyデータベースの一般的な操作には、分類名からのtaxonomy ID(taxid)問い合わせ、または分類群からの系統問い合わせなどがある。NCBI taxaonomyデータベース(https://www.ncbi.nlm.nih.gov/taxonomy)には、視覚化とデータクエリのための包括的なドキュメントとツールが用意されている。
NCBIの公式Entrezプログラミングユーティリティ(E-utilities)(Sayers、2010)は、taxonomyデータベースから問い合わせるためのWebサービスを提供している。これは、バッチ処理などのプログラミング的な方法で使用できる。いくつかのツールキットもクエリ機能を提供している。 BioPythonのEntrezモジュール(Cock、et al、2009)は、データベースに対するさまざまな問い合わせのために、オンラインのEntrezサービスをpython関数にラップする。これらのオンラインクエリツールは最新のデータへのアクセスを提供するが、その間、処理速度はインターネット接続によって制限される。スタンドアロンツールはクエリを高速化するためにtaxonomy dump file(ftp://ftp.ncbi.nih.gov/pub/taxonomy/)をローカルデータベースにパースする。 ETE Toolkit(Huerta-Cepas et al、2016)は、NCBI taxonomy dump fileをSQLiteデータベースにして、pythonモジュールを介してクエリ機能を提供する。 Taxadb(Gourlé、2006)は、taxonomyデータをSQLite、MySQL、PostgreSQLなどのリレーショナルデータベースに変換する。 Ncbitax2lin(Xue、2016)は、NCBI taxonomy dump fileを系統に変換するPythonコマンドラインスクリプトである。それでも、taxonomyデータベースは頻繁に更新されるため、ローカルデータベースの再構築が必要になる。リレーショナルデータベースからのSQLクエリは、バッチクエリでは特に効率的ではない。taxonomy dump fileのファイルサイズがわずかであることと、ストレージデバイスの読み取り速度が徐々に増加していることを考慮すると、一般的なtaxonomyのデータ操作には、インターネット接続の制限がないダンプファイルの直接解析が速い。この記事では、NCBI taxonomyデータを迅速に操作するためのコマンドライン・ツールキットTaxonKitについて説明する。
taxonomyダンプファイルを効率的に解析するために、ツールキットを実装するためのコンパイル言語Go(https://golang.org/)を選択した。これは、Windows、Linux、およびMac OS Xを含む最も一般的なオペレーティングシステムのクロスコンパイルをサポートしている。 単一の実行可能バイナリファイルは、展開と実行が簡単である。 Taxonkitは「コマンドサブコマンド」の構造を採用している。サブコマンドは完全に独立した機能を提供し、標準ストリームまたはローカルファイルからのプレーンまたはgzip圧縮の入出力をサポートしている。 したがって、Taxonkitをコマンドラインパイプに簡単に組み合わせて、複雑な操作を実行できる。
現時点では、names.dmpおよびnodes.dmpファイル内の命名法および階層情報のみが使用されている。 Taxonkitのすべてのサブコマンドは、必要なデータをランダムアクセスメモリ(RAM)にロードし直接解析する。デーモンプロセスは使用しない。
usage
https://bioinf.shenwei.me/taxonkit/usage/
tutorial
Tutorial - TaxonKit - NCBI Taxonomy Toolkit
2022/02/25
TaxonKit v0.10.0 brings another new command for manipulating CAMI taxonomic profile format, `cami2-filter`, for removing taxa of given TaxIds and their descendants in CAMI metagenomic profile, and fixes a little bug for `taxonkit reformat`. Please update https://t.co/cZilfVI09j
— Wei Shen 沈伟 (@shenwei356) 2022年2月24日
2021 4/16
The TaxonKit (NCBI Taxonomy Toolkit) paper is online! Hope it could be helpful for taxonomy data manipulation in biomedical and ecological studies! https://t.co/PJi3IpZcOf pic.twitter.com/InMT8GxLZs
— Wei Shen 沈伟 (@shenwei356) 2021年4月16日
インストール
mac os10.14向け64bitバイナリをダウンロードし、テストした。
TaxonKit is implemented in Go programming language
本体
Donwloadよりmac、linux、windows向けバイナリをダウンロードできる。
sudo cp taxonkit /usr/local/bin/
#conda (link)
conda install -c bioconda taxonkit
#他にもbrew、goでのインストールがサポートされている。上のdownloadリンク参照
> taxonkit
$ taxonkit
TaxonKit - A cross-platform and Efficient NCBI Taxonomy Toolkit
Version: 0.3.0
Author: Wei Shen <shenwei356@gmail.com>
Source code: https://github.com/shenwei356/taxonkit
Documents : http://bioinf.shenwei.me/taxonkit
Dataset:
Please download and decompress "taxdump.tar.gz":
ftp://ftp.ncbi.nih.gov/pub/taxonomy/taxdump.tar.gz
and copy "names.dmp" and "nodes.dmp" to data directory:
"/Users/kazuma/.taxonkit"
or some other directory, and later you can refer to using flag --data-dir,
or environment variable TAXONKIT_DB
Usage:
taxonkit [command]
Available Commands:
genautocomplete generate shell autocompletion script
help Help about any command
lineage query lineage of given taxids
list list taxon tree of given taxids
name2taxid query taxid by taxon scientific name
reformat reformat lineage
version print version information and check for update
Flags:
--data-dir string directory containing nodes.dmp and names.dmp (default "/Users/kazuma/.taxonkit")
-h, --help help for taxonkit
--line-buffered use line buffering on output, i.e., immediately writing to stdin/file for every line of output
-o, --out-file string out file ("-" for stdout, suffix .gz for gzipped out) (default "-")
-j, --threads int number of CPUs. (default value: 1 for single-CPU PC, 2 for others) (default 2)
--verbose print verbose information
Use "taxonkit [command] --help" for more information about a command.
データベースの準備
使用前にNCBIの系統分類データベース(学名、階級など)を準備する。
wget ftp://ftp.ncbi.nih.gov/pub/taxonomy/taxdump.tar.gz
tar -zxvf taxdump.tar.gz
mkdir $HOME/.taxonkit
cp names.dmp nodes.dmp $HOME/.taxonkit/
最新のデータが使いたいなら、定期的にダウンロードし直す。
実行方法
1、taxonkit list - taxonomy IDの照会
$ taxonkit list -h
list taxon tree of given taxids
Usage:
taxonkit list [flags]
Flags:
-h, --help help for list
--ids string taxid(s), multiple values should be separated by comma
--indent string indent (default " ")
--json output in JSON format. you can save the result in file with suffix ".json" and open with modern text editor
--show-name output scientific name
--show-rank output rank
Global Flags:
--data-dir string directory containing nodes.dmp and names.dmp (default "/Users/kazuma/.taxonkit")
--line-buffered use line buffering on output, i.e., immediately writing to stdin/file for every line of output
-o, --out-file string out file ("-" for stdout, suffix .gz for gzipped out) (default "-")
-j, --threads int number of CPUs. (default value: 1 for single-CPU PC, 2 for others) (default 2)
--verbose print verbose information
NCBI taxonomy ID照会サービス(link)と同じように使える。-
指定のtaxon IDリストを表示
taxonkit list -j 8 --ids 9605,239934
$ taxonkit list --ids 9605,239934
9605
9606
63221
741158
1425170
239934
239935
349741
512293
512294
1131822
1262691
1263034
1131336
1574264
1574265
1638783
1679444
1755639
1872421
1896967
1929996
1945963
1945964
1945965
1945966
2478952
分類学の階級、 学名も表示する。
taxonkit list -j 8 --show-rank --show-name --ids 9605
- --show-name output scientific name
- --show-rank output rank
- -j number of CPUs. (default value: 1 for single-CPU PC, 2 for others) (default 2)
$ taxonkit list --show-rank --show-name --ids 9605,239934
9605 [genus] Homo
9606 [species] Homo sapiens
63221 [subspecies] Homo sapiens neanderthalensis
741158 [subspecies] Homo sapiens subsp. 'Denisova'
1425170 [species] Homo heidelbergensis
"--json"をつければ、JSON形式で出力できる。目的によってはかなり役立つオプション。
2、lineage - 系統情報の照会
$ taxonkit lineage -h
query lineage of given taxids
Usage:
taxonkit lineage [flags]
Flags:
-d, --delimiter string field delimiter in lineage (default ";")
-h, --help help for lineage
-t, --show-lineage-taxids show lineage consisting of taxids
-r, --show-rank show rank of taxids
-i, --taxid-field int field index of taxid. data should be tab-separated (default 1)
Global Flags:
--data-dir string directory containing nodes.dmp and names.dmp (default "/Users/kazuma/.taxonkit")
--line-buffered use line buffering on output, i.e., immediately writing to stdin/file for every line of output
-o, --out-file string out file ("-" for stdout, suffix .gz for gzipped out) (default "-")
-j, --threads int number of CPUs. (default value: 1 for single-CPU PC, 2 for others) (default 2)
--verbose print verbose information
例えばファイル中のtaxonomy IDからlineageを照会。照会元のtaxonomic IDも左端の列につく。
$ cat taxids.txt
9606
349741
239935
$ taxonkit lineage taxids.txt
$ taxonkit lineage taxids.txt
9606 cellular organisms;Eukaryota;Opisthokonta;Metazoa;Eumetazoa;Bilateria;Deuterostomia;Chordata;Craniata;Vertebrata;Gnathostomata;Teleostomi;Euteleostomi;Sarcopterygii;Dipnotetrapodomorpha;Tetrapoda;Amniota;Mammalia;Theria;Eutheria;Boreoeutheria;Euarchontoglires;Primates;Haplorrhini;Simiiformes;Catarrhini;Hominoidea;Hominidae;Homininae;Homo;Homo sapiens
349741 cellular organisms;Bacteria;PVC group;Verrucomicrobia;Verrucomicrobiae;Verrucomicrobiales;Akkermansiaceae;Akkermansia;Akkermansia muciniphila;Akkermansia muciniphila ATCC BAA-835
taxonomic rankを表示。
taxonkit lineage -j 8 -r taxids.txt | cut -f 1,3
- -r show rank of taxids
$ taxonkit lineage -r taxids.txt | cut -f 1,3
9606 species
349741 no rank
239935 species
系統と、右端の列にtax idを階級順に出力する。
taxonkit lineage -j 8 -t taxids.txt
- -t show lineage consisting of taxids
9606 cellular organisms;Eukaryota;Opisthokonta;Metazoa;Eumetazoa;Bilateria;Deuterostomia;Chordata;Craniata;Vertebrata;Gnathostomata;Teleostomi;Euteleostomi;Sarcopterygii;Dipnotetrapodomorpha;Tetrapoda;Amniota;Mammalia;Theria;Eutheria;Boreoeutheria;Euarchontoglires;Primates;Haplorrhini;Simiiformes;Catarrhini;Hominoidea;Hominidae;Homininae;Homo;Homo sapiens 131567;2759;33154;33208;6072;33213;33511;7711;89593;7742;7776;117570;117571;8287;1338369;32523;32524;40674;32525;9347;1437010;314146;9443;376913;314293;9526;314295;9604;207598;9605;9606
349741 cellular organisms;Bacteria;PVC group;Verrucomicrobia;Verrucomicrobiae;Verrucomicrobiales;Akkermansiaceae;Akkermansia;Akkermansia muciniphila;Akkermansia muciniphila ATCC BAA-835 131567;2;1783257;74201;203494;48461;1647988;239934;239935;349741
239935 cellular organisms;Bacteria;PVC group;Verrucomicrobia;Verrucomicrobiae;Verrucomicrobiales;Akkermansiaceae;Akkermansia;Akkermansia muciniphila 131567;2;1783257;74201;203494;48461;1647988;239934;239935
3、reformat - 2の"lineage"コマンドの系統出力ファイルをリフォーマット
$ taxonkit reformat -h
reformat lineage
Output format can be formated by flag --format, available placeholders:
{k}: superkingdom
{p}: phylum
{c}: class
{o}: order
{f}: family
{g}: genus
{s}: species
{S}: subspecies
Output format can contains some escape charactors like " ".
This command appends reformated lineage to the input line.
The corresponding taxids of reformated lineage can be provided as another
column by flag "-t/--show-lineage-taxids".
Usage:
taxonkit reformat [flags]
Flags:
-d, --delimiter string field delimiter in input lineage (default ";")
-F, --fill-miss-rank fill missing rank with original lineage information (experimental)
-f, --format string output format, placeholders of rank are needed (default "{k};{p};{c};{o};{f};{g};{s}")
-h, --help help for reformat
-i, --lineage-field int field index of lineage. data should be tab-separated (default 2)
-r, --miss-rank-repl string replacement string for missing rank, if given "", "unclassified xxx xxx" will used, where "unclassified " is settable by flag -p/--miss-rank-repl-prefix
-p, --miss-rank-repl-prefix string prefix for estimated taxon level (default "unclassified ")
-R, --miss-taxid-repl string replacement string for missing taxid
-t, --show-lineage-taxids show corresponding taxids of reformated lineage
Global Flags:
--data-dir string directory containing nodes.dmp and names.dmp (default "/Users/kazuma/.taxonkit")
--line-buffered use line buffering on output, i.e., immediately writing to stdin/file for every line of output
-o, --out-file string out file ("-" for stdout, suffix .gz for gzipped out) (default "-")
-j, --threads int number of CPUs. (default value: 1 for single-CPU PC, 2 for others) (default 2)
--verbose print verbose information
2の出力フォーマットを再変換するために使う。
#まずlineageコマンドを実行、idから系統情報を得る
taxonkit lineage taxids.txt > lineage.txt
#情報が多くて分かりにくい。reformatコマンド出力で簡潔にする
taxonkit reformat -j 8 lineage.txt | cut -f 3
$ taxonkit reformat lineage.txt | cut -f 3
Eukaryota;Chordata;Mammalia;Primates;Hominidae;Homo;Homo sapiens
Bacteria;Verrucomicrobia;Verrucomicrobiae;Verrucomicrobiales;Akkermansiaceae;Akkermansia;Akkermansia muciniphila
Bacteria;Verrucomicrobia;Verrucomicrobiae;Verrucomicrobiales;Akkermansiaceae;Akkermansia;Akkermansia muciniphila
genusとspeciesのみ表示する
taxonkit reformat -j 8 -f "{g};{s}" lineage.txt | cut -f 3
- -f string output format, placeholders of rank are needed (default "{k};{p};{c};{o};{f};{g};{s}")
$ taxonkit reformat -j 8 -f "{g};{s}" lineage.txt | cut -f 3
Homo;Homo sapiens
Akkermansia;Akkermansia muciniphila
Akkermansia;Akkermansia muciniphila
4、 name2taxid - 学名からTax IDsを照合
$ taxonkit name2taxid -h
query taxid by taxon scientific name
Usage:
taxonkit name2taxid [flags]
Flags:
-h, --help help for name2taxid
-i, --name-field int field index of name. data should be tab-separated (default 1)
--show-rank show rank
Global Flags:
--data-dir string directory containing nodes.dmp and names.dmp (default "/Users/kazuma/.taxonkit")
--line-buffered use line buffering on output, i.e., immediately writing to stdin/file for every line of output
-o, --out-file string out file ("-" for stdout, suffix .gz for gzipped out) (default "-")
-j, --threads int number of CPUs. (default value: 1 for single-CPU PC, 2 for others) (default 2)
--verbose print verbose information
scientific names のファイルを準備し、実行
$ cat names.txt
Homo sapiens
Akkermansia muciniphila ATCC BAA-835
Akkermansia muciniphila
Mouse Intracisternal A-particle
Wei Shen
uncultured murine large bowel bacterium BAC 54B
Croceibacter phage P2559Y
$ cat names.txt | taxonkit name2taxid
$ cat names.txt | taxonkit name2taxid
Homo sapiens 9606
Akkermansia muciniphila ATCC BAA-835 349741
Akkermansia muciniphila 239935
Mouse Intracisternal A-particle 11932
Wei Shen
uncultured murine large bowel bacterium BAC 54B 314101
Croceibacter phage P2559Y 1327037
taxonomic idが右端につく。
=taxonomic rankも表示
cat names.txt | taxonkit name2taxid --show-rank
$ cat names.txt | taxonkit name2taxid --show-rank
Homo sapiens 9606 species
Akkermansia muciniphila ATCC BAA-835 349741 no rank
Akkermansia muciniphila 239935 species
Mouse Intracisternal A-particle 11932 species
Wei Shen
uncultured murine large bowel bacterium BAC 54B 314101 species
Croceibacter phage P2559Y 1327037 species
scientific names => taxonomic id => taxonomic rankファイル
cat names.txt | taxonkit name2taxid | taxonkit lineage --taxid-field 2
$ cat names.txt | taxonkit name2taxid | taxonkit lineage --taxid-field 2
Homo sapiens 9606 cellular organisms;Eukaryota;Opisthokonta;Metazoa;Eumetazoa;Bilateria;Deuterostomia;Chordata;Craniata;Vertebrata;Gnathostomata;Teleostomi;Euteleostomi;Sarcopterygii;Dipnotetrapodomorpha;Tetrapoda;Amniota;Mammalia;Theria;Eutheria;Boreoeutheria;Euarchontoglires;Primates;Haplorrhini;Simiiformes;Catarrhini;Hominoidea;Hominidae;Homininae;Homo;Homo sapiens
Akkermansia muciniphila ATCC BAA-835 349741 cellular organisms;Bacteria;PVC group;Verrucomicrobia;Verrucomicrobiae;Verrucomicrobiales;Akkermansiaceae;Akkermansia;Akkermansia muciniphila;Akkermansia muciniphila ATCC BAA-835
Akkermansia muciniphila 239935 cellular organisms;Bacteria;PVC group;Verrucomicrobia;Verrucomicrobiae;Verrucomicrobiales;Akkermansiaceae;Akkermansia;Akkermansia muciniphila
Mouse Intracisternal A-particle 11932 Viruses;Ortervirales;Retroviridae;unclassified Retroviridae;Intracisternal A-particles;Mouse Intracisternal A-particle
Wei Shen
uncultured murine large bowel bacterium BAC 54B 314101 cellular organisms;Bacteria;environmental samples;uncultured murine large bowel bacterium BAC 54B
Croceibacter phage P2559Y 1327037 Viruses;dsDNA viruses, no RNA stage;Caudovirales;Siphoviridae;unclassified Siphoviridae;Croceibacter phage P2559Y
scientific names => taxonomic id => taxonomic rankファイルと taxonomic rank順のtaxonomic id
cat names.txt | taxonkit name2taxid | taxonkit lineage --taxid-field 2 --show-lineage-taxids
$ cat names.txt | taxonkit name2taxid | taxonkit lineage --taxid-field 2 --show-lineage-taxids
Homo sapiens 9606 cellular organisms;Eukaryota;Opisthokonta;Metazoa;Eumetazoa;Bilateria;Deuterostomia;Chordata;Craniata;Vertebrata;Gnathostomata;Teleostomi;Euteleostomi;Sarcopterygii;Dipnotetrapodomorpha;Tetrapoda;Amniota;Mammalia;Theria;Eutheria;Boreoeutheria;Euarchontoglires;Primates;Haplorrhini;Simiiformes;Catarrhini;Hominoidea;Hominidae;Homininae;Homo;Homo sapiens 131567;2759;33154;33208;6072;33213;33511;7711;89593;7742;7776;117570;117571;8287;1338369;32523;32524;40674;32525;9347;1437010;314146;9443;376913;314293;9526;314295;9604;207598;9605;9606
Akkermansia muciniphila ATCC BAA-835 349741 cellular organisms;Bacteria;PVC group;Verrucomicrobia;Verrucomicrobiae;Verrucomicrobiales;Akkermansiaceae;Akkermansia;Akkermansia muciniphila;Akkermansia muciniphila ATCC BAA-835 131567;2;1783257;74201;203494;48461;1647988;239934;239935;349741
Akkermansia muciniphila 239935 cellular organisms;Bacteria;PVC group;Verrucomicrobia;Verrucomicrobiae;Verrucomicrobiales;Akkermansiaceae;Akkermansia;Akkermansia muciniphila 131567;2;1783257;74201;203494;48461;1647988;239934;239935
Mouse Intracisternal A-particle 11932 Viruses;Ortervirales;Retroviridae;unclassified Retroviridae;Intracisternal A-particles;Mouse Intracisternal A-particle 10239;2169561;11632;35276;11749;11932
Wei Shen
uncultured murine large bowel bacterium BAC 54B 314101 cellular organisms;Bacteria;environmental samples;uncultured murine large bowel bacterium BAC 54B 131567;2;48479;314101
Croceibacter phage P2559Y 1327037 Viruses;dsDNA viruses, no RNA stage;Caudovirales;Siphoviridae;unclassified Siphoviridae;Croceibacter phage P2559Y 10239;35237;28883;10699;196894;1327037
この他、シェルを自動補完してくれる"genautocomplete"がある。
引用
TaxonKit: a cross-platform and efficient NCBI taxonomy toolkit
Wei Shen, Jie Xiong
bioRxiv preprint first posted online Jan. 8, 2019;
TaxonKit: a practical and efficient NCBI Taxonomy toolkit
Wei Shen, Hong Ren
Journal of Genetics and Genomics, https://doi.org/10.1016/j.jgg.2021.03.006.
関連