This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Rename Tag in BAM file

Lets say I have a BAM file with a read like so:

SRR2057595.3333414_ATCGG        0       chr19   3571763 255     44M     *       0       0       *       *       XA:i:2  MD:Z:13C27C2    NM:i:2    BX:Z:ATCGG

but a program I want to use requires what is currently in the BX tag to be in the UM tag. So it looks thus:

SRR2057595.3333414_ATCGG        0       chr19   3571763 255     44M     *       0       0       *       *       XA:i:2  MD:Z:13C27C2    NM:i:2    UM:Z:ATCGG

I could write pysam script to do this, but I feel like there should be a less home-made way to do this.

bam

1 answer

using samjdk: http://lindenb.github.io/jvarkit/SamJdk.html

 java -jar dist/jvarkit.jar samjdk -e 'final Object s=record.getAttribute("BX"); if(s!=null) {record.setAttribute("BX",null);record.setAttribute("UM",s);} return record;' in.bam

Log in to answer this question.