Class: Bio::Grid

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

Defined Under Namespace

Classes: Job

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, number, uuid) ⇒ Grid



6
7
8
9
10
# File 'lib/bio/grid.rb', line 6

def initialize(input,number, uuid)
  @input = input
  @number = number
  @uuid = uuid ? uuid : UUID.new.generate.split("-").first 
end

Instance Attribute Details

#inputObject

Returns the value of attribute input.



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

def input
  @input
end

#numberObject

Returns the value of attribute number.



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

def number
  @number
end

#uuidObject

Returns the value of attribute uuid.



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

def uuid
  @uuid
end

Class Method Details

.run(options) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bio/grid.rb', line 12

def self.run(options)
  options[:number] = "all" unless options[:number]
  grid = self.new options[:input], options[:number], options[:uuid]
  options[:uuid] = grid.uuid unless options[:uuid]
  groups = grid.prepare_input_groups
  inputs = groups.keys.sort
  groups[inputs.shift].each_with_index do |input1,index|
    if options[:cmd]=~/<(\d+),(\d+)(,\d+)*>/
      step = ($3) ? $3.tr(",","").to_i : 1
      range = Range.new($1.to_i,$2.to_i,false).step(step).to_a
      range.each do |value|
        cmd_line = options[:cmd].gsub(/<(\d+),(\d+)(,\d+)*>/,value.to_s)
        job = Bio::Grid::Job.new(options) # inherit global options
        job.options[:parameter_value] = "-param:#{value}"
        job.execute(cmd_line,inputs,input1,groups,index)
      end
    elsif options[:params]
      options[:params].each do |p|
        cmd_line = options[:cmd].gsub(/<param>|<parameter>/,p)
        job = Bio::Grid::Job.new(options)
        job.options[:parameter_value] = "-param:#{p}"
        job.execute(cmd_line,inputs,input1,groups,index)
      end
    else
      job = Bio::Grid::Job.new(options) # inherit global options
      job.execute(options[:cmd],inputs,input1,groups,index)
    end

    break if options[:test]
  end      
end

Instance Method Details

#prepare_input_groupsObject



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/bio/grid.rb', line 44

def prepare_input_groups
  groups = Hash.new {|h,k| h[k] = [] }
  self.input.each_with_index do |location,index|
    list = Dir.glob(location).sort
    raise ArgumentError,"Input file or folder #{location} do not exist!" if list.empty?
    if self.number == "all"
      groups["input#{index+1}"] = [list]
    else
      list.each_slice(self.number.to_i) {|subgroup| groups["input#{index+1}"] << subgroup}
    end
  end
  groups
end