[Gmod-ajax] JBrowse global override of Alignments2 color/border with js callback

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[Gmod-ajax] JBrowse global override of Alignments2 color/border with js callback

Keiran Raine
Hi,

I have a couple of functions (included below) to colour the boarder and fill of Alignment2 tracks that I want to apply globally for all tracks of this type without having to include 500b of text in every track definition.

What's the best way to do this?  Under GBrowse you could just reference a perl module function that could be found on PERL5LIB but I'm not expecting it to be that easy (perhaps I'll be surprised).

Thanks,

Keiran Raine
Principal Bioinformatician
Cancer Genome Project
Wellcome Trust Sanger Institute

Tel:+44 (0)1223 834244 Ext: 7703
Office: H104

# fill fades as MAPQ decreases, only visible in 'normal' view
"color": "function(f) { var mq = f.get('mq'); var lightness = 75 - (mq/3); var saturation = 55; var hue = 240; if(f.get('strand') != 1) { hue = 0; } return 'hsl('+hue+','+saturation+'%%,'+lightness+'%%)'; }",

# border colour indicates mate mapping class (colours whole read on compact)
"borderColor": "function(f) { var bc; if(f.get('multi_segment_all_correctly_aligned')) { return bc; } if(f.get('multi_segment_next_segment_unmapped')) { return 'purple'; } if(f.get('seq_id') != f.get('next_seq_id')) { return 'red'; } return 'green'; }",

-- The Wellcome Trust Sanger Institute is operated by Genome Research Limited, a charity registered in England with number 1021457 and a company registered in England with number 2742969, whose registered office is 215 Euston Road, London, NW1 2BE.

------------------------------------------------------------------------------

_______________________________________________
Gmod-ajax mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gmod-ajax
Reply | Threaded
Open this post in threaded view
|

Re: JBrowse global override of Alignments2 color/border with js callback

Richard Hayes
I handle this situation with an additional include of a common library of function declarations. For example, the color gradient calculated for our expression tracks:
https://phytozome.jgi.doe.gov/jbrowse/index.html?data=genomes%2FPtrichocarpa%2F&loc=Chr01%3A70665..140937&tracks=Transcripts%2CAlt_Transcripts%2CGeneExpression_GeneAtlas1_0&highlight=

I tend to use the flat text config style, as it's easier to debug javascript when not constrained by double quotes surrounding everything in JSON...

In jbrowse.conf:
   include  = {dataRoot}/trackList.json
   include += {dataRoot}/tracks.conf
   include += genomes/commonConfig/functions.conf

The track parameter is simply (in trackList.json):
   "style" : {
            "color" : "{expression_gene_color}"
   }

and the matching function in function.conf, delivering darker blue for larger coefficient of variance for the FPKM values at that locus:
expression_gene_color = function(feature) {
    /* varying blue shade based on Coeffvar GFF3 attribute (darker blue = higher c.o.v. value), or default gray color */
    var cov = feature.get('Coeffvar');
    var maxFPKM = feature.get('Maxfpkm');
    if ( maxFPKM > 0 ) {
        if ( cov > 0 ) {
            var max = 3.1;
            var shade = (cov/max) * 255;
            var red = 0;
            var blue = 255 - shade;
            var green = blue - 50;
            if ( green < 0 ) { green = 0; }
            red = Math.floor(red);
            green = Math.floor(green);
            blue = Math.floor(blue);
            var redHex = Number(red).toString(16);
            var greenHex = Number(green).toString(16);
            var blueHex = Number(blue).toString(16);
            if (redHex == "0") { redHex = "00"; }
            if (greenHex == "0") { greenHex = "00"; }
            if (blueHex == "0") { blueHex = "00"; }
            return '#' + redHex + greenHex + blueHex;
        }
        else {
            return "gray";
        }
    }
    else {
        return "gray";
    }
  }


This is covered somewhat here with another example, though not in great detail:
http://gmod.org/wiki/JBrowse_Configuration_Guide#Customizing_CanvasFeatures_tracks_with_callbacks


Richard D. Hayes, Ph.D.
Joint Genome Institute / Lawrence Berkeley National Lab
http://phytozome.jgi.doe.gov

On Tue, Sep 6, 2016 at 10:44 PM, Keiran Raine <[hidden email]> wrote:
Hi,

I have a couple of functions (included below) to colour the boarder and fill of Alignment2 tracks that I want to apply globally for all tracks of this type without having to include 500b of text in every track definition.

What's the best way to do this?  Under GBrowse you could just reference a perl module function that could be found on PERL5LIB but I'm not expecting it to be that easy (perhaps I'll be surprised).

Thanks,

Keiran Raine
Principal Bioinformatician
Cancer Genome Project
Wellcome Trust Sanger Institute

Tel:<a href="tel:%2B44%20%280%291223%20834244%20Ext%3A%207703" value="+441223834244" target="_blank">+44 (0)1223 834244 Ext: 7703
Office: H104

# fill fades as MAPQ decreases, only visible in 'normal' view
"color": "function(f) { var mq = f.get('mq'); var lightness = 75 - (mq/3); var saturation = 55; var hue = 240; if(f.get('strand') != 1) { hue = 0; } return 'hsl('+hue+','+saturation+'%%,'+lightness+'%%)'; }",

# border colour indicates mate mapping class (colours whole read on compact)
"borderColor": "function(f) { var bc; if(f.get('multi_segment_all_correctly_aligned')) { return bc; } if(f.get('multi_segment_next_segment_unmapped')) { return 'purple'; } if(f.get('seq_id') != f.get('next_seq_id')) { return 'red'; } return 'green'; }",

-- The Wellcome Trust Sanger Institute is operated by Genome Research Limited, a charity registered in England with number 1021457 and a company registered in England with number 2742969, whose registered office is 215 Euston Road, London, NW1 2BE.

------------------------------------------------------------------------------

_______________________________________________
Gmod-ajax mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gmod-ajax



------------------------------------------------------------------------------

_______________________________________________
Gmod-ajax mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gmod-ajax
Reply | Threaded
Open this post in threaded view
|

Re: JBrowse global override of Alignments2 color/border with js callback

Keiran Raine
Hi Richard,

Thanks, I did as indicated but still put the js in the jbrowse_conf.json as I don't have code editing jbrowse.conf at all.

Regards,

Keiran Raine
Principal Bioinformatician
Cancer Genome Project
Wellcome Trust Sanger Institute

Tel:+44 (0)1223 834244 Ext: 7703
Office: H104

On 7 Sep 2016, at 19:11, Richard Hayes <[hidden email]> wrote:

I handle this situation with an additional include of a common library of function declarations. For example, the color gradient calculated for our expression tracks:
https://phytozome.jgi.doe.gov/jbrowse/index.html?data=genomes%2FPtrichocarpa%2F&loc=Chr01%3A70665..140937&tracks=Transcripts%2CAlt_Transcripts%2CGeneExpression_GeneAtlas1_0&highlight=

I tend to use the flat text config style, as it's easier to debug javascript when not constrained by double quotes surrounding everything in JSON...

In jbrowse.conf:
   include  = {dataRoot}/trackList.json
   include += {dataRoot}/tracks.conf
   include += genomes/commonConfig/functions.conf

The track parameter is simply (in trackList.json):
   "style" : {
            "color" : "{expression_gene_color}"
   }

and the matching function in function.conf, delivering darker blue for larger coefficient of variance for the FPKM values at that locus:
expression_gene_color = function(feature) {
    /* varying blue shade based on Coeffvar GFF3 attribute (darker blue = higher c.o.v. value), or default gray color */
    var cov = feature.get('Coeffvar');
    var maxFPKM = feature.get('Maxfpkm');
    if ( maxFPKM > 0 ) {
        if ( cov > 0 ) {
            var max = 3.1;
            var shade = (cov/max) * 255;
            var red = 0;
            var blue = 255 - shade;
            var green = blue - 50;
            if ( green < 0 ) { green = 0; }
            red = Math.floor(red);
            green = Math.floor(green);
            blue = Math.floor(blue);
            var redHex = Number(red).toString(16);
            var greenHex = Number(green).toString(16);
            var blueHex = Number(blue).toString(16);
            if (redHex == "0") { redHex = "00"; }
            if (greenHex == "0") { greenHex = "00"; }
            if (blueHex == "0") { blueHex = "00"; }
            return '#' + redHex + greenHex + blueHex;
        }
        else {
            return "gray";
        }
    }
    else {
        return "gray";
    }
  }


This is covered somewhat here with another example, though not in great detail:
http://gmod.org/wiki/JBrowse_Configuration_Guide#Customizing_CanvasFeatures_tracks_with_callbacks


Richard D. Hayes, Ph.D.
Joint Genome Institute / Lawrence Berkeley National Lab
http://phytozome.jgi.doe.gov

On Tue, Sep 6, 2016 at 10:44 PM, Keiran Raine <[hidden email]> wrote:
Hi,

I have a couple of functions (included below) to colour the boarder and fill of Alignment2 tracks that I want to apply globally for all tracks of this type without having to include 500b of text in every track definition.

What's the best way to do this?  Under GBrowse you could just reference a perl module function that could be found on PERL5LIB but I'm not expecting it to be that easy (perhaps I'll be surprised).

Thanks,

Keiran Raine
Principal Bioinformatician
Cancer Genome Project
Wellcome Trust Sanger Institute

Tel:<a href="tel:%2B44%20%280%291223%20834244%20Ext%3A%207703" value="+441223834244" target="_blank" class="">+44 (0)1223 834244 Ext: 7703
Office: H104

# fill fades as MAPQ decreases, only visible in 'normal' view
"color": "function(f) { var mq = f.get('mq'); var lightness = 75 - (mq/3); var saturation = 55; var hue = 240; if(f.get('strand') != 1) { hue = 0; } return 'hsl('+hue+','+saturation+'%%,'+lightness+'%%)'; }",

# border colour indicates mate mapping class (colours whole read on compact)
"borderColor": "function(f) { var bc; if(f.get('multi_segment_all_correctly_aligned')) { return bc; } if(f.get('multi_segment_next_segment_unmapped')) { return 'purple'; } if(f.get('seq_id') != f.get('next_seq_id')) { return 'red'; } return 'green'; }",

-- The Wellcome Trust Sanger Institute is operated by Genome Research Limited, a charity registered in England with number 1021457 and a company registered in England with number 2742969, whose registered office is 215 Euston Road, London, NW1 2BE.

------------------------------------------------------------------------------

_______________________________________________
Gmod-ajax mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gmod-ajax




-- The Wellcome Trust Sanger Institute is operated by Genome Research Limited, a charity registered in England with number 1021457 and a company registered in England with number 2742969, whose registered office is 215 Euston Road, London, NW1 2BE.

------------------------------------------------------------------------------

_______________________________________________
Gmod-ajax mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gmod-ajax