Class: StatsJobGenerator

Inherits:
JobGenerator show all
Defined in:
lib/generators/stats_job_generator.rb

Overview

A class for parsing a data directory and creating a default Stats Job Intialize a StatsJobGenerator with a config hash including the following optional keys:

  • subid : SubjectID (i.e. ‘mrt00015’)

  • conditions : An array of condition names for analysis.

  • scans : A hash containing scan information (labels, bold_reps, etc.)

Instance Attribute Summary

Attributes inherited from JobGenerator

#previous_step, #spec

Instance Method Summary collapse

Methods inherited from JobGenerator

#config_requires, #spec_validates

Constructor Details

#initialize(config = {}) ⇒ StatsJobGenerator

Returns a new instance of StatsJobGenerator.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/generators/stats_job_generator.rb', line 13

def initialize(config = {})
  config_defaults = {}
  config_defaults['epi_task_pattern'] = /Task/i
  config_defaults['regressors_prefix'] = 'rp_a'
  super config_defaults.merge(config)
  
  @spec['step'] = 'stats'

  config_requires 'scans', 'subid', 'conditions', 'responses_dir'
  
  @scans = []
  @config['scans'].each { |scan| @scans << scan if scan['label'] =~ @config['epi_task_pattern'] }
  
end

Instance Method Details

#bold_repsObject



36
37
38
39
40
# File 'lib/generators/stats_job_generator.rb', line 36

def bold_reps
  return @bold_reps if @bold_reps
  bold_reps = []
  @scans.collect {|scan| scan['bold_reps'] - scan['volumes_to_skip']}
end

#buildObject



28
29
30
31
32
33
34
# File 'lib/generators/stats_job_generator.rb', line 28

def build
  @spec['bold_reps']        = bold_reps
  @spec['responses']        = responses
  @spec['conditions']       = @config['conditions']
  @spec['regressorsfiles']  = regressorsfiles
  return @spec 
end

#logfilesObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/generators/stats_job_generator.rb', line 52

def logfiles
  return @logfiles if @logfiles
  if @responses['directory']
    logfiles = Dir.glob(File.join(@responses['directory'], @config['subid'] + "*.txt"))
    raise IOError, "No logfiles found in #{@responses['directory']} matching #{@config['subid']}" if logfiles.empty?
    logfiles = logfiles.collect! {|file| Logfile.new(file)}.sort
    @logfiles = logfiles.collect! {|file| File.basename(file.textfile) }
  else
    puts "Warning: No responses specified."
  end
end

#regressorsfilesObject



64
65
66
67
68
# File 'lib/generators/stats_job_generator.rb', line 64

def regressorsfiles
  return @regressorsfiles if @regressorsfiles
  regressorsfiles = []
  @regressorsfiles = @scans.collect {|scan| "%s%s_%s.txt" % [ @config['regressors_prefix'], @config['subid'], scan['label'] ]}
end

#responsesObject

A getter/builder method for behavioural responses.



43
44
45
46
47
48
49
50
# File 'lib/generators/stats_job_generator.rb', line 43

def responses
  return @responses if @responses
  @responses = {}
  @responses['directory'] = @config['responses_dir']
  @responses['logfiles'] = logfiles

  return @responses
end

#valid?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/generators/stats_job_generator.rb', line 70

def valid?
  spec_validates 'regressorsfiles', 'responses'
end