Question: Add color tag to bam alignedReads using pysam
1
gravatar for pyKey
16 months ago by
pyKey30
pyKey30 wrote:

Hello everyone,

I have some STAR_aligned bam file. I want to add color tags to some reads in the file using pysam, in order to track them better in IGV.

Here is the code part which adds the tag:

red = '255,0,0'

r = pysam.AlignedRead()

r.tags += [('YC', red)]

This updates the file with new tag, which however does not work properly in IGV. I think some casting is missing here which I cannot think of.

Has anyone done this before? Thank for your help :)

igv rna-seq pysam • 692 views
ADD COMMENTlink modified 16 months ago • written 16 months ago by pyKey30

can you see this YC tag in your bam using samtools view ?

ADD REPLYlink written 16 months ago by Pierre Lindenbaum112k

Yes, and it looks like a decent one:

HISEQ:280:C9J9KANXX:2:2101:7621:44090   16  chr10   31332804    255 50M *   0   0   GAGCAGGCAGATTGACCAGCAGCAGCCCAGGCGGGACCTAGCACTGCAGC  FFGGFGGGEFDEFFGGGGGFGGFGF0GGGFFGGGGGGF;GGGGGDCBBB@  XC:Z:CCGGAC GE:Z:ENSMUSG00000000296 XF:Z:CODING PG:Z:STAR   RG:A:A  NH:i:1  NM:i:0  XM:Z:GAAGTTATGG UQ:i:0  AS:i:49 GS:A:-  YC:Z:255,0,0

But in IGV I get this error once I try hover over these reads (and of course no view):

"Error encountered querying alignments: java.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.String"

ADD REPLYlink modified 16 months ago • written 16 months ago by pyKey30

Hi Pierre, you are right one tag is not of correct type. That's curious! Please take a look at these two queries of the same read, before and after adding the color tag:

HISEQ:280:C9J9KANXX:1:1210:16223:39511  16  chr10   3176253 255 39M7965N7M4S    *   0   0   TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTGAAACCTTATGC  GGGGDGGGDGGGGGGGGGGGGGGGGGGGGGGDDGGGCB=00000>CBB@A  XC:Z:CCGGAC XF:Z:CODING PG:Z:STAR   RG:Z:A  NH:i:1  NM:i:0  XM:Z:AGAAAGGTGG UQ:i:0  AS:i:45

after:

HISEQ:280:C9J9KANXX:1:1210:16223:39511  16  chr10   3176253 255 39M7965N7M4S    *   0   0   TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTGAAACCTTATGC  GGGGDGGGDGGGGGGGGGGGGGGGGGGGGGGDDGGGCB=00000>CBB@A  XC:Z:CCGGAC XF:Z:CODING PG:Z:STAR   RG:A:A  NH:i:1  NM:i:0  XM:Z:AGAAAGGTGG UQ:i:0  AS:i:45 YC:Z:255,0,0

I did not make any changes to the RG tag, but somehow its type has changed. Any theories? Tag parsing maybe??

ADD REPLYlink modified 16 months ago • written 16 months ago by pyKey30

yes, you should change your read group to a two-letter code.

ADD REPLYlink written 16 months ago by Pierre Lindenbaum112k
1
gravatar for Pierre Lindenbaum
16 months ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum112k wrote:

HISEQ:280:C9J9KANXX:2:2101:7621:44090 16 chr10 31332804 255 50M * 0 0 GAGCAGGCAGATTGACCAGCAGCAGCCCAGGCGGGACCTAGCACTGCAGC FFGGFGGGEFDEFFGGGGGFGGFGF0GGGFFGGGGGGF;GGGGGDCBBB@ XC:Z:CCGGAC GE:Z:ENSMUSG00000000296 XF:Z:CODING PG:Z:STAR RG:A:A NH:i:1 NM:i:0 XM:Z:GAAGTTATGG UQ:i:0 AS:i:49 GS:A:- YC:Z:255,0,0

the problem comes from your RG flag. The specification says it must be a String RG:Z:A but you have a character RG:A:A

I've created a tool to inject a YC tag using a javascript expression: http://lindenb.github.io/jvarkit/SamColorTag.html

I've just tested it with IGV 2.2.4 , it works fine:

enter image description here

ADD COMMENTlink modified 16 months ago • written 16 months ago by Pierre Lindenbaum112k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1506 users visited in the last hour