In order to use MergeBamAlignment (Picard), I need an unmapped BAM file and a mapped BAM file. I have two mapped BAM files:

  • one with reads mapped to the reference I want but without metadata such as read group
  • a second one with reads mapped to the incorrect reference but with metadata

When I try to use MergeBamAlignment with these two files, I get errors, such as "Second read from pair not found in unmapped bam". So I am trying to unmap the reads from my second BAM file. How can I do that? Is there a tool for it? Otherwise, I'll have to manually change the bitwise FLAGs, reference names, CIGARS, etc.


2 Answers 2


Looks like you need Picard's RevertSam operation (described in context here, manual here).

java -jar picard.jar RevertSam \
     I=input.bam \

What happens if you use the bam with the metadata as the input to your aligner? Maybe it will keep all those fields.

  • $\begingroup$ bwa mem requires a fastq file, it does not accept a BAM $\endgroup$ Jul 11, 2019 at 13:19
  • 1
    $\begingroup$ Okay, I didn't know you had to use that. You see that bwa aln will take a bam? $\endgroup$
    – swbarnes2
    Jul 11, 2019 at 15:54
  • $\begingroup$ good point, the RevertSam worked though $\endgroup$ Jul 11, 2019 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.