This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Quickest Way To Pull A List Of Reads Out Of A Bam File?

What is the quickest way find the final aligned locations of a list of reads in BAM file? I can call

samtools view my.bam | grep -e uniqueID1 -e uniqueID2 > output

to grep for uniqueID1 and uniqueID2 in my.bam, but crawling through the SAM is quite slow. I'd like to call:

handyTool extractID my.bam -l listOfIdentifiers > output

and get the SAM line for each identifier found in the BAM. Is there a better way?

samtools next-gen

I'm not sure if there's another tool, but you could always use

samtools view input.bam | grep -Ff listOfIdentifiers

As I have tried before, grep -f is extremely slow for this purpose.

1 answer

duplicate of:

Extracting subsets of reads from a BAM file

Log in to answer this question.