0
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ Did you check UMI-tools, this is afaik exactly what it is doing? $\endgroup$
    – ATpoint
    Nov 22 '20 at 11:11
  • $\begingroup$ @ATpoint, unless I'm incorrect, UMI-tools can't do this directly. umi_tools extract moves sequences from a position in the FASTA sequence onto the read name, but in this case the reads have been added to a tag via fgbio. $\endgroup$
    – SPPearce
    Nov 22 '20 at 11:38
1
$\begingroup$

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 > temp2.sam
samtools view temp.sam | 
awk '{OFS = "\t"} {for(i=1;i<=NF;i++)  if ($i ~ /^RX:Z:/) {$1=$1"_"$i; gsub("RX:Z:","",$1); print}}' >> temp2.sam

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

$\endgroup$

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.