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?
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?
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.
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.
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. "
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Thanks all. Will just reheader the old way.