Class: Nimbus::Application

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

Overview

Nimbus main application object.

When invoking nimbus from the command line, a Nimbus::Application object is created and run.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(c = nil) ⇒ Application

Initialize a Nimbus::Application object. Check and load the configuration options.



14
15
16
17
18
19
20
# File 'lib/nimbus/application.rb', line 14

def initialize(c = nil)
  @config = c unless c.nil?
  nimbus_exception_handling do
    config.load
    @forest = nil
  end
end

Instance Attribute Details

#configObject

Creates an instance of Nimbus::Configuration if it does not exist. This config object contains every option to be used for the random forest including the user input set through the config.yml file.



52
53
54
# File 'lib/nimbus/application.rb', line 52

def config
  @config
end

Instance Method Details

#display_error_message(ex) ⇒ Object

Display an error message that caused a exception.



72
73
74
75
76
77
78
79
80
# File 'lib/nimbus/application.rb', line 72

def display_error_message(ex)
  Nimbus.error_message "* Nimbus encountered an error! The random forest was not generated *"
  Nimbus.error_message "#{ex.class}: #{ex.message}"
  # if config.trace
  #   Nimbus.error_message ex.backtrace.join("\n")
  # else
  #   Nimbus.error_message "(See full error trace by running Nimbus with --trace)"
  # end
end

#nimbus_exception_handlingObject

Provides the default exception handling for the given block.



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/nimbus/application.rb', line 57

def nimbus_exception_handling
  begin
    yield
  rescue SystemExit => ex
    raise
  rescue Nimbus::Error => ex
    display_error_message(ex)
    Nimbus.stop
  rescue Exception => ex
    display_error_message(ex)
    Nimbus.stop
  end
end

#runObject

Run the Nimbus application. The run method performs the following three steps:

  • Create a Nimbus::Forest object.

  • Decide action to take: training a random forest and/or use the forest to predict values for a testing set

  • Write results to output files.



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

def run
  nimbus_exception_handling do

    if @config.do_training && @config.load_training_data
      @forest = ::Nimbus::Forest.new @config
      @forest.grow
      output_random_forest_file(@forest)
      output_tree_errors_file(@forest)
      output_training_file_predictions(@forest)
      output_snp_importances_file(@forest) if @config.do_importances
    end

    if @config.do_testing
      @forest = @config.load_forest if @config.forest_file
      @forest.traverse
      output_testing_set_predictions(@forest)
    end

  end
end