Add color tag to bam alignedReads using pysam
1
1
Entering edit mode
7.5 years ago
pyKey ▴ 70

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 :)

RNA-Seq pysam IGV • 3.9k views
ADD COMMENT
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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 REPLY
0
Entering edit mode

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 REPLY
0
Entering edit mode

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

ADD REPLY
1
Entering edit mode
7.5 years ago

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 COMMENT

Login before adding your answer.

Traffic: 2144 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