1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/8269f76312af/ changeset: 8269f76312af user: jgoecks date: 2012-10-09 05:33:03 summary: Fixes that (a) simplify data providers framework and (b) make it possible to view different trees in the same nexus file. affected #: 7 files diff -r 02fe49c3d251bd30114dcd616336b73b2e8d1ab2 -r 8269f76312af60e356707bc660b6e9903e402106 lib/galaxy/visualization/data_providers/genome.py --- a/lib/galaxy/visualization/data_providers/genome.py +++ b/lib/galaxy/visualization/data_providers/genome.py @@ -520,7 +520,7 @@ rval.append( payload ) - return { 'data': rval, 'message': message } + return { 'data': rval, 'dataset_type': self.dataset_type, 'message': message } def write_data_to_file( self, regions, filename ): out = open( filename, "w" ) @@ -550,8 +550,6 @@ for large datasets. """ - dataset_type = 'interval_index' - def get_iterator( self, chrom=None, start=None, end=None ): # Read first line in order to match chrom naming format. line = source.readline() @@ -696,8 +694,6 @@ for large datasets. """ - dataset_type = 'tabix' - def get_iterator( self, chrom, start, end ): # Read first line in order to match chrom naming format. line = source.readline() @@ -1278,7 +1274,7 @@ results.append( payload ) - return { 'data': results, 'message': message } + return { 'data': results, 'dataset_type': self.dataset_type, 'message': message } class GtfTabixDataProvider( TabixDataProvider ): """ diff -r 02fe49c3d251bd30114dcd616336b73b2e8d1ab2 -r 8269f76312af60e356707bc660b6e9903e402106 lib/galaxy/visualization/data_providers/phyloviz/__init__.py --- a/lib/galaxy/visualization/data_providers/phyloviz/__init__.py +++ b/lib/galaxy/visualization/data_providers/phyloviz/__init__.py @@ -7,36 +7,37 @@ class PhylovizDataProvider( BaseDataProvider ): + dataset_type = "phylo" + def __init__( self, original_dataset=None ): super( PhylovizDataProvider, self ).__init__( original_dataset=original_dataset ) - def get_data( self ): - """returns [trees], meta - Trees are actually an array of JsonDicts. It's usually one tree, except in the case of Nexus + def get_data( self, tree_index=0 ): + """ + Returns trees. + Trees are actually an array of JsonDicts. It's usually one tree, except in the case of Nexus """ - jsonDicts, meta = [], {} file_ext = self.original_dataset.datatype.file_ext file_name = self.original_dataset.file_name - try: - if file_ext == "nhx": # parses newick files - newickParser = Newick_Parser() - jsonDicts, parseMsg = newickParser.parseFile( file_name ) - elif file_ext == "phyloxml": # parses phyloXML files - phyloxmlParser = Phyloxml_Parser() - jsonDicts, parseMsg = phyloxmlParser.parseFile( file_name ) - elif file_ext == "nex": # parses nexus files - nexusParser = Nexus_Parser() - jsonDicts, parseMsg = nexusParser.parseFile( file_name ) - meta["trees"] = parseMsg - else: - raise Exception("File type is not supported") + parseMsg = None + jsonDicts = [] + rval = { 'dataset_type': self.dataset_type } - meta["msg"] = parseMsg + if file_ext == "nhx": # parses newick files + newickParser = Newick_Parser() + jsonDicts, parseMsg = newickParser.parseFile( file_name ) + elif file_ext == "phyloxml": # parses phyloXML files + phyloxmlParser = Phyloxml_Parser() + jsonDicts, parseMsg = phyloxmlParser.parseFile( file_name ) + elif file_ext == "nex": # parses nexus files + nexusParser = Nexus_Parser() + jsonDicts, parseMsg = nexusParser.parseFile( file_name ) + jsonDicts = jsonDicts[ int( tree_index ) ] + rval["trees"] = parseMsg - except Exception, e: - raise e - jsonDicts, meta["msg"] = [], "Parse failed" + rval[ "data" ] = jsonDicts + rval[ "msg"] = parseMsg + + return rval - return jsonDicts, meta - diff -r 02fe49c3d251bd30114dcd616336b73b2e8d1ab2 -r 8269f76312af60e356707bc660b6e9903e402106 lib/galaxy/visualization/data_providers/registry.py --- a/lib/galaxy/visualization/data_providers/registry.py +++ b/lib/galaxy/visualization/data_providers/registry.py @@ -1,5 +1,8 @@ from galaxy.visualization.data_providers.basic import ColumnDataProvider from galaxy.visualization.data_providers.genome import * +from galaxy.visualization.data_providers.phyloviz import PhylovizDataProvider +from galaxy.datatypes.xml import Phyloxml +from galaxy.datatypes.data import Newick, Nexus class DataProviderRegistry( object ): """ @@ -45,6 +48,8 @@ data_provider_class = RawVcfDataProvider elif isinstance( original_dataset.datatype, Tabular ): data_provider_class = ColumnDataProvider + elif isinstance( original_dataset.datatype, ( Nexus, Newick, Phyloxml ) ): + data_provider_class = PhylovizDataProvider data_provider = data_provider_class( original_dataset=original_dataset ) diff -r 02fe49c3d251bd30114dcd616336b73b2e8d1ab2 -r 8269f76312af60e356707bc660b6e9903e402106 lib/galaxy/webapps/galaxy/api/datasets.py --- a/lib/galaxy/webapps/galaxy/api/datasets.py +++ b/lib/galaxy/webapps/galaxy/api/datasets.py @@ -185,19 +185,7 @@ return msg # Return data. - data = None data_provider = trans.app.data_provider_registry.get_data_provider( trans, raw=True, original_dataset=dataset ) - - if isinstance( data_provider, ColumnDataProvider ): - data = data_provider.get_data( **kwargs ) - - else: - # Default to genomic data. - # FIXME: need better way to set dataset_type. - low, high = int( kwargs.get( 'low' ) ), int( kwargs.get( 'high' ) ) - data = data_provider.get_data( start=low, end=high, **kwargs ) - data[ 'dataset_type' ] = 'interval_index' - data[ 'extra_info' ] = None - if isinstance( dataset.datatype, Vcf ): - data[ 'dataset_type' ] = 'tabix' + data = data_provider.get_data( **kwargs ) + return data diff -r 02fe49c3d251bd30114dcd616336b73b2e8d1ab2 -r 8269f76312af60e356707bc660b6e9903e402106 lib/galaxy/webapps/galaxy/controllers/visualization.py --- a/lib/galaxy/webapps/galaxy/controllers/visualization.py +++ b/lib/galaxy/webapps/galaxy/controllers/visualization.py @@ -847,8 +847,7 @@ # Get data. pd = PhylovizDataProvider( original_dataset=hda ) - json, config = pd.get_data() - json = json[tree_index] + config = pd.get_data( tree_index=tree_index ) config["title"] = hda.display_name() config["ext"] = hda.datatype.file_ext @@ -857,7 +856,7 @@ config["saved_visualization"] = False # Return viz. - return trans.fill_template_mako( "visualization/phyloviz.mako", data = json, config=config ) + return trans.fill_template_mako( "visualization/phyloviz.mako", data = config[ "data" ], config=config ) @web.json def bookmarks_from_dataset( self, trans, hda_id=None, ldda_id=None ): diff -r 02fe49c3d251bd30114dcd616336b73b2e8d1ab2 -r 8269f76312af60e356707bc660b6e9903e402106 static/scripts/viz/phyloviz.js --- a/static/scripts/viz/phyloviz.js +++ b/static/scripts/viz/phyloviz.js @@ -1,4 +1,4 @@ -define(['libs/d3', 'viz/visualization'], function(d3, visualization_mod) { +define(['libs/d3', 'viz/visualization', 'mvc/data'], function(d3, visualization_mod, data_mod) { var UserMenuBase = Backbone.View.extend({ /** @@ -181,6 +181,12 @@ nodeAttrChangedTime : 0 }, + initialize: function(options) { + this.set("dataset", new data_mod.Dataset({ + id: options.dataset_id + })); + }, + root : {}, // Root has to be its own independent object because it is not part of the viz_config toggle : function (d) { @@ -255,7 +261,7 @@ }, success: function(res){ var viz_id = res.url.split("id=")[1].split("&")[0], - viz_url = "/phyloviz/visualization?id=" + viz_id; + viz_url = "/visualization?id=" + viz_id; window.history.pushState({}, "", viz_url + window.location.hash); hide_modal(); } @@ -662,11 +668,11 @@ * Primes the Ajax URL to load another Nexus tree */ var self = this, - treeIndex = $("#phylovizNexSelector :selected").val(), - dataset_id = self.phyloTree.get("dataset_id"), - url = "phyloviz/getJsonData?dataset_id=" + dataset_id + "&treeIndex=" + String(treeIndex); - $.getJSON(url, function(packedJson){ - window.initPhyloViz(packedJson.data, packedJson.config); + treeIndex = $("#phylovizNexSelector :selected").val(); + $.getJSON(self.phyloTree.get("dataset").url(), { tree_index: treeIndex, data_type: 'raw_data' }, function(packedJson){ + self.data = packedJson.data; + self.config = packedJson; + self.render(); }); } }); diff -r 02fe49c3d251bd30114dcd616336b73b2e8d1ab2 -r 8269f76312af60e356707bc660b6e9903e402106 templates/visualization/phyloviz.mako --- a/templates/visualization/phyloviz.mako +++ b/templates/visualization/phyloviz.mako @@ -165,7 +165,7 @@ // -- Render viz. -- phyloviz.render(); - } + }; $(function firstVizLoad(){ // calls when viz is loaded for the first time var config = JSON.parse( '${ h.to_json_string( config )}'); Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.