Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tabix histogram for CanvasFeatuers #956

Merged
merged 14 commits into from
Feb 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/tutorial/data_files/volvox.bw.gff3.gz.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[ tracks . volvox_gff3_tabix_bw ]
storeClass = JBrowse/Store/SeqFeature/GFF3Tabix
histograms.storeClass = JBrowse/Store/SeqFeature/BigWig
histograms.urlTemplate = ../../raw/volvox/volvox-sorted.bam.coverage.bw
urlTemplate = ../../raw/volvox/volvox.sort.gff3.gz.1
tbiUrlTemplate = ../../raw/volvox/volvox.sort.gff3.gz.tbi
type = CanvasFeatures
metadata.description = This is just all the features in the volvox.gff3 test file, displayed using GFF3 and tabix, but a BW histogram.
category = Miscellaneous
maxFeatureScreenDensity = 0.05
key = GFF3Tabix - volvox.gff3 in-memory adaptor with BW historgram
1 change: 1 addition & 0 deletions docs/tutorial/data_files/volvox.sort.gff3.gz.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ tbiUrlTemplate = ../../raw/volvox/volvox.sort.gff3.gz.tbi
type = CanvasFeatures
metadata.description = This is just all the features in the volvox.gff3 test file, displayed using GFF3 and tabix
category = Miscellaneous
maxFeatureScreenDensity = 0.05
key = GFF3Tabix - volvox.gff3 in-memory adaptor
1 change: 1 addition & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ echo -n "Formatting Volvox example data ...";
cat docs/tutorial/data_files/volvox.gff3.conf >> sample_data/json/volvox/tracks.conf
cat docs/tutorial/data_files/volvox.gtf.conf >> sample_data/json/volvox/tracks.conf
cat docs/tutorial/data_files/volvox.sort.gff3.gz.conf >> sample_data/json/volvox/tracks.conf
cat docs/tutorial/data_files/volvox.bw.gff3.gz.conf >> sample_data/json/volvox/tracks.conf
cat docs/tutorial/data_files/volvox.sort.bed.gz.conf >> sample_data/json/volvox/tracks.conf
cat docs/tutorial/data_files/bookmarks.conf >> sample_data/json/volvox/tracks.conf
bin/add-json.pl '{ "dataset_id": "volvox", "include": [ "../../raw/volvox/functions.conf" ] }' sample_data/json/volvox/trackList.json
Expand Down
13 changes: 12 additions & 1 deletion src/JBrowse/QueryParamConfigMapper.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/**
* This library interprets options passed in via dot-notation instead of JSON in the Query URL.
* The implementation is both for readability and security in some systems, esp. tomcat where
* passing JSON in the Query URL is both bad-form and potentially insecure.
*
* This is the dot-object library: https://www.npmjs.com/package/dot-object
*
* Usage is depicted here:
* http://gmod.org/wiki/JBrowse_Configuration_Guide#addFeatures
*
*/
define(['dojo/_base/declare', 'JBrowse/Util/dot-object'], function (declare, dotObject) {
return declare(null, {

Expand Down Expand Up @@ -59,7 +70,7 @@ define(['dojo/_base/declare', 'JBrowse/Util/dot-object'], function (declare, dot
var storeTracks = {};
var storeBookmarks = {};
Object.keys(queryParams).forEach(function (queryParam) {
if (queryParam.indexOf('addStore\.') == 0) {
if (queryParam.indexOf('addStores\.') == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a block comment to the top of this file saying what this class does? For posterity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added doc at the top. Thanks.

queryNameArray = queryParam.split("\.");
propertyName = queryNameArray.slice(1).join('.');
dotObject.str('stores.'+propertyName, queryParams[queryParam], config)
Expand Down
72 changes: 72 additions & 0 deletions src/JBrowse/Store/SeqFeature/GFF3Tabix.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,78 @@ return declare( [ SeqFeatureStore, DeferredStatsMixin, DeferredFeaturesMixin, Gl
}, errorCallback );
},


getRegionFeatureDensities: function( query, successCallback, errorCallback ) {

var thisB = this ;

var numBins, basesPerBin;
if( query.numBins ) {
numBins = query.numBins;
basesPerBin = (query.end - query.start)/numBins;
}
else if( query.basesPerBin ) {
basesPerBin = query.basesPerBin || query.ref.basesPerBin;
numBins = Math.ceil( (query.end-query.start)/basesPerBin );
}
else {
throw new Error('numBins or basesPerBin arg required for getRegionFeatureDensities');
}

var statEntry = (function( basesPerBin, stats ) {
for (var i = 0; i < stats.length; i++) {
if( stats[i].basesPerBin >= basesPerBin ) {
return stats[i];
}
}
return undefined;
})( basesPerBin, [] );

var stats = {};
stats.basesPerBin = basesPerBin ;

stats.scoreMax = 0 ;
stats.max = 0 ;
var firstServerBin = Math.floor( query.start / basesPerBin);
var histogram = [];
var binRatio = 1 / basesPerBin;

var binStart, binEnd ;

for(var bin = 0 ; bin < numBins ; bin++){
histogram[bin] = 0;
}


thisB.getHeader().then( function() {
thisB.indexedData.getLines(
query.ref || thisB.refSeq.name,
query.start,
query.end,
function( line ) {
// var feat = thisB.lineToFeature(line);
// if(!feat.attributes.parent) // only count if has NO parent
var start = line.start ;
var binValue = Math.round( (start - query.start )* binRatio) ;

// in case it extends over the end, just push it on the end
binValue = binValue >=0 ? binValue : 0 ;
binValue = binValue < histogram.length ? binValue : histogram.length -1 ;

histogram[binValue] += 1;
if(histogram[binValue] > stats.max){
stats.max = histogram[binValue];
}
},
function() {
successCallback({ bins: histogram, stats: stats});
},
errorCallback
);
}, errorCallback );

},

lineToFeature: function( line ) {
var attributes = GFF3.parse_attributes( line.fields[8] );
var ref = line.fields[0];
Expand Down
20 changes: 10 additions & 10 deletions tests/js_tests/spec/QueryParamConfigMapper.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require(['JBrowse/QueryParamConfigMapper', 'dojo/io-query'], function (QueryParamConfigMapper, ioQuery) {

describe("QueryParamConfigMapper", function () {
it("should interpret addStore properly", function () {
it("should interpret addStores properly", function () {
var mapper = QueryParamConfigMapper();
expect(mapper).toBeTruthy();
var queryString = 'addStore.store1.type=HMLFeatures&addStore.store1.urlTemplate=http://abc.com/test.gff';
var queryString = 'addStores.store1.type=HMLFeatures&addStores.store1.urlTemplate=http://abc.com/test.gff';
var config = {};
var queryParams = ioQuery.queryToObject(queryString);
runs(function () {
Expand All @@ -14,10 +14,10 @@ require(['JBrowse/QueryParamConfigMapper', 'dojo/io-query'], function (QueryPara
})
});

it("tests bookmarks, addStore, and addTracks", function () {
it("tests addBookmarks, addStores, and addTracks", function () {
var mapper = QueryParamConfigMapper();
expect(mapper).toBeTruthy();
var queryString = 'addStore.store1.type=JBrowse/Store/SeqFeature/GFF3&addStore.store1.urlTemplate=http://localhost/volvox.gff3&addTracks.store1.label=genes&addTracks.store1.type=JBrowse/View/Track/HTMLFeatures&highlight=&addBookmarks.bookmark1.start=3000&addBookmarks.bookmark1.end=4000&addBookmarks.bookmark1.ref=ctgA';
var queryString = 'addStores.store1.type=JBrowse/Store/SeqFeature/GFF3&addStores.store1.urlTemplate=http://localhost/volvox.gff3&addTracks.store1.label=genes&addTracks.store1.type=JBrowse/View/Track/HTMLFeatures&highlight=&addBookmarks.bookmark1.start=3000&addBookmarks.bookmark1.end=4000&addBookmarks.bookmark1.ref=ctgA';
var config = {};
var queryParams = ioQuery.queryToObject(queryString);
runs(function () {
Expand Down Expand Up @@ -53,7 +53,7 @@ require(['JBrowse/QueryParamConfigMapper', 'dojo/io-query'], function (QueryPara
var mapper = QueryParamConfigMapper();
expect(mapper).toBeTruthy();
var inputJson = {
'addStore': {
'addStores': {
'stores': {
'store1': {
'type': 'HMLFeatures',
Expand All @@ -64,7 +64,7 @@ require(['JBrowse/QueryParamConfigMapper', 'dojo/io-query'], function (QueryPara
};
runs(function () {
var generatedUrl = mapper.generateUrl(inputJson);
var answer = 'addStore.stores.store1.type=HMLFeatures&addStore.stores.store1.urlTemplate=http://abc.com/test.gff';
var answer = 'addStores.stores.store1.type=HMLFeatures&addStores.stores.store1.urlTemplate=http://abc.com/test.gff';
expect(generatedUrl).toEqual(answer);
})
});
Expand All @@ -73,10 +73,10 @@ require(['JBrowse/QueryParamConfigMapper', 'dojo/io-query'], function (QueryPara
it("test multiple nested ingest", function () {
var mapper = QueryParamConfigMapper();
expect(mapper).toBeTruthy();
var queryString = 'addStore.stores.store1.type=HMLFeatures&addStore.stores.store1.urlTemplate=http://abc.com/test.gff';
var queryString = 'addStores.stores.store1.type=HMLFeatures&addStores.stores.store1.urlTemplate=http://abc.com/test.gff';
var config = {};
var answer = {
'addStore': {
'addStores': {
'stores': {
'store1': {
'type': 'HMLFeatures',
Expand All @@ -94,7 +94,7 @@ require(['JBrowse/QueryParamConfigMapper', 'dojo/io-query'], function (QueryPara
it("test multiple nested views", function () {
var mapper = QueryParamConfigMapper();
expect(mapper).toBeTruthy();
var queryString = 'addStore.store1.type=HMLFeatures&addStore.store1.urlTemplate=http://abc.com/test.gff';
var queryString = 'addStores.store1.type=HMLFeatures&addStores.store1.urlTemplate=http://abc.com/test.gff';
var config = {};
var answer = {
'stores': {
Expand Down Expand Up @@ -136,4 +136,4 @@ require(['JBrowse/QueryParamConfigMapper', 'dojo/io-query'], function (QueryPara
});

});
});
});