Hello,
I need to add CB tags to my bam files. Below is what I'm doing. I see the tags when I pipe to stdout but the tag is not written to the new bam. What is it that I'm missing? Thanks!
# $LINE is the path to the original input bam, there is one bam for each $cell
samtools view -h -b -o ${cell}.bam ${LINE} | sed -e "/^@/! s/$/ CB:Z:${cell}/"
# or
samtools view -h -b ${LINE} | sed -e "/^@/! s/$/ CB:Z:${cell}/" > ${cell}.bam
# or
samtools view -h ${LINE} | sed -e "/^@/! s/$/ CB:Z:${cell}/" | samtools view -hb -o {cell}.bam -
Pierre Lindenbaum had written this: Adding optional tags to a BAM file
https://github.com/ruqianl/appendCB may also be useful.