Class: FSL::FIRST
- Inherits:
-
Object
- Object
- FSL::FIRST
- Defined in:
- lib/fsl-ruby/first.rb
Constant Summary collapse
- @@command_path =
e.g.: run_first_all -i im1 -o output_name
'/usr/local/fsl/bin/run_first_all'
- @@options_map =
{ method: '-m', already_bet: '-b', structure: '-s', affine: '-a', threestage: '-3', no_cleanup: '-d', verbose: '-v', help: '-h' }
Class Method Summary collapse
Instance Method Summary collapse
- #argument_list ⇒ Object
- #command ⇒ Object
- #get_result ⇒ Object
-
#initialize(input_file, output_file, opt = {}) ⇒ FIRST
constructor
A new instance of FIRST.
- #map_options(opt = {}) ⇒ Object
- #map_vals(val) ⇒ Object
Constructor Details
#initialize(input_file, output_file, opt = {}) ⇒ FIRST
Returns a new instance of FIRST.
48 49 50 51 52 53 54 |
# File 'lib/fsl-ruby/first.rb', line 48 def initialize(input_file, output_file, opt = {}) @input_file = input_file @basename = File.basename(input_file, '.nii.gz') @output_file = output_file @output_dir = File.dirname(output_file) @opt = opt end |
Class Method Details
.command_path ⇒ Object
32 33 34 |
# File 'lib/fsl-ruby/first.rb', line 32 def self.command_path @@command_path end |
.command_path=(path) ⇒ Object
28 29 30 |
# File 'lib/fsl-ruby/first.rb', line 28 def self.command_path=(path) @@command_path = path end |
.options_map ⇒ Object
56 57 58 |
# File 'lib/fsl-ruby/first.rb', line 56 def self. @@options_map end |
Instance Method Details
#argument_list ⇒ Object
72 73 74 |
# File 'lib/fsl-ruby/first.rb', line 72 def argument_list (@opt).collect {|k,v| v}.join(' ') end |
#command ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/fsl-ruby/first.rb', line 76 def command command_str = "#{self.class.command_path} #{argument_list} -i #{@input_file} -o #{@output_file}" puts "Running FIRST with command: #{command_str}..." result = `#{command_str}` exit_code = $? case exit_code when 0 puts "Done running FIRST." return result else puts "An error ocurred while running FIRST" # exit_error = Dcm2nii::Runner::UnexpectedExitError.new # exit_error.exit_code = exit_code # raise exit_error # end end end |
#get_result ⇒ Object
94 95 96 97 98 99 |
# File 'lib/fsl-ruby/first.rb', line 94 def get_result first_files = {} first_files[:origsegs] = `find #{@output_dir} -name *origsegs.nii*`.chomp first_files[:firstseg] = `find #{@output_dir} -name *firstseg.nii*`.chomp return first_files end |
#map_options(opt = {}) ⇒ Object
68 69 70 |
# File 'lib/fsl-ruby/first.rb', line 68 def (opt ={}) opt.inject({}) { |h, (k, v)| h[k] = (self.class.[k] + ' ' + map_vals(v)); h } end |
#map_vals(val) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/fsl-ruby/first.rb', line 60 def map_vals(val) if val == true || val == false '' else val.to_s end end |