擴增子分析:qiime2平臺全流程分析

Amplicon sequencing analysis pipeline through qiime2 platform

qiime2是擴增子數據分析的最佳平臺之一,其提供了大量從原始data到統計分析的插件,尤其是它的可重復分析且可擴展插件的理念使得其成為擴增子分析首選的平臺。

Platform

qiime2是擴增子數據分析的最佳平臺之一,其提供了大量從原始data到統計分析的插件,尤其是它的可重復分析且可擴展插件的理念使得其成為擴增子分析首選的平臺。對于如何安裝該平臺,個人建議使用conda安裝,并且官網也提供了conda安裝的yaml文件,但為了快速安裝,我們需要把conda鏡像重新設置修改一下。

step1: download the yaml file

wget https://data.qiime2.org/distro/core/qiime2-2020.8-py36-linux-conda.yml

step2: update the conda version

conda update conda -y

step3: modify the .condarc and yaml file

# reset the conda channels 
channels:
  - conda-forge
  - bioconda
  - biobakery
  - qiime2
  - ohmeta
  - defaults
show_channel_urls: true
channel_alias: https://mirrors.bfsu.edu.cn/anaconda
default_channels:
  - https://mirrors.bfsu.edu.cn/anaconda/pkgs/main
  - https://mirrors.bfsu.edu.cn/anaconda/pkgs/free
  - https://mirrors.bfsu.edu.cn/anaconda/pkgs/r
custom_channels:
  conda-forge: https://mirrors.bfsu.edu.cn/anaconda/cloud
  bioconda: https://mirrors.bfsu.edu.cn/anaconda/cloud
  biobakery: https://mirrors.bfsu.edu.cn/anaconda/cloud
  qiime2: https://mirrors.bfsu.edu.cn/anaconda/cloud
  ohmeta: https://mirrors.bfsu.edu.cn/anaconda/cloud
  knights-lab: https://conda.anaconda.org
  alienzj: https://conda.anaconda.org
  
 # change the yaml channel
 - qiime2/label/r2020.8
 + qiime2

step4: create the qiime2-2020.8 conda environment

conda env create -n qiime2-2020.8 --file qiime2-2020.8-py36-linux-conda_update.yml -y

step5: activate environment and test installation

# actiavate 
conda activate qiime2-2020.8 
# test 
qiime --help
# deactivate 
conda deactivate 

# Note: if you have trouble with no activate command, you need use *eval "$(conda shell.bash hook)"*

Analysis pipeline

Check the fastq phred score

通過fastqc軟件處理fastq獲取原始數據的reads質量分布等情況,為后續設置堿基質量閾值做好準備。

fastqc --noextract -f fastq input.fq.gz  -o result/outdir

Get the positions of primer in the fastq

DADA2算法需要提供forward和reverse引物序列在reads上的位置信息,我們可以通過使用usearch和vsearch軟件獲取引物的位置信息,并將其作為參數配置給qiime2 dada2插件。獲取primer_hits.txt文件的開始和結束10個reads的primer信息,找到引物的位置信息。

# step1: merge fq
echo "step1: mkdir result and merger all PE fq files"
mkdir result
./usearch -fastq_mergepairs rawdata/*_R1.fq -fastqout result/all_samples_merged.fq -relabel @

# step2: sampling sequence
echo "step2: sampling sequence for primer check"
./usearch -fastx_subsample result/all_samples_merged.fq -sample_size 20000 -fastqout result/all_sub_for_primer_check.fq

# step3: search primer position
echo "step3: search primer position of the sequence"
./usearch -search_oligodb result/all_sub_for_primer_check.fq -db primers.fasta -strand both -userout result/primer_hits.txt -userfields query+qlo+qhi+qstrand

# step4: obtain the position information of primer
head primer_hits.txt  # head 23  tail 19
#HTN1.182        452     471     -
#HTN1.182        7       23      +
#HTN1.183        447     466     -
#HTN1.183        7       23      +
#HTN1.233        428     447     -
#HTN1.233        7       23      +
#HTN1.570        430     449     -
#HTN1.570        7       23      +
#HTN1.219        448     467     -
#HTN1.219        7       23      +
tail primer_hits.txt # head 23  tail 19
#Normal6.996134  429     448     -
#Normal6.996134  7       23      +
#Normal6.996331  430     449     -
#Normal6.996331  7       23      +
#Normal6.996257  448     467     -
#Normal6.996257  7       23      +
#Normal6.996360  429     448     -
#Normal6.996360  7       23      +
#Normal6.961965  430     449     -
#Normal6.961965  7       23      +

Convert fastq into qza

step1: 準備符合import格式的文件 manifest.tsv(包含樣本ID以及forward和reverse fq路徑的文件)和sample-metadata.tsv(樣本的分組信息)

# generate manifest.tsv 
find /rawdata/ -name "*gz" | grep '1_' | sort | perl -e 'print"sampleid\tforward-absolute-filepath\treverse-absolute-filepath\n"; while(<>){chomp; $name=(split("\/", $_))[-1]; $name1=$name; $name2=$_; $name1=~s/_[1|2]_.fq.gz//g; $name2=~s/1_/2_/; print "$name1\t$_\t$name2\n";}'  > pe-33-manifest-trimmed.tsv

# sample-metadata.tsv details
#sampleid        Treatment
#HTN1    HTN
#HTN2    HTN
#Normal1 Normal

step2: import fastq into qza,雙端和單端數據的import參數不同,并且不同的phred score使用的參數也不一樣

# PE mode 
qiime tools import \
      --type 'SampleData[PairedEndSequencesWithQuality]' \
      --input-path pe-33-manifest-trimmed.tsv \
      --output-path result/paired-end-demux.qza \
      --input-format PairedEndFastqManifestPhred33V2

# SE mode 
qiime tools import \
  --type "SampleData[SequencesWithQuality]" \
  --input-path single-33-manifest.tsv \
  --output-path result/single-end-demux.qza \
  --input-format SingleEndFastqManifestPhred33V2 

Sequence quality control

Step1: 為了更加準確地過濾低質量的堿基,可以再使用qiime2自帶summarize插件查看低質量堿基的位置分布,最后再結合第二步usearch和vsearch的primer位置信息設置適合過濾的參數。

qiime demux summarize \
  --i-data result/paired-end-demux.qza \
  --o-visualization result/paired-end-demux-summary.qzv

Step2: DADA2算法相比常用的OTU算法,其計算的amplicon variant sequences(ASV)的feature會更好一些,feature代替OTU是一種趨勢。在此之后,Usearch的開發者Robert C Edgar迅速開發了更好的unoise2算法,該算法已更新到unoise3,并放話unoise2比DADA2更準確。

DADA2是R的一個軟件包,可以進行過濾,去重,嵌合體過濾,reads的拼接,可以修正擴增子的測序錯誤,確定更多的真實變異。擴增子測序本身就具有內在的限制,但是聚類OTU的方式進一步限制了它的發展。OTU不是物種,它們不應該成為錯誤的一部分,DADA2可以具有更高的分辨率

DADA(Divisive Amplicon Denoising Algorithm)含義為區分擴增子降噪方程可以確定真實的變異在454測序擴增子數據輸出更少的假陽性。DADA2是DADA的擴展和增強可以應用于Illumina測序數據

  • 特點:DADA2最重要的優勢是它用了更多的數據。DADA2的錯誤模型包含了質量信息,而其他的方法都在過濾低質量之后把序列的質量信息忽略。而且DADA2的錯誤模型也包括了定量的豐度,而且該模型也計算了各種不同轉置的概率A->C。而且DADA2以自身數據的錯誤模型為參數,不用依賴于其他參數分布模型。
    DADA2算法:一種分列式算法
  • 原理:
    • 1 首先將每個reads全部看作單獨的單元,Sequence相同的reads被納入一個sequence,reads個數即成為該sequence的豐度(abundance)(其實就是去冗余的過程)
    • 2 計算每個sequence豐度的p-value。當最小的p-value低于設定的閾值時, 將產生一個新的partition。每一個sequence將會被歸入最可能生成該sequence的partition。
    • 3 依次類推,完成分割歸并。
# DADA2 denosie
qiime dada2 denoise-paired \
        --i-demultiplexed-seqs result/paired-end-demux.qza \
        --p-trim-left-f 23 \
        --p-trim-left-r 19 \
        --p-trunc-len-f 0 \
        --p-trunc-len-r 0 \
        --p-n-threads 20 \
        --o-table result/table.qza \
        --o-representative-sequences result/rep-seqs.qza \
        --o-denoising-stats result/stats.qza

# summary feature table
 qiime feature-table summarize \
        --i-table result/table.qza \
        --o-visualization result/table.qzv \
        --m-sample-metadata-file sample-metadata.tsv

Taxonomic annotation

step1: 通過比對已知分類學組成的參考數據庫的序列,可以獲知feature table的代表序列的物種注釋情況。在qiime2通常可以使用已經搭建好的分類學分類器:silva132和Greengene 13_8等。

GreenGene數據庫比較明顯的問題就是屬種水平注釋低,所以很多條目里,g和s下劃線后面都是空的,如果關注屬種水平的注釋,則不建議使用該數據庫。

結合相關專業人士的反饋意見,個人建議使用silva數據庫作為物種注釋的首選參考數據庫。

# downlaod silva classifier data 
wget https://data.qiime2.org/2020.8/common/silva-138-99-nb-classifier.qza 

# annotation
qiime feature-classifier classify-sklearn \
                --i-classifier database/silva-138-99-nb-classifier.qza  \
                --i-reads result/rep-seqs.qza \
                --o-classification result/taxonomy-dada2-sliva.qza \
                --p-n-jobs 20 \
                --verbose \
                --output-dir result/

step2: 可通過將某些代表序列與擴增子數據庫在blast軟件下再進行物種注釋,該結果與qiime2提供的分類學分類器結果比較,從而可以評估分類學分類器的性能,這適合在構造新的分類學分類器時候使用。

# extract the validated sequences by qiime2 view network site
qiime feature-table tabulate-seqs \
   --i-data result/rep-seqs.qza \
   --o-visualization result/rep-seqs.qzv

Filter the unsuitable ASV

step1: remove low occurrence ASVs

根據table的結果設置過濾threshold,閾值有frequency和samples,即ASV在所有樣本的總reads和出現在樣本數目。計算平均采樣深度(對所有ASV的count加和并求平均值),設置采樣閾值后再乘以平均采樣深度即獲得frequency閾值,另外也可以設置ASV出現在多少樣本內。

qiime feature-table filter-features \
   --i-table result/table.qza \
   --p-min-frequency 10 \
   --p-min-samples 1 \
   --o-filtered-table result/table_filter_low_freq.qza
step2: remove contamination and mitochondria, chloroplast sequence.

16s擴增子常見污染序列是來自于線粒體和葉綠體等16s序列,另外也存在一些未注釋的序列,均需要去除。

qiime taxa filter-table \
   --i-table result/table_filter_low_freq.qza \
   --i-taxonomy result/taxonomy-dada2-sliva.qza \
   --p-exclude mitochondria,chloroplast \
   --o-filtered-table  result/table_filter_low_freq_contam.qza 
step3: drop the low depth samples:

經過上述處理后,某些樣本含有較少的ASV總量,因此可以將其剔除。通常使用的threshold的范圍是1,000 - 4,000 reads。

# summarise all the ASV counts in each sample 
qiime feature-table summarize \
   --i-table result/table_filter_low_freq_contam.qza \
   --o-visualization result/table_filter_low_freq_contam_summary.qzv
# remove samples
qiime feature-table filter-samples \
   --i-table  result/table_filter_low_freq_contam.qza \
   --p-min-frequency 4000 \
   --o-filtered-table  result/final_table.qza 
# representative sequence
qiime feature-table filter-seqs \
   --i-data result/rep-seqs.qza \
   --i-table result/final_table.qza \
   --o-filtered-data result/final_rep_seqs.qza
# reannotate
qiime feature-classifier classify-sklearn \
   --i-classifier database/silva-138-99-nb-classifier.qza  \
   --i-reads result/final_rep_seqs.qza \
   --o-classification result/final_taxonomy_sliva.qza \
   --p-n-jobs 20 \
   --verbose \
   --output-dir result/
# core features
qiime feature-table core-features \
   --i-table result/final_table.qza \
   --p-min-fraction 0.6 \
   --p-max-fraction 1 \
   --p-steps 11 \
   --o-visualization result/final_table_cores.qzv \
   --output-dir result

Downstream analysis

Constructing phylogenetic tree and diversity analysis

step1: 系統發育樹能夠服務于后續多樣性分析
qiime phylogeny align-to-tree-mafft-fasttree \
      --i-sequences result/final_rep_seqs.qza \
      --o-alignment result/final_rep_seqs_aligned.qza \
      --o-masked-alignment result/final_rep_seqs_masked.qza \
      --p-n-threads 20 \
      --o-tree result/unrooted-tree.qza \
      --o-rooted-tree result/rooted-tree.qza
step2: rarefication curve:

稀疏曲線可以了解測序深度與ASV的關系

qiime diversity alpha-rarefaction \
     --i-table result/final_table.qza \
     --i-phylogeny result/rooted-tree.qza \
     --p-max-depth 60000 \
     --m-metadata-file sample-metadata.tsv \
     --o-visualization result/p-max-depth-60000-alpha-rarefaction.qzv
step3: diversity analysis

根據ASV的最小測序深度設置sampling參數

# all diversity index and distance 
qiime diversity core-metrics-phylogenetic \
     --i-phylogeny result/rooted-tree.qza \
     --i-table result/final_table.qza \
     --p-sampling-depth 60000 \
     --m-metadata-file sample-metadata.tsv \
     --output-dir result/sample-depth-60000-core-metrics-results    
step4: faith_pd diversity parameters
# example for faith_pd_vector of group analysis
qiime diversity alpha-group-significance \
     --i-alpha-diversity result/sample-depth-60000-core-metrics-results/faith_pd_vector.qza \
     --m-metadata-file sample-metadata.tsv \
     --o-visualization result/sample-depth-60000-core-metrics-results/faith-pd-group-significance.qzv
# example for alpha diversity of group analysis
qiime diversity alpha-group-significance \
     --i-alpha-diversity result/sample-depth-60000-core-metrics-results/shannon_vector.qza \
     --m-metadata-file sample-metadata.tsv \
     --o-visualization result/shannon_compare_groups.qzv 
# beta diversity 
qiime diversity beta-group-significance \
    --i-distance-matrix result/sample-depth-60000-core-metrics-results/unweighted_unifrac_distance_matrix.qza \
    --m-metadata-file sample-metadata.tsv \
    --m-metadata-column Treatment \
    --p-pairwise false \
    --p-permutations 999 \
    --o-visualization result/unweighted-unifrac-subject-significance.qzv 
# three dimensions to show beta diversity
qiime emperor plot \
    --i-pcoa result/sample-depth-60000-core-metrics-results/unweighted_unifrac_pcoa_results.qza \
    --m-metadata-file sample-metadata.tsv \
    --p-custom-axes Treatment \
    --o-visualization result/unweighted-unifrac-emperor-height.qzv

visualizing taxonomic composition

qiime taxa barplot \
     --i-table result/final_table.qza \
     --i-taxonomy result/final_taxonomy_sliva.qza \
     --m-metadata-file sample-metadata.tsv \
     --o-visualization result/final_taxa_barplots_sliva.qzv

Analysis of composition of microbiomes (ANCOM)

ANCOM(可以了解下sparse compositional correlation (SparCC) to analyze correlation networks among taxa)可用于比較微生物在組間差異的分析方法, 結果與LEfse類似。該方法基于成分對數比的方法,即先對count數據進行對數轉換,再通過簡單的秩和檢驗(stats包內的aov, friedman.test, lme等函數)進行比較,最后計算統計量w。ANCOM的結果用W值來衡量組間差異顯著性。W值越高代表該物種在組間的差異顯著性越高。ANCOM的R代碼(推薦!!!)。

# add pseudocount for log transform
qiime composition add-pseudocount \
   --i-table result/final_table.qza \
   --p-pseudocount 1 \
   --o-composition-table result/final_table_pseudocount.qza
# ANCOM 
qiime composition ancom \
   --i-table result/final_table_pseudocount.qza \
   --m-metadata-file sample-metadata.tsv \
   --m-metadata-column Treatment \
   --output-dir result/ancom_output

export qza into other format type data

qza數據文件

QIIME2為了使分析流程標準化,分析過程可重復,制定了統一的分析過程文件格式.qza;qza文件類似于一個封閉的系統,里面包括原始數據、分析的過程和結果;這樣保證了文件格式的標準,同時可以追溯每一步的分析,以及圖表繪制參數。這一方案為實現將來可重復的分析提供了基礎。

# representative sequences
qiime tools export \
   --input-path result/final_rep_seqs.qza \
   --output-path final_result
# features table
qiime tools export \
   --input-path result/final_table.qza \
   --output-path final_result
biom normalize-table \
    -i final_result/feature-table.biom \
    -r \
    -o final_result/feature-table-norm.biom
biom convert \
    -i final_result/feature-table-norm.biom \
    -o final_result/feature-table-norm.tsv \
    --to-tsv \
    --header-key taxonomy

LEfse

LEfse是LDA Effect Size分析,其本質是一類判別分析。其結果一般配合進化分支圖使用,也即是展示差異物種在進化上的關系。推薦使用yintools的LEfse的R腳本remotes::install_github("ying14/yingtools2")

原理:首先使用non-parametric factorial Kruskal-Wallis (KW) sum-rank test(非參數因子克魯斯卡爾—沃利斯和秩驗檢)檢測具有顯著豐度差異特征,并找到與豐度有顯著性差異的類群。最后,LEfSe采用線性判別分析(LDA)來估算每個組分(物種)豐度對差異效果影響的大小。

進化分支圖:由內至外輻射的圓圈代表了由門至屬(或種)的分類級別。在不同分類級別上的每一個小圓圈代表該水平下的一個分類,小圓圈直徑大小與相對豐度大小呈正比。著色原則:無顯著差異的物種統一著色為黃色,差異物種Biomarker跟隨組進行著色,紅色節點表示在紅色組別中起到重要作用的微生物類群,綠色節點表示在綠色組別中起到重要作用的微生物類群,若圖中某一組缺失,則表明此組中并無差異顯著的物種,故此組缺失。圖中英文字母表示的物種名稱在右側圖例中進行展示。

step1: install lefse through conda
conda create -n lefse -c biobakery lefse -y 
conda activate lefse 
which format_input.py
step2: collapse the table.gza to the L6 level
qiime taxa collapse \
    --i-table result/final_table.qza \
    --o-collapsed-table collapse/collapse.table.qza \
    --p-level 6 \
    --i-taxonomy result/final_taxonomy_sliva.qza
step3: calculate relative-frequency for the collapsed table (relative abundance instead of counts)
qiime feature-table relative-frequency \
    --i-table collapse/collapse.table.qza \
    --o-relative-frequency-table collapse/collapse.frequency.table.qza \
    --output-dir collapse/ 
step4: export biom file
qiime tools export \
    --input-path collapse/collapse.frequency.table.qza \
    --output-path collapse/
step5: convert biom to text file
biom convert \
    -i collapse/feature-table.biom \
    -o collapse/collapse.frequency.table.tsv \
    --header-key "taxonomy" \
    --to-tsv
step6: filter tax
sed 's/;/\|/g' collapse/collapse.frequency.table.tsv | \
    awk '{split($1, a, "|");if( a[6] != "__"){print $0}}' | \
    #sed 's/d\_\_Bacteria|//g' | \
    grep -vE "g__uncultured|d__Archaea|p__WPS-2|p__SAR324_clade|Constructed" | \
    sed 's/#OTU ID/Group/g;s/taxonomy//g' > collapse/collapse.frequency.table.lefse.tsv
step7: run lefse
conda activate lefse
# convert text file into lefse.input file 
format_input.py \
    collapse/collapse.frequency.table.lefse.tsv \
    result/collapse.frequency.table.lefse.in \
    -c 1 \
    -m f \
    -o 100000
# run lefse
run_lefse.py \
    result/collapse.frequency.table.lefse.in \
    result/collapse.frequency.table.lefse.res 
# select significant result Lefse
grep -E "HTN|Normal" \
        result/collapse.frequency.table.lefse.res \
        > result/collapse.frequency.table.lefse_signif.res
# plot lda 
plot_res.py \
    result/collapse.frequency.table.lefse_signif.res \
    result/lefse_final_lda.pdf \
    --format pdf \
    --autoscale 0
# plot cladogram 
plot_cladogram.py \
    result/collapse.frequency.table.lefse_signif.res \
    result/lefse_total_clado.pdf \
    --format pdf

Functional prediction: picrust2

Picrust是Phylogenetic Investigationof Communities by Reconstruction of Unobserved States的簡稱,是一款基于16s rRNA基因序列預測微生物群落功能的軟件。

其原理:

(1)基因內容預測(gene content inference)。該步先對Greengenes數據庫的“closed reference”序列劃分OTU后構建進化樹,通過祖先狀態重構(Ancestralstate reconstruction)算法并結合IMG/M數據庫,預測出樹中未進行全基因組測序OTU的基因組信息。

(2)宏基因組預測(metagenome inference)。將16SrDNA測序結果與Greengenes數據庫進行比對,挑選出與“closed reference”數據庫相似性高的(默認為≥97%)OTU;根據OTU對應基因組中16SrDNA的拷貝數信息,將每個OTU對應序列數除以其16S拷貝數來進行標準化;最后,將標準化的數據乘以其對應的基因組中基因含量從而實現宏基因組預測的目的。獲得的預測結果可以通過KEGG Orthology、COGs或Pfams等對基因家族進行分類。

qiime2-2020.8版本暫時無法安裝q2-picrust插件,因此使用picurst2軟件做微生物功能預測分析。

# install picrust2
conda create -n picrust2 -c bioconda -c conda-forge picrust2=2.3.0_b -y 
# export representative sequences
conda activate qiime2-2020.8
qiime tools export --input-path result/final_rep_seqs.qza --output-path ./ 
conda deactivate 
# run picrust2
conda activate picrust2
picrust2_pipeline.py -s dna-sequences.fasta -i feature-table.biom -o picrust2_out_pipeline -p 30
conda deactivate

The key output files are:

  • EC_metagenome_out - Folder containing unstratified EC number metagenome predictions (pred_metagenome_unstrat.tsv.gz), sequence table normalized by predicted 16S copy number abundances (seqtab_norm.tsv.gz), and the per-sample NSTI values weighted by the abundance of each ASV (weighted_nsti.tsv.gz).
  • KO_metagenome_out - As EC_metagenome_out above, but for KO metagenomes.
  • pathways_out - Folder containing predicted pathway abundances and coverages per-sample, based on predicted EC number abundances.

Reference

  1. qiime2 docs
  2. fastqc tutorial
  3. usearch tutorial
  4. vsearch tutorial
  5. import data in qiime2
  6. 擴增子分析軟件qiime2必知必會
  7. 擴增子數據庫整理
  8. Greengene數據庫整理
  9. SILVA 數據庫整理
  10. 差異檢驗
  11. lefse after qiime2
  12. lefse scripts github
  13. picrust2安裝及對16s數據進行功能預測
  14. picrust2 wiki
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容