From the fastq, in python, with biopython:
import Bio.SeqIO
output = open("Modified.fastq", "w")
for record in Bio.SeqIO.parse("my_file.fastq"):
name = record.id
parts = name[1:].strip().split(":")
name = @+":".join(part[1:] + part[0])
record.id = name
Bio.SeqIO.write(record, output, "fastq")
output.close()
Or for the BAM, in python, with pysam
import pysam
inbam = pysam.AlignmentFile("my_bam.bam")
outbam = pysam.AlignmentFile("modified.bam", "wb", template=inbam)
for read in inbam.fetch(until_eof=True):
name = read.query_name
parts = name.split(":")
read.query_name = ":".join(parts[1:])
read.set_tag("RX", parts[0])
outbam.write(read)
outbam.close()
Curious as to how the UMI got to the place where it is at. No program I know of does this so this may have been done by some custom manipulation. You may want to find the original data and go from there, if possible.