Chip-Seq 分析過程二

全文分析流程學習按照:九月學徒ChIP-seq學習成果展

一、 怎么將SAR文件轉為fastq文件?

1. 【方法】利用軟件sratoolkit,下載后解壓,找到其中的 fastq-dump.exe 可執行文件

(export PATH方法沒用,用的alias方法。Export路徑寫到bin , alias路徑寫到可執行文件的絕對路徑)

fastq-dump  -I  --split-3  SRR948800.sra -O  /output/path/ #使用方法
#其中split-3表示如果是單端測序則一個sra文件出來一個fastq文件,如果是雙末端,則一個sra問件對應兩個fastq文件。

2. 【應用】寫一個腳本:

Vim sra_to_fastq


#!bin/bash
# sra conver to fastq
#BSUB -J align145
#BSUB -n 10
#BSUB -R span[hosts=1]
#BSUB -o %J.out
#BSUB -e %J.err
#BSUB -q normal
nohup fastq-dump -I --split-3 /public/home/thu/chip_seq/sra/SRR*.sra &
bash sra_to_fastq

ps
##查看進程

Jobs -l
##查看nohup & 掛在后臺的進程情況

二、 怎么用fastQC進行質控分析

【應用】寫一個腳本:

#!bin/bash

# sra conver to fastq

#BSUB -J align145

#BSUB -n 10

#BSUB -R span[hosts=1]

#BSUB -o %J.out

#BSUB -e %J.err

#BSUB -q normal

nohup fastqc -o ./fastqc *.fastq &

三、 用multiqc整合報告

【方法】Multiqc 安裝使用過程的問題

  • multiqc *zip -o ./multiqc/

四、過濾低質量的fq文件

1. 【方法】用Trim Galore軟件

說明書:Taking appropriate QC measures for RRBS-type or other -Seq applications with Trim Galore!

2. 【應用】運行一個腳本

  1 #!bin/bash
  2 #trim_galore
  3 #BSUB -J align145
  4 #BSUB -n 10
  5 #BSUB -R span[hosts=1]
  6 #BSUB -o %J.out
  7 #BSUB -e %J.err
  8 #BSUB -q normal
  9 
 10 fq1=/public/home/thu/chip_seq/sra/SRR6795678_1.fastq.gz
 11 fq2=/public/home/thu/chip_seq/sra/SRR6795678_2.fastq.gz
 12 
 13 nohup trim_galore -q 20 --phred33 \
 14                 --paired \         #雙端測序
 15                 --length 40 \    #小于40的read刪除(可變,大小浮動對后續分析影響不大)
 16                 --fastqc \         #同時生成fastqc文件
 17                 --stringency 3 \ 
 18                 $fq1 $fq2  \     #fastq文件
 19                 --gzip &          #壓縮形式

3. trim_galore報告(若使用后臺命令,則報告在nohup.out文件中):

SUMMARISING RUN PARAMETERS
==========================
Input filename: ENCFF108UVC.fastq.gz #輸入文件
Trimming mode: paired-end  #雙端測序結果
Trim Galore version: 0.5.0
Cutadapt version: 1.18
Quality Phred score cutoff: 25  #質量低于25的被刪除,默認20(99%)
Quality encoding type selected: ASCII+33  #質量得分算法類型
Adapter sequence: 'AGATCGGAAGAGC' (Illumina TruSeq, Sanger iPCR; auto-detected)
Maximum trimming error rate: 0.1 (default) #最大錯誤率
Minimum required adapter overlap (stringency): 5 bp  #最大adapter重復數目?
Minimum required sequence length for both reads before a sequence pair gets removed: 75 bp  #最小的長度數量(可以適當放寬)
Output file will be GZIP compressed


This is cutadapt 1.18 with Python 2.7.6
Command line parameters: -f fastq -e 0.1 -q 25 -O 5 -a AGATCGGAAGAGC ENCFF108UVC.fastq.gz
Processing reads on 1 core in single-end mode ...
Finished in 1038.93 s (40 us/read; 1.50 M reads/minute).

=== Summary ===

Total reads processed:              26,038,229
Reads with adapters:                   714,205 (2.7%)  #讀到的adapter數目
Reads written (passing filters):    26,038,229 (100.0%)

Total basepairs processed: 2,603,822,900 bp
Quality-trimmed:              82,577,636 bp (3.2%)  #過濾了3.2%數據
Total written (filtered):  2,513,138,030 bp (96.5%)  #保留了96.5%的數據
————————————————
版權聲明:本文為CSDN博主「super_qun」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/weixin_44452187/java/article/details/87688276

五、 對水稻基因組建立索引(這步比較慢)

1. 構建索引 基本命令就是bowtie2-build 基因組序列.fa 索引名字

bowtie2-build all.fa rice

#all.fa: 水稻基因組序列(絕對路徑)
#rice: 建立索引的前綴名

2. 索引后得到 6個文件 ,為.bt2索引文件的前綴

rice.1.bt2
rice.2.bt2
rice.3.bt2
rice.4.bt2
rice.rev.1.bt2
rice.rev.2.bt2

六、利用bowtie2比對

1. 參考:

Bowtie2使用方法與參數詳細介紹
bowtie序列比對軟件的使用
tophat2、hisat2、trimmomatic、cufflinks、samtools和stringtie
samtools的用法簡介
SAMtools的使用說明
samtools用法詳解
處理SAM、BAM你需要Samtools

2. 【方法】

 nohup bowtie2 -p 8 \     #設置線程數
         -x $index \           #索引路徑
        -1 ${fq1} -2 ${fq2} \  #雙端測序fastq文件
        -S SRR6795678.sam &    #生成sam文件的文件名

3. bowtie相關參數

【必須參數】:

  • -x <bt2-idx>
    由bowtie2-build所生成的索引文件的前綴。首先 在當前目錄搜尋,然后在環境變量BOWTIE2_INDEXES中制定的文件夾中搜尋。
  • -1 <m1>
    雙末端測尋對應的文件1。可以為多個文件,并用逗號分開;多個文件必須和-2<m2>中制定的文件一一對應。比如:"-1flyA_1.fq,flyB_1.fq -2 flyA_2.fq,flyB_2.fq".測序文件中的reads的長度可以不一樣。
  • -2 <m2>
    雙末端測尋對應的文件2.-U <r>非雙末端測尋對應的文件。可以為多個文件,并用逗號分開。測序文件中的reads的長度可以不一樣。
  • -S <hit>
    所生成的SAM格式的文件前綴。默認是輸入到標準輸出。

4. 將sam 格式轉為bam格式

【應用】

#寫一個腳本
bowtie2 -p 8 -n 2 -x $index \
-1 ./SRR6795670_1_val_1.fq.gz \
-2 ./SRR6795670_2_val_2.fq.gz \
-S SRR6795670.sam     #進行比對得到bam文件

samtools view -Sbh SRR6795669.sam > SRR6795669.bam 
#得到的sam文件為bam文件 

#-b 以BAM格式輸出,可以用于samtools的后續分析
#-S 輸入文件為SAM格式
#-u 以未壓縮的BAM格式輸出,可以節約時間,一般在管道執行時使用
#-h 在結果中包含頭header
samtools sort SRR6795669.bam -@ 10 -o SRR6795669.sorted.bam #對bam文件進行排序
#-@ 線程數
samtools index -@ 10 SRR6795669.sorted.bam

5. 對bam文件進行QC

ls  *sorted.bam  |xargs -i samtools index {} 
ls  *sorted.bam  | while read id ;do (samtools flagstat $id > $(basename $id ".sorted.bam").stat);done
#查看成功率:
cat *stat*|grep %
[thu@mn02 mapping]$ cat *stat*|grep %
51413901 + 0 mapped (71.24% : N/A)
45088678 + 0 properly paired (62.47% : N/A)
5349781 + 0 singletons (7.41% : N/A)
38939471 + 0 mapped (77.03% : N/A)
35879950 + 0 properly paired (70.98% : N/A)
2515027 + 0 singletons (4.98% : N/A)
67913650 + 0 mapped (93.74% : N/A)
67386764 + 0 properly paired (93.01% : N/A)
186796 + 0 singletons (0.26% : N/A)
67389488 + 0 mapped (94.44% : N/A)
66910562 + 0 properly paired (93.77% : N/A)
204310 + 0 singletons (0.29% : N/A)

七、samtoolsPCR重復的去除

#samtools rmdup 去重復
samtools rmdup input.sorted.bam  rmdup.bam
#對rmdup.bam文件進行QC
ls  *.rmdup.bam  | while read id ;do (nohup samtools flagstat $id > $(basename $id ".bam").stat & );done
#查看QC質控結果:
cat *stat*|grep %
51413901 + 0 mapped (71.24% : N/A)
45088678 + 0 properly paired (62.47% : N/A)
5349781 + 0 singletons (7.41% : N/A)
38939471 + 0 mapped (77.03% : N/A)
35879950 + 0 properly paired (70.98% : N/A)
2515027 + 0 singletons (4.98% : N/A)
#去除重復前后比較(主要看文件大小)
ls -lh

八、利用macs2來callpeak

  vim callpeaking      #創建一個腳本文件名為callpeaking
  1 #!bin/bash
  2 #callpeak
  3 #BSUB -J align145
  4 #BSUB -n 10
  5 #BSUB -R span[hosts=1]
  6 #BSUB -o %J.out
  7 #BSUB -e %J.err
  8 #BSUB -q normal
  9 
 10 
 11 control="/public/home/thu/chip_seq/sra/5.RemovePCRduplicated/input.rmdup.bam"
 12 treatment="/public/home/thu/chip_seq/sra/5.RemovePCRduplicated/control_H3K9ac_Chipseq_rep2_rmdup.bam"
 13 outname="control_H3K9ac_Chipseq_rep2_rmdup"
 14 
 15 nohup macs2 callpeak -c ${control} -t ${treatment} -f BAM -g 400000000 -n ${outname} &


#-c 后面加上control組樣本名
#-t 后面加上treatment組樣本名
#-f {AUTO,BAM,SAM,BED,ELAND,ELANDMULTI,ELANDEXPORT,BOWTIE,BAMPE,BEDPE}
#            后面加上format 輸出文件的格式
#-q QVALUE 后面加上人為設定的q值。默認為0.05
#-B, --bdg    加上這個選項則表示需要輸出extended fragment pileup和local lambda tracks (two files)
#-n NAME  指定輸出文件名
#-g GSIZE    Effective genome size,可以是具體數字,也可以用簡寫:
#        'hs' for human (2.7e9), 'mm' for mouse (1.87e9), 'ce' for C. elegans (9e7) 
#        'dm' for fruitfly (1.2e8), Default:hs
#       這里水稻的EGS為4.00e+08
# GES定義:A number of tools can accept an “effective genome size”. This is defined as the length of the “mappable” genome. There are two common alternative ways to calculate this:1. The number of non-N bases in the genome.2. The number of regions (of some size) in the genome that are uniquely mappable (possibly given some maximal edit distance).
#- 水稻基因組大小大約是4*10^8(總堿基數)。 一般要除去端粒和著絲粒等測序測不到的部位,但影響不大。

1. 【使用參數 】

-c: 對照組的輸出結果

  • control 或 mock(非特異性抗體,如IgG)組
    control:input DNA,沒有經過免疫共沉淀處理;
  • mock:
    1)未使用抗體富集與蛋白結合的DNA片段
    2)非特異性抗體,如IgG

-f: -t和-c提供文件的格式,可以是”ELAND”, “BED”, “ELANDMULTI”, “ELANDEXPORT”, “ELANDMULTIPET” (for pair-end tags), “SAM”, “BAM”, “BOWTIE”, “BAMPE” “BEDPE” 任意一個。如果不提供這項,就是自動檢測選擇。MACS2讀入文件格式。

-g: 基因組大小, 默認提供了hs, mm, ce, dm選項, 不在其中的話,比如說擬南芥,就需要自己提供了。

  • 有效基因組大小(可比對基因組大小);基因組中有大量重復序列測序測不到,實際上可比對的基因組大小只有原基因組90% 或 70%;人類默認值是– 2.7e9(UCSC human hg18 assembly)

-n: 輸出文件的前綴名

eg:NAME .會產生‘NAME_peaks.xls’, ‘NAME_negative_peaks.xls’, ‘NAME_peaks.bed’ , ‘NAME_summits.bed’, ‘NAME_model.r’四個文件

-B: 會保存更多的信息在bedGraph文件中,如fragment pileup, control lambda, -log10pvalue and -log10qvalue scores

-q: q值,也就是最小的PDR閾值, 默認是0.05。q值是根據p值利用BH計算,也就是多重試驗矯正后的結果。

-p:這個是p值,指定p值后MACS2就不會用q值了。

-m: 和MFOLD有關,而MFOLD和MACS預構建模型有關,默認是5:50,MACS會先尋找100多個peak區構建模型,一般不用改,因為我們很大概率上不會懂。

2. macs2結果輸出

control_H3K9ac_Chipseq_rep2_rmdup_model.r
control_H3K9ac_Chipseq_rep2_rmdup_peaks.narrowPeak
control_H3K9ac_Chipseq_rep2_rmdup_peaks.xls
control_H3K9ac_Chipseq_rep2_rmdup_summits.bed

3. 得到的 NAME_peaks.xls 文件

Chr2    17873714    17875118    1405    17874072    30  13.2471 5.04787 11.6898 control_H3K9ac_Chipseq_rep2_rmdup_peak_11539
Chr2    17880926    17882366    1441    17881114    47.02   30.3482 8.24866 28.4358 control_H3K9ac_Chipseq_rep2_rmdup_peak_11540
Chr2    17888892    17889834    943 17889240    55.13   37.9717 9.40114 35.9095 control_H3K9ac_Chipseq_rep2_rmdup_peak_11541
Chr2    17905088    17905946    859 17905509    69.73   54.316  12.1478 51.9143 control_H3K9ac_Chipseq_rep2_rmdup_peak_11542

雖然后綴名是xls,但實際上就是一個普通的文本文件。包含peak信息的tab分割的文件,前幾行會顯示callpeak時的命令。輸出信息包含:

  • 染色體號

  • peak起始位點

  • peak結束位點

  • peak區域長度

  • peak的峰值位點(summit position)

  • peak 峰值的屬性(包括pileup峰高和可信度)(pileup height at peak summit, -log10(pvalue) for the peak summit)都是值越高越好

  • peak的富集倍數(相對于random Poisson distribution with local lambda)

4. 得到的 NAME_peaks.narrowPeak 文件

Chr1    28122534    28123365    control_H3K9ac_Chipseq_rep2_rmdup_peak_2602 555 .   12.3587 57.9451 55.5223 567
Chr1    28126628    28127930    control_H3K9ac_Chipseq_rep2_rmdup_peak_2603 233 .   7.42181 25.0983 23.3049 220
Chr1    28133217    28134651    control_H3K9ac_Chipseq_rep2_rmdup_peak_2604 211 .   6.82834 22.8667 21.1265 280
Chr1    28136385    28136908    control_H3K9ac_Chipseq_rep2_rmdup_peak_2605 93  .   4.4158  10.8192 9.32836 336

narrowPeak文件是BED6+4格式,可以上傳到UCSC瀏覽。輸出文件每列信息分別包含:

  • 染色體號

  • peak起始位點

  • 結束位點

  • peak name

  • int(-10*log10qvalue)可信度,值越大越好

  • 正負鏈

  • fold change

  • -log10pvalue可信度,值越大越好

  • -log10qvalue可信度,值越大越好

  • relative summit position to peak start相對于起始位點來說peaks峰值的位置

bed格式的文件和其他Peak文件唯一不同的是——Peak文件中,由于以1為基,而bed文件是以0為基,所以peak的起始位置需要減1才是bed格式的文件。

5. 得到的 NAME_summits.bed 文件

Chr1    34159624    34159625    control_H3K9ac_Chipseq_rep2_rmdup_peak_3468 39.8115
Chr1    34162177    34162178    control_H3K9ac_Chipseq_rep2_rmdup_peak_3469 6.22312
Chr1    34165994    34165995    control_H3K9ac_Chipseq_rep2_rmdup_peak_3470 45.9992
Chr1    34179707    34179708    control_H3K9ac_Chipseq_rep2_rmdup_peak_3471 23.5895

BED格式的文件,包含peak的summits位置,第5列是-log10pvalue。如果想找motif,推薦使用此文件。
能夠直接載入UCSC browser,用其他軟件分析時需要去掉第一行。?

6. 得到的 NAME_model.r 文件

NAME_model.r能通過 $ Rscript NAME_model.r作圖,得到是基于你提供數據的peak模型。
可以看到非常貼心的幫我們寫好了腳本,直接運行即可出pdf圖。

十、使用deeptools是進行可視化

1. 數據的連續密度圖(在基因組瀏覽器上查看)

[1] bam文件轉為bw文件

  • 為什么要用bigWig(bw格式)? 主要是因為BAM文件比較大,直接用于展示時對服務器要求較大。
cd  /public/home/thu/chip-seq/sra/5.RemovePCRduplicated

ls  *.bam  |xargs -i samtools index {}     #進行轉換前需要先建立index
cat >bam2bw.command  #寫一個腳本

#bin/bash
#callpeak
#BSUB -J align145
#BSUB -n 10
#BSUB -R span[hosts=1]
#BSUB -o %J.out
#BSUB -e %J.err
#BSUB -q normal

ls *.sorted.bam |while read id;do
bamCoverage -p 10 --normalizeUsing CPM -b $id -o ${id%%.*}.bw 
done 
ls *.rmdup.bam |while read id;do
bamCoverage -p 10 --normalizeUsing CPM -b $id -o ${id%%.*}.rmdup.bw 
done 

:wq

nohup bash bam2bw.command &
mkdir bwfile
mv *bw bwfile
cd bwfile
sz *.bw    #將bw文件發送到本地

【2】載入IGV中進行查看:

  • 用于可視化的基因組瀏覽器:IGVJBrowse
  • IGV 中需要導入基因組參考文件和上面得到的bw文件
    genomes>load from file 選擇對應的基因組參考文件
    file>load from file 選擇對應的bam文件
  • 這里下載水稻基因序列參考文件all.con,網站 http://rice.plantbiology.msu.edu/,如下下載:
    Rice Genome Annotation Project - 搜狗_51Record.gif

    得到密度圖:
    image.png

2. 折線圖/熱圖:所有轉錄本上peak區域reads的分布情況

【1】依賴:

  • deeptools bamCoverage得到的bw文件
  • 基因組注釋文件bed文件

【2】原理:

  • 為了統計全基因組范圍的peak在基因特征的分布情況,用deeptools軟件:也就是需要用到computeMatrix函數計算,用plotHeatmap函數以熱圖的方式對覆蓋進行可視化,用plotProfile函數以折線圖的方式展示覆蓋情況。

【3】應用:

mkdir 7.rice_tss.bed && cd 7.rice_tss.bed
ln -s 5.RemovePCRduplicated/bwfile ./

#下載水稻基因組注釋文件all.locus_brief_info.7.0(非bed格式)
nohup wget http://rice.plantbiology.msu.edu/pub/data/Eukaryotic_Projects/o_sativa/annotation_dbs/pseudomolecules/version_7.0/all.dir/all.locus_brief_info.7.0 & 

#將下載的注釋文件按順序提取染色體號chrom、染色體起始位置chromStart、染色體終止位置chromEnd、基因名字四列,生成bed文件
cat all.locus_brief_info.7.0 | cut -f 1,4,5 > rice.1
cat all.locus_brief_info.7.0 | cut -f 2 > rice.2
paste rice1 rice2 > rice.bed
sed -i '1d' rice.bed
#創建computermatric腳本
vim computermatric
  1 #!bin/bash
  2 #computeMatric
  3 #BSUB -J align145
  4 #BSUB -n 10
  5 #BSUB -R span[hosts=1]
  6 #BSUB -o %J.out
  7 #BSUB -e %J.err
  8 #BSUB -q normal
  9 
 10 bed=/public/home/thu/2.chip_seq/sra/7.rice_tss.bed/rice.bed
 11 for id in bwfile/*bw;
 12 do
 13 file=$(basename $id )
 14 sample=${file%%.bw}
 15 echo $sample
 16 
 17 computeMatrix reference-point  --referencePoint TSS  -p 15  \
 18 -b 2000 -a 2000    \
 19 -R  $bed \
 20 -S $id  \
 21 --skipZeros  -o matrix1_${sample}_TSS_2K.gz  \
 22 --outFileSortedRegions regions1_${sample}_TSS_2K.bed

 24 #plotHeatmap和plotProfile函數
 25 plotHeatmap -m matrix1_${sample}_TSS_2K.gz  -out ${sample}_Heatmap_2K.png
 26 plotHeatmap -m matrix1_${sample}_TSS_2K.gz  -out ${sample}_Heatmap_2K.pdf --plotFileFormat pdf  --dpi 720
 27 plotProfile -m matrix1_${sample}_TSS_2K.gz  -out ${sample}_Profile_2K.png
 28 plotProfile -m matrix1_${sample}_TSS_2K.gz  -out ${sample}_Profile_2K.pdf --plotFileFormat pdf --perGroup --dpi 720
 29 done

#computeMatrix reference-point函數的參數
#--referencePoint {TSS,TES,center}    The reference point for the plotting could be either the region start (TSS), the region end (TES) or the center of the region
#-b/--beforeRegionStartLength INT bp:區域前多少bp
#-a/--afterRegionStartLength INT bp:區域后多少bp
#-R/--regionsFileName File:指定bed文件
#-S/--scoreFileName File:指定bw文件
#--skipZeros:默認為False
#-o/-out/--outFileName OUTFILENAME:指定輸出文件名
#--outFileSortedRegions BED file

#plotHeatmap和plotProfile函數參數
#-m/--matrixFile MATRIXFILE:指定matrix名字(computeMatrix的輸出文件名)
#-o/-out/--outFileName OUTFILENAME:指定輸出文件名,根據后綴自動決定圖像的格式
#--plotFileFormat {"png", "eps", "pdf", "plotly","svg"}:指定輸出文件格式
#--dpi DPI:指定dpi
#--perGroup:默認是畫一個樣本的所有區域群的圖,使用這個選項后則按區域群畫所有樣本的情況

【4】結果如圖:

image.png

【5】參考:

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容