Skip to content

Commit

Permalink
Merge branch 'release/0.8.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
abought committed Sep 13, 2018
2 parents 5190d7f + a5bd165 commit 2da2ac0
Show file tree
Hide file tree
Showing 18 changed files with 4,118 additions and 2,204 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
{ "args": "none" }
]
},
"globals": {
"XDomainRequest": false
},
"env": {
"browser": true
}
Expand Down
51 changes: 33 additions & 18 deletions assets/js/app/Data.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ LocusZoom.DataSources.prototype.toJSON = function() {
* `[namespace:]name[|transformation][|transformation]`. For example, `association:pvalue|neglog10`
*/
LocusZoom.Data.Field = function(field){

var parts = /^(?:([^:]+):)?([^:|]*)(\|.+)*$/.exec(field);
/** @member {String} */
this.full_name = field;
Expand All @@ -145,7 +145,7 @@ LocusZoom.Data.Field = function(field){
this.name = parts[2] || null;
/** @member {Array} */
this.transformations = [];

if (typeof parts[3] == "string" && parts[3].length > 1){
this.transformations = parts[3].substring(1).split("|");
this.transformations.forEach(function(transform, i){
Expand All @@ -172,7 +172,7 @@ LocusZoom.Data.Field = function(field){
}
return d[this.full_name];
};

};

/**
Expand Down Expand Up @@ -221,7 +221,7 @@ LocusZoom.Data.Requester = function(sources) {
if (!sources.get(key)) {
throw("Datasource for namespace " + key + " not found");
}
return sources.get(key).getData(state, requests[key].fields,
return sources.get(key).getData(state, requests[key].fields,
requests[key].outnames, requests[key].trans);
});
//assume the fields are requested in dependent order
Expand Down Expand Up @@ -303,7 +303,7 @@ LocusZoom.Data.Source.prototype.getURL = function(state, chain, fields) { return
*/
LocusZoom.Data.Source.prototype.fetchRequest = function(state, chain, fields) {
var url = this.getURL(state, chain, fields);
return LocusZoom.createCORSPromise("GET", url);
return LocusZoom.createCORSPromise("GET", url);
};

/**
Expand Down Expand Up @@ -369,10 +369,10 @@ LocusZoom.Data.Source.prototype.getData = function(state, fields, outnames, tran
* Ensure the server response is in a canonical form, an array of one object per record. [ {field: oneval} ].
* If the server response contains columns, reformats the response from {column1: [], column2: []} to the above.
*
* Does not apply namespacing or transformations.
* Does not apply namespacing, transformations, or field extraction.
*
* May be overridden by data sources that inherently return more complex payloads, or that exist to annotate other
* sources.
* sources (eg, if the payload provides extra data rather than a series of records).
*
* @param {Object[]|Object} data The original parsed server response
* @protected
Expand Down Expand Up @@ -601,7 +601,7 @@ LocusZoom.Data.Source.extend = function(constructorFun, uniqueName, base) {
* @returns {Object}
*/
LocusZoom.Data.Source.prototype.toJSON = function() {
return [Object.getPrototypeOf(this).constructor.SOURCE_NAME,
return [Object.getPrototypeOf(this).constructor.SOURCE_NAME,
{url:this.url, params:this.params}];
};

Expand All @@ -628,13 +628,27 @@ LocusZoom.Data.AssociationSource.prototype.preGetData = function(state, fields,
};

LocusZoom.Data.AssociationSource.prototype.getURL = function(state, chain, fields) {
var analysis = state.analysis || chain.header.analysis || this.params.analysis || 3;
var analysis = state.analysis || chain.header.analysis || this.params.analysis;
if (typeof analysis == "undefined") {
throw "Association source must specify an analysis ID to plot";
}
return this.url + "results/?filter=analysis in " + analysis +
" and chromosome in '" + state.chr + "'" +
" and position ge " + state.start +
" and position le " + state.end;
};

LocusZoom.Data.AssociationSource.prototype.normalizeResponse = function (data) {
// Some association sources do not sort their data in a predictable order, which makes it hard to reliably
// align with other sources (such as LD). For performance reasons, sorting is an opt-in argument.
// TODO: Consider more fine grained sorting control in the future
data = LocusZoom.Data.Source.prototype.normalizeResponse.call(this, data);
if (this.params && this.params.sort && data.length && data[0]["position"]) {
data.sort(function (a, b) { return a["position"] - b["position"]; });
}
return data;
};

/**
* Data Source for LD Data, as fetched from the LocusZoom API server (or compatible)
* This source is designed to connect its results to association data, and therefore depends on association data having
Expand All @@ -658,7 +672,7 @@ LocusZoom.Data.LDSource.prototype.preGetData = function(state, fields) {

LocusZoom.Data.LDSource.prototype.findMergeFields = function(chain) {
// since LD may be shared across sources with different namespaces
// we use regex to find columns to join on rather than
// we use regex to find columns to join on rather than
// requiring exact matches
var exactMatch = function(arr) {return function() {
var regexes = arguments;
Expand Down Expand Up @@ -739,11 +753,11 @@ LocusZoom.Data.LDSource.prototype.getURL = function(state, chain, fields) {
}
if (!chain.header) {chain.header = {};}
chain.header.ldrefvar = refVar;
return this.url + "results/?filter=reference eq " + refSource +
" and chromosome2 eq '" + state.chr + "'" +
" and position2 ge " + state.start +
" and position2 le " + state.end +
" and variant1 eq '" + refVar + "'" +
return this.url + "results/?filter=reference eq " + refSource +
" and chromosome2 eq '" + state.chr + "'" +
" and position2 ge " + state.start +
" and position2 le " + state.end +
" and variant1 eq '" + refVar + "'" +
"&fields=chr,pos,rsquare";
};

Expand Down Expand Up @@ -776,6 +790,7 @@ LocusZoom.Data.LDSource.prototype.combineChainBody = function (data, chain, fiel
}
}
};

leftJoin(chain.body, data, reqFields.ldout, "rsquare");
if(reqFields.isrefvarin && chain.header.ldrefvar) {
tagRefVariant(chain.body, chain.header.ldrefvar, keys.id, reqFields.isrefvarout);
Expand All @@ -797,7 +812,7 @@ LocusZoom.Data.GeneSource = LocusZoom.Data.Source.extend(function(init) {
LocusZoom.Data.GeneSource.prototype.getURL = function(state, chain, fields) {
var source = state.source || chain.header.source || this.params.source || 2;
return this.url + "?filter=source in " + source +
" and chrom eq '" + state.chr + "'" +
" and chrom eq '" + state.chr + "'" +
" and start le " + state.end +
" and end ge " + state.start;
};
Expand Down Expand Up @@ -902,8 +917,8 @@ LocusZoom.Data.IntervalSource = LocusZoom.Data.Source.extend(function(init) {

LocusZoom.Data.IntervalSource.prototype.getURL = function(state, chain, fields) {
var source = state.bedtracksource || chain.header.bedtracksource || this.params.source || 16;
return this.url + "?filter=id in " + source +
" and chromosome eq '" + state.chr + "'" +
return this.url + "?filter=id in " + source +
" and chromosome eq '" + state.chr + "'" +
" and start le " + state.end +
" and end ge " + state.start;
};
Expand Down
18 changes: 9 additions & 9 deletions assets/js/app/LocusZoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @namespace
*/
var LocusZoom = {
version: "0.8.0"
version: "0.8.1"
};

/**
Expand Down Expand Up @@ -179,24 +179,24 @@ LocusZoom.prettyTicks = function(range, clip_range, target_tick_count){
target_tick_count = 5;
}
target_tick_count = parseInt(target_tick_count);

var min_n = target_tick_count / 3;
var shrink_sml = 0.75;
var high_u_bias = 1.5;
var u5_bias = 0.5 + 1.5 * high_u_bias;

var d = Math.abs(range[0] - range[1]);
var c = d / target_tick_count;
if ((Math.log(d) / Math.LN10) < -2){
c = (Math.max(Math.abs(d)) * shrink_sml) / min_n;
}

var base = Math.pow(10, Math.floor(Math.log(c)/Math.LN10));
var base_toFixed = 0;
if (base < 1 && base !== 0){
base_toFixed = Math.abs(Math.round(Math.log(base)/Math.LN10));
}

var unit = base;
if ( ((2 * base) - c) < (high_u_bias * (c - unit)) ){
unit = 2 * base;
Expand All @@ -207,7 +207,7 @@ LocusZoom.prettyTicks = function(range, clip_range, target_tick_count){
}
}
}

var ticks = [];
var i = parseFloat( (Math.floor(range[0]/unit)*unit).toFixed(base_toFixed) );
while (i < range[1]){
Expand All @@ -218,7 +218,7 @@ LocusZoom.prettyTicks = function(range, clip_range, target_tick_count){
}
}
ticks.push(i);

if (typeof clip_range == "undefined" || ["low", "high", "both", "neither"].indexOf(clip_range) === -1){
clip_range = "neither";
}
Expand All @@ -228,7 +228,7 @@ LocusZoom.prettyTicks = function(range, clip_range, target_tick_count){
if (clip_range === "high" || clip_range === "both"){
if (ticks[ticks.length-1] > range[1]){ ticks.pop(); }
}

return ticks;
};

Expand Down Expand Up @@ -279,7 +279,7 @@ LocusZoom.createCORSPromise = function (method, url, body, headers, timeout) {
}
// Send the request
xhr.send(body);
}
}
return response.promise;
};

Expand Down
2 changes: 1 addition & 1 deletion dist/ext/lz-dynamic-urls.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2da2ac0

Please sign in to comment.