This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Extract Fastq file from BAM File by reference name using samtools.

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!

bam sam samtools

1 answer

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

( 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

Log in to answer this question.