從BAM文件提取unmapped reads并轉(zhuǎn)換成fastq格式

用到的程序,samtools和bedtools,都用conda安裝。

目標(biāo)是將第一次比對(duì)的bam中unmapped reads提取出來,并轉(zhuǎn)換成fastq進(jìn)行下次比對(duì)。

第一步:提取unmapped reads(格式bam)

用到samtools view

選項(xiàng):-b #表示生成bam格式??

? ? ? ? ? ?-f? #“The?-f?options flags to keep the reads 'Only output alignments with all bits set in INT present in the FLAG field'”? 保留你選擇的reads?

? ? ? ? ? ?-F #"The?-F?option flags to remove the reads 'Only output alignments with all bits set in INT present in the FLAG field'"? 去除你選擇的reads

示例?

samtools view -b -F 4 -f 8 file.bam > onlyThisEndMapped.bam?

samtools view -b -F 8 -f 4 file.bam > onlyThatEndMapped.bam

samtools view -b -F12 file.bam > bothEndsMapped.bam?

4,8,12這些參數(shù)代表你選擇的reads,具體參見?http://broadinstitute.github.io/picard/explain-flags.html

我是需要提取 unmapped reads,使用 -f 4可以保留所有的unmapped reads

samtools view -b -f 4 file.bam > file_unmapped.bam

但這里面包含的reads包括所有paired和 unpaired,如果只想要paired unmapped reads,可以使用 -f 13

提取出 unmapped.bam后,要把他轉(zhuǎn)化為fastq,可使用bedtools的 “bamToFastq”實(shí)現(xiàn)

注意:bam要先排序!? 不然會(huì)一直報(bào)錯(cuò),錯(cuò)誤的原因就是在read1附近找不到對(duì)應(yīng)的read2.。我使用samtools以名稱排序。

指令 : samtools sort -n input.bam output.bam

然后就是bamToFastq了 :bamToFastq -i < input.bam > -fq < file1.fq > -fq2 < file2.fq >



參考:https://www.biostars.org/p/56246/

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容