2
$\begingroup$

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.

$\endgroup$
2
$\begingroup$

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

java -jar picard.jar RevertSam \
     I=input.bam \
     O=reverted.bam
$\endgroup$
0
$\begingroup$

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

$\endgroup$
  • $\begingroup$ bwa mem requires a fastq file, it does not accept a BAM $\endgroup$ – charlesdarwin Jul 11 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 at 15:54
  • $\begingroup$ good point, the RevertSam worked though $\endgroup$ – charlesdarwin Jul 11 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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