Last active
August 29, 2015 14:00
-
-
Save florin-chelaru/11026256 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
epiviz.EpiViz.SETTINGS.dataProviders.push('epiviz.plugins.data.MyDataProvider'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Florin Chelaru ( florinc [at] umd [dot] edu ) | |
* Date: 4/17/14 | |
* Time: 10:09 PM | |
*/ | |
goog.provide('epiviz.plugins.data.MyDataProvider'); | |
/** | |
* @constructor | |
* @extends {epiviz.data.DataProvider} | |
*/ | |
epiviz.plugins.data.MyDataProvider = function () { | |
epiviz.data.DataProvider.call(this); | |
this._mockMeasurement = new epiviz.measurements.Measurement( | |
'my_feature_column', // The column in the data source table that contains the values for this feature measurement | |
'My Feature Measurement', // A name not containing any special characters (only alphanumeric and underscores) | |
epiviz.measurements.Measurement.Type.FEATURE, | |
'my_datasource', // Data source: the table/data frame containing the data | |
'my_datasourcegroup', // An identifier for use to group with other measurements from different data providers | |
// that have the same seqName, start and end values | |
this.id(), // Data provider | |
null, // Formula: always null for measurements coming directly from the data provider | |
'Line Track', // Default chart type filter | |
null, // Annotation | |
-5, // Min Value | |
25, // Max Value | |
['my_metadata'] // Metadata | |
); | |
}; | |
/** | |
* Copy methods from upper class | |
*/ | |
epiviz.plugins.data.MyDataProvider.prototype = epiviz.utils.mapCopy(epiviz.data.DataProvider.prototype); | |
epiviz.plugins.data.MyDataProvider.constructor = epiviz.plugins.data.MyDataProvider; | |
epiviz.plugins.data.MyDataProvider.DEFAULT_ID = 'myprovider'; | |
/** | |
* @param {epiviz.data.Request} request | |
* @param {function(epiviz.data.Response)} callback | |
* @override | |
*/ | |
epiviz.plugins.data.MyDataProvider.prototype.getData = function (request, callback) { | |
var requestId = request.id(); | |
var action = request.get('action'); | |
var seqName = request.get('chr'); | |
var start = request.get('start'); | |
var end = request.get('end'); | |
var datasource = request.get('datasource'); | |
// Return a genomic range of 100 base pairs every 1000 base pairs | |
var step = 1000, width = 100; | |
var globalStartIndex, firstStart, firstEnd; | |
if (action == epiviz.data.Request.Action.GET_ROWS || action == epiviz.data.Request.Action.GET_VALUES) { | |
globalStartIndex = Math.floor((start - 1) / step) + 1; | |
firstStart = globalStartIndex * step + 1; | |
firstEnd = firstStart + width; | |
if (firstEnd < start) { | |
firstStart += step; | |
firstEnd += step; | |
} | |
} | |
var globalIndex, s; | |
switch (action) { | |
case epiviz.data.Request.Action.GET_ROWS: | |
if (firstStart >= end) { | |
// Nothing to return | |
callback(epiviz.data.Response.fromRawObject({ | |
data: { | |
values: { id: null, start: [], end:[], strand: [], metadata:{my_metadata:[]} }, | |
globalStartIndex: null, | |
useOffset: false | |
}, | |
requestId: requestId | |
})); | |
return; | |
} | |
var ids = [], starts = [], ends = [], strands = '*', myMetadata = []; | |
for (globalIndex = globalStartIndex, s = firstStart; s < end; ++globalIndex, s += step) { | |
ids.push(globalIndex); | |
starts.push(s); | |
ends.push(s + width); | |
myMetadata.push(epiviz.utils.generatePseudoGUID(5)); // Random string | |
} | |
callback(epiviz.data.Response.fromRawObject({ | |
data: { | |
values: { id: ids, start: starts, end: ends, strand: strands, metadata:{ my_metadata: myMetadata } }, | |
globalStartIndex: globalStartIndex, | |
useOffset: false | |
}, | |
requestId: requestId | |
})); | |
return; | |
case epiviz.data.Request.Action.GET_VALUES: | |
if (firstStart >= end) { | |
// Nothing to return | |
callback(epiviz.data.Response.fromRawObject({ | |
data: { values: [], globalStartIndex: null }, | |
requestId: requestId | |
})); | |
return; | |
} | |
var values = []; | |
for (globalIndex = globalStartIndex, s = firstStart; s < end; ++globalIndex, s += step) { | |
var v = Math.random() | |
* (this._mockMeasurement.maxValue() - this._mockMeasurement.minValue()) | |
+ this._mockMeasurement.minValue(); | |
values.push(v); | |
} | |
callback(epiviz.data.Response.fromRawObject({ | |
data: { | |
values: values, | |
globalStartIndex: globalStartIndex | |
}, | |
requestId: requestId | |
})); | |
return; | |
case epiviz.data.Request.Action.GET_MEASUREMENTS: | |
callback(epiviz.data.Response.fromRawObject({ | |
requestId: request.id(), | |
data: { | |
id: [this._mockMeasurement.id()], | |
name: [this._mockMeasurement.name()], | |
type: [this._mockMeasurement.type()], | |
datasourceId: [this._mockMeasurement.datasourceId()], | |
datasourceGroup: [this._mockMeasurement.datasourceGroup()], | |
defaultChartType: [this._mockMeasurement.defaultChartType()], | |
annotation: [this._mockMeasurement.annotation()], | |
minValue: [this._mockMeasurement.minValue()], | |
maxValue: [this._mockMeasurement.maxValue()], | |
metadata: [this._mockMeasurement.metadata()] | |
} | |
})); | |
return; | |
case epiviz.data.Request.Action.GET_SEQINFOS: | |
callback(epiviz.data.Response.fromRawObject({ | |
requestId: request.id(), | |
data: [['chr1', 1, 248956422], ['myChr', 1, 1000000000]] | |
})); | |
return; | |
default: | |
epiviz.data.DataProvider.prototype.getData.call(this, request, callback); | |
break; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment