Skip to content

Commit

Permalink
Move utils around to only use canonical pair orientations for insert …
Browse files Browse the repository at this point in the history
…size stats
  • Loading branch information
cmdcolin committed Nov 18, 2018
1 parent 79f60c8 commit a37e313
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 83 deletions.
13 changes: 9 additions & 4 deletions src/JBrowse/Store/SeqFeature/_PairCache.js
Expand Up @@ -48,6 +48,7 @@ return declare(null, {
this.insertLowerPercentile = args.insertLowerPercentile || 0.05
this.insertStatsCacheMin = args.insertStatsCacheMin || 400
this.insertMaxSize = args.insertMaxSize || 50000
this.orientationType = args.orientationType || 'fr'
},


Expand Down Expand Up @@ -109,14 +110,18 @@ return declare(null, {

getStatsForPairCache() {
if(Object.keys(this.featureCache).length > this.insertStatsCacheMin) {
var total = Object.keys(this.featureCache).length
var tlens = Object.entries(this.featureCache)
.map(([k, v]) => Math.abs(v.get('template_length')))
.filter(x => x < this.insertMaxSize)
.filter(tlen => tlen < this.insertMaxSize)
.sort((a, b) => a - b)
var sum = tlens.reduce((a, b) => a + b, 0)
var sum2 = tlens.map(a => a*a).reduce((a, b) => a + b, 0)
var avg = sum / total;
var sd = Math.sqrt((total * sum2 - sum*sum) / (total * total));
return {
upper: Util.percentile(tlens, this.insertUpperPercentile),
avg: Util.percentile(tlens, 0.5),
lower: Util.percentile(tlens, this.insertLowerPercentile)
upper: avg + 3*sd,
lower: avg - 3*sd
}
}
return { upper: Infinity, lower: 0 }
Expand Down
48 changes: 48 additions & 0 deletions src/JBrowse/Util.js
Expand Up @@ -593,7 +593,55 @@ Util = {

if (upper >= arr.length) return arr[lower];
return arr[lower] * (1 - weight) + arr[upper] * weight;
},

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 Util;
Expand Down
54 changes: 4 additions & 50 deletions src/JBrowse/View/FeatureGlyph/PairUtils.js
@@ -1,52 +1,7 @@
define( [
'JBrowse/Util'
],
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"
}
};
function(Util) {

var PairUtils = {
colorAlignment( feature, path, glyph, track ) {
Expand All @@ -55,13 +10,12 @@ var PairUtils = {
return track.colorForBase('reference');
}
else if (track.config.colorByOrientation) {
console.log(track.upperPercentile)
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 type = Util.orientationTypes[track.config.orientationType]
const orientation = type[feature.get('pair_orientation')]
const map = {
'LR': 'color_pair_lr',
Expand Down Expand Up @@ -133,7 +87,7 @@ var PairUtils = {
} else if (track.lowerPercentile > Math.abs(feature.get('template_length'))) {
return 'pink'
}
const type = orientationTypes[track.config.orientationType]
const type = Util.orientationTypes[track.config.orientationType]
const orientation = type[feature.get('pair_orientation')]
const map = {
'LR': 'color_pair_lr',
Expand Down
70 changes: 41 additions & 29 deletions src/JBrowse/View/Track/Alignments2.js
@@ -1,15 +1,15 @@
define( [
'dojo/_base/declare',
'dojo/_base/array',
'dojo/promise/all',
'dijit/MenuItem',
'JBrowse/Util',
'JBrowse/View/Track/CanvasFeatures',
'JBrowse/View/Track/_AlignmentsMixin'
],
function(
declare,
array,
all,
MenuItem,
Util,
CanvasFeatureTrack,
AlignmentsMixin
Expand All @@ -33,7 +33,7 @@ return declare( [ CanvasFeatureTrack, AlignmentsMixin ], {
hideUnmapped: true,
hideUnsplicedReads: false,
hideMissingMatepairs: false,
hideForwardStrand: false,
hideForwardStrant: false,
hideReverseStrand: false,
useXS: false,
useReverseTemplate: false,
Expand All @@ -59,30 +59,19 @@ return declare( [ CanvasFeatureTrack, AlignmentsMixin ], {
var thisB = this;
var displayOptions = [];


if(this.config.useReverseTemplateOption) {
displayOptions.push({
label: 'Use reversed template',
type: 'dijit/CheckedMenuItem',
checked: this.config.useReverseTemplate,
onClick: function(event) {
thisB.config.useReverseTemplate = this.get('checked');
thisB.browser.publish('/jbrowse/v1/v/tracks/replace', [thisB.config]);
}
});
var m = {
type: 'dijit/Menu',
label: 'Pair options',
children: []
}
if(this.config.useXSOption) {
displayOptions.push({
label: 'Use XS',
type: 'dijit/CheckedMenuItem',
checked: this.config.useXS,
onClick: function(event) {
thisB.config.useXS = this.get('checked');
thisB.browser.publish('/jbrowse/v1/v/tracks/replace', [thisB.config]);
}
});
var c = {
type: 'dijit/Menu',
label: 'Color options',
children: []
}



displayOptions.push({
label: 'View coverage',
onClick: function(event) {
Expand All @@ -102,8 +91,20 @@ return declare( [ CanvasFeatureTrack, AlignmentsMixin ], {
thisB.browser.publish('/jbrowse/v1/v/tracks/replace', [thisB.config]);
}
});
displayOptions.push(m)

displayOptions.push({
c.children.push({
label: 'Color by XS tag (RNA-seq strandedness)',
type: 'dijit/CheckedMenuItem',
checked: this.config.useXS,
onClick: function(event) {
thisB.config.useXS = this.get('checked');
thisB.browser.publish('/jbrowse/v1/v/tracks/replace', [thisB.config]);
}
});


m.children.push({
label: 'View as pairs',
onClick: function(event) {
thisB.config.viewAsPairs = true
Expand All @@ -113,7 +114,7 @@ return declare( [ CanvasFeatureTrack, AlignmentsMixin ], {
}
});

displayOptions.push({
m.children.push({
label: 'View paired arcs',
onClick: function(event) {
thisB.config.viewAsPairs = true
Expand All @@ -122,7 +123,7 @@ return declare( [ CanvasFeatureTrack, AlignmentsMixin ], {
thisB.browser.publish('/jbrowse/v1/v/tracks/replace', [thisB.config]);
}
});
displayOptions.push({
m.children.push({
label: 'View pairs as read cloud',
onClick: function(event) {
thisB.config.viewAsPairs = true
Expand All @@ -131,7 +132,17 @@ return declare( [ CanvasFeatureTrack, AlignmentsMixin ], {
thisB.browser.publish('/jbrowse/v1/v/tracks/replace', [thisB.config]);
}
});
displayOptions.push({

m.children.push({
label: 'Flip mate pair (RNA-seq strandedness)',
type: 'dijit/CheckedMenuItem',
checked: this.config.useReverseTemplate,
onClick: function(event) {
thisB.config.useReverseTemplate = this.get('checked');
thisB.browser.publish('/jbrowse/v1/v/tracks/replace', [thisB.config]);
}
});
c.children.push({
label: 'Color by pair orientation and insert size',
type: 'dijit/CheckedMenuItem',
checked: this.config.colorByOrientation,
Expand All @@ -140,7 +151,8 @@ return declare( [ CanvasFeatureTrack, AlignmentsMixin ], {
thisB.browser.publish('/jbrowse/v1/v/tracks/replace', [thisB.config]);
}
});
return all([ this.inherited(arguments), this._alignmentsFilterTrackMenuOptions(), displayOptions ])

return Promise.all([ this.inherited(arguments), this._alignmentsFilterTrackMenuOptions(), displayOptions ])
.then( function( options ) {
var o = options.shift();
options.unshift({ type: 'dijit/MenuSeparator' } );
Expand Down

0 comments on commit a37e313

Please sign in to comment.