Class: FSL::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/fsl-ruby/stats.rb

Constant Summary collapse

@@command_path =

Note - thresholds are not inclusive ie lthresh<allowed<uthresh

'/usr/local/fsl/bin/fslstats'
@@options_map =
{
low_threshold: '-l', # <lthresh> : set lower threshold
up_threshold: '-u', # <uthresh> : set upper threshold
robust_intensity: '-r', # output <robust min intensity> <robust max intensity>
intensity: '-R', # output <min intensity> <max intensity>
entropy: '-e', # output mean entropy ; mean(-i*ln(i))
entropy_nonzero: '-E',# output mean entropy (of nonzero voxels)
voxels: '-v', # output <voxels> <volume>
voxels_nonzero: '-V', # output <voxels> <volume> (for nonzero voxels)
mean: '-m', # output mean
mean_nonzero: '-M',# output mean (for nonzero voxels)
stdev: '-s', # output standard deviation
stdev_nonzero: '-S', # output standard deviation (for nonzero voxels)
smallest_roi: '-w', # output smallest ROI <xmin> <xsize> <ymin> <ysize> <zmin> <zsize> <tmin> <tsize> containing nonzero voxels
coord_maxvoxel: '-x', # output co-ordinates of maximum voxel
coord_minvoxel: '-X', # output co-ordinates of minimum voxel
cog_mm: '-c', # output centre-of-gravity (cog) in mm coordinates
cog_voxel: '-C', # output centre-of-gravity (cog) in voxel coordinates
nth_percentile: '-p', # <n> output nth percentile (n between 0 and 100)
nth_percentage_nonzero: '-P', # <n> output nth percentile (for nonzero voxels)
abs: '-a', # use absolute values of all image intensities
nan_as_zero: '-n', # treat NaN or Inf as zero for subsequent stats
mask: '-k', #<mask> use the specified image (filename) for masking - overrides lower and upper thresholds
hist: '-h', #<nbins> output a histogram (for the thresholded/masked voxels only) with nbins
hist_minmax: '-H' # <nbins> <min> <max>   : output a histogram (for the thresholded/masked voxels only) with nbins and histogram limits of min and max
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_file, separate = false, opt = {}) ⇒ Stats

Returns a new instance of Stats.



73
74
75
76
77
78
# File 'lib/fsl-ruby/stats.rb', line 73

def initialize(input_file, separate=false, opt = {})
	@input_file = input_file
	@basename = File.basename(input_file, '.nii.gz')
	@separate = separate
	@opt = opt
end

Class Method Details

.command_pathObject



42
43
44
# File 'lib/fsl-ruby/stats.rb', line 42

def self.command_path
	@@command_path
end

.command_path=(path) ⇒ Object



38
39
40
# File 'lib/fsl-ruby/stats.rb', line 38

def self.command_path=(path)
	@@command_path = path
end

.options_mapObject



80
81
82
# File 'lib/fsl-ruby/stats.rb', line 80

def self.options_map
	@@options_map
end

Instance Method Details

#argument_listObject



96
97
98
# File 'lib/fsl-ruby/stats.rb', line 96

def argument_list
	map_options(@opt).collect {|k,v| v}.join(' ')
end

#commandObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/fsl-ruby/stats.rb', line 100

def command
	sf = @separate ? '-t' : ''
	command_str = "#{self.class.command_path} #{sf} #{@input_file} #{argument_list}"
	puts "Running FSLSTATS with command: #{command_str}..."
	result = `#{command_str}`
	exit_code = $?
	case exit_code
		when 0
			puts "Done running FSLSTATS."
			return result
		else
			puts "An error ocurred while running FSLSTATS"
	        #   exit_error = Dcm2nii::Runner::UnexpectedExitError.new
	        #   exit_error.exit_code = exit_code
	        #   raise exit_error
	        # end
	end
end

#get_resultObject



119
120
121
# File 'lib/fsl-ruby/stats.rb', line 119

def get_result
			# return `find #{@output_dir} -name *_brain.nii*`.chomp
end

#map_options(opt = {}) ⇒ Object



92
93
94
# File 'lib/fsl-ruby/stats.rb', line 92

def map_options(opt ={})
	opt.inject({}) { |h, (k, v)| h[k] = (self.class.options_map[k] + ' ' + map_vals(v)); h }
end

#map_vals(val) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/fsl-ruby/stats.rb', line 84

def map_vals(val)
	if val == true || val == false
		''
	else
		val.to_s
	end
end