Fast BAM header editing
3
1
Entering edit mode
11 months ago

I would like to change some information in the BAM header (specifically, chromosome size information). Is there a smarter/faster way to do this without extracting to an intermediate SAM file and remaking the BAM file from the edited SAM file?

bam • 863 views
ADD COMMENT
0
Entering edit mode

Thanks all. Will just reheader the old way.

ADD REPLY
1
Entering edit mode
11 months ago
Zhenyu Zhang ★ 1.2k

You can pipe/stream the process without explicitly writing a temp file to disk.

For better solutions, unfortunately BAM file is not defined to have a fixed size header block at the beginning. Otherwise, we would be able to swap the header directly without touching the reads.

ADD COMMENT
1
Entering edit mode
11 months ago

In the context of java/htsjdk you could create a custom SamReaderFactory that would change the dictionary by changing CUSTOM_READER_FACTORY https://www.javadoc.io/doc/com.github.samtools/htsjdk/2.5.1/htsjdk/samtools/Defaults.html#CUSTOM_READER_FACTORY with -Dsamjdk.custom_reader . I can elaborate if needed.

ADD COMMENT
0
Entering edit mode
11 months ago
cmdcolin ★ 3.8k

See samtools reheader

http://www.htslib.org/doc/samtools-reheader.html

quote from the docs " Replace the header in in.bam with the header in in.header.sam. This command is much faster than replacing the header with a BAM->SAM->BAM conversion. "

ADD COMMENT

Login before adding your answer.

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