Skip to content

Commit

Permalink
add track config as part of track metadata, add logic to *join* track…
Browse files Browse the repository at this point in the history
… metadata to the track config instead of adding it in, meaning that metadata rows that don't have a configured track are ignored
  • Loading branch information
rbuels committed May 3, 2012
1 parent d3773b9 commit 25b336e
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 55 deletions.
4 changes: 2 additions & 2 deletions faceted_track_selector.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
}

#faceted_tracksel .gridContainer {
height: 95%;
width: 90%;
height: 300px;
float: left;
}

#faceted_tracksel .facetSelect,
Expand Down
137 changes: 88 additions & 49 deletions js/Model/TrackMetaData.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ dojo.declare( 'JBrowse.Model.TrackMetaData', null,
this.onReadyFuncs = dojo.clone(args.onReady);
}

// index the track configurations as a store
this._indexItems({ store: this, items: args.trackConfigs });

// fetch and index all the items from each of the stores
var stores_fetched_count = 0;
dojo.forEach( args.metadataStores, function(store) {
store.fetch({
scope: this,
onComplete: Util.debugHandler( this, function(items) {
// build our indexes
this._indexItems( store, items );
this._indexItems({ store: store, items: items, supplementalOnly: true });

// if this is the last store to be fetched, call
// our onReady callbacks
Expand All @@ -46,63 +49,99 @@ dojo.declare( 'JBrowse.Model.TrackMetaData', null,
},this);
},

_indexItems: function( store, items ) {

_indexItems: function( args ) {
// get our (filtered) list of facets we will index for
var seen = {};
var facets = this.facets =
dojo.filter( ( this.facets || [] ).concat( store.getAttributes(items[0])),
function(facetName) {
var take = this._filterFacet(facetName) && !seen[facetName];
seen[facetName] = true;
return take;
},
this
);

// initialize our indexes if necessary
var store = args.store,
items = args.items;

// convert the items to a uniform format
items = dojo.map( items, function( item ) {
var attributes = store.getAttributes(item);

//convert the item into a uniform data format of plain objects
var newitem = {};
dojo.forEach( attributes, function(attr) {
newitem[attr] = store.getValue(item,attr);
});
return newitem;
},
this
);

// merge them with any existing records, filtering out ones
// that should be ignored if we were passed
// 'supplementalOnly', and update the identity index
this.identIndex = this.identIndex || {};
items = dojo.filter( items, function(item) {
// merge the new item attributes with any existing
// record for this item
var ident = this.getIdentity(item);
var existingItem = this.identIndex[ ident ];
if( args.supplementalOnly && !existingItem) {
// skip this item if we are supplementalOnly and it
// does not already exist
return false;
}
this.identIndex[ ident ] = dojo.mixin( existingItem || {}, item );
return true;
},
this
);

// update our facet list to include any new attrs these
// items have
var old_facets = this.facets || [];
this.facets = (function() {
var seen = {};
return dojo.filter( old_facets.concat( this.getAttributes( items[0] ) ),
function(facetName) {
var take = this._filterFacet(facetName) && !seen[facetName];
seen[facetName] = true;
return take;
},
this
);
}).call(this);
var new_facets = this.facets.slice( old_facets.length );

// initialize indexes for any new facets
this.facetIndexes = this.facetIndexes || { itemCount: 0, bucketCount: 0, byName: {} };
dojo.forEach( facets, function(facet) {
dojo.forEach( new_facets, function(facet) {
if( ! this.facetIndexes.byName[facet] ) {
this.facetIndexes.bucketCount++;
this.facetIndexes.byName[facet] = { itemCount: 0, bucketCount: 0, byValue: {} };
}
}, this);

// put each of the items into our indexes
dojo.forEach( items, function( item ) {

//convert the item into a uniform data format of plain objects
item = (function(){
var newitem = {};
dojo.forEach(store.getAttributes(item), function(attr) {
newitem[attr] = store.getValue(item,attr);
});
return newitem;
}).call(this);

this.identIndex[ this.getIdentity(item) ] = item;

this.facetIndexes.itemCount++;
dojo.forEach( facets, function( facet ) {
var value = this.getValue( item, facet, undefined );
if( typeof value == 'undefined' )
return;
var facetValues = this.facetIndexes.byName[facet];
var bucket = facetValues.byValue[value];
if( !bucket ) {
bucket = facetValues.byValue[value] = { itemCount: 0, items: [] };
facetValues.bucketCount++;
}
bucket.itemCount++;
bucket.items.push(item);
},this);
}, this);

this.facetIndexes.facetRank = this.facets.sort(dojo.hitch(this,function(a,b){
return this.facetIndexes.byName[b].bucketCount - this.facetIndexes.byName[a].bucketCount;
}));
// now update the indexes with the new facets
if( new_facets.length ) {
dojo.forEach( items, function( item ) {
this.facetIndexes.itemCount++;
dojo.forEach( new_facets, function( facet ) {

var value = this.getValue( item, facet, undefined );
if( typeof value == 'undefined' )
return;
var facetValues = this.facetIndexes.byName[facet];
var bucket = facetValues.byValue[value];
if( !bucket ) {
bucket = facetValues.byValue[value] = { itemCount: 0, items: [] };
facetValues.bucketCount++;
}
bucket.itemCount++;
bucket.items.push(item);
},this);
}, this);

// calculate the rank of the facets: make an array of
// facet names sorted by smallest average bucket size,
// descending
this.facetIndexes.facetRank = this.facets.sort(dojo.hitch(this,function(a,b){
a = this.facetIndexes.byName[a];
b = this.facetIndexes.byName[b];
return b.itemCount/b.bucketCount - a.itemCount/a.bucketCount;
}));
}

console.log(this.facetIndexes);
},
Expand Down
5 changes: 1 addition & 4 deletions js/View/TrackList/Faceted.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ dojo.declare( 'JBrowse.View.TrackList.Faceted', null,
draggable: false,
resizable: true,
title: "Track Selection",
style: "width: 95%;"
},
this.container
);
Expand All @@ -53,9 +52,7 @@ dojo.declare( 'JBrowse.View.TrackList.Faceted', null,
this.gridContainer = dojo.create('div',{
className: 'gridContainer',
style: {
width: (12+facets.length * 100) + 'px',
height: '80%',
"float": 'left'
width: (20+facets.length * 100) + 'px',
}
},this.container);
// make a data grid that will hold the search results
Expand Down

0 comments on commit 25b336e

Please sign in to comment.