Created
October 30, 2014 12:23
-
-
Save ktym/1b0fb8657ee6268b44ff to your computer and use it in GitHub Desktop.
Ruby port of the BaseSpace Native App test python script
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
require 'json' | |
def metadatajson | |
json = JSON.parse(' | |
{ | |
"Name": "", | |
"Description": "", | |
"HrefAppSession": "", | |
"Properties": [ | |
{ | |
"Type": "sample[]", | |
"Name": "Input.Samples", | |
"Items": [] | |
} | |
] | |
} | |
') | |
return json | |
end | |
json_object = JSON.parse(File.read('/data/input/AppSession.json')) | |
puts ">> json_object" | |
p json_object | |
items = json_object['Properties']['Items'] | |
parameters = [] | |
sample_hrefs = [] | |
project_id = nil | |
items.each do |item| | |
case item['Name'] | |
when 'Input.textbox' | |
parameters.push(item['Content']) | |
when 'Input.radio' | |
parameters.push(item['Content']) | |
when 'Input.checkbox' | |
parameters.push(item['Items'][0]) | |
when 'Input.numeric' | |
parameters.push(item['Content']) | |
when 'Input.Projects' | |
project_id = item['Items'][0]['Id'] | |
end | |
end | |
puts ">> parameters" | |
p parameters | |
puts ">> project_id" | |
p project_id | |
items.each do |item| | |
if item['Name'] == 'Input.Samples' | |
item['Items'].each do |sample| | |
sample_dir = "/data/input/samples/#{sample['Id']}/Data/Intensities/BaseCalls" | |
if not File.exists?(sample_dir) | |
sample_dir = "/data/input/samples/#{sample['Id']}" | |
end | |
puts ">> sample_dir" | |
p sample_dir | |
r1_files = Dir.glob("#{sample_dir}/*_R1_*") | |
r2_files = Dir.glob("#{sample_dir}/*_R2_*") | |
puts ">> r1_files" | |
p r1_files | |
puts ">> r2_files" | |
p r2_files | |
if r1_files.size != r2_files.size | |
puts "number of R1 and R2 files do not match" | |
exit | |
end | |
sample_out_dir = "/data/output/appresults/#{project_id}/#{sample['Name']}" | |
puts ">> sample_out_dir" | |
p sample_out_dir | |
system("mkdir -p '#{sample_out_dir}'") | |
File.open("#{sample_out_dir}/parameters.csv", "w") do |file| | |
parameters.each_with_index do |parameter, count| | |
file.puts "#{count},#{parameter}" | |
end | |
end | |
puts ">> parameters.csv" | |
p File.read("#{sample_out_dir}/parameters.csv") | |
meta_json_object = metadatajson | |
meta_json_object['Name'] = sample['Id'] | |
meta_json_object['Description'] = 'Sample Description' | |
meta_json_object['HrefAppSession'] = json_object['Href'] | |
meta_json_object['Properties'][0]['Items'].push(sample['Href']) | |
# not sure why generating a file everytime in a loop | |
File.open("#{sample_out_dir}/_metadata.json", "w") do |file| | |
file.puts meta_json_object.to_json | |
end | |
puts ">> meta_json_object" | |
puts File.read("#{sample_out_dir}/_metadata.json") | |
end | |
end | |
end |
Original python script can be found at https://illumina.app.box.com/shared/lv2bnr7rmevufrnnfi0z/1/2616054777
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Debug code will print outputs into a "Container log" file (URL for the file can be found in your spacedock log).