Moving UMI from tag into read name I have a bam file with Unique Molecular Identifiers (UMIs) for each read present on the RX tag ( such as RX:Z:TGAGAAGGG), as expected by picard and fgbio tools.
However, several other tools (such as UMI-tools) expect the UMIs to be present at the end of the read name, such as (NB501943:73:HK333BGXC:3:12402:20313:16437_TGAGAAGGG).
Does anyone know of a tool to do this?
I have an awk solution which I'll self-answer with, but I don't know whether that is robust.
My current solution is (awk is not a tool I'm very familiar with, so this may not be good awk code, there is presumably a way to get it to print the header lines unmodified.):
samtools view -H temp.sam &gt; temp2.sam
samtools view temp.sam | 
awk '{OFS = &quot;\t&quot;} {for(i=1;i&lt;=NF;i++)  if ($i ~ /^RX:Z:/) {$1=$1"_"$i; gsub("RX:Z:","",$1); print}}' &gt;&gt; temp2.sam

This seems to work when I test it, but I don't know if I'm missing anything.