用到的程序,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 >