Created
December 3, 2015 15:37
-
-
Save afgane/8abe8565f64bba382913 to your computer and use it in GitHub Desktop.
Galaxy tool popularity WIP
This file contains 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
<% | |
root = h.url_for( "/" ) | |
app_root = root + "plugins/visualizations/popularity/static/" | |
title = "Tool popularity derived from dataset '" + hda.name + "'" | |
## creating_job = hda.creating_job.id | |
creating_job = trans.security.encode_id( hda.creating_job.id ) | |
creating_job_id = hda.creating_job.id | |
tool1 = hda.creating_job.tool_id | |
# optionally bootstrap data from dprov | |
##data = list( hda.datatype.dataset_column_dataprovider( hda, limit=10000 ) ) | |
# Use root for resource loading. | |
root = h.url_for( '/' ) | |
%> | |
## ---------------------------------------------------------------------------- | |
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<title>${title}</title> | |
## ---------------------------------------------------------------------------- | |
${h.css( 'base' )} | |
## ${h.stylesheet_link( root + 'plugins/visualizations/scatterplot/static/scatterplot.css' )} | |
## ---------------------------------------------------------------------------- | |
${h.js( 'libs/jquery/jquery', | |
## 'libs/jquery/jquery.migrate', | |
## 'libs/jquery/jquery-ui', | |
## 'libs/bootstrap', | |
'libs/require', | |
'libs/underscore', | |
'libs/backbone/backbone' )} | |
## 'libs/d3', | |
## 'libs/handlebars.runtime', | |
## 'ui/peek-column-selector', | |
## 'ui/pagination', | |
## 'mvc/visualization/visualization-model' )} | |
${h.javascript_link( app_root + 'app.js' )} | |
<script type="text/javascript"> | |
/** | |
* Get a list of popular tools that based on the inputs to the selected dataset. | |
*/ | |
function getToolList(){ | |
job1Info = jQuery.ajax( '/api/jobs/${creating_job}' ); | |
toolIds = [ '${tool1}' ] | |
job1Info.done( function( response ) { | |
inputs = response.inputs; | |
// Look for ID(s) of job(s) preceeding this dataset's job | |
jobsInfo = [] | |
jQuery.each(inputs, function( k, v ) { | |
jobsInfo.push( | |
jQuery.ajax( '/api/jobs/' + v.id ) | |
.done( function( jobn ) { | |
window.console.log(jobn.tool_id); | |
toolIds.push( jobn.tool_id ); | |
})); | |
}); | |
// A list of tool IDs that are ignorred | |
ignoreTools = [ 'upload1', '__SET_METADATA__' ]; | |
// Wait for all the requests to return and filter tool IDs | |
jQuery.when.apply($, jobsInfo) | |
.done(function() { | |
for( i=0; i<ignoreTools.length; i++ ) { | |
if ( toolIds.indexOf( ignoreTools[i] ) > -1 ) { | |
// window.console.log("Removing tool on the ignore list: " + ignoreTools[i]); | |
toolIds.splice( toolIds.indexOf( ignoreTools[i] ), 1 ); | |
} | |
} | |
key = toolIds.join( [ ',' ] ); | |
window.console.log("key: " + key); | |
// Given the chain key, get the popular tools | |
popular = jQuery.ajax( '/api/tools/popular?tool_chain=' + key ); | |
popular.done( function( response ) { | |
// window.console.log( response ); | |
showTools(response); | |
}); | |
}); | |
}); | |
} | |
/** | |
* Parse the tools list and display it. | |
*/ | |
function showTools(toolsInfo) { | |
window.console.log(toolsInfo); | |
tp = toolsInfo.popular; | |
tools = "<table><tr><th>Tool ID</th><th>Relevance</th></tr>"; | |
for ( i=0; i<tp.length; i++ ) { | |
tools += "<tr><td>" + tp[i].tool_id + "</td><td>" + (tp[i].relevance*100).toFixed(2) + "%</td</tr>"; | |
} | |
tools += "</table"; | |
$('#tools-container').html( tools ); | |
} | |
</script> | |
</head> | |
## ---------------------------------------------------------------------------- | |
<body> | |
<div class="chart-header"> | |
<h2>${title}</h2> | |
</div> | |
<div id="tools-container"> | |
Please wait - computing tool popularity... | |
</div> | |
<script type="text/javascript"> | |
getToolList(); | |
// get configuration | |
// var config = { | |
// root : '${root}', | |
// app_root : '${app_root}' | |
// }; | |
// // link galaxy | |
// var Galaxy = Galaxy || parent.Galaxy; | |
// // console protection | |
// window.console = window.console || { | |
// log : function(){}, | |
// debug : function(){}, | |
// info : function(){}, | |
// warn : function(){}, | |
// error : function(){}, | |
// assert : function(){} | |
// }; | |
// // configure require | |
// require.config({ | |
// baseUrl: config.root + "static/scripts/", | |
// paths: { | |
// "plugin" : "${app_root}", | |
// // "d3" : "libs/d3" | |
// }, | |
// shim: { | |
// "libs/underscore": { exports: "_" }, | |
// "libs/backbone/backbone": { exports: "Backbone" } | |
// // "d3": { exports: "d3"} | |
// } | |
// }); | |
// // application | |
// var app = null; | |
// $(function() { | |
// // request application script | |
// require(['plugin/app'], function(App) { | |
// // load options | |
// var options = { | |
// id : ${h.dumps( visualization_id )} || undefined, | |
// config : ${h.dumps( config )} | |
// } | |
// // create application | |
// app = new App(options); | |
// // add to body | |
// $('body').append(app.$el); | |
// }); | |
// }); | |
// get configuration | |
// var config = { | |
// root : '${root}', | |
// app_root : '${app_root}' | |
// }; | |
// // configure require | |
// require.config({ | |
// baseUrl: config.root + "static/scripts/", | |
// // paths: { | |
// // "plugin" : "${app_root}" | |
// // }, | |
// // shim: { | |
// // "libs/underscore": { exports: "_" }, | |
// // "libs/backbone/backbone": { exports: "Backbone" } | |
// // } | |
// }); | |
// // var app = new PopularityVis(); | |
// // // application | |
// var app = null; | |
// $(function() { | |
// // request application script | |
// require(['libs/backbone/backbone'], function( POPULARITY ) { | |
// $(function(){ | |
// // create application | |
// app = new POPULARITY.PopularityVis(); | |
// // add to body | |
// $('body').append(app.$el); | |
// }); | |
// }); | |
// }); | |
// $('#tools-container').text( popular.responseText ); | |
// window.console.log('title: ' + model.get( 'creating_job' )); | |
// $(function(){ | |
// var model = getModel(), | |
// hdaJSON = getHDAJSON(), | |
// editor = new ScatterplotConfigEditor({ | |
// el : $( '.scatterplot-editor' ).attr( 'id', 'scatterplot-editor-hda-' + hdaJSON.id ), | |
// model : getModel(), | |
// dataset : hdaJSON | |
// }).render(); | |
// window.editor = editor; | |
// $( '.chart-header h2' ).click( function(){ | |
// var returned = prompt( 'Enter a new title:' ); | |
// if( returned ){ | |
// model.set( 'title', returned ); | |
// } | |
// }); | |
// model.on( 'change:title', function(){ | |
// $( '.chart-header h2' ).text( model.get( 'title' ) ); | |
// document.title = model.get( 'title' ) + ' | ' + '${visualization_display_name}'; | |
// }) | |
// }); | |
</script> | |
</body> |
This file contains 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
@web.expose_api_anonymous | |
def popular( self, trans, **kwd ): | |
""" | |
* GET /api/tools/popular | |
Return information about popular tools to use based on provided tools. | |
The popularity is based on sequences of supplied tools | |
as used on Galaxy Main from years 2006 to 2015. | |
:type tool_chain: str | |
:param tool_chain: a comma-separated list of tool ID's | |
# Not (yet) implemented | |
:type filter: list | |
:param filter: a list of strings by which to filter the results | |
:rtype: dict | |
:returns: two keys are included in the returned dict: | |
- ``tool_chain``: a string of supplied tool ID's; | |
- ``popular``: a list of dictionaries containing | |
popular tools. Each dict further contains keys | |
``tool_id`` (str), ``relevance`` (str). | |
""" | |
rval = {} | |
chains = {} # Global historic chains (TODO: supply this) | |
chains = {'join1,Remove beginning1': [{'tool_id': 'T1', 'relevance': '0.43'}, | |
{'tool_id': 'T2', 'relevance': '0.57'}]} | |
fp = 'tool-data/total_triplets.json' | |
with open( fp, 'r') as f: | |
chains = load(f) | |
popular = [] # A list of popular tools to return | |
tool_chain = kwd.get( 'tool_chain', '' ) | |
if tool_chain: | |
chain = chains.get( tool_chain, {} ) | |
for tool_id, relevance in chain.iteritems(): | |
popular.append( { 'tool_id': tool_id, | |
'relevance': relevance } ) | |
rval[ 'tool_chain' ] = tool_chain | |
rval[ 'popular' ] = popular | |
return rval |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment