Class: Bio::Conduit::Step

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/conduit/process.rb

Constant Summary collapse

UNITCONV =
{
    '' => 1,
    'b' => 1,
    'k' => 1024,
    'm' => 1048576,
    'g' => 1073741824,
    't' => 1099511627776
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, hash, resources, addpath = true) ⇒ Step

Returns a new instance of Step.



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bio/conduit/process.rb', line 24

def initialize(name, hash, resources, addpath = true)
    @name = name
    @info = hash
    @resources = resources

    if addpath
        if @info['run'].is_a?(String)
            @info['run'] = ["mkdir -p <sample_output_path/>#{@name}", "cd <sample_output_path/>#{@name}", @info['run']]
        elsif @info['run'].is_a?(Array)
            @info['run'].unshift("mkdir -p <sample_output_path/>#{@name}", "cd <sample_output_path/>#{@name}")
        end
    end
end

Instance Attribute Details

#infoObject (readonly)

Returns the value of attribute info.



13
14
15
# File 'lib/bio/conduit/process.rb', line 13

def info
  @info
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/bio/conduit/process.rb', line 13

def name
  @name
end

#resourcesObject (readonly)

Returns the value of attribute resources.



13
14
15
# File 'lib/bio/conduit/process.rb', line 13

def resources
  @resources
end

Instance Method Details

#+(other) ⇒ Object



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
# File 'lib/bio/conduit/process.rb', line 50

def +(other)
    name = self.name + "_" + other.name
    resources = self.resources.merge(other.resources)
    info = self.info.merge(other.info) do |k, first, second|
        case k
        when 'mem', 'cpu', 'nodes'
            matched1 = /\A(\d+)([kmgtb]?)/.match(first)
            matched2 = /\A(\d+)([kmgtb]?)/.match(second)
            if (matched1[1].to_i * Bio::Conduit::Step::UNITCONV[matched1[2]]) > (matched2[1].to_i * Bio::Conduit::Step::UNITCONV[matched2[2]])
                first
            elsif (matched1[1].to_i * Bio::Conduit::Step::UNITCONV[matched1[2]]) < (matched2[1].to_i * Bio::Conduit::Step::UNITCONV[matched2[2]])
                second
            else
                first
            end
        else
            if first.is_a?(String) && second.is_a?(String)
                [first, second]
            elsif first.is_a?(Array) && second.is_a?(String)
                first + [second]
            elsif first.is_a?(String) && second.is_a?(Array)
                [first] + second
            else
                first + second
            end
        end
    end
    Bio::Conduit::Step.new(name, info, resources, false)
end

#create_jobscript(sample, template) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/bio/conduit/process.rb', line 80

def create_jobscript(sample, template)
    total_resources = @resources.merge(sample['resources'])
    total_resources['sample_path'] = sample['path']
    total_resources['sample'] = sample['name']
    total_resources['sample_output_path'] = "#{total_resources['output'].chomp('/')}" + "#{sample.has_key?('group') ? "/#{sample['group']}" : ''}" + "/#{sample['name']}"
    @jobname = sample['name'] + "_" + @name
    @commands = @info['run'].is_a?(Array) ? @info['run'].join("\n") : @info['run'].clone
    subslist = {}
    @commands.scan(/(\<([\w\/]+)\>)/).each do |entry|
        entry[1].scan(/[^\/]+/).each do |res|
            entry[1].sub!(/#{res}/, total_resources[res])
        end
        @commands.sub!(/#{entry[0]}/, entry[1])
    end
    return ERB.new(template, nil, '-').result(binding)
end

#dependence?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/bio/conduit/process.rb', line 38

def dependence?
    return @info.has_key?('pre')
end

#dependencyObject



42
43
44
45
46
47
48
# File 'lib/bio/conduit/process.rb', line 42

def dependency
    if self.dependence?
        return @info['pre']
    else
        return nil
    end
end