Module: DefaultPreproc
- Included in:
- Preprocessing
- Defined in:
- lib/default_methods/default_preproc.rb
Overview
Shared preprocessing routines for rpipe
Instance Method Summary collapse
- #check_permissions(files) ⇒ Object
-
#customize_templates ⇒ Object
Customizes the template job in preproc_spec to be specific for this particular preproc job.
-
#deal_with_motion ⇒ Object
Calculates the realignment motion derivatives and checks that displacement in all directions was less than the MOTION_THRESHOLD.
-
#link_files_into_proc ⇒ Object
Links all the slice timing corrected data from the source “orig” directory using a wildcard a$subid*.nii, where subid is the subject id specified in the preproc_spec hash.
-
#preproc_visit ⇒ Object
(also: #perform)
Runs the preprocessing job, including spm job customization, run spm job, and handling motion issues.
-
#run_spm_jobs ⇒ Object
Runs the customized spm job using the shell script runSpmJob.sh.
Instance Method Details
#check_permissions(files) ⇒ Object
34 35 36 37 38 |
# File 'lib/default_methods/default_preproc.rb', line 34 def (files) unwritable = [] files.collect { |file| unwritable << file unless File.writable?(file) } raise IOError, "Cannot write to #{unwritable.join(", ")} files." unless unwritable.empty? end |
#customize_templates ⇒ Object
Customizes the template job in preproc_spec to be specific for this particular preproc job. Performs to recursive string replacements inside the spm job:
-
path inside template is replaced with destination “proc” directory
-
subid inside template is replaced with the current subid
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/default_methods/default_preproc.rb', line 44 def customize_templates flash "Customizing template SPM job: #{@tspec['job']}" replacecmd = "spmjobStringReplace.sh" templatejob = File.join(@spmdir, @tspec['job']) thisjob = @subid + '_preproc.mat' File.copy(templatejob, thisjob) system("#{replacecmd} #{thisjob} #{@tspec['path']} #{@procdir} #{thisjob}") system("#{replacecmd} #{thisjob} #{@tspec['subid']} #{@subid} #{thisjob}") end |
#deal_with_motion ⇒ Object
Calculates the realignment motion derivatives and checks that displacement in all directions was less than the MOTION_THRESHOLD. Operates on all files in the current working directory that match rp_a*txt (SPM convention). Uses two shell scripts that must both be available on the local machine:
-
calc_derivs.sh
-
fmri_motion_check.sh
69 70 71 72 73 74 75 |
# File 'lib/default_methods/default_preproc.rb', line 69 def deal_with_motion flash "Calculating motion derivatives and checking for excessive motion" Dir.glob("rp_a*txt").each do |rp| run("calc_derivs.sh #{rp}") run("fmri_motion_check.sh #{rp} #{@motion_threshold}") end end |
#link_files_into_proc ⇒ Object
Links all the slice timing corrected data from the source “orig” directory using a wildcard a$subid*.nii, where subid is the subject id specified in the preproc_spec hash.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/default_methods/default_preproc.rb', line 23 def link_files_into_proc flash "Linking files from #{@origdir} into #{@procdir}" wildcard = File.join(@origdir,"a*#{@subid}*.nii") files = Dir.glob(wildcard) unless files.empty? system("ln -s #{wildcard} #{@procdir}") else raise(IOError, "No files matching #{wildcard} found.") end end |
#preproc_visit ⇒ Object Also known as: perform
Runs the preprocessing job, including spm job customization, run spm job, and handling motion issues. This function assumes a destination directory is set up; it will overwrite preexisting data. Careful!
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/default_methods/default_preproc.rb', line 6 def preproc_visit $Log.info "Spatial Preprocessing Subject: #{@subid}" setup_directory(@procdir, "PREPROC") Dir.chdir(@procdir) do link_files_into_proc customize_templates run_spm_jobs deal_with_motion end end |
#run_spm_jobs ⇒ Object
Runs the customized spm job using the shell script runSpmJob.sh. Make sure this is available at your site.
57 58 59 60 61 |
# File 'lib/default_methods/default_preproc.rb', line 57 def run_spm_jobs thisjob = "#{@subid}_preproc.mat" flash "Running spatial preprocessing SPM job: #{thisjob}" system("runSpmJob.sh #{thisjob}") end |