Class: Bio::Grid::Job
- Inherits:
-
Object
- Object
- Bio::Grid::Job
- Defined in:
- lib/bio/grid/job.rb
Instance Attribute Summary collapse
-
#instructions ⇒ Object
Returns the value of attribute instructions.
-
#job_output ⇒ Object
Returns the value of attribute job_output.
-
#options ⇒ Object
Returns the value of attribute options.
-
#runner ⇒ Object
Returns the value of attribute runner.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Instance Method Summary collapse
- #append_options ⇒ Object
- #execute(command_line, inputs, input1, groups, index) ⇒ Object
-
#initialize(options) ⇒ Job
constructor
A new instance of Job.
- #run(filename) ⇒ Object
- #set_commandline(cmd_line, inputs, input1, groups, index) ⇒ Object
- #set_output_dir ⇒ Object
- #set_scheduler_options(type) ⇒ Object
- #write_runner(filename) ⇒ Object
Constructor Details
#initialize(options) ⇒ Job
Returns a new instance of Job.
6 7 8 9 |
# File 'lib/bio/grid/job.rb', line 6 def initialize() @options = self.instructions = [] end |
Instance Attribute Details
#instructions ⇒ Object
Returns the value of attribute instructions.
5 6 7 |
# File 'lib/bio/grid/job.rb', line 5 def instructions @instructions end |
#job_output ⇒ Object
Returns the value of attribute job_output.
5 6 7 |
# File 'lib/bio/grid/job.rb', line 5 def job_output @job_output end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/bio/grid/job.rb', line 5 def @options end |
#runner ⇒ Object
Returns the value of attribute runner.
5 6 7 |
# File 'lib/bio/grid/job.rb', line 5 def runner @runner end |
#uuid ⇒ Object
Returns the value of attribute uuid.
5 6 7 |
# File 'lib/bio/grid/job.rb', line 5 def uuid @uuid end |
Instance Method Details
#append_options ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bio/grid/job.rb', line 34 def if self.[:copy] self.instructions << ("mkdir -p #{self.[:copy]}\n") copy_type = (self.[:output_folder]) ? "cp -r" : "cp" self.instructions << ("#{copy_type} #{self.job_output}* #{self.[:copy]}\n") end if self.[:clean] rm_type = (self.[:output_folder]) ? "rm -fr" : "rm -f" self.instructions << ("#{rm_type} #{self.job_output}*\n") end if self.[:path] self.instructions.insert(2, "export PATH=$PATH:#{[:path].join(':')}\n") end end |
#execute(command_line, inputs, input1, groups, index) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/bio/grid/job.rb', line 67 def execute(command_line,inputs,input1,groups,index) self.(:pbs) # set script specific options for the scheduling system self.set_commandline(command_line,inputs,input1,groups,index) self.set_output_dir self. job_filename = (self.[:keep]) ? "job_#{index+1}#{self.[:parameter_value]}.sh" : "job.sh" self.run(job_filename) end |
#run(filename) ⇒ Object
58 59 60 61 |
# File 'lib/bio/grid/job.rb', line 58 def run(filename) self.write_runner(filename) system("qsub #{self.runner}") unless self.[:dry] end |
#set_commandline(cmd_line, inputs, input1, groups, index) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/bio/grid/job.rb', line 16 def set_commandline(cmd_line,inputs,input1,groups,index) commandline = cmd_line.gsub(/<input1>|<input>/,input1.join(self.[:sep])) inputs.each do |input| commandline.gsub!(/<#{input}>/,groups[input][index].join(self.[:sep])) end job_output = self.[:output]+"/#{[:uuid]}_"+self.[:name]+"_%03d" % (index+1).to_s + "#{self.[:parameter_value]}" if commandline =~/<output>\.(\S+)/ extension = $1 commandline.gsub!(/<output>/,job_output) #job_output << ".#{extension}" else self.[:output_folder] = true commandline.gsub!(/<output>/,job_output) end self.instructions << commandline+"\n" self.job_output = job_output end |
#set_output_dir ⇒ Object
11 12 13 14 |
# File 'lib/bio/grid/job.rb', line 11 def set_output_dir output_dir = (self.[:output_folder]) ? "mkdir -p #{self.job_output}\ncd #{self.job_output}\n" : "mkdir -p #{self.[:output]}\n" self.instructions.insert(1,output_dir) end |
#set_scheduler_options(type) ⇒ Object
63 64 65 |
# File 'lib/bio/grid/job.rb', line 63 def (type) self.instructions << "#!/bin/bash\n#PBS -N #{self.[:name]}\n#PBS -l ncpus=#{self.[:processes]}\n\n" if type == :pbs end |
#write_runner(filename) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/bio/grid/job.rb', line 51 def write_runner(filename) self.runner = filename out = File.open(Dir.pwd+"/"+filename,"w") out.write(self.instructions.join+"\n") out.close end |