dasmoth / dalliance

Interactive web-based genome browser.
http://www.biodalliance.org/
BSD 2-Clause "Simplified" License
226 stars 68 forks source link

Switch track back-ends in response to zoom level. #96

Closed dasmoth closed 9 years ago

dasmoth commented 9 years ago

Primary use case: switch from BAM to bigWig when zooming out. (suggested by Roy Chaudhuri on the mailing list).

OverlayFeatureSource already handles the logic of wrapping multiple back-ends up in a single track, so just need a way to switch back-ends on and off when zooming.

dasmoth commented 9 years ago

The master branch now has basic support for doing this. Example track configuration:

             {name: 'Alternates test',
               merge: 'alternates',
               overlay: [
                 {name: 'bam_subtrack',
                  bamURI: 'http://hgdownload.cse.ucsc.edu/goldenPath/hg19/encodeDCC/wgEncodeUwDnase/wgEncodeUwDnaseK562AlnRep1.bam'},
                 {name: 'bwg_subtrack',
                  bwgURI: 'http://hgdownload.cse.ucsc.edu/goldenPath/hg19/encodeDCC/wgEncodeUwDnase/wgEncodeUwDnaseK562RawRep1.bigWig'}
               ],
               style: [
                 {method: 'bam_subtrack', type: 'default', zoom: 'high',
                  style: {"glyph": "__SEQUENCE",
                          "HEIGHT": 8,
                          "BUMP": true,
                          "LABEL": false}},
                 {method: 'bwg_subtrack', type: 'default', zoom: 'medium',
                  style: {"glyph": "HISTOGRAM",
                          "BGCOLOR": "blue",
                          "HEIGHT": 30}},
                 {method: 'bwg_subtrack', type: 'default', zoom: 'low',
                  style: {"glyph": "HISTOGRAM",
                          "BGCOLOR": "blue",
                          "HEIGHT": 30}}]
               }

There are two points to note here:

  1. The "merge: 'alternates'" line to indicate that these are alternate data sources for the track, not a normal merge or overlay situation.
  2. The explicit stylesheet with "method" filters on each style rule. When in merge: 'alternates' mode, the methods of all features are set to be equal to the name of the subtrack they come from, so we can write style rules which explicitly refer to single subtracks. The overlay data-source checks the currently active style rules and only fetches sub-tracks that are required.

One issue at the moment is that you have to give an explicit stylesheet for this kind of track, there's no way to use the default styles because there's no way to weave the appropriate zoom-level filters into them. This is something I'm eager to see addressed (see #89 for some discussions), but may not happen for a while.