Class: Bio::Pipengine::Job
- Inherits:
-
Object
- Object
- Bio::Pipengine::Job
- Defined in:
- lib/bio/pipengine/job.rb
Instance Attribute Summary collapse
-
#command_line ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples.
-
#cpus ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples.
-
#custom_name ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples.
-
#custom_output ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples.
-
#local ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples.
-
#log ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples.
-
#log_adapter ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples.
-
#mem ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples.
-
#multi_samples ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples.
-
#name ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples.
-
#nodes ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples.
-
#resources ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples.
-
#samples_obj ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples.
Instance Method Summary collapse
- #add_resources(resources) ⇒ Object
-
#add_step(step, sample) ⇒ Object
add all the command lines for a given step.
-
#initialize(name) ⇒ Job
constructor
A new instance of Job.
- #output ⇒ Object
-
#to_pbs(options) ⇒ Object
convert the job object into a TORQUE::Qsub object.
- #to_script(options) ⇒ Object
Constructor Details
#initialize(name) ⇒ Job
Returns a new instance of Job.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/bio/pipengine/job.rb', line 12 def initialize(name) @name = generate_uuid + "-" + name @shortname = name @command_line = [] @resources = {} @cpus = 1 @nodes = "1" @log = "stdin" @log_adapter = nil end |
Instance Attribute Details
#command_line ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples
9 10 11 |
# File 'lib/bio/pipengine/job.rb', line 9 def command_line @command_line end |
#cpus ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples
9 10 11 |
# File 'lib/bio/pipengine/job.rb', line 9 def cpus @cpus end |
#custom_name ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples
9 10 11 |
# File 'lib/bio/pipengine/job.rb', line 9 def custom_name @custom_name end |
#custom_output ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples
9 10 11 |
# File 'lib/bio/pipengine/job.rb', line 9 def custom_output @custom_output end |
#local ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples
9 10 11 |
# File 'lib/bio/pipengine/job.rb', line 9 def local @local end |
#log ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples
9 10 11 |
# File 'lib/bio/pipengine/job.rb', line 9 def log @log end |
#log_adapter ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples
9 10 11 |
# File 'lib/bio/pipengine/job.rb', line 9 def log_adapter @log_adapter end |
#mem ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples
9 10 11 |
# File 'lib/bio/pipengine/job.rb', line 9 def mem @mem end |
#multi_samples ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples
9 10 11 |
# File 'lib/bio/pipengine/job.rb', line 9 def multi_samples @multi_samples end |
#name ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples
9 10 11 |
# File 'lib/bio/pipengine/job.rb', line 9 def name @name end |
#nodes ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples
9 10 11 |
# File 'lib/bio/pipengine/job.rb', line 9 def nodes @nodes end |
#resources ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples
9 10 11 |
# File 'lib/bio/pipengine/job.rb', line 9 def resources @resources end |
#samples_obj ⇒ Object
a Job object holds information on a job to be submitted samples_groups and samples_obj are used to store information in case of steps that require to combine info from multiple samples
9 10 11 |
# File 'lib/bio/pipengine/job.rb', line 9 def samples_obj @samples_obj end |
Instance Method Details
#add_resources(resources) ⇒ Object
23 24 25 |
# File 'lib/bio/pipengine/job.rb', line 23 def add_resources(resources) self.resources.merge! resources end |
#add_step(step, sample) ⇒ Object
add all the command lines for a given step
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/bio/pipengine/job.rb', line 32 def add_step(step,sample) # setting job working directory working_dir = "" if self.local working_dir = self.local+"/"+self.name else working_dir = self.output if step.is_multi? folder = (self.custom_output) ? self.custom_output : @shortname working_dir += "/#{folder}" else folder = if self.custom_output self.custom_output elsif self.custom_name self.custom_name else step.name end working_dir += "/#{sample.name}/#{folder}" end end # set job cpus number to the higher step cpus (this in case of multiple steps) self.cpus = step.cpus if step.cpus > self.cpus # set number of nodes for job self.nodes = (step.nodes) ? step.nodes : @nodes # set the memory used self.mem = step.mem # adding job working directory unless step.name.start_with? "_" self.command_line << "if [ ! -f #{working_dir}/checkpoint ]" self.command_line << "then" self.command_line << logger(step, "start") self.command_line << "\nmkdir -p #{working_dir}" self.command_line << "cd #{working_dir}" end # generate command lines for this step if step.run.kind_of? Array step.run.each_with_index do |cmd, i| command = generate_cmd_line(cmd,sample,step) # TODO verify that logger works in this case # self.command_line << "#{command} || { echo \"FAILED `date`: #{step.name}:#{i}\" ; exit 1; }" self.command_line << "#{command} || { #{logger(step, "FAILED #{i}" )}; exit 1; }" end else command = generate_cmd_line(step.run,sample,step) # TODO verify that logger works in this case # self.command_line << "#{command} || { echo \"FAILED `date`: #{step.name} \" ; exit 1; }" self.command_line << "#{command} || { #{logger(step, "FAILED" )}; exit 1; }" end self.command_line << logger(step, "finished") self.command_line << "touch #{working_dir}/checkpoint" self.command_line << "else" self.command_line << logger(step, "already executed, skipping this step") self.command_line << "fi" # check if a temporary (i.e. different from 'output') directory is set if self.local final_output = "" if step.is_multi? folder = (self.custom_output) ? self.custom_output : @shortname final_output = self.output+"/#{folder}" else folder = (self.custom_output) ? self.custom_output : step.name final_output = self.output+"/#{sample.name}/#{folder}" end self.command_line << "mkdir -p #{final_output}" self.command_line << "cp -r #{working_dir}/* #{final_output}" self.command_line << "rm -fr #{working_dir}" end end |
#output ⇒ Object
27 28 29 |
# File 'lib/bio/pipengine/job.rb', line 27 def output self.resources["output"] end |
#to_pbs(options) ⇒ Object
convert the job object into a TORQUE::Qsub object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/bio/pipengine/job.rb', line 116 def to_pbs() TORQUE::Qsub.new() do |torque_job| torque_job.name = self.name torque_job.working_directory = self.output # where pbs scripts and stdout / stderr files will be saved if [:pbs_opts] torque_job.l = [:pbs_opts] else l_string = [] l_string << "nodes=#{self.nodes}:ppn=#{self.cpus}" l_string << "mem=#{self.mem}" if self.mem torque_job.l = l_string if [:mail_exit] torque_job.m = "e" torque_job.M = [:mail_exit] end if [:mail_start] torque_job.m = "b" torque_job.M = [:mail_start] end end torque_job.q = [:pbs_queue] if [:pbs_queue] torque_job.script = self.command_line.join("\n")+"\n" end end |
#to_script(options) ⇒ Object
141 142 143 144 145 146 |
# File 'lib/bio/pipengine/job.rb', line 141 def to_script() File.open(self.name+'.sh','w') do |file| file.puts "#!/usr/bin/env bash -l" file.puts self.command_line.join("\n") end end |