Class: Bio::Grid::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/grid/job.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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)
	@options = options
	self.instructions = []
end

Instance Attribute Details

#instructionsObject

Returns the value of attribute instructions.



5
6
7
# File 'lib/bio/grid/job.rb', line 5

def instructions
  @instructions
end

#job_outputObject

Returns the value of attribute job_output.



5
6
7
# File 'lib/bio/grid/job.rb', line 5

def job_output
  @job_output
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/bio/grid/job.rb', line 5

def options
  @options
end

#runnerObject

Returns the value of attribute runner.



5
6
7
# File 'lib/bio/grid/job.rb', line 5

def runner
  @runner
end

#uuidObject

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_optionsObject



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 append_options
	if self.options[:copy]
		self.instructions << ("mkdir -p #{self.options[:copy]}\n")
		copy_type = (self.options[:output_folder]) ? "cp -r" : "cp"
		self.instructions << ("#{copy_type} #{self.job_output}* #{self.options[:copy]}\n")
	end

	if self.options[:clean]
		rm_type = (self.options[:output_folder]) ? "rm -fr" : "rm -f"
		self.instructions << ("#{rm_type} #{self.job_output}*\n")
	end

	if self.options[:path]
		self.instructions.insert(2, "export PATH=$PATH:#{options[: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.set_scheduler_options(:pbs) # set script specific options for the scheduling system
     		self.set_commandline(command_line,inputs,input1,groups,index)
	self.set_output_dir
     		self.append_options
     		job_filename = (self.options[:keep]) ? "job_#{index+1}#{self.options[: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.options[: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.options[:sep]))
	inputs.each do |input|
		commandline.gsub!(/<#{input}>/,groups[input][index].join(self.options[:sep]))
	end
	job_output = self.options[:output]+"/#{options[:uuid]}_"+self.options[:name]+"_%03d" % (index+1).to_s + "#{self.options[:parameter_value]}"
	if commandline =~/<output>\.(\S+)/
		extension = $1
		commandline.gsub!(/<output>/,job_output)	
		#job_output << ".#{extension}"
	else
		self.options[:output_folder] = true
		commandline.gsub!(/<output>/,job_output)
	end
	self.instructions << commandline+"\n"
	self.job_output = job_output
end

#set_output_dirObject



11
12
13
14
# File 'lib/bio/grid/job.rb', line 11

def	set_output_dir
	output_dir = (self.options[:output_folder]) ? "mkdir -p #{self.job_output}\ncd #{self.job_output}\n" : "mkdir -p #{self.options[: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 set_scheduler_options(type)
	self.instructions << "#!/bin/bash\n#PBS -N #{self.options[:name]}\n#PBS -l ncpus=#{self.options[: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