Class: Cagnut::Configuration::Checks::Tools

Inherits:
Object
  • Object
show all
Defined in:
lib/cagnut/configuration/checks/tools.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Tools

Returns a new instance of Tools.



7
8
9
# File 'lib/cagnut/configuration/checks/tools.rb', line 7

def initialize config
  @config = config
end

Instance Attribute Details

#check_completedObject

Returns the value of attribute check_completed.



5
6
7
# File 'lib/cagnut/configuration/checks/tools.rb', line 5

def check_completed
  @check_completed
end

#configObject

Returns the value of attribute config.



5
6
7
# File 'lib/cagnut/configuration/checks/tools.rb', line 5

def config
  @config
end

#javaObject

Returns the value of attribute java.



5
6
7
# File 'lib/cagnut/configuration/checks/tools.rb', line 5

def java
  @java
end

Instance Method Details

#checkObject



11
12
13
14
15
16
17
# File 'lib/cagnut/configuration/checks/tools.rb', line 11

def check
  @check_completed = true
  check_each_tool
  result = @check_completed ? 'Completed!' : 'Failed!'
  puts "Check Tools: #{result}"
  exit unless @check_completed
end

#check_each_toolObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/cagnut/configuration/checks/tools.rb', line 19

def check_each_tool
  tools = @config['tools']
  refs = @config['refs']
  puts 'Start Checking...'
  check_execute_system
  check_ref_fasta refs['ref_fasta']
  check_java tools['java']
  check_r tools['R']
  check_tool tools, refs
end

#check_execute_systemObject



30
31
32
# File 'lib/cagnut/configuration/checks/tools.rb', line 30

def check_execute_system
  puts "Using Local System"
end

#check_java(path) ⇒ Object



44
45
46
47
48
49
# File 'lib/cagnut/configuration/checks/tools.rb', line 44

def check_java path
  failed = check_tool_ver 'Java' do
    `#{path} -version 2>&1| grep version | cut -f3 -d ' '` if path
  end
  @java = path unless failed
end

#check_r(path) ⇒ Object



51
52
53
54
55
56
# File 'lib/cagnut/configuration/checks/tools.rb', line 51

def check_r path
  check_tool_ver 'R' do
    `#{path} --version 2>&1 |grep ' version '| cut -f3 -d ' '` if path
  end
  check_r_libs path if path
end

#check_r_libs(r_path) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/cagnut/configuration/checks/tools.rb', line 58

def check_r_libs r_path
  %w(gplots ggplot2 reshape gsalib).each do |lib|
    check_tool_ver "R library: #{lib}" do
      `#{r_path}script -e 'packageVersion("#{lib}")' | cut -f2 -d ' '`
    end
  end
end

#check_ref_fasta(ref_path) ⇒ Object



66
67
68
69
70
71
# File 'lib/cagnut/configuration/checks/tools.rb', line 66

def check_ref_fasta ref_path
  puts 'Checking Reference Files...'
  return if File.exist?(ref_path)
  puts "\tReference not founded in #{ref_path}"
  @check_completed = false
end

#check_tool(tools_path, refs = nil) ⇒ Object



34
35
# File 'lib/cagnut/configuration/checks/tools.rb', line 34

def check_tool tools_path, refs=nil
end

#check_tool_ver(tool) ⇒ Object



37
38
39
40
41
42
# File 'lib/cagnut/configuration/checks/tools.rb', line 37

def check_tool_ver tool
  ver = yield if block_given?
  @check_completed = false if ver.blank?
  ver = ver.blank? ? 'Not Found' : ver.chomp!
  puts "Using #{tool} (#{ver})"
end