This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Write free text comment with @CO in BAM file

I'm trying to add a free text while writing the reads in a BAM file. As the Java hstjdk samtool doc mentions, I can add a free text with @CO SAMTag. For example,

I'm adding the NM tag and MD tag using this code

record.setAttribute(htsjdk.samtools.SAMTag.MD.name(), "Value");
record.setAttribute(htsjdk.samtools.SAMTag.NM.name(), "Value");

But when I try to do the same for @CO tag

record.setAttribute(htsjdk.samtools.SAMTag.CO.name(), "Value");

I get the following error

cannot find symbol
symbol:   variable CO
location: class htsjdk.samtools.SAMTag

Can someone help me figure out how to add free text while writing a BAM file? Thanks in advance.

bam hstjdk java

samtools 1.2 Using htslib 1.2.1

Samtools is up to v.1.12 so consider updating.

Can this be an issue because of the earlier version of samtools? I tried the

record.setAttribute("SO","value");

It runs through without error, but nothing was written in the BAM file

but nothing was written in the BAM file

we cannot help without seeing the code.

htsjdk version 1.133

Can the version cause this issue?

Got it, Thanks for the help.

1 answer

use setAttribute(String,String) https://github.com/samtools/htsjdk/blob/master/src/main/java/htsjdk/samtools/SAMRecord.java#L1529

record.setAttribute("SO","value");

Log in to answer this question.