This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How Do I Pull Out One Read (Given Its Id) From A Bam?

Hi there

Does anyone know how I can pull just one read from a BAM file, when I know the read-id (and sequence) of that read? I'm doing this because I've just got an error saying that one of the reads has no quality information. Since the original BAM is huge, I don't want to convert the whole thing to SAM or fastq and find that read-id. Any suggestions (also on BAM validation) welcome!

cheers Zam

samtools

1 answer

Have you tried piping? E g

samtools view file.bam | grep read_id

(or using the sequence, in case the read id is somehow inconsistent between FASTQ and BAM as sometimes happens)

No I haven't, because I didn't want to read the entire file, which is several hundred Gb. Is there a way for grep to just give its first hit? I'll check that...

grep -m 1 would return the first match and exit.

Log in to answer this question.