metamri 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/convert_visit.rb +8 -3
- data/bin/import_visit.rb +6 -4
- data/bin/list_visit +69 -0
- data/lib/metamri.rb +8 -0
- data/lib/metamri/core_additions.rb +85 -0
- data/lib/metamri/raw_image_dataset_resource.rb +20 -0
- data/lib/metamri/visit_raw_data_directory_resource.rb +20 -0
- data/lib/raw_image_dataset.rb +23 -1
- data/lib/visit_raw_data_directory.rb +51 -101
- data/metamri.gemspec +6 -3
- data/test/nifti_builder_spec.rb +14 -9
- metadata +7 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.11
|
data/bin/convert_visit.rb
CHANGED
@@ -36,7 +36,8 @@ require 'logger'
|
|
36
36
|
#
|
37
37
|
#
|
38
38
|
# == Usage
|
39
|
-
#
|
39
|
+
#
|
40
|
+
# convert_visit.rb /Data/vtrak1/raw/ries.aware.visit1/awr001_9999_010110/ ries.aware.visit1 /tmp/awr001
|
40
41
|
#
|
41
42
|
# == Example
|
42
43
|
#
|
@@ -66,9 +67,13 @@ if File.basename(__FILE__) == File.basename($PROGRAM_NAME)
|
|
66
67
|
RDoc::usage() if (ARGV[0] == '-h')
|
67
68
|
raw_directory = ARGV[0]
|
68
69
|
|
69
|
-
|
70
|
-
|
70
|
+
|
71
|
+
# Optional Scan Procdedure Codename
|
72
|
+
# If not given this is inferred by VisitRawDataDirectory#get_scan_procedure_based_on_raw_directory
|
73
|
+
scan_procedure_codename = ARGV[1] ? ARGV[1] : nil
|
71
74
|
|
75
|
+
# Optional Output Directory
|
76
|
+
# If not given this is inferred by VisitRawDataDirectory#default_preprocess_directory
|
72
77
|
output_directory = ARGV[2] ? ARGV[2] : nil
|
73
78
|
|
74
79
|
convert_visit(raw_directory, scan_procedure_codename, output_directory)
|
data/bin/import_visit.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#
|
3
3
|
# == Synopsis
|
4
|
-
# A simple utility for importing imaging data collected during one
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
4
|
+
# A simple utility for importing imaging data collected during one
|
5
|
+
# visit into the WADRC Data Tools web application. Data from a visit
|
6
|
+
# is contained in one large directory that may have many subdirectories.
|
7
|
+
# Each individual imaging scan may be composed of an entire directory
|
8
|
+
# of dicom files or one single p-file. This utility scans through all
|
9
|
+
# of the image data sets and retrieved meta-data about the scans from their
|
8
10
|
# header information.
|
9
11
|
#
|
10
12
|
# == Examples
|
data/bin/list_visit
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# == Synopsis
|
4
|
+
# A simple utility for listing visit details and scan acquistion
|
5
|
+
# information from the terminal, either through freshly scanning
|
6
|
+
# the filesystem or connecting to an imaging database and looking
|
7
|
+
# up information through there (for Image Quality Checks, for
|
8
|
+
# example.
|
9
|
+
#
|
10
|
+
# == Examples
|
11
|
+
#
|
12
|
+
# list_visit /Data/vtrak1/raw/ries.aware.visit1/awr001_7854_02102009
|
13
|
+
#
|
14
|
+
# cd /Data/vtrak1/raw/ries.aware.visit1/awr001_7854_02102009
|
15
|
+
# list_visit
|
16
|
+
#
|
17
|
+
# If no raw data directory is given, the current directory will be assumed.
|
18
|
+
# list_visit
|
19
|
+
#
|
20
|
+
# == Usage
|
21
|
+
# list_visit <raw_data_directory>
|
22
|
+
#
|
23
|
+
# For help use: list_vist -h
|
24
|
+
#
|
25
|
+
# == Options
|
26
|
+
# -h, --help Displays help message
|
27
|
+
#
|
28
|
+
# == Author
|
29
|
+
# Erik Kastman
|
30
|
+
# WADRC Imaging Core
|
31
|
+
#
|
32
|
+
|
33
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
34
|
+
|
35
|
+
require 'metamri'
|
36
|
+
require 'pathname'
|
37
|
+
require 'rdoc/usage'
|
38
|
+
require 'logger'
|
39
|
+
|
40
|
+
def list_visit(raw_directory)
|
41
|
+
$LOG = Logger.new(STDOUT)
|
42
|
+
$LOG.level = Logger::INFO
|
43
|
+
visit = VisitRawDataDirectory.new(raw_directory)
|
44
|
+
# visit = VisitRawDataDirectoryResource.find(:all, :from => '/visits/found.xml', :params => {:visit_search => {:rmr => 'rmr'}})
|
45
|
+
|
46
|
+
begin
|
47
|
+
visit.scan
|
48
|
+
# visit.datasets = RawImageDatasetResource.find(:all, :from => "/visits/#{visit.database_id}/image_datasets.xml" )
|
49
|
+
rescue IndexError => e
|
50
|
+
$LOG.error "Are you sure #{raw_directory} is a valid raw visit directory?"
|
51
|
+
raise e
|
52
|
+
rescue Exception => e
|
53
|
+
$LOG.error "There was a problem scanning a dataset in #{visit.visit_directory}... skipping."
|
54
|
+
$LOG.error "Exception message: #{e.message}"
|
55
|
+
raise e
|
56
|
+
end
|
57
|
+
|
58
|
+
visit.to_s
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
if File.basename(__FILE__) == File.basename($PROGRAM_NAME)
|
63
|
+
RDoc::usage() if (ARGV[0] == '-h')
|
64
|
+
|
65
|
+
# Default to scanning the current directory if no argument was given.
|
66
|
+
raw_directory = ARGV[0] ||= File.expand_path('.')
|
67
|
+
|
68
|
+
list_visit(raw_directory)
|
69
|
+
end
|
data/lib/metamri.rb
CHANGED
@@ -4,6 +4,14 @@ require 'raw_image_file'
|
|
4
4
|
require 'raw_image_dataset'
|
5
5
|
require 'visit_raw_data_directory'
|
6
6
|
require 'metamri/core_additions'
|
7
|
+
require 'metamri/raw_image_dataset_resource'
|
8
|
+
require 'metamri/visit_raw_data_directory_resource'
|
9
|
+
|
10
|
+
begin
|
11
|
+
require 'hirb'
|
12
|
+
rescue LoadError => e
|
13
|
+
puts "Hirb must be installed for pretty output. Use 'sudo gem install hirb'"
|
14
|
+
end
|
7
15
|
|
8
16
|
module Metamri
|
9
17
|
end
|
@@ -14,4 +14,89 @@ Does same basic string replacements to ensure valid filenames.
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
end
|
18
|
+
|
19
|
+
class Pathname
|
20
|
+
MIN_PFILE_SIZE = 10_000_000
|
21
|
+
|
22
|
+
def each_subdirectory
|
23
|
+
each_entry do |leaf|
|
24
|
+
next if leaf.to_s =~ /^\./
|
25
|
+
branch = self + leaf
|
26
|
+
next if not branch.directory?
|
27
|
+
next if branch.symlink?
|
28
|
+
branch.each_subdirectory { |subbranch| yield subbranch }
|
29
|
+
yield branch
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def each_pfile(min_file_size = MIN_PFILE_SIZE)
|
34
|
+
entries.each do |leaf|
|
35
|
+
next unless leaf.to_s =~ /^P.*\.7|^P.*\.7\.bz2/
|
36
|
+
branch = self + leaf
|
37
|
+
next if branch.symlink?
|
38
|
+
if branch.size >= min_file_size
|
39
|
+
lc = branch.local_copy
|
40
|
+
begin
|
41
|
+
yield lc
|
42
|
+
rescue Exception => e
|
43
|
+
puts "#{e}"
|
44
|
+
ensure
|
45
|
+
lc.delete
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def first_dicom
|
52
|
+
entries.each do |leaf|
|
53
|
+
branch = self + leaf
|
54
|
+
if leaf.to_s =~ /^I\.|\.dcm(\.bz2)?$|\.0[0-9]+(\.bz2)?$/
|
55
|
+
lc = branch.local_copy
|
56
|
+
begin
|
57
|
+
yield lc
|
58
|
+
rescue Exception => e
|
59
|
+
puts "#{e}"
|
60
|
+
ensure
|
61
|
+
lc.delete
|
62
|
+
end
|
63
|
+
return
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def all_dicoms
|
69
|
+
local_copies = []
|
70
|
+
Dir.mktmpdir do |tempdir|
|
71
|
+
begin
|
72
|
+
|
73
|
+
entries.each do |leaf|
|
74
|
+
branch = self + leaf
|
75
|
+
if leaf.to_s =~ /^I\.|\.dcm(\.bz2)?$|\.0[0-9]+(\.bz2)?$/
|
76
|
+
local_copies << branch.local_copy(tempdir)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
yield local_copies
|
81
|
+
|
82
|
+
ensure
|
83
|
+
local_copies.each { |lc| lc.delete }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
return
|
88
|
+
end
|
89
|
+
|
90
|
+
def local_copy(tempdir = Dir.tmpdir)
|
91
|
+
tfbase = self.to_s =~ /\.bz2$/ ? self.basename.to_s.chomp(".bz2") : self.basename.to_s
|
92
|
+
tfbase.escape_filename
|
93
|
+
tmpfile = File.join(tempdir, tfbase)
|
94
|
+
if self.to_s =~ /\.bz2$/
|
95
|
+
`bunzip2 -k -c '#{self.to_s}' >> '#{tmpfile}'`
|
96
|
+
else
|
97
|
+
FileUtils.cp(self.to_s, tmpfile)
|
98
|
+
end
|
99
|
+
return Pathname.new(tmpfile)
|
100
|
+
end
|
101
|
+
|
17
102
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'active_resource'
|
2
|
+
|
3
|
+
class RawImageDatasetResource < ActiveResource::Base
|
4
|
+
self.site = VisitRawDataDirectory::DATAPANDA_SERVER
|
5
|
+
self.element_name = "image_dataset"
|
6
|
+
|
7
|
+
# Creates a Backwards Transfer to go from ActiveRecord to Metamri Classes
|
8
|
+
# ActiveResource will provide :attr methods for column names from the database,
|
9
|
+
# so check the current schema.rb file for those.
|
10
|
+
def to_metamri_image_dataset
|
11
|
+
# A Metamri Class requires at least one valid image file.
|
12
|
+
# This is a little tricky since we really only care about the variables, not rescanning them.
|
13
|
+
|
14
|
+
Pathname.new(path).first_dicom do |fd|
|
15
|
+
@dataset = RawImageDataset.new( path, [RawImageFile.new(fd)] )
|
16
|
+
end
|
17
|
+
|
18
|
+
return @dataset
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'active_resource'
|
2
|
+
|
3
|
+
DATAPANDA_SERVER = 'http://144.92.151.228'
|
4
|
+
|
5
|
+
class VisitRawDataDirectoryResource < ActiveResource::Base
|
6
|
+
self.site = VisitRawDataDirectory::DATAPANDA_SERVER
|
7
|
+
self.element_name = "visit"
|
8
|
+
|
9
|
+
# Creates a Backwards Transfer to go from ActiveRecord to Metamri Classes
|
10
|
+
# ActiveResource will provide :attr methods for column names from the database,
|
11
|
+
# so check the current schema.rb file for those.
|
12
|
+
def to_metamri_visit_raw_data_directory
|
13
|
+
@visit = VisitRawDataDirectory.new(path)
|
14
|
+
@visit.timestamp = date
|
15
|
+
@visit.rmr_number = rmr
|
16
|
+
@visit.scanner_source = scanner_source
|
17
|
+
@visit.database_id = id
|
18
|
+
return @visit
|
19
|
+
end
|
20
|
+
end
|
data/lib/raw_image_dataset.rb
CHANGED
@@ -177,14 +177,36 @@ have more component files than shell commands can handle.
|
|
177
177
|
end
|
178
178
|
end
|
179
179
|
|
180
|
-
|
181
180
|
|
181
|
+
def file_count
|
182
|
+
@file_count ||= Dir.open(@directory).reject{ |branch| /^\./.match(branch) }.length
|
183
|
+
end
|
184
|
+
|
185
|
+
# Creates an Hirb Table for pretty output of dataset info.
|
186
|
+
# It takes an array of either RawImageDatasets or RawImageDatasetResources
|
187
|
+
def self.to_table(datasets)
|
188
|
+
if datasets.first.class.to_s == "RawImageDatasetResource"
|
189
|
+
datasets = datasets.map { |ds| ds.to_metamri_image_dataset }
|
190
|
+
end
|
191
|
+
|
192
|
+
Hirb::Helpers::AutoTable.render(
|
193
|
+
datasets.sort_by{ |ds| [ds.timestamp, File.basename(ds.directory)] },
|
194
|
+
:headers => { :directory_basename => 'Directory', :series_description => 'Series Description', :file_count => 'File Count'},
|
195
|
+
:fields => [:directory_basename, :series_description, :file_count]
|
196
|
+
)
|
197
|
+
|
198
|
+
end
|
182
199
|
private
|
183
200
|
|
184
201
|
# Gets the earliest timestamp among the raw image files in this dataset.
|
185
202
|
def get_earliest_timestamp
|
186
203
|
@timestamp = (@raw_image_files.sort_by { |i| i.timestamp }).first.timestamp
|
187
204
|
end
|
205
|
+
|
206
|
+
# Directory Basename is hardcoded for Pretty Printing using Hirb, which takes symbols as method names for its columns.
|
207
|
+
def directory_basename
|
208
|
+
File.basename(@directory)
|
209
|
+
end
|
188
210
|
|
189
211
|
end
|
190
212
|
#### END OF CLASS ####
|
@@ -7,17 +7,20 @@ require 'fileutils'
|
|
7
7
|
require 'raw_image_file'
|
8
8
|
require 'raw_image_dataset'
|
9
9
|
require 'sqlite3'
|
10
|
+
require 'logger'
|
10
11
|
|
11
12
|
|
12
13
|
# A shared function that displays a message and the date/time to standard output.
|
13
14
|
def flash(msg)
|
15
|
+
flash_size =msg.size + 20
|
16
|
+
|
14
17
|
puts
|
15
|
-
puts "+" *
|
18
|
+
puts "+" * flash_size
|
16
19
|
printf "\t%s\n", msg
|
17
20
|
printf "\t%s\n", Time.now
|
18
|
-
puts "+" *
|
21
|
+
puts "+" * flash_size
|
19
22
|
puts
|
20
|
-
$LOG.
|
23
|
+
$LOG.debug msg if $LOG
|
21
24
|
end
|
22
25
|
|
23
26
|
|
@@ -37,21 +40,25 @@ class VisitRawDataDirectory
|
|
37
40
|
# The absolute path of the visit directory, as a string.
|
38
41
|
attr_reader :visit_directory
|
39
42
|
# An array of :RawImageDataset objects acquired during this visit.
|
40
|
-
|
43
|
+
attr_accessor :datasets
|
41
44
|
# Timestamp for this visit, obtained from the first :RawImageDataset
|
42
|
-
|
45
|
+
attr_accessor :timestamp
|
43
46
|
# RMR number for this visit.
|
44
|
-
|
47
|
+
attr_accessor :rmr_number
|
45
48
|
# scan_procedure name
|
46
49
|
attr_reader :scan_procedure_name
|
47
50
|
# scanner source
|
48
|
-
|
51
|
+
attr_accessor :scanner_source
|
49
52
|
#
|
50
53
|
attr_accessor :db
|
51
54
|
# Scan ID is the short name for the scan (tbiva018, tbiva018b)
|
52
55
|
attr_accessor :scanid
|
56
|
+
# The id of the visit to be used when doing reverse-lookup in data panda.
|
57
|
+
attr_accessor :database_id
|
53
58
|
|
54
59
|
PREPROCESS_REPOSITORY_DIRECTORY = '/Data/vtrak1/preprocessed/visits'
|
60
|
+
# DATAPANDA_SERVER = 'http://localhost:3000'
|
61
|
+
DATAPANDA_SERVER = 'http://144.92.151.228'
|
55
62
|
|
56
63
|
|
57
64
|
# A new Visit instance needs to know the path to its raw data and scan_procedure name. The scan_procedure
|
@@ -65,6 +72,7 @@ class VisitRawDataDirectory
|
|
65
72
|
@rmr_number = nil
|
66
73
|
@scan_procedure_name = scan_procedure_name.nil? ? get_scan_procedure_based_on_raw_directory : scan_procedure_name
|
67
74
|
@db = nil
|
75
|
+
initialize_log
|
68
76
|
end
|
69
77
|
|
70
78
|
# Recursively walks the filesystem inside the visit directory. At each subdirectory, any and all
|
@@ -72,7 +80,7 @@ class VisitRawDataDirectory
|
|
72
80
|
# @datasets will hold an array of ImageDataset instances. Setting the rmr here can raise an
|
73
81
|
# exception if no valid rmr is found in the datasets, be prepared to catch it.
|
74
82
|
def scan
|
75
|
-
flash "Scanning visit raw data directory #{@visit_directory}"
|
83
|
+
flash "Scanning visit raw data directory #{@visit_directory}" if $LOG.level <= Logger::INFO
|
76
84
|
d = Pathname.new(@visit_directory)
|
77
85
|
d.each_subdirectory do |dd|
|
78
86
|
begin
|
@@ -87,7 +95,7 @@ class VisitRawDataDirectory
|
|
87
95
|
@timestamp = get_visit_timestamp
|
88
96
|
@rmr_number = get_rmr_number
|
89
97
|
@scanner_source = get_scanner_source
|
90
|
-
flash "Completed scanning #{@visit_directory}"
|
98
|
+
flash "Completed scanning #{@visit_directory}" if $LOG.level <= Logger::DEBUG
|
91
99
|
else
|
92
100
|
raise(IndexError, "No datasets could be scanned for directory #{@visit_directory}")
|
93
101
|
end
|
@@ -173,6 +181,30 @@ Returns an array of the created nifti files.
|
|
173
181
|
@scanid ||= File.basename(visit_directory).split('_')[0]
|
174
182
|
end
|
175
183
|
|
184
|
+
def to_s
|
185
|
+
puts; @visit_directory.length.times { print "-" }; puts
|
186
|
+
puts "#{@visit_directory}"
|
187
|
+
puts "#{@rmr_number} - #{@scanner_source}"
|
188
|
+
puts "#{@scan_procedure_name}"
|
189
|
+
puts "#{@scanid}"
|
190
|
+
puts RawImageDataset.to_table(@datasets)
|
191
|
+
return
|
192
|
+
rescue NameError => e
|
193
|
+
# Header Line
|
194
|
+
printf "\t%-15s %-30s [%s]\n", "Directory", "Series Description", "Files"
|
195
|
+
|
196
|
+
# Dataset Lines
|
197
|
+
@datasets.sort_by{|ds| [ds.timestamp, File.basename(ds.directory)] }.each do |dataset|
|
198
|
+
printf "\t%-15s %-30s [%s]\n", File.basename(dataset.directory), dataset.series_description, dataset.file_count
|
199
|
+
end
|
200
|
+
|
201
|
+
# Reminder Line
|
202
|
+
puts "(This would be much prettier if you installed hirb.)"
|
203
|
+
|
204
|
+
return
|
205
|
+
end
|
206
|
+
|
207
|
+
|
176
208
|
private
|
177
209
|
|
178
210
|
def get_existing_dataset_id(ds)
|
@@ -273,7 +305,7 @@ generates an sql insert statement to insert this visit with a given participant
|
|
273
305
|
end
|
274
306
|
|
275
307
|
def import_dataset(rawfile, original_parent_directory)
|
276
|
-
puts "Importing scan session: #{original_parent_directory.to_s} using raw data file: #{rawfile.basename}"
|
308
|
+
puts "Importing scan session: #{original_parent_directory.to_s} using raw data file: #{rawfile.basename}" if $LOG.level <= Logger::DEBUG
|
277
309
|
|
278
310
|
begin
|
279
311
|
rawimagefile = RawImageFile.new(rawfile.to_s)
|
@@ -381,103 +413,21 @@ generates an sql insert statement to insert this visit with a given participant
|
|
381
413
|
|
382
414
|
when /ries.aware.visit1/
|
383
415
|
return 'ries.aware.visit1'
|
416
|
+
|
417
|
+
when /carlson.sharp.visit1/
|
418
|
+
return 'carlson.sharp.visit1'
|
384
419
|
|
385
420
|
else
|
386
421
|
return 'unknown.scan_procedure'
|
387
422
|
end
|
388
423
|
end
|
389
424
|
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
class Pathname
|
399
|
-
MIN_PFILE_SIZE = 10_000_000
|
400
|
-
|
401
|
-
def each_subdirectory
|
402
|
-
each_entry do |leaf|
|
403
|
-
next if leaf.to_s =~ /^\./
|
404
|
-
branch = self + leaf
|
405
|
-
next if not branch.directory?
|
406
|
-
next if branch.symlink?
|
407
|
-
branch.each_subdirectory { |subbranch| yield subbranch }
|
408
|
-
yield branch
|
409
|
-
end
|
410
|
-
end
|
411
|
-
|
412
|
-
def each_pfile(min_file_size = MIN_PFILE_SIZE)
|
413
|
-
entries.each do |leaf|
|
414
|
-
next unless leaf.to_s =~ /^P.*\.7|^P.*\.7\.bz2/
|
415
|
-
branch = self + leaf
|
416
|
-
next if branch.symlink?
|
417
|
-
if branch.size >= min_file_size
|
418
|
-
lc = branch.local_copy
|
419
|
-
begin
|
420
|
-
yield lc
|
421
|
-
rescue Exception => e
|
422
|
-
puts "#{e}"
|
423
|
-
ensure
|
424
|
-
lc.delete
|
425
|
-
end
|
426
|
-
end
|
425
|
+
def initialize_log
|
426
|
+
# If a log hasn't been created, catch that here and go to STDOUT.
|
427
|
+
unless $LOG
|
428
|
+
$LOG = Logger.new(STDOUT)
|
429
|
+
$LOG.level = Logger::DEBUG
|
427
430
|
end
|
428
431
|
end
|
429
|
-
|
430
|
-
def first_dicom
|
431
|
-
entries.each do |leaf|
|
432
|
-
branch = self + leaf
|
433
|
-
if leaf.to_s =~ /^I\.|\.dcm(\.bz2)?$|\.0[0-9]+(\.bz2)?$/
|
434
|
-
lc = branch.local_copy
|
435
|
-
begin
|
436
|
-
yield lc
|
437
|
-
rescue Exception => e
|
438
|
-
puts "#{e}"
|
439
|
-
ensure
|
440
|
-
lc.delete
|
441
|
-
end
|
442
|
-
return
|
443
|
-
end
|
444
|
-
end
|
445
|
-
end
|
446
|
-
|
447
|
-
def all_dicoms
|
448
|
-
local_copies = []
|
449
|
-
Dir.mktmpdir do |tempdir|
|
450
|
-
begin
|
451
|
-
|
452
|
-
entries.each do |leaf|
|
453
|
-
branch = self + leaf
|
454
|
-
if leaf.to_s =~ /^I\.|\.dcm(\.bz2)?$|\.0[0-9]+(\.bz2)?$/
|
455
|
-
local_copies << branch.local_copy(tempdir)
|
456
|
-
end
|
457
|
-
end
|
458
432
|
|
459
|
-
|
460
|
-
|
461
|
-
ensure
|
462
|
-
local_copies.each { |lc| lc.delete }
|
463
|
-
end
|
464
|
-
end
|
465
|
-
|
466
|
-
return
|
467
|
-
end
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
def local_copy(tempdir = Dir.tmpdir)
|
472
|
-
tfbase = self.to_s =~ /\.bz2$/ ? self.basename.to_s.chomp(".bz2") : self.basename.to_s
|
473
|
-
tfbase.escape_filename
|
474
|
-
tmpfile = File.join(tempdir, tfbase)
|
475
|
-
if self.to_s =~ /\.bz2$/
|
476
|
-
`bunzip2 -k -c '#{self.to_s}' >> '#{tmpfile}'`
|
477
|
-
else
|
478
|
-
FileUtils.cp(self.to_s, tmpfile)
|
479
|
-
end
|
480
|
-
return Pathname.new(tmpfile)
|
481
|
-
end
|
482
|
-
|
483
|
-
end
|
433
|
+
end
|
data/metamri.gemspec
CHANGED
@@ -5,14 +5,14 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{metamri}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.11"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kristopher J. Kosmatka"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-02-03}
|
13
13
|
s.description = %q{Extraction of MRI metadata and insertion into compatible sqlite3 databases.}
|
14
14
|
s.email = %q{kk4@medicine.wisc.edu}
|
15
|
-
s.executables = ["
|
15
|
+
s.executables = ["import_study.rb", "import_visit.rb", "import_respiratory_files.rb", "list_visit", "convert_visit.rb"]
|
16
16
|
s.extra_rdoc_files = [
|
17
17
|
"README.rdoc"
|
18
18
|
]
|
@@ -26,8 +26,11 @@ Gem::Specification.new do |s|
|
|
26
26
|
"bin/import_respiratory_files.rb",
|
27
27
|
"bin/import_study.rb",
|
28
28
|
"bin/import_visit.rb",
|
29
|
+
"bin/list_visit",
|
29
30
|
"lib/metamri.rb",
|
30
31
|
"lib/metamri/core_additions.rb",
|
32
|
+
"lib/metamri/raw_image_dataset_resource.rb",
|
33
|
+
"lib/metamri/visit_raw_data_directory_resource.rb",
|
31
34
|
"lib/mysql_tools.rb",
|
32
35
|
"lib/nifti_builder.rb",
|
33
36
|
"lib/raw_image_dataset.rb",
|
data/test/nifti_builder_spec.rb
CHANGED
@@ -4,6 +4,7 @@ require 'rubygems'
|
|
4
4
|
require 'spec'
|
5
5
|
require 'fileutils'
|
6
6
|
require 'tmpdir'
|
7
|
+
require 'metamri/core_additions'
|
7
8
|
require 'visit_raw_data_directory'
|
8
9
|
require 'raw_image_dataset'
|
9
10
|
require 'raw_image_file'
|
@@ -17,20 +18,24 @@ VISIT_FIXTURE_UNZIPPED = File.join(Dir.tmpdir, 'fixtures/visit_raw_data_director
|
|
17
18
|
describe "Convert Unknown Dicoms to Nifti Files" do
|
18
19
|
before(:all) do
|
19
20
|
# Initialize a local scratch directory to hold fixtures for testing if it doesn't already exist.
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
unless File.directory?(VISIT_FIXTURE)
|
22
|
+
FileUtils.mkdir_p(File.dirname(VISIT_FIXTURE))
|
23
|
+
FileUtils.cp_r(VISIT_FIXTURE_SRC, VISIT_FIXTURE)
|
24
|
+
end
|
25
|
+
unless File.directory?(VISIT_FIXTURE_UNZIPPED)
|
26
|
+
FileUtils.cp_r(VISIT_FIXTURE, VISIT_FIXTURE_UNZIPPED)
|
24
27
|
`find #{VISIT_FIXTURE_UNZIPPED} -name '*.bz2' -exec bunzip2 {} \\;`
|
25
|
-
|
28
|
+
end
|
26
29
|
end
|
27
30
|
|
28
31
|
before(:each) do
|
29
32
|
@visit = VisitRawDataDirectory.new(VISIT_FIXTURE, 'johnson.tbi-va.visit1')
|
30
|
-
@
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
Pathname.new(File.join(@visit.visit_directory, '001')).first_dicom do |fd|
|
34
|
+
@dataset = RawImageDataset.new(
|
35
|
+
File.join(VISIT_FIXTURE, '001'),
|
36
|
+
[RawImageFile.new(fd)]
|
37
|
+
)
|
38
|
+
end
|
34
39
|
|
35
40
|
@visit_unzipped = VisitRawDataDirectory.new(VISIT_FIXTURE_UNZIPPED, 'johnson.tbi-va.visit1')
|
36
41
|
@dataset_unzipped = RawImageDataset.new(
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metamri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kristopher J. Kosmatka
|
@@ -9,17 +9,18 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-02-03 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: Extraction of MRI metadata and insertion into compatible sqlite3 databases.
|
17
17
|
email: kk4@medicine.wisc.edu
|
18
18
|
executables:
|
19
|
-
- convert_visit.rb
|
20
19
|
- import_study.rb
|
21
20
|
- import_visit.rb
|
22
21
|
- import_respiratory_files.rb
|
22
|
+
- list_visit
|
23
|
+
- convert_visit.rb
|
23
24
|
extensions: []
|
24
25
|
|
25
26
|
extra_rdoc_files:
|
@@ -34,8 +35,11 @@ files:
|
|
34
35
|
- bin/import_respiratory_files.rb
|
35
36
|
- bin/import_study.rb
|
36
37
|
- bin/import_visit.rb
|
38
|
+
- bin/list_visit
|
37
39
|
- lib/metamri.rb
|
38
40
|
- lib/metamri/core_additions.rb
|
41
|
+
- lib/metamri/raw_image_dataset_resource.rb
|
42
|
+
- lib/metamri/visit_raw_data_directory_resource.rb
|
39
43
|
- lib/mysql_tools.rb
|
40
44
|
- lib/nifti_builder.rb
|
41
45
|
- lib/raw_image_dataset.rb
|