root/galaxy-taverna/workflow-to-galaxy/test/Expected_BioAID_ProteinDiscovery_rb @ 84

Revision 84, 2.9 KB (checked in by kostas.karasavvas@…, 3 years ago)

updated test files for new generated output

Line 
1#!/usr/bin/env ruby
2
3require 'rubygems'
4require 't2-server'
5require 'open-uri'
6
7   
8# method that flattens the list of list of list ... result of get_output
9def print_flattened_result(out, data_lists)
10  data_lists.each do |l|
11    if l.instance_of? Array
12      print_flattened_result(out, l)
13    else
14      out.puts l
15    end
16  end
17end
18
19
20# method that acquires all the results of the specified output
21def get_outputs(run, refs, outfile, dir)
22  data_lists = run.get_output(dir, refs)
23  print_flattened_result(outfile, data_lists)
24end
25
26
27#
28# Sanitize single quotes, double quotes, at symbol and newline in str. E.g. Galaxy
29# substitutes them to __sq__, __dq__, __at__ and __cr____cn__ respectively. This
30# methods turns them back to their original values before using them (i.e.
31# sending them to the taverna server
32#
33def sanitize(string)
34  string.gsub(/(__sq__|__dq__|__at__|__cr____cn__)/) do
35    if $1 == '__sq__'
36      "'"
37    elsif $1 == '__dq__'
38      '\"'
39    elsif $1 == '__cr____cn__'
40      '
'
41    else
42      '@'
43    end
44  end
45end
46
47#
48# Deletes last new line of file if it exists! It is needed for t2 workflows that
49# do not sanitize properly, i.e. via a user-provided beanshell script
50#
51def chomp_last_newline(file)
52
53  if File.file?(file) and File.size(file) > 1
54    f = open(file, "rb+")
55    f.seek(-1, File::SEEK_END)
56    f.truncate(File.size(file) - 1) if f.read(1) == "\n"
57    f.close
58  end
59
60end
61
62
63
64# use the uri reference to download the workflow locally
65wkf_file = URI.parse('http://www.myexperiment.org/workflows/74/download/bioaid_proteindiscovery_221429.xml?version=3')
66in_wkf = open(wkf_file)
67wkf = in_wkf.read()
68
69# create run
70begin
71  run = T2Server::Run.create('http://localhost:8980/taverna-server', wkf)
72rescue T2Server::T2ServerError => e
73  exit 1
74end
75
76# get input arguments -- for each input a boolean specifies if it's from history
77# thus, for each me_rest input we have two arguments in the script!
78Query_from_history = ARGV[0].chomp
79Query_tmp = ARGV[1].chomp
80if Query_from_history == "true"
81  chomp_last_newline(Query_tmp)
82  run.upload_input_file('Query', Query_tmp)
83else
84  run.set_input('Query', sanitize(Query_tmp))
85end
86maxHits_parameter_from_history = ARGV[2].chomp
87maxHits_parameter_tmp = ARGV[3].chomp
88if maxHits_parameter_from_history == "true"
89  chomp_last_newline(maxHits_parameter_tmp)
90  run.upload_input_file('maxHits_parameter', maxHits_parameter_tmp)
91else
92  run.set_input('maxHits_parameter', sanitize(maxHits_parameter_tmp))
93end
94
95# start run and wait until it is finished
96run.start
97run.wait(:progress => true)
98
99# get output arguments and associated them with a file
100output4 = File.open(ARGV[4], "w")
101begin
102  get_outputs(run, false, output4, 'ValidatedProtein')
103rescue Exception => err
104  get_outputs(run, false, output4, 'ValidatedProtein.error')
105end
106output5 = File.open(ARGV[5], "w")
107begin
108  get_outputs(run, false, output5, 'UniProtID')
109rescue Exception => err
110  get_outputs(run, false, output5, 'UniProtID.error')
111end
112
113# delete run
114run.delete
Note: See TracBrowser for help on using the browser.