Class: JobStep

Inherits:
Object
  • Object
show all
Defined in:
lib/rpipe.rb

Direct Known Subclasses

Preprocessing, Reconstruction, Stats

Constant Summary collapse

COLLISION_POLICY =

options – :panic, :destroy, :overwrite

:panic

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workflow_spec, job_spec) ⇒ JobStep

Intialize with two configuration option hashes - workflow_spec and job_spec



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rpipe.rb', line 29

def initialize(workflow_spec, job_spec)
	# allow jobspec to override the workflow spec
	@subid        = job_spec['subid']       || workflow_spec['subid']
	@rawdir       = job_spec['rawdir']      || workflow_spec['rawdir']
	@origdir      = job_spec['origdir']     || workflow_spec['origdir']
	@procdir      = job_spec['procdir']     || workflow_spec['procdir']
	@statsdir     = job_spec['statsdir']    || workflow_spec['statsdir']
	@spmdir       = job_spec['spmdir']      || workflow_spec['spmdir'] || default_spmdir
	@scans        = job_spec['scans']       || workflow_spec['scans']
	@scan_labels  = job_spec['scan_labels'] || workflow_spec['scan_labels'] 
	@collision_policy = (job_spec['collision'] || workflow_spec['collision'] || COLLISION_POLICY).to_sym
	@step   = job_spec['step']
	@method = job_spec['method']
	include_custom_methods(@method)
	@libdir = File.dirname(Pathname.new(__FILE__).realpath)
	
	job_requires 'subid'
end

Instance Attribute Details

#collision_policyObject

Returns the value of attribute collision_policy.



26
27
28
# File 'lib/rpipe.rb', line 26

def collision_policy
  @collision_policy
end

#libdirObject

Returns the value of attribute libdir.



26
27
28
# File 'lib/rpipe.rb', line 26

def libdir
  @libdir
end

#origdirObject

Returns the value of attribute origdir.



26
27
28
# File 'lib/rpipe.rb', line 26

def origdir
  @origdir
end

#procdirObject

Returns the value of attribute procdir.



26
27
28
# File 'lib/rpipe.rb', line 26

def procdir
  @procdir
end

#rawdirObject

Returns the value of attribute rawdir.



26
27
28
# File 'lib/rpipe.rb', line 26

def rawdir
  @rawdir
end

#spmdirObject

Returns the value of attribute spmdir.



26
27
28
# File 'lib/rpipe.rb', line 26

def spmdir
  @spmdir
end

#statsdirObject

Returns the value of attribute statsdir.



26
27
28
# File 'lib/rpipe.rb', line 26

def statsdir
  @statsdir
end

#stepObject

Returns the value of attribute step.



26
27
28
# File 'lib/rpipe.rb', line 26

def step
  @step
end

#subidObject

Returns the value of attribute subid.



26
27
28
# File 'lib/rpipe.rb', line 26

def subid
  @subid
end

Instance Method Details

#check_instance_vars(*args) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/rpipe.rb', line 106

def check_instance_vars(*args)
  undefined_vars = []
  args.each do |arg|
    unless instance_variable_defined?("@" + arg) && eval("@" + arg).nil? == false
      undefined_vars << arg
    end
  end
  
  unless undefined_vars.size == 0
    yield undefined_vars
  end
end

#default_spmdirObject

Raises:

  • (IOError)


125
126
127
128
129
130
131
# File 'lib/rpipe.rb', line 125

def default_spmdir
  spmdirs = %w{/Applications/spm/spm8/spm8_current /apps/spm/spm8_current}
  spmdirs.each do |dir|
    return dir if File.directory? dir
  end
  raise IOError, "Couldn't find default SPM directory in #{spmdirs.join("; ")}."
end

#include_custom_methods(module_name) ⇒ Object

Dynamically load custom methods for advanced processing.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/rpipe.rb', line 49

def include_custom_methods(module_name)
	if module_name.nil? or ['default','wadrc'].include?(module_name)
		# do nothing, use default implementation
	else
     # Search the load path and require a file named after the custom method.
     # Include methods contained in the custom method module.  
	  # Ensure it's named properly according to file convention or it won't be correctly included.
		begin 
 			require module_name
	    extend self.class.const_get(module_name.dot_camelize)
		rescue LoadError => e
		  puts "Unable to find the specified method #{module_name}"
		  puts "Please either use a standard preprocessing step or put a method in app/methods/#{module_name}.rb"
		  puts "Looking in: #{$LOAD_PATH.join(":")}"
		  raise e
    rescue NameError => e
      $Log.error "Unable to include a module #{module_name.dot_camelize} (for custom #{@step} step)."
      puts "Please check app/methods/#{module_name}.rb and ensure that you declared a module named _exactly_ #{module_name.dot_camelize}."
      puts
      raise e
     end

	end
end

#job_requires(*args) ⇒ Object

Check for required keys in instance variables.



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/rpipe.rb', line 93

def job_requires(*args)
  check_instance_vars *args do |missing_vars|
    error = "
    Warning: Misconfiguration detected.
    You are missing the following required variables from your spec file:
    #{missing_vars.collect { |var| "\t  - #{var} \n" } }
    "
    
    puts error
    raise ScriptError, "Missing Vars: #{missing_vars.join(", ")}"
  end
end

#setup_directory(path, logging_tag) ⇒ Object

Setup directory path according to collision policy.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/rpipe.rb', line 75

def setup_directory(path, logging_tag)
	if File.exist?(path)
		if @collision_policy == :destroy
			puts "#{logging_tag} :: Deleting directory #{path}"
			FileUtils.rm_rf(path)
			FileUtils.mkdir_p(path)
		elsif @collision_policy == :overwrite
			puts "#{logging_tag} :: Overwriting inside directory #{path}"
		else
			raise(IOError, "Directory already exists, exiting: #{path}")
		end
	else
		puts "#{logging_tag} :: Creating new directory #{path}"
		FileUtils.mkdir_p(path)
	end
end

#validate_existence_of(*args) ⇒ Object

Raises:

  • (ScriptError)


119
120
121
122
123
# File 'lib/rpipe.rb', line 119

def validate_existence_of(*args)
  missing_files = []
  args.flatten.collect { |file| missing_files << file unless File.exist?(file) }
  raise ScriptError, "Missing files: #{missing_files.join(", ")}" unless missing_files.empty?
end