Adding CB tag to bam file
1
0
Entering edit mode
7 months ago
Maria • 0

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 -
samtools bam • 1.7k views
ADD COMMENT
1
Entering edit mode
ADD REPLY
0
Entering edit mode
7 months ago

Shouldn't you use PicardTools for this?

ADD COMMENT
0
Entering edit mode

I checked Picard AddOrReplaceReadsGroups and AddOATag. Is that what you're referring to?

ADD REPLY
0
Entering edit mode

Yes. Why wouldn't you use, say, AddOrReplaceReadsGroups?

ADD REPLY
0
Entering edit mode

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!

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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?

enter image description here

ADD REPLY
0
Entering edit mode

samtools addreplacerg is for read groups. This is not what OP asked.

ADD REPLY
0
Entering edit mode

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!

ADD REPLY

Login before adding your answer.

Traffic: 2506 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6