This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Extract Bamfile using samtools

Hello

It's the first time try to use samtools and I wonder how I can extract bam file by sample.

I need to analyze bam file by Sample and make another BAM file by Sample.

In side of bam file there is sample ID like B1, B2, B3, ... B384.

I wonder if I want to extract only B3 sample from original bam file.

How can I command?

original bam file original.bam -> new bam file b3.bam.

Thank you.

bam sam samtools

1 answer

using samtools view with the -r option. See the sam spec to understand what is a group-id in a SAM file.

-r STR   only include reads in read group STR [null]
  
samtool view -r B3 -b -o out.bam in.bam

Log in to answer this question.