Skip to content

Commit

Permalink
Add a util class for coloring features
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Nov 8, 2018
1 parent e25ab27 commit 38a9a24
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 178 deletions.
119 changes: 3 additions & 116 deletions src/JBrowse/View/FeatureGlyph/Alignment.js
Expand Up @@ -2,61 +2,18 @@ define([
'dojo/_base/declare',
'dojo/_base/array',
'JBrowse/View/FeatureGlyph/Box',
'JBrowse/View/FeatureGlyph/PairUtils',
'JBrowse/Store/SeqFeature/_MismatchesMixin'
],
function(
declare,
array,
BoxGlyph,
PairUtils,
MismatchesMixin
) {

var orientationTypes = {
"fr": {

"F1R2": "LR",
"F2R1": "LR",

"F1F2": "LL",
"F2F1": "LL",

"R1R2": "RR",
"R2R1": "RR",

"R1F2": "RL",
"R2F1": "RL"
},

"rf": {

"R1F2": "LR",
"R2F1": "LR",

"R1R2": "LL",
"R2R1": "LL",

"F1F2": "RR",
"F2F1": "RR",

"F1R2": "RL",
"F2R1": "RL"
},

"ff": {

"F2F1": "LR",
"R1R2": "LR",

"F2R1": "LL",
"R1F2": "LL",

"R2F1": "RR",
"F1R2": "RR",

"R2R1": "RL",
"F1F2": "RL"
}
};

return declare( [BoxGlyph,MismatchesMixin], {

Expand All @@ -75,77 +32,7 @@ return declare( [BoxGlyph,MismatchesMixin], {
{
//maxFeatureScreenDensity: 400
style: {
color: function( feature, path, glyph, track ) {
var strand = feature.get('strand');
if(Math.abs(strand) != 1 && strand != '+' && strand != '-') {
return track.colorForBase('reference');
}
else if(track.config.colorByOrientation) {
if(track.upperPercentile < Math.abs(feature.get('template_length'))) {
return 'red'
} else if(track.lowerPercentile > Math.abs(feature.get('template_length'))) {
return 'pink'
}
const type = orientationTypes[track.config.orientationType]
const orientation = type[feature.get('pair_orientation')]
const map = {
'LR': 'color_pair_lr',
'RR': 'color_pair_rr',
'RL': 'color_pair_rl',
'LL': 'color_pair_ll'
};
return glyph.getStyle( feature, map[orientation] || 'color_nostrand' );
}
else if(track.config.useXS) {
var xs = feature.get('xs')
var strand={'-':'color_rev_strand','+':'color_fwd_strand'}[xs];
if(!strand) strand='color_nostrand';
return glyph.getStyle( feature, strand );
}
else if(feature.get('multi_segment_template')) {
var revflag=feature.get('multi_segment_first');
if(feature.get('multi_segment_all_correctly_aligned')) {
if(revflag||!track.config.useReverseTemplate){
return strand == 1 || strand == '+'
? glyph.getStyle( feature, 'color_fwd_strand' )
: glyph.getStyle( feature, 'color_rev_strand' );
}else {
return strand == 1 || strand == '+'
? glyph.getStyle( feature, 'color_rev_strand' )
: glyph.getStyle( feature, 'color_fwd_strand' );
}
}
if(feature.get('multi_segment_next_segment_unmapped')) {
if(revflag||!track.config.useReverseTemplate){
return strand == 1 || strand == '+'
? glyph.getStyle( feature, 'color_fwd_missing_mate' )
: glyph.getStyle( feature, 'color_rev_missing_mate' );
}else{
return strand == 1 || strand == '+'
? glyph.getStyle( feature, 'color_rev_missing_mate' )
: glyph.getStyle( feature, 'color_fwd_missing_mate' );
}
}
if(feature.get('seq_id') == feature.get('next_seq_id')) {
if(revflag||!track.config.useReverseTemplate){
return strand == 1 || strand == '+'
? glyph.getStyle( feature, 'color_fwd_strand_not_proper' )
: glyph.getStyle( feature, 'color_rev_strand_not_proper' );
}else{
return strand == 1 || strand == '+'
? glyph.getStyle( feature, 'color_rev_strand_not_proper' )
: glyph.getStyle( feature, 'color_fwd_strand_not_proper' );
}
}
// should only leave aberrant chr
return strand == 1 || strand == '+'
? glyph.getStyle( feature, 'color_fwd_diff_chr' )
: glyph.getStyle( feature, 'color_rev_diff_chr' );
}
return strand == 1 || strand == '+'
? glyph.getStyle( feature, 'color_fwd_strand' )
: glyph.getStyle( feature, 'color_rev_strand' );
},
color: PairUtils.colorAlignment,
color_fwd_strand_not_proper: '#ECC8C8',
color_rev_strand_not_proper: '#BEBED8',
color_fwd_strand: '#EC8B8B',
Expand Down
152 changes: 152 additions & 0 deletions src/JBrowse/View/FeatureGlyph/PairUtils.js
@@ -0,0 +1,152 @@
define( [
],
function() {
var orientationTypes = {
"fr": {

"F1R2": "LR",
"F2R1": "LR",

"F1F2": "LL",
"F2F1": "LL",

"R1R2": "RR",
"R2R1": "RR",

"R1F2": "RL",
"R2F1": "RL"
},

"rf": {

"R1F2": "LR",
"R2F1": "LR",

"R1R2": "LL",
"R2R1": "LL",

"F1F2": "RR",
"F2F1": "RR",

"F1R2": "RL",
"F2R1": "RL"
},

"ff": {

"F2F1": "LR",
"R1R2": "LR",

"F2R1": "LL",
"R1F2": "LL",

"R2F1": "RR",
"F1R2": "RR",

"R2R1": "RL",
"F1F2": "RL"
}
};

var PairUtils = {
colorAlignment( feature, path, glyph, track ) {
var strand = feature.get('strand');
if (Math.abs(strand) != 1 && strand != '+' && strand != '-') {
return track.colorForBase('reference');
}
else if (track.config.colorByOrientation) {
if (track.upperPercentile < Math.abs(feature.get('template_length'))) {
return 'red'
} else if (track.lowerPercentile > Math.abs(feature.get('template_length'))) {
return 'pink'
}
const type = orientationTypes[track.config.orientationType]
const orientation = type[feature.get('pair_orientation')]
const map = {
'LR': 'color_pair_lr',
'RR': 'color_pair_rr',
'RL': 'color_pair_rl',
'LL': 'color_pair_ll'
};
return glyph.getStyle(feature, map[orientation] || 'color_nostrand');
}
else if (track.config.useXS) {
var xs = feature.get('xs')
var strand = {
'-':'color_rev_strand',
'+':'color_fwd_strand'
};
if (!strand[xs]) {
strand = 'color_nostrand';
}
return glyph.getStyle(feature, strand[xs]);
}
else if (feature.get('multi_segment_template')) {
var revflag = feature.get('multi_segment_first');
if (feature.get('multi_segment_all_correctly_aligned')) {
if (revflag || !track.config.useReverseTemplate) {
return strand == 1 || strand == '+'
? glyph.getStyle( feature, 'color_fwd_strand' )
: glyph.getStyle( feature, 'color_rev_strand' );
} else {
return strand == 1 || strand == '+'
? glyph.getStyle( feature, 'color_rev_strand' )
: glyph.getStyle( feature, 'color_fwd_strand' );
}
}
if (feature.get('multi_segment_next_segment_unmapped')) {
if (revflag || !track.config.useReverseTemplate) {
return strand == 1 || strand == '+'
? glyph.getStyle( feature, 'color_fwd_missing_mate' )
: glyph.getStyle( feature, 'color_rev_missing_mate' );
} else{
return strand == 1 || strand == '+'
? glyph.getStyle( feature, 'color_rev_missing_mate' )
: glyph.getStyle( feature, 'color_fwd_missing_mate' );
}
}
if (feature.get('seq_id') == feature.get('next_seq_id')) {
if (revflag || !track.config.useReverseTemplate) {
return strand == 1 || strand == '+'
? glyph.getStyle( feature, 'color_fwd_strand_not_proper' )
: glyph.getStyle( feature, 'color_rev_strand_not_proper' );
} else {
return strand == 1 || strand == '+'
? glyph.getStyle( feature, 'color_rev_strand_not_proper' )
: glyph.getStyle( feature, 'color_fwd_strand_not_proper' );
}
}
// should only leave aberrant chr
return strand == 1 || strand == '+'
? glyph.getStyle( feature, 'color_fwd_diff_chr' )
: glyph.getStyle( feature, 'color_rev_diff_chr' );
}
return strand == 1 || strand == '+'
? glyph.getStyle( feature, 'color_fwd_strand' )
: glyph.getStyle( feature, 'color_rev_strand' );
},
colorAlignmentArc( feature, score, glyph, track ) {
if (track.config.colorByOrientation) {
if (track.upperPercentile < Math.abs(feature.get('template_length'))) {
return 'red'
} else if (track.lowerPercentile > Math.abs(feature.get('template_length'))) {
return 'pink'
}
const type = orientationTypes[track.config.orientationType]
const orientation = type[feature.get('pair_orientation')]
const map = {
'LR': 'color_pair_lr',
'RR': 'color_pair_rr',
'RL': 'color_pair_rl',
'LL': 'color_pair_ll'
};
return glyph.getStyle(feature, map[orientation] || 'color_nostrand');
}

return 'hsl(' + Math.abs(score / 10) + ',50%,50%)';
}
};

return PairUtils;

});
67 changes: 5 additions & 62 deletions src/JBrowse/View/FeatureGlyph/PairedArc.js
Expand Up @@ -2,79 +2,22 @@ define([
'dojo/_base/declare',
'dojo/_base/array',
'dojo/_base/lang',
'JBrowse/View/FeatureGlyph/Box'
'JBrowse/View/FeatureGlyph/Box',
'JBrowse/View/FeatureGlyph/PairUtils'
],
function(
declare,
array,
lang,
FeatureGlyph
FeatureGlyph,
PairUtils
) {
var orientationTypes = {
"fr": {

"F1R2": "LR",
"F2R1": "LR",

"F1F2": "LL",
"F2F1": "LL",

"R1R2": "RR",
"R2R1": "RR",

"R1F2": "RL",
"R2F1": "RL"
},

"rf": {

"R1F2": "LR",
"R2F1": "LR",

"R1R2": "LL",
"R2R1": "LL",

"F1F2": "RR",
"F2F1": "RR",

"F1R2": "RL",
"F2R1": "RL"
},

"ff": {

"F2F1": "LR",
"R1R2": "LR",

"F2R1": "LL",
"R1F2": "LL",

"R2F1": "RR",
"F1R2": "RR",

"R2R1": "RL",
"F1F2": "RL"
}
};
return declare(FeatureGlyph, {

_defaultConfig: function() {
return this._mergeConfigs(lang.clone(this.inherited(arguments)), {
style: {
color: function( feature, score, glyph, track ) {
if(track.config.colorByOrientation) {
const type = orientationTypes[track.config.orientationType]
const orientation = type[feature.get('pair_orientation')]
const map = {
'LR': 'color_pair_lr',
'RR': 'color_pair_rr',
'RL': 'color_pair_rl',
'LL': 'color_pair_ll'
};
return glyph.getStyle( feature, map[orientation] || 'color_nostrand' );
}
return 'hsl(' + Math.abs(score / 10) + ',50%,50%)';
},
color: PairUtils.colorAlignmentArc,
color_pair_lr: 'grey',
color_pair_rr: 'navy',
color_pair_rl: 'teal',
Expand Down

0 comments on commit 38a9a24

Please sign in to comment.