wadrc-bcp-scripts 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.svn/entries +41 -0
- data/.svn/format +1 -0
- data/.svn/prop-base/reconstruct_dti_test.rb.svn-base +5 -0
- data/.svn/text-base/reconstruct_dti_test.rb.svn-base +25 -0
- data/Gemfile +4 -0
- data/README.md +5 -0
- data/Rakefile +7 -0
- data/VERSION +1 -0
- data/bin/FS_local_recon +98 -0
- data/bin/FieldmapAtWaisman.rb +35 -0
- data/bin/createFieldmap.rb +33 -0
- data/bin/preprocess_dti.rb +110 -0
- data/bin/run_dti_fit_for_study.sh +26 -0
- data/bin/run_dti_fit_script.sh +28 -0
- data/bin/tensor_transpose.rb +45 -0
- data/lib/.svn/entries +54 -0
- data/lib/.svn/format +1 -0
- data/lib/.svn/prop-base/dti_wrapper.rb.svn-base +5 -0
- data/lib/.svn/prop-base/dtifit_processing.rb.svn-base +5 -0
- data/lib/.svn/text-base/dti_wrapper.rb.svn-base +33 -0
- data/lib/.svn/text-base/dtifit_processing.rb.svn-base +95 -0
- data/lib/additions/NetSshConnectionSession.rb +20 -0
- data/lib/wadrc-bcp-scripts.rb +13 -0
- data/lib/wadrc-bcp-scripts/basic_task.rb +137 -0
- data/lib/wadrc-bcp-scripts/dtitask.rb +156 -0
- data/lib/wadrc-bcp-scripts/fieldmap_classes.rb +166 -0
- data/lib/wadrc-bcp-scripts/freesurfer_roi_task.rb +134 -0
- data/lib/wadrc-bcp-scripts/tensor.rb +25 -0
- data/lib/wadrc-bcp-scripts/version.rb +3 -0
- data/spec/.svn/entries +28 -0
- data/spec/.svn/format +1 -0
- data/spec/FS_local_recon_spec.rb +22 -0
- data/spec/blueprints.rb +12 -0
- data/spec/dtitask_spec.rb +95 -0
- data/spec/examples/johnson.alz.snodrest.visit2.yaml +14 -0
- data/spec/examples/johnson.tbi.aware.visit1.yaml +11 -0
- data/spec/examples/johnson.wrap140.visit1.yaml +12 -0
- data/spec/examples/johnson.wrap140.visit1_TR12s.yaml +12 -0
- data/spec/examples/spec.yaml +22 -0
- data/spec/factories.rb +11 -0
- data/spec/helper_spec.rb +8 -0
- data/test/.svn/entries +41 -0
- data/test/.svn/format +1 -0
- data/test/.svn/prop-base/reconstruct_dti_test.rb.svn-base +5 -0
- data/test/.svn/text-base/reconstruct_dti_test.rb.svn-base +25 -0
- data/test/reconstruct_dti_test.rb +25 -0
- metadata +188 -0
data/.gitignore
ADDED
data/.svn/entries
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
8
|
2
|
+
|
3
|
+
dir
|
4
|
+
146
|
5
|
+
file:///Data/vtrak1/SysAdmin/lab_repository/trunk/ImageProcessing/test
|
6
|
+
file:///Data/vtrak1/SysAdmin/lab_repository
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
2009-05-08T17:32:47.685248Z
|
11
|
+
146
|
12
|
+
erik
|
13
|
+
|
14
|
+
|
15
|
+
svn:special svn:externals svn:needs-lock
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
fd7843e3-2c87-496d-a67a-9fe0c7cb9cb9
|
28
|
+
|
29
|
+
reconstruct_dti_test.rb
|
30
|
+
file
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
2009-05-08T17:33:51.000000Z
|
36
|
+
692bb730b8001354d2fde46acd336087
|
37
|
+
2009-05-08T17:32:47.685248Z
|
38
|
+
146
|
39
|
+
erik
|
40
|
+
has-props
|
41
|
+
|
data/.svn/format
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
8
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'fileutils'
|
7
|
+
require 'dtifit_processing'
|
8
|
+
|
9
|
+
class ReconstructDTI_test < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
@input_directory = '/Data/vtrak1/raw/wrap140/wrp002_5938_03072008/017'
|
12
|
+
@output_directory = '/tmp/wrp002/dti'
|
13
|
+
@subject_prefix = 'wrp002'
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_dti_reconstruction_class
|
17
|
+
ReconstructDTI.reconstruct!(@input_directory, @output_directory, @subject_prefix)
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def teardown
|
22
|
+
FileUtils.rm_r @output_directory
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/FS_local_recon
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Usage: FS_local_recon <computer> -s <subject> <autorecon_options>
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
4
|
+
|
5
|
+
require 'optparse'
|
6
|
+
require 'etc'
|
7
|
+
begin
|
8
|
+
require 'net/ssh'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rubygems'
|
11
|
+
require 'net/ssh'
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'additions/NetSshConnectionSession'
|
15
|
+
|
16
|
+
|
17
|
+
def run!(hostname, subject, options = {})
|
18
|
+
local_dir ||= '/Data/FS_local_recon'
|
19
|
+
server_analysis_dir = options[:server_analysis_dir]
|
20
|
+
dataset_path = File.join(server_analysis_dir, subject)
|
21
|
+
fs_home = options[:fs_home] if options[:fs_home]
|
22
|
+
|
23
|
+
ssh_to_host hostname do |ssh|
|
24
|
+
unless fs_home
|
25
|
+
fs_home = case ssh.exec!("uname").chomp
|
26
|
+
when "Darwin" then "/Applications/freesurfer"
|
27
|
+
when "Linux" then "/usr/local/freesurfer"
|
28
|
+
else raise ScriptError, "Can't determine freesurfer home. Try using --fs-home option if you know what it should be."
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
commands = []
|
33
|
+
commands << "mv #{dataset_path} #{local_dir}; chmod -R ug+w #{File.join(local_dir, subject)}"
|
34
|
+
commands << [
|
35
|
+
"export FREESURFER_HOME=#{fs_home}",
|
36
|
+
"source $FREESURFER_HOME/SetUpFreeSurfer.sh",
|
37
|
+
"export SUBJECTS_DIR=#{local_dir}",
|
38
|
+
"recon-all -s #{subject} #{options[:autorecon_args].join(" ")}"].join(";\n")
|
39
|
+
commands << "mv #{File.join(local_dir, subject)} #{server_analysis_dir}"
|
40
|
+
|
41
|
+
commands.each { |cmd| puts cmd; ssh.exec_realtime(cmd) }
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
def ssh_to_host(hostname, &block)
|
47
|
+
Net::SSH.start(hostname, Etc.getlogin) do |ssh|
|
48
|
+
puts "Running commands on: #{hostname}"
|
49
|
+
yield ssh
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def parse_options
|
54
|
+
options = {:server_analysis_dir => '/Data/vtrak1/analyses/freesurfer/subjects', :autorecon_args => ['-autorecon2-cp', '-autorecon3']}
|
55
|
+
parser = OptionParser.new do |opts|
|
56
|
+
opts.banner = "Usage: #{File.basename(__FILE__)} hostname [options]"
|
57
|
+
|
58
|
+
opts.on('-s', '--subject SUBJECT', "Subject to Recon") do |subject|
|
59
|
+
options[:subject] = subject
|
60
|
+
end
|
61
|
+
|
62
|
+
opts.on('-d', '--dir DIR', "Directory if other than default (#{options[:server_analysis_dir]})") do |server_analysis_dir|
|
63
|
+
options[:server_analysis_dir] = File.expand_path(server_analysis_dir)
|
64
|
+
end
|
65
|
+
|
66
|
+
opts.on('-r', '--recon-args ARGS', Array, "Arguments list for recon-all") do |args|
|
67
|
+
options[:autorecon_args] = args
|
68
|
+
end
|
69
|
+
|
70
|
+
opts.on('-f', '--fs-home DIR', "FREESURFER_HOME directory") do |dir|
|
71
|
+
options[:fs_home] = dir
|
72
|
+
end
|
73
|
+
|
74
|
+
opts.on_tail('-h', '--help', "Show this message") { puts(parser); exit }
|
75
|
+
opts.on_tail("Example: #{File.basename(__FILE__)} nelson -s tami99999 --recon-args -autorecon2-cp,-autorecon3")
|
76
|
+
end
|
77
|
+
|
78
|
+
parser.parse!(ARGV)
|
79
|
+
|
80
|
+
if ARGV.size == 0
|
81
|
+
warn "Error: Missing hostname - maybe you forgot it?"
|
82
|
+
puts(parser); exit
|
83
|
+
end
|
84
|
+
|
85
|
+
if ARGV.size != 1
|
86
|
+
puts "Problem with arguments: #{ARGV}"
|
87
|
+
puts(parser); exit
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
return options
|
92
|
+
end
|
93
|
+
|
94
|
+
if File.basename(__FILE__) == File.basename($0)
|
95
|
+
options = parse_options
|
96
|
+
hostname = ARGV.shift
|
97
|
+
run!(hostname, options[:subject], options)
|
98
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
=begin rdoc
|
4
|
+
This command-line utility executes local preprocessing required for fieldmapping. It prepares a tar-file to transfer to a remote machine for processing, in the form:
|
5
|
+
|
6
|
+
incoming.tar.gz/
|
7
|
+
|-- fieldmap
|
8
|
+
| |-- I0001.dcm
|
9
|
+
| `-- I0002.dcm
|
10
|
+
`-- files_to_fieldmap
|
11
|
+
|-- rSnodC.nii
|
12
|
+
`-- rSnodD.nii
|
13
|
+
=end
|
14
|
+
|
15
|
+
if __FILE__ == $0
|
16
|
+
if ARGV.size != 1
|
17
|
+
puts "Usage: FieldmapAtWaisman.rb "
|
18
|
+
else
|
19
|
+
prefix = ARGV[0]
|
20
|
+
files_to_fieldmap_directory = ARGV[1]
|
21
|
+
dicoms_directory = ARGV[2]
|
22
|
+
|
23
|
+
|
24
|
+
t = LocalFieldmapSetup.new(prefix, files_to_fieldmap_directory, dicoms_directory)
|
25
|
+
|
26
|
+
fieldmap_directory = t.find_fieldmap_directory(dicoms_directory)
|
27
|
+
files_to_fieldmap = t.find_files_to_fieldmap(files_to_fieldmap_directory)
|
28
|
+
local_tarfile = t.create_tarfile(prefix, files_to_fieldmap, fieldmap_directory)
|
29
|
+
remote_tarfile = t.transfer_tarfile_to_move(local_tarfile)
|
30
|
+
t.execute_remote_fieldmapping(remote_tarfile)
|
31
|
+
t.transfer_tarfile_from_remote
|
32
|
+
t.unpack_tarfile_locally
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib')
|
3
|
+
|
4
|
+
require 'wadrc-bcp-scripts/FieldmapAtWaisman'
|
5
|
+
require 'logger'
|
6
|
+
|
7
|
+
=begin rdoc
|
8
|
+
This script creates and applies fieldmaps in a scratch directory and handles some basic file zipping and unzipping.
|
9
|
+
|
10
|
+
Pass in the path to a tar of fieldmaps and files. The file should have two directories inside:
|
11
|
+
incoming.tar.gz/
|
12
|
+
|-- fieldmap
|
13
|
+
| |-- I0001.dcm
|
14
|
+
| `-- I0002.dcm
|
15
|
+
`-- files_to_fieldmap
|
16
|
+
|-- rSnodC.nii
|
17
|
+
`-- rSnodD.nii
|
18
|
+
=end
|
19
|
+
|
20
|
+
if __FILE__ == $0
|
21
|
+
if ARGV.size != 1
|
22
|
+
puts "Usage: createFieldmap.rb incoming_tarfile.tar.gz"
|
23
|
+
else
|
24
|
+
t = FieldmapTask.new(ARGV[0])
|
25
|
+
t.setup_paths
|
26
|
+
tmpdir, fieldmap_directory, files_to_fieldmap = t.unpack(t.incoming_tar_file)
|
27
|
+
Dir.chdir(tmpdir)
|
28
|
+
|
29
|
+
fieldmap_file = t.create_fieldmap(fieldmap_directory)
|
30
|
+
t.apply_fieldmap(fieldmap_file, files_to_fieldmap)
|
31
|
+
t.cleanup(tmpdir)
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
## A command-line DTI-preprocessing script generation utility.
|
3
|
+
|
4
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
5
|
+
require 'yaml'
|
6
|
+
require 'optparse'
|
7
|
+
begin
|
8
|
+
require 'wadrc-bcp-scripts/basic_task'
|
9
|
+
require 'wadrc-bcp-scripts/dtitask'
|
10
|
+
rescue LoadError
|
11
|
+
require 'rubygems'
|
12
|
+
require 'wadrc-bcp-scripts/basic_task'
|
13
|
+
require 'wadrc-bcp-scripts/dtitask'
|
14
|
+
end
|
15
|
+
|
16
|
+
=begin rdoc
|
17
|
+
This library provides basic processing for Diffusion Tensor Images (DTI)
|
18
|
+
This command-line processing script takes raw DTI dicoms and outputs FA, MD &
|
19
|
+
associated diffusion maps (eigenvalues & eigenvectors).
|
20
|
+
|
21
|
+
Currently, the script assumes raw data are unzipped and the output directory
|
22
|
+
exists, the glob and DTI params are passed in with a specification file.
|
23
|
+
=end
|
24
|
+
|
25
|
+
|
26
|
+
def run!
|
27
|
+
# Parse CLI Options and Spec File
|
28
|
+
options = parse_options
|
29
|
+
config = load_spec(options[:spec_file])
|
30
|
+
config.merge!(options)
|
31
|
+
|
32
|
+
# Create a DTI Preprocessing Flow Task and run it.
|
33
|
+
output_directory = ARGV.pop
|
34
|
+
input_directories = ARGV
|
35
|
+
input_directories.each do |input_directory|
|
36
|
+
task = WadrcBcpScripts::Dtitask.new(config)
|
37
|
+
task.reconstruct!(input_directory, output_directory)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
def load_spec(spec_file)
|
43
|
+
if File.exist?(spec_file)
|
44
|
+
YAML::load_file(spec_file)
|
45
|
+
else
|
46
|
+
raise IOError, "Cannot find yaml spec file #{spec_file}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def parse_options
|
52
|
+
options = {:rotate => true}
|
53
|
+
parser = OptionParser.new do |opts|
|
54
|
+
opts.banner = "Usage: #{File.basename(__FILE__)} [options] input_directory output_directory"
|
55
|
+
|
56
|
+
opts.on('-s', '--spec SPEC', "Spec File for script parameters") do |spec_file|
|
57
|
+
options[:spec_file] = spec_file
|
58
|
+
end
|
59
|
+
|
60
|
+
opts.on('-p', '--prefix PREFIX', "Filename Prefix") do |prefix|
|
61
|
+
options[:file_prefix] = prefix
|
62
|
+
end
|
63
|
+
|
64
|
+
opts.on('-d', '--dry-run', "Display Script without executing it.") do
|
65
|
+
options[:dry_run] = true
|
66
|
+
end
|
67
|
+
|
68
|
+
opts.on('-f', '--force', "Overwrite output directory if it exists.") do
|
69
|
+
options[:force_overwrite] = true
|
70
|
+
end
|
71
|
+
|
72
|
+
opts.on('-m', '--mask MASK', "Add an arbitrary mask to apply to data.") do |mask|
|
73
|
+
options[:mask] = File.expand_path(mask)
|
74
|
+
abort "Cannot find mask #{mask}." unless (File.exist?(options[:mask]) || options[:dry_run])
|
75
|
+
end
|
76
|
+
|
77
|
+
opts.on('-t', '--tmp', "Sandbox the input directory in the case of zipped dicoms.") do
|
78
|
+
options[:force_sandbox] = true
|
79
|
+
end
|
80
|
+
|
81
|
+
opts.on('--values VALUES_FILE', "Specify a b-values file.") do |bvalues_file|
|
82
|
+
options[:bvalues_file] = bvalues_file
|
83
|
+
end
|
84
|
+
|
85
|
+
opts.on('--vectors VECTORS_FILE', "Specify a b-vectors file.") do |bvectors_file|
|
86
|
+
options[:bvectors_file] = bvectors_file
|
87
|
+
end
|
88
|
+
|
89
|
+
opts.on('--no-rotate', "Don't rotate vectors prior to processing") do
|
90
|
+
options[:rotate] = false
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
opts.on_tail('-h', '--help', "Show this message") { puts(parser); exit }
|
95
|
+
opts.on_tail("Example: #{File.basename(__FILE__)} -s configuration/dti_spec.yaml -p pd006 raw/pd006 orig/pd006")
|
96
|
+
end
|
97
|
+
parser.parse!(ARGV)
|
98
|
+
|
99
|
+
if ARGV.size == 0
|
100
|
+
# puts "Problem with arguments: #{ARGV}"
|
101
|
+
puts(parser); exit
|
102
|
+
end
|
103
|
+
|
104
|
+
return options
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
if File.basename(__FILE__) == File.basename($0)
|
109
|
+
run!
|
110
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
# run_dti_fit_for_study.sh
|
3
|
+
# Constructs and runs an interface to the preprocess_dti.rb command line
|
4
|
+
# interface for a given study.
|
5
|
+
|
6
|
+
|
7
|
+
# Sample Arguments
|
8
|
+
# raw_dir=/Data/vtrak1/raw/johnson.predict.visit1
|
9
|
+
# study_proc_dir=/Data/vtrak1/preprocessed/visits/johnson.predict.visit1
|
10
|
+
# study_prefix=pdt
|
11
|
+
# yaml_config=/Data/vtrak1/preprocessed/visits/johnson.predict.visit1/dti_config/dti_config.yaml
|
12
|
+
|
13
|
+
raw_dir=$1
|
14
|
+
study_proc_dir=$2
|
15
|
+
study_prefix=$3
|
16
|
+
yaml_config=$4
|
17
|
+
|
18
|
+
for directory in ${raw_dir}/${study_prefix}*; do
|
19
|
+
# Assume that directories in /raw are named <subject>_<exam-number>_<date>
|
20
|
+
subject=`basename $directory | awk -F_ '{print $1}'`
|
21
|
+
|
22
|
+
# Full command for running DTI with Eddy Current Correction
|
23
|
+
ruby -rubygems ~erik/code/ImageProcessing/bin/preprocess_dti.rb -t \
|
24
|
+
-s ${yaml_config} -p ${subject} ${raw_dir}/${subject}*/dicoms/*dti* \
|
25
|
+
${study_proc_dir}/${subject}/dti_FSL_recon
|
26
|
+
done
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
# 05/11/10
|
3
|
+
# Full command for running DTI with Eddy Current Correction and Sundry Options
|
4
|
+
|
5
|
+
# subject=pdt00001;
|
6
|
+
# rawdir=/Data/vtrak1/raw/johnson.predict.visit1
|
7
|
+
# procdir=/Data/vtrak1/preprocessed/visits/johnson.predict.visit1/pdt00001/dti_FSL_recon
|
8
|
+
# yaml_config=/Data/vtrak1/preprocessed/visits/johnson.predict.visit1/dti_config/dti_config.yaml
|
9
|
+
|
10
|
+
|
11
|
+
subject=$1
|
12
|
+
rawdir=$2
|
13
|
+
procdir=$3
|
14
|
+
yaml_config=$4
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
# This is kinda a shity way of doing it, but... It's alright.
|
20
|
+
|
21
|
+
# The reason why you have to give it here, at the final call to
|
22
|
+
# preprocess_dti.rb, is because it's possible that there are more than one
|
23
|
+
# series named dti. The script will handle that, as it will actually process
|
24
|
+
# each series that matches /dti/, but only when they're multilple arguments
|
25
|
+
# given to the preprocess_dti.rb; other shell scripts (like run_dti_fit_script)
|
26
|
+
# would intercept and mess up the arguments.
|
27
|
+
|
28
|
+
# We don't need 2 of these shell scripts now.'
|