Get Reference file from BAM
1
0
Entering edit mode
9.9 years ago
win ▴ 990

Is is possible to determine the reference file from a BAM file? I want to programmatically determine the reference file that was used during alignment and use it for variant detection.

BAM • 3.2k views
ADD COMMENT
0
Entering edit mode

Are you wanting to compute the content of the reference (i.e. the FASTA sequence) or just the name of the reference file?

ADD REPLY
0
Entering edit mode

I just need the name of the reference file so I can use it for pulling up variants.

ADD REPLY
3
Entering edit mode
9.9 years ago
donfreed ★ 1.6k

Besides the @SQ header lines, the bam file header may have information on the reference used in the @PG lines. If this header line is present, you can parse it to determine the reference which was used for alignment. An example line from a BWA mem aligned bam file is below.

@PG    ID:bwa  PN:bwa  VN:0.7.9a-r788-dirty    CL:bwa mem -t 6 -R @RG\tID:foo\tSM:bar /mnt/data/reference/hs37d5.fa ../ERR194147_1.fastq.gz ../ERR194147_2.fastq.gz

Which shows that this bam file was aligned to hs37d5.fa

ADD COMMENT
0
Entering edit mode

Thanks. Is there a way to extract this info programmatically?

ADD REPLY

Login before adding your answer.

Traffic: 1615 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