I subset a BAM to only include primary reads using the following samtools commands:
samtools view -F 256 input.bam > input.primaryOnly.sam
Now, in order to convert this SAM into a new subsetted BAM, I would need to add a header. The way I normally do this is with Picard:
java -jar picard.jar ReplaceSamHeader \
whereby the header
input.header.sam is from the original BAM:
samtools view -H input.bam > input.header.sam
Then I could convert the SAM into a BAM with
samtools view -S -b i new.sam > new.bam
My problem is, I'm using the original BAM header. If I look back at the BAM, it now contains wrong information, e.g.
samtools flagstat new.bam
might save that secondary alignments exist, when they don't.
How do I get a BAM header that makes sense given my new BAM (with only primary alignments)?