macでインフォマティクス

macでインフォマティクス

HTS (NGS) 関連のインフォマティクス情報についてまとめています。

MetaPhlAnなどの出力からGraPhlAn用のアノテーションファイルとツリーファイルを作成する Export2graphlan

 

 export2graphlanは、GraPhlAn用の注釈ファイルとツリーファイルの両方を作成するための変換ソフトウェアツールである。特に、アノテーションファイルでは、どのノードが重要であるかを入力ファイルから自動的に導き出し、特定のサブツリーを強調しようとする。export2graphlanの2つの出力ファイルを使って、graphlan_annotate.pyを実行すると、派生したアノテーション系統樹に添付することができ、最終的にgraphlan.pyを実行すると、出力画像を得ることができる。

 

論文より

 Export2graphlanは、MetaPhlAn(バージョン1または2のいずれか)またはHUMANの解析結果と、LEfSeの解析結果の2つのファイルを入力として受け取ることができる。これら2つの入力ファイルのうち、少なくとも1つは必須である。Export2graphlanは、GraPhlAnで使用可能なツリーファイルとアノテーションファイルを作成する。さらに、export2graphlanはBIOMファイル(バージョン1または2のいずれか)を入力として受け取ることができる。Export2graphlanは、アバンダンス値と、存在する場合はLEfSeによって割り当てられたLDAスコアの分析を行い、最も豊富なクレードとバイオマーカーであることが判明したものをアノテーションして強調する。

 

インストール

Github

 

#bioconda (link)
mamba create -n graphlan python=2.7 -y
conda activate graphlan 
mamba install -c bioconda -y export2graphlan
mamba install -c bioconda -y graphlan

#pypi (link)
pip install export2graphlan

> export2graphlan.py -h

# export2graphlan.py -h

usage: export2graphlan.py [-h] [-i LEFSE_INPUT] [-o LEFSE_OUTPUT] -t TREE -a

ANNOTATION [--annotations ANNOTATIONS]

[--external_annotations EXTERNAL_ANNOTATIONS]

[--background_levels BACKGROUND_LEVELS]

[--background_clades BACKGROUND_CLADES]

[--background_colors BACKGROUND_COLORS]

[--title TITLE] [--title_font_size TITLE_FONT_SIZE]

[--def_clade_size DEF_CLADE_SIZE]

[--min_clade_size MIN_CLADE_SIZE]

[--max_clade_size MAX_CLADE_SIZE]

[--def_font_size DEF_FONT_SIZE]

[--min_font_size MIN_FONT_SIZE]

[--max_font_size MAX_FONT_SIZE]

[--annotation_legend_font_size ANNOTATION_LEGEND_FONT_SIZE]

[--abundance_threshold ABUNDANCE_THRESHOLD]

[--most_abundant MOST_ABUNDANT]

[--least_biomarkers LEAST_BIOMARKERS]

[--discard_otus] [--internal_levels]

[--biomarkers2colors BIOMARKERS2COLORS] [--sep SEP]

[--out_table OUT_TABLE] [--fname_row FNAME_ROW]

[--sname_row SNAME_ROW]

[--metadata_rows METADATA_ROWS]

[--skip_rows SKIP_ROWS] [--sperc SPERC]

[--fperc FPERC] [--stop STOP] [--ftop FTOP]

[--def_na DEF_NA]

 

export2graphlan.py (ver. 0.20 of 29th May 2017). Convert MetaPhlAn, LEfSe,

and/or HUMAnN output to GraPhlAn input format. Authors: Francesco Asnicar

(f.asnicar@unitn.it)

 

optional arguments:

-h, --help show this help message and exit

--annotations ANNOTATIONS

List which levels should be annotated in the tree. Use

a comma separate values form, e.g.,

--annotation_levels 1,2,3. Default is None

--external_annotations EXTERNAL_ANNOTATIONS

List which levels should use the external legend for

the annotation. Use a comma separate values form,

e.g., --annotation_levels 1,2,3. Default is None

--background_levels BACKGROUND_LEVELS

List which levels should be highlight with a shaded

background. Use a comma separate values form, e.g.,

--background_levels 1,2,3. Default is None

--background_clades BACKGROUND_CLADES

Specify the clades that should be highlight with a

shaded background. Use a comma separate values form

and surround the string with " if there are spaces.

Example: --background_clades "Bacteria.Actinobacteria,

Bacteria.Bacteroidetes.Bacteroidia,

Bacteria.Firmicutes.Clostridia.Clostridiales". Default

is None

--background_colors BACKGROUND_COLORS

Set the color to use for the shaded background. Colors

can be either in RGB or HSV (using a semi-colon to

separate values, surrounded with ()) format. Use a

comma separate values form and surround the string

with " if it contains spaces. Example:

--background_colors "#29cc36, (150; 100; 100), (280;

80; 88)". To use a fixed set of colors associated to a

fixed set of clades, you can specify a mapping file in

a tab-separated format, where the first column is the

clade (using the same format as for the "--

background_clades" param) and the second colum is the

color associated. Default is None

--title TITLE If specified set the title of the GraPhlAn plot.

Surround the string with " if it contains spaces,

e.g., --title "Title example"

--title_font_size TITLE_FONT_SIZE

Set the title font size. Default is 15

--def_clade_size DEF_CLADE_SIZE

Set a default size for clades that are not found as

biomarkers by LEfSe. Default is 10

--min_clade_size MIN_CLADE_SIZE

Set the minimum value of clades that are biomarkers.

Default is 20

--max_clade_size MAX_CLADE_SIZE

Set the maximum value of clades that are biomarkers.

Default is 200

--def_font_size DEF_FONT_SIZE

Set a default font size. Default is 10

--min_font_size MIN_FONT_SIZE

Set the minimum font size to use. Default is 8

--max_font_size MAX_FONT_SIZE

Set the maximum font size. Default is 12

--annotation_legend_font_size ANNOTATION_LEGEND_FONT_SIZE

Set the font size for the annotation legend. Default

is 10

--abundance_threshold ABUNDANCE_THRESHOLD

Set the minimun abundace value for a clade to be

annotated. Default is 20.0

--most_abundant MOST_ABUNDANT

When only lefse_input is provided, you can specify how

many clades highlight. Since the biomarkers are

missing, they will be chosen from the most abundant.

Default is 10

--least_biomarkers LEAST_BIOMARKERS

When only lefse_input is provided, you can specify the

minimum number of biomarkers to extract. The taxonomy

is parsed, and the level is choosen in order to have

at least the specified number of biomarkers. Default

is 3

--discard_otus If specified the OTU ids will be discarde from the

taxonmy. Default is True, i.e. keep OTUs IDs in

taxonomy

--internal_levels If specified sum-up from leaf to root the abundances

values. Default is False, i.e. do not sum-up

abundances on the internal nodes

--biomarkers2colors BIOMARKERS2COLORS

Mapping file that associates biomarkers to a specific

color... I'll define later the specific format of this

file!

 

input parameters:

You need to provide at least one of the two arguments

 

-i LEFSE_INPUT, --lefse_input LEFSE_INPUT

LEfSe input data. A file that can be given to LEfSe

for biomarkers analysis. It can be the result of a

MetaPhlAn or HUMAnN analysis

-o LEFSE_OUTPUT, --lefse_output LEFSE_OUTPUT

LEfSe output result data. The result of LEfSe analysis

performed on the lefse_input file

 

output parameters:

-t TREE, --tree TREE Output filename where save the input tree for GraPhlAn

-a ANNOTATION, --annotation ANNOTATION

Output filename where save GraPhlAn annotation

 

Input data matrix parameters:

--sep SEP

--out_table OUT_TABLE

Write processed data matrix to file

--fname_row FNAME_ROW

row number containing the names of the features

[default 0, specify -1 if no names are present in the

matrix

--sname_row SNAME_ROW

column number containing the names of the samples

[default 0, specify -1 if no names are present in the

matrix

--metadata_rows METADATA_ROWS

Row numbers to use as metadata[default None, meaning

no metadata

--skip_rows SKIP_ROWS

Row numbers to skip (0-indexed, comma separated) from

the input file[default None, meaning no rows skipped

--sperc SPERC Percentile of sample value distribution for sample

selection

--fperc FPERC Percentile of feature value distribution for sample

selection

--stop STOP Number of top samples to select (ordering based on

percentile specified by --sperc)

--ftop FTOP Number of top features to select (ordering based on

percentile specified by --fperc)

--def_na DEF_NA Set the default value for missing values [default None

which means no replacement]

 

 

テストラン

examplesに3つの例が用意されている。

git clone https://github.com/SegataLab/export2graphlan.git
cd export2graphlan/examples/hmp_aerobiosis/

> cat PIPELINE.sh

#!/bin/bash

 

# remove the generated files, if any

echo "Removing files"

rm -f tree.txt annot.txt outtree.txt outimg*.png

 

# convert it!

echo "Converting to GraPhlAn"

export2graphlan.py -i lefse_input.txt -o lefse_output.txt -t tree.txt -a annot.txt --title "HMP Aerobiosis" --annotations 2,3 --external_annotations 4,5,6 --fname_row 0 --skip_rows 1,2 --ftop 200

 

# attach annotation to the tree

echo "Running Graphlan"

graphlan_annotate.py --annot annot.txt tree.txt outtree.txt

 

# generate the beautiful image

graphlan.py --dpi 150 outtree.txt outimg.png --external_legends

 

実行する。

sh PIPELINE.sh

f:id:kazumaxneo:20210708225703p:plain

 

GraPhlAnを利用するには、 GraPhlAnの注釈付きカスタムdendrogramを描画するために必要な情報を書いたannotation.txtを用意する必要があります。このannotation.txtに書く情報はGraPhlAnのレポジトリ(README)にまとめられていますが、準備するにはかなり手間です。自動でannotation.txtを用意してくれるには便利かと思います。実際の使い方は、metaphlanのチュートリアルを紹介した時に触れています。


引用

Compact graphical representation of phylogenetic data and metadata with GraPhlAn
Francesco Asnicar, George Weingart, Timothy L Tickle, Curtis Huttenhower, Nicola Segata

PeerJ. 2015 Jun 18;3:e1029