How Do I Pull Out One Read (Given Its Id) From A Bam?
1
0
Entering edit mode
10.9 years ago

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 • 5.7k views
ADD COMMENT
0
Entering edit mode

Sorry, should have spotted that

ADD REPLY
1
Entering edit mode
10.9 years ago

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)

ADD COMMENT
0
Entering edit mode

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...

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

Thanks for that!

ADD REPLY

Login before adding your answer.

Traffic: 2727 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6