I checked Picard AddOrReplaceReadsGroups and AddOATag. Is that what you're referring to?
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 -
1 answer
Shouldn't you use PicardTools for this?
Yes. Why wouldn't you use, say, AddOrReplaceReadsGroups?
Sorry for the delay in my answer, I got sidetracked.
I am using
samtools addreplacerg -r "@RG\tID:$cell" -o $cell.bam -h $LINE
but I just don't see how I go from RG to CB. I need the CB tag as that is what vartrix is picking
Thanks!
I think both these programs are just adding the same tag to every line. I don't think either cares whether it's called RG or CB
When I try samtools addreplacerg -r "@CB\tID:$cell" -o $cell.bam $LINE the CB tag gets add to the header, but the tag in every line gets reversed to RG (I'm attaching a screenshot of the output I get). Is there anything I'm missing?
samtools addreplacerg is for read groups. This is not what OP asked.
Just for reference, I ended up using
java -jar jvarkit.jar samjdk -e 'String c=record.GetReadName(); record.setAttribute("CB",c.substring(0,21)),return record;' $cell.bam
However, ideally I would like to use something like:
java -jar jvarkit.jar samjdk -e 'String c="$cell"; record.setAttribute("CB",c),return record;' $cell.bam
But I can't seem to find the right way to pass a bash variable to java. When I execute the line above I get a CB tag that is CB:Z:$cell, the $cell variable does not get interpreted. Do you know how to make samjdk interpret my $cell variable?
Thanks!
Log in to answer this question.
Pierre Lindenbaum had written this: Adding optional tags to a BAM file
https://github.com/ruqianl/appendCB may also be useful.