好吧,這是本周(2016.10.21-28)的學習任務之一:安裝bowtie2並學習其使用方法&參數設置
所以,啃文檔咯,官方文檔Version 2.2.9 http://bowtie-bio.sourceforge.net/bowtie2/manual.shtml
以下是我的整理。我不生產文檔,我只是文檔的搬運工么么噠~
Bowtie2適合將長度50-1000bp的reads比對到長的參考序列上。Bowtie 2 indexes the genome with an FM Index
(based on the Burrows-Wheeler Transform or BWT) 。輸出結果為SAM格式。已集成在很多軟件中,如
TopHat(a fast splice junction mapper for RNA-seq reads),
Cufflinks(transcriptome assembly and isoform quantitiation from RNA-seq reads),
Crossbow( cloud-enabled tool for analyzing reseuqncing data),
Myrna(a cloud-enabled tool for aligning RNA-seq reads and measuring differential gene expression)。
Bowtie1和2的區別:Bowtie 2's command-line arguments and genome index format are both different from Bowtie 1's.
1,bowtie1出現的早,所以對於測序長度在50bp以下的序列效果不錯,而bowtie2在長度在50bp以上的更好。
2,Bowtie 2支持有空位的比對Number of gaps and gap lengths are not restricted, except by way of the configurable scoring scheme.
3,Bowtie 2支持局部比對(local, some chars will be omited/trimmed),也可以全局比對(end-to-end, all char participate)
4,Bowtie 2對最長序列沒有要求,但是Bowtie 1最長不能超過1000bp。
5. Bowtie 2 allows alignments to [overlap ambiguous characters] (e.g. `N`s) in the reference. Bowtie 1 does not.
6,Bowtie 2不能比對colorspace reads.
7, Bowtie 2's paired-end alignment is more flexible. Try to find unpaired alignments for each mate。
8, Bowtie 2 reports a spectrum of mapping qualities, Bowtie 1 reports either 0 or high。
MUMmer: align 2 very large sequences(eg: 2 genomes)
NUCmer, BLAT/BLAST, Bowtie2: sensitive alignment to short ref seq(eg: a bacterial genome)
安裝bowtie2: 直接下載bowtie2-2.2.9-linux-x86_64.zip,解壓,修改環境路徑即可
(設置環境路徑請自行百度,或者參考這個http://www.cnblogs.com/pxy7896/p/5886305.html)
Scores: 更高分=更相似
--ma :match bonus
--mp :mismatch penalty
--np :penality for having N in either the read or the ref
--rdg :affine read gap penalty
--rfg :affine ref gap penalty
全局比對栗子:默認,高質量位點的mismatch罰分為-6,長度為2的gap罰分為-11(gap open-5, extension-3),如果在長度為50的read中只有這兩個問題,則總分為-17。所以,最好的分數是0,指read和ref完全相同。
default min score threshold:
可以用--score-min設置
-0.6-0.6*L(read長度)
局部比對栗子:罰分同上,但每個match獲得bonus,+2,則如果是上面情況,則得分為2*49-6-11=81
default min score threshold:
20+8*ln(L)(read長度)
paired-end read:兩個mate的分數相加
Mapping quality:higher=more unique
如果一個read來自重復區域,則可能map到多個地方,所以需要知道比對的可信程度。在SAM文件中,MAPQ就是這個,值為Q=-10log10p。p是對比對錯誤的概率的估計。一個read越特殊,比對錯誤的概率越小,Q值越大。
bowtie2是對paired read的每個mate分別比對的,所以如果兩個比對結果不符合預期(比如方向不合適或者距離不合適),就說是align discordantly,這種在研究structural variants時有用。
--ff --fr --rf: expected relative orientation of the mates
-I and -X: expected range of inter-mates distances
--no-discordant: 禁止找discordant alignments
--no-mixed: mixed mode指對一個pair找不到paired-end alignment時,為每個mate找unpaired alignments。關了這個會快一點點。
SAM 格式中有一些flag和optional fields描述了paired-end特征
Mates can overlap, contain, or dovetail each other
overlap:
contain: mate2剛好是mate1的子序列
dovetail: 咬合,延長
bowtie2默認overlap和contain是concordant的,dovetai是disconcordant的。所以:
--no-overlap和--no-contain使得這兩種情況變為disconcordant
--dovetail: 讓dovetail變為concordant
Reporting mode:
dafault mode: 找多個匹配,報告最好的
-D和-R: 會使程序變慢,但是增大了找到最好比對的可能性(針對有多個比對的)
-k mode: 找一個或多個匹配,全報告
-k N找最多N個匹配,按比對分數降序排序
-a mode: 找和報告所有的。對大基因組,這個會很慢。
bowtie2找匹配時采用隨機的策略,會使用--seed產生隨機數來選擇需要報告的匹配。所以如果使用
--non-deterministic,則對同樣的輸入reads,可能會產生不同的比對結果輸出。
To rapidly narrow the number of possible alignments that must be considered, Bowtie 2 begins by
extracting substrings ("seeds") from the read and its reverse complement and aligning them in an
ungapped fashion with the help of the FM Index.
-L: seed length
-i: interval between extracted seeds
-N: # mismatches permitted per seed
如果想要更sensitive的比對,可以減小L和i,增大N。同樣,-D和-R也與此相關。
--n-ceil: upper limit on # N if valid
Presets: setting many settings at once
--very-sensitive: 等價於-D 20 -R 3 -N 0 -L 20 -i S,1,0.50 //可以查看文檔得知
過濾:
bowtie2會在SAM記錄里寫出低質量read,YF:i SAM optional field 也會解釋過濾它們的原因(多個原因只說一個),但是不會去比對它們。
YF:Z:LN read長度<=seed mismatches(-N)
YF:Z:NS read里N的數量>(--n-ceil)
YF:Z:SC 低於--score-min
YF:Z:QC 與--qv-filter設定相關。Illumina的QSEQ格式中,read最后一個域含1
small(32-bit numbers, for <4 billion nucleotides in length, index.bt2) and large(64-bit numbers, .bt21) index自動選擇,無需擔心
Performance tuning:
-p: 多線程
-o/--offrate: 使用bowtie2-build時,這個值比default設得小些。這樣會有更大的index,適合-k和-a模式(報告多個比對的)。但如果計算機內存小,還是把這個值設大,減少內存消耗。
×××××××××××××××××××××××××××××××××××××××實驗×××××××××××××××××××××××××××××××××××××××××××××××××××××××
Step 1:建索引
新建文件夾,在新文件夾下運行,
bowtie2-build /home/pxy7896/Downloads/bowtie2/example/reference/lambda_virus.fa lambda_virus
結果:產生六個文件。(eg1,eg2,eg3是后面的)
可以使用預先建好的索引。
可以一次為多個文件建立索引,文件名之間用,分隔
Step 2: 比對reads
bowtie2 -x lambda_virus -U /home/pxy7896/Downloads/bowtie2/example/reads/reads_1.fq -S eg1.sam
參數解釋:
-x: 查看index文件首先在當前目錄下找,找不到再去環境變量BOWTIE2_INDEXES下找。
-U: 后面跟需要比對的read文件。多個用,分隔。
-S: 后跟結果文件的名字。
比對結果寫到eg1.sam,要查看:head eg1.sam
sam格式:(haven’t read yet)
Step 3: 比對paired-end reads
bowtie2 -x lambda_virus -1 /home/pxy7896/Downloads/bowtie2/example/reads/reads_1.fq -2 /home/pxy7896/Downloads/bowtie2/example/reads/reads_2.fq -S eg2.sam
Step 4: long reads local alignment
bowtie2 --local -x lambda_virus -U /home/pxy7896/Downloads/bowtie2/example/reads/longreads.fq -S eg3.sam
samtools:(可以輸入命令,查詢可以選擇的參數)
Step 5: sam轉為bam格式 (binary format of sam)
samtools view -b /home/pxy7896/Desktop/eg/eg2.sam -o eg2.bam
Step 6: sam排序為.sorted文件(這是壓縮了的文件,適合存儲)
samtools sort eg2.bam -o eg2.sorted
Step 7: generate variant calls in VCF format
發現居然沒有裝bcftools(for calling variants and manipulating VCF and BCF files)
sudo apt install bcftools
然后執行
samtools mpileup -v -u -f $BT2_HOME/example/reference/lambda_virus.fa eg2.sorted | bcftools view -o eg2.raw.bcf
解釋:將eg2.sorted和參考序列放一起比對,然后用bcftools將結果放到eg2.raw.bcf中
很奇怪,手冊里的命令我運行的不對。。。可能還是這樣找使用方法靠譜一點。
產生eg2.raw.bcf文件,大概長這個樣子:
×××××××××××××××××××××××××××××××××××××××參數×××××××××××××××××××××××××××××××××××××××××××××××××××××××
bowtie2
bowtie2-build(關於目錄建立)
bowtie2-inspect