Extract Fastq file from BAM File by reference name using samtools.
1
0
Entering edit mode
5.9 years ago
clear.choi ▴ 30

Hello,

I am trying to understand how to use samtools, and there is a little bit confusion.

I have one .BAM file which is 96 index is existed.

I can extract that specific index like below

samtool view -r B3 -b -o out.bam in.bam

[ Ref : Extract Bamfile using samtools ]

But I wonder if I want to use also Reference Name (fg, Reference name : A_01_01)

And Flag which is contain 0 or 16 . ( 0 mean Forward sequence and 16 mean Reverse sequence )

If I want to extract reference "A_01_01" and Flag 0 .

What is exactly command line I can use?

After that I can extract to fastq file using below command.

samtools bam2fq output.bam > output.fastq

Thank you!

sam samtools bam • 2.7k views
3
Entering edit mode
5.9 years ago

It might help if you clarify your question, but I think you want:

samtools view -f 0 -r B3 -b -o out.bam in.bam A_01_01

1
Entering edit mode

( 0 mean Forward sequence and 16 mean Reverse sequence )

I really like samtools, but the flag notation is just so confusing to most people. -f 0 will not work at all!! You want -F 16

0
Entering edit mode

Thank you :)