Show
Ignore:
Timestamp:
10-02-11 15:26:21 (3 years ago)
Author:
kostas.karasavvas@…
Message:

updated test plus produces better looking XML

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • galaxy-taverna/workflow-to-galaxy/test/Expected_BioAID_ProteinDiscovery_rb

    r84 r89  
    44require 't2-server' 
    55require 'open-uri' 
     6require 'zip/zipfilesystem' 
     7 
     8 
     9# sends the zip file to specified output 
     10def output_zip_file(uuid, zip_out) 
     11  File.open("/tmp/#{uuid}.zip") do |zip| 
     12    while data = zip.read(4096) 
     13      zip_out.write data 
     14    end 
     15  end 
     16  File.delete("/tmp/#{uuid}.zip") 
     17end 
     18 
     19 
     20# 
     21# replicates the directory result structure as constructed by the 
     22# taverna server and recreates it in a zip File 
     23# 
     24def add_to_zip_file(output_dir, data_lists, zip_out)  
     25  zip_out.dir.mkdir("#{output_dir}") 
     26  data_lists.each_with_index do |item, index| 
     27    if item.instance_of? Array 
     28      add_to_zip_file("#{output_dir}/#{index+1}", item, zip_out) 
     29    else 
     30      zip_out.file.open("#{output_dir}/#{index+1}", "w") { |f| f.puts item } 
     31    end 
     32  end 
     33end 
    634 
    735     
     
    1846 
    1947 
    20 # method that acquires all the results of the specified output 
    21 def get_outputs(run, refs, outfile, dir) 
     48# 
     49# Method that acquires all the results of the specified output directory. 
     50# If valid zip File is passed it also accumulates results as a zip file. 
     51# 
     52def get_outputs(run, refs, outfile, dir, zip_out=nil)  
    2253  data_lists = run.get_output(dir, refs) 
    2354  print_flattened_result(outfile, data_lists) 
     55  if zip_out 
     56    add_to_zip_file(dir, data_lists, zip_out) 
     57  end 
    2458end 
    2559 
     
    3670      "'" 
    3771    elsif $1 == '__dq__' 
    38       '\"' 
     72      '\\\"' 
    3973    elsif $1 == '__cr____cn__' 
    4074      '
' 
     
    74108end 
    75109 
    76 # get input arguments -- for each input a boolean specifies if it's from history 
     110# 
     111# Get input arguments -- for each input a boolean specifies if it's from history 
    77112# thus, for each me_rest input we have two arguments in the script! 
     113# 
    78114Query_from_history = ARGV[0].chomp 
    79115Query_tmp = ARGV[1].chomp 
     
    93129end 
    94130 
     131# get results_as_zip input and open zip file if appropriate 
     132zipped = ARGV[4].chomp == "yes" 
     133zip_out = Zip::ZipFile.open("/tmp/#{run.uuid}.zip", Zip::ZipFile::CREATE) if zipped 
     134 
     135 
    95136# start run and wait until it is finished 
    96137run.start 
     
    98139 
    99140# get output arguments and associated them with a file 
    100 output4 = File.open(ARGV[4], "w") 
    101 begin 
    102   get_outputs(run, false, output4, 'ValidatedProtein') 
    103 rescue Exception => err 
    104   get_outputs(run, false, output4, 'ValidatedProtein.error') 
    105 end 
    106141output5 = File.open(ARGV[5], "w") 
    107142begin 
    108   get_outputs(run, false, output5, 'UniProtID') 
     143  get_outputs(run, false, output5, 'ValidatedProtein', zip_out) 
    109144rescue Exception => err 
    110   get_outputs(run, false, output5, 'UniProtID.error') 
     145  get_outputs(run, false, output5, 'ValidatedProtein.error', zip_out) 
     146ensure 
     147  output5.close 
     148end 
     149output6 = File.open(ARGV[6], "w") 
     150begin 
     151  get_outputs(run, false, output6, 'UniProtID', zip_out) 
     152rescue Exception => err 
     153  get_outputs(run, false, output6, 'UniProtID.error', zip_out) 
     154ensure 
     155  output6.close 
     156end 
     157 
     158# close zip_out (the newly created zip file) if opened 
     159zip_out.close if zip_out 
     160 
     161# open galaxy zip output and write zip file 
     162if zipped 
     163  galaxy_zip_out = File.open(ARGV[7], "w") 
     164  output_zip_file(run.uuid, galaxy_zip_out) 
     165  galaxy_zip_out.close 
    111166end 
    112167