Modified: trunk/lib/taverna_to_galaxy.rb (2898 => 2899)
--- trunk/lib/taverna_to_galaxy.rb 2012-01-16 15:07:29 UTC (rev 2898)
+++ trunk/lib/taverna_to_galaxy.rb 2012-01-16 15:16:17 UTC (rev 2899)
@@ -5,9 +5,8 @@
require 'zip/zip'
require 'workflow-to-galaxy'
+require 'myexperiment-rest'
-include Generator
-
module TavernaToGalaxy
def self.generate(workflow, version, t2_server, zip_file_name)
@@ -15,21 +14,21 @@
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")
+ doc.root << (XML::Node.new("title") << wv.title)
+ doc.root << (XML::Node.new("description") << wv.body)
+ doc.root << (XML::Node.new("content-uri") << workflow.named_download_url)
+ doc.root << (XML::Node.new("uploader") << workflow.contributor.label)
- w2g_workflow = W2GWorkflow.new(nil, wkf_title, wkf_descr, wkf_inputs, wkf_outputs)
+ doc.root << wv.components
- w2g_rest_object = W2GRestObject.new("#{workflow.named_download_url}?version=#{version}", w2g_workflow)
+ response = MyExperimentREST::MyExperimentWorkflow.parse(doc.root.to_s)
# Set output files
- xml_file = wv.unique_name + ".xml"
- script_file = wv.unique_name + ".rb"
+ xml_file = wv.unique_name + ".xml"
+ rb_file = wv.unique_name + ".rb"
# Set taverna server if not specified
t2_server = "http://localhost:8980/taverna-server" if t2_server == ""
@@ -37,98 +36,22 @@
# 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(xml_file) do |xml_stream|
+ zip_file.get_output_stream(rb_file) do |rb_stream|
- zip_file.get_output_stream(script_file) do |stream|
- generate_script(w2g_rest_object, t2_server, stream)
- end
+ tool = WorkflowToGalaxy::GalaxyTool.new(
+ :wkf_source => WorkflowToGalaxy::Workflows::MYEXPERIMENT_TAVERNA2,
+ :params => {
+ :t2_server => t2_server,
+ :xml_out => xml_stream,
+ :rb_out => rb_stream,
+ :response => response })
- 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
+ tool.generate
end
-
- io_data << W2GIOData.new(name, descriptions, examples)
end
- io_data
+ zip_file.close
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