myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [2563] trunk: added taverna 2 to galaxy wrapper


From: noreply
Subject: [myexperiment-hackers] [2563] trunk: added taverna 2 to galaxy wrapper
Date: Thu, 24 Feb 2011 09:58:56 -0500 (EST)

Revision
2563
Author
dgc
Date
2011-02-24 09:58:56 -0500 (Thu, 24 Feb 2011)

Log Message

added taverna 2 to galaxy wrapper

Modified Paths

Added Paths

Diff

Modified: trunk/app/controllers/workflows_controller.rb (2562 => 2563)


--- trunk/app/controllers/workflows_controller.rb	2011-02-24 14:39:40 UTC (rev 2562)
+++ trunk/app/controllers/workflows_controller.rb	2011-02-24 14:58:56 UTC (rev 2563)
@@ -7,7 +7,7 @@
 
   include ApplicationHelper
 
-  before_filter :login_required, :except => [:index, :show, :download, :named_download, :statistics, :launch, :search]
+  before_filter :login_required, :except => [:index, :show, :download, :named_download, :galaxy_tool, :galaxy_tool_download, :statistics, :launch, :search]
   
   before_filter :find_workflows_rss, : [:index]
   before_filter :find_workflow_auth, :except => [:search, :index, :new, :create]
@@ -22,7 +22,7 @@
 
   # declare sweepers and which actions should invoke them
   cache_sweeper :workflow_sweeper, : [ :create, :create_version, :launch, :update, :update_version, :destroy_version, :destroy ]
-  cache_sweeper :download_viewing_sweeper, : [ :show, :download, :named_download, :launch ]
+  cache_sweeper :download_viewing_sweeper, : [ :show, :download, :named_download, :galaxy_tool, :galaxy_tool_download, :launch ]
   cache_sweeper :permission_sweeper, : [ :create, :update, :destroy ]
   cache_sweeper :bookmark_sweeper, : [ :destroy, :favourite, :favourite_delete ]
   cache_sweeper :tag_sweeper, : [ :create, :update, :tag, :destroy ]
@@ -162,6 +162,32 @@
     end
   end
 
+  # GET /workflows/:id/versions/:version/galaxy_tool
+  def galaxy_tool
+  end
+
+  # GET /workflows/:id/versions/:version/galaxy_tool_download
+  def galaxy_tool_download
+
+    if params[:server].nil? || params[:server].empty?
+      flash.now[:error] = "You must provide a URL to a Taverna server."
+      render(:action ="" :galaxy_tool, :id => @workflow.id, :version => @viewing_version_number.to_s)
+      return
+    end
+
+    zip_file_name = "tmp/galaxy_tool.#{Process.pid}"
+
+    TavernaToGalaxy.generate(@workflow, @viewing_version_number, params[:server], zip_file_name)
+
+    zip_file = File.read(zip_file_name)
+    File.unlink(zip_file_name)
+
+    send_data(zip_file,
+        :filename => "address@hidden",
+        :type => 'application/zip',
+        :disposition => 'attachment')
+  end
+
   # GET /workflows
   def index
     respond_to do |format|

Modified: trunk/app/views/workflows/_breadcrumbs.rhtml (2562 => 2563)


--- trunk/app/views/workflows/_breadcrumbs.rhtml	2011-02-24 14:39:40 UTC (rev 2562)
+++ trunk/app/views/workflows/_breadcrumbs.rhtml	2011-02-24 14:58:56 UTC (rev 2563)
@@ -1,6 +1,6 @@
 <li><%= link_to 'Workflows', workflows_path %></li>
 
-<% if ["show", "new", "edit", "search", "all", "new_version", "edit_version", "comments_timeline"].include? controller.action_name.to_s %>
+<% if ["show", "new", "edit", "search", "all", "new_version", "edit_version", "comments_timeline", "galaxy_tool"].include? controller.action_name.to_s %>
   <li><b>&#187;</b></li>
   
   <% case controller.action_name.to_s; when "show" %>
@@ -27,6 +27,10 @@
 		<li><%= link_to "#{h(@workflow.title)}", workflow_path(@workflow) %></li>
 		<li><b>&#187;</b></li>
     <li>Comments Timeline</li>
+	<% when "galaxy_tool" %>
+		<li><%= link_to "#{h(@workflow.title)}", workflow_path(@workflow) %></li>
+		<li><b>&#187;</b></li>
+    <li>Galaxy tool download</li>
   <% else %>
     <!-- no breadcrumb -->
   <% end %>

Added: trunk/app/views/workflows/galaxy_tool.rhtml (0 => 2563)


--- trunk/app/views/workflows/galaxy_tool.rhtml	                        (rev 0)
+++ trunk/app/views/workflows/galaxy_tool.rhtml	2011-02-24 14:58:56 UTC (rev 2563)
@@ -0,0 +1,36 @@
+<% t "#{h @workflow.title} - Download as Galaxy tool" -%>
+
+<center>
+  <%= error_messages_for :workflow %>
+</center>
+
+<h1>Galaxy tool download</h1>
+
+<p>This download option provides you with a Galaxy tool that will execute a
+Taverna 2 workflow from Galaxy.  This requires access to a Taverna Server and
+you will need to provide a URL to that server so that Galaxy knows where to
+execute it.</p>
+
+<div style="margin: 2em; padding: 1em; border: solid 1px gray">
+
+  <% form_tag( { :action ="" :galaxy_tool_download } ) do %>
+
+    <p>
+      <b>Taverna server URL:</b><br />
+      <%= text_field_tag("server", "", :size => 100) %><br />
+      <small>E.g. http://www.example.com:8980/taverna-server</small>
+    </p>
+
+    <p style="text-align: center">
+      <%= submit_tag("Download Galaxy tool") %>
+    </p>
+
+  <% end %>
+</div>
+
+<p style="text-align: center; margin: 1em">
+  <% form_tag( { :action ="" "show" }, :method => :get) do %>
+    <%= submit_tag("Return to workflow") -%>
+  <% end %>
+</p>
+

Modified: trunk/app/views/workflows/show.rhtml (2562 => 2563)


--- trunk/app/views/workflows/show.rhtml	2011-02-24 14:39:40 UTC (rev 2562)
+++ trunk/app/views/workflows/show.rhtml	2011-02-24 14:58:56 UTC (rev 2563)
@@ -218,9 +218,21 @@
         </h3>
         
         <% if @authorised_to_download %>
+
+          <br />
+
           <ul class="sectionIcons">
             <li style="margin-left: 0;"><%= icon('workflow', @named_download_url, "Download Workflow file/package (for version address@hidden)", nil, "Download Workflow File/Package (address@hidden)") -%></li>
           </ul>
+
+          <% if @workflow.content_type.title == "Taverna 2" %>
+            <br />
+
+            <ul class="sectionIcons">
+              <li style="margin-left: 0;"><%= icon('workflow', galaxy_tool_path(:id => @workflow.id, :version => @viewing_version_number.to_s), "Download Workflow file/package (for version address@hidden)", nil, "Download Workflow as a Galaxy tool") -%></li>
+            </ul>
+          <% end %>
+
         <% else %>
           <p class="none_text">
             You do not have permission to download this workflow

Modified: trunk/config/routes.rb (2562 => 2563)


--- trunk/config/routes.rb	2011-02-24 14:39:40 UTC (rev 2562)
+++ trunk/config/routes.rb	2011-02-24 14:58:56 UTC (rev 2563)
@@ -124,6 +124,9 @@
   map.workflow_version           '/workflows/:id/versions/:version',         :conditions => { :method => :get }, :controller => 'workflows', :action ="" 'show'
   map.formatted_workflow_version '/workflows/:id/versions/:version.:format', :conditions => { :method => :get }, :controller => 'workflows', :action ="" 'show'
 
+  map.galaxy_tool 'workflows/:id/versions/:version/galaxy_tool', :controller => 'workflows', :action ="" 'galaxy_tool'
+  map.galaxy_tool_download 'workflows/:id/versions/:version/galaxy_tool_download', :controller => 'workflows', :action ="" 'galaxy_tool_download'
+
   # curation
   ['workflows', 'files', 'packs'].each do |contributable_type|
     map.curation "#{contributable_type}/:contributable_id/curation",
@@ -248,7 +251,7 @@
   map.connect ':controller/:id/download/:name', :action ="" 'named_download', :requirements => { :name => /.*/ }
   
   map.connect 'files/:id/download/:name', :controller => 'blobs', :action ="" 'named_download', :requirements => { :name => /.*/ }
-  
+
   # (general) announcements
   # NB! this is moved to the bottom of the file for it to be discovered
   # before 'announcements' resource within 'groups'

Modified: trunk/lib/authorization.rb (2562 => 2563)


--- trunk/lib/authorization.rb	2011-02-24 14:39:40 UTC (rev 2562)
+++ trunk/lib/authorization.rb	2011-02-24 14:58:56 UTC (rev 2563)
@@ -492,7 +492,7 @@
         action = ''
       when 'edit', 'new', 'create', 'update', 'new_version', 'create_version', 'destroy_version', 'edit_version', 'update_version', 'new_item', 'create_item', 'edit_item', 'update_item', 'quick_add', 'resolve_link', 'process_tag_suggestions', 'process_extra_metadata', 'edit_relationships'
         action = ''
-      when 'download', 'named_download', 'launch', 'submit_job', 'save_inputs', 'refresh_status', 'rerun', 'refresh_outputs', 'render_output', 'outputs_xml', 'outputs_package'
+      when 'download', 'named_download', 'launch', 'submit_job', 'save_inputs', 'refresh_status', 'rerun', 'refresh_outputs', 'render_output', 'outputs_xml', 'outputs_package', 'galaxy_tool', 'galaxy_tool_download'
         action = ''
       when 'destroy', 'delete', 'destroy_item'
         action = ''

Added: trunk/lib/taverna_to_galaxy.rb (0 => 2563)


--- trunk/lib/taverna_to_galaxy.rb	                        (rev 0)
+++ trunk/lib/taverna_to_galaxy.rb	2011-02-24 14:58:56 UTC (rev 2563)
@@ -0,0 +1,134 @@
+# myExperiment: lib/taverna_to_galaxy.rb
+# 
+# Copyright (c) 2011 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+require 'zip/zip'
+require 'workflow-to-galaxy'
+
+include Generator
+
+module TavernaToGalaxy
+
+  def self.generate(workflow, version, t2_server, zip_file_name)
+
+    wv = workflow.find_version(version)
+
+    doc = XML::Document.new
+    doc.root = XML::Node.new("workflow")
+    doc.root << wv.components
+
+    wkf_title   = wv.title
+    wkf_descr   = wv.body
+    wkf_inputs  = get_IOData(doc, "source")
+    wkf_outputs = get_IOData(doc, "sink")
+
+    w2g_workflow = W2GWorkflow.new(nil, wkf_title, wkf_descr, wkf_inputs, wkf_outputs)
+
+    w2g_rest_object = W2GRestObject.new("#{Conf.base_uri}/workflows/#{workflow.id}/versions/#{version}", w2g_workflow)
+
+    # Set output files
+    xml_file    = wv.unique_name + ".xml"
+    script_file = wv.unique_name + ".rb"
+
+    # Set taverna server if not specified
+    t2_server = "http://localhost:8980/taverna-server"  if t2_server == ""
+
+    # Generate Galaxy tool's files
+    zip_file = Zip::ZipFile.open(zip_file_name, Zip::ZipFile::CREATE)
+
+    zip_file.get_output_stream(xml_file) do |stream|
+      generate_xml(w2g_rest_object, xml_file, stream)
+    end
+
+    zip_file.get_output_stream(script_file) do |stream|
+      generate_script(w2g_rest_object, t2_server, stream)
+    end
+
+    zip_file.close
+  end
+
+  #
+  # Populate _IOData_ objects for specified type: value +source+'+ is for inputs
+  # and +sink+ for outputs
+  #
+  def self.get_IOData(doc, type)
+    io_data = []
+
+    # Get all sources or sinks and create appropriate objects
+    doc.find("//workflow/components/dataflows/address@hidden'top']/#{type}s/#{type}").each do |node|
+      name = ''
+      descriptions = []
+      examples = []
+
+      node.each_element do |n|
+        if n.name.eql? "name"
+          name = n.children[0].to_s
+        elsif n.name.eql? "descriptions"
+          n.each_element do |d|
+            descriptions << d.children[0].to_s
+          end if n.children?
+        elsif n.name.eql? "examples"
+          n.each_element do |e|
+            examples << e.children[0].to_s
+          end if n.children?
+        end
+      end
+
+      io_data << W2GIOData.new(name, descriptions, examples)
+    end
+
+    io_data
+  end
+
+  class W2GRestObject
+
+    attr_reader(:uri, :workflow)
+
+    def initialize(uri, workflow)
+      @uri      = uri
+      @workflow = workflow
+    end
+
+  end
+
+  #
+  # Contains all available information about a workflow: _xml_uri_, _title_, _description_,
+  # _inputs_ and _outputs_. The _xml_uri_ specifies the XML description on myExperiment and
+  # not the XML of the workflow itself.
+  #
+  class W2GWorkflow
+
+    attr_reader(:xml_uri, :title, :description, :inputs, :outputs)
+
+    def initialize(xml_uri, title, description, inputs, outputs)
+      @xml_uri     = xml_uri
+      @title       = title
+      @description = description
+      @inputs      = inputs
+      @outputs     = outputs
+    end
+
+  end
+
+  #
+  # Contains all available information about an input or output: name, descriptions
+  # and examples. The last two are lists.
+  #--
+  # Currently both inputs and outputs contain the same information. If that
+  # changes we can subclass this one.
+  #
+  class W2GIOData
+
+    attr_reader(:name, :descriptions, :examples)
+
+    def initialize(name, descriptions, examples)
+      @name         = name
+      @descriptions = descriptions
+      @examples     = examples
+    end
+
+  end
+
+end
+

reply via email to

[Prev in Thread] Current Thread [Next in Thread]