brainmap-metamri 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/import_study.rb +5 -5
- data/bin/import_visit.rb +6 -6
- data/lib/raw_image_file.rb +13 -6
- data/lib/visit_raw_data_directory.rb +28 -12
- data/metamri.gemspec +1 -1
- metadata +2 -3
data/bin/import_study.rb
CHANGED
@@ -27,7 +27,7 @@
|
|
27
27
|
# Copyright (c) 2009 WADRC Imaging Core.
|
28
28
|
#
|
29
29
|
|
30
|
-
$:.unshift File.join(File.dirname(__FILE__),'..')
|
30
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
31
31
|
|
32
32
|
require 'visit_raw_data_directory'
|
33
33
|
require 'pathname'
|
@@ -65,7 +65,7 @@ STUDIES = {
|
|
65
65
|
:filter => /^esp3/,
|
66
66
|
:codename => 'carlsson.esprit.visit2.9month'
|
67
67
|
},
|
68
|
-
:gallagher_pd => { :dir => '/Data/vtrak1/raw/
|
68
|
+
:gallagher_pd => { :dir => '/Data/vtrak1/raw/gallagher.pd',
|
69
69
|
:logfile => 'gallagher.scan.log',
|
70
70
|
:filter => /^pd..._/,
|
71
71
|
:codename => 'gallagher.pd.visit1'
|
@@ -95,7 +95,7 @@ STUDIES = {
|
|
95
95
|
:filter => /^tbi..._2/,
|
96
96
|
:codename => 'johnson.tbi1000.visit2'
|
97
97
|
},
|
98
|
-
:tbi1000_3 => { :dir => '/Data/vtrak1/raw/
|
98
|
+
:tbi1000_3 => { :dir => '/Data/vtrak1/raw/johnson.tbi.aware.visit3',
|
99
99
|
:logfile => 'tbiaware.visit3.scan.log',
|
100
100
|
:filter => /^tbi..._3$/,
|
101
101
|
:codename => 'johnson.tbiaware.visit3'
|
@@ -141,8 +141,8 @@ def import_study(study, dbfile)
|
|
141
141
|
rescue Exception => e
|
142
142
|
puts "There was a problem scanning a dataset in #{visitdir}... skipping."
|
143
143
|
puts "Exception message: #{e.message}"
|
144
|
-
|
145
|
-
|
144
|
+
log.error "There was a problem scanning a dataset in #{visitdir}... skipping."
|
145
|
+
log.error "Exception message: #{e.message}"
|
146
146
|
ensure
|
147
147
|
v = nil
|
148
148
|
end
|
data/bin/import_visit.rb
CHANGED
@@ -29,12 +29,12 @@
|
|
29
29
|
# Copyright (c) 2009 WADRC Imaging Core.
|
30
30
|
#
|
31
31
|
|
32
|
-
$:.unshift File.join(File.dirname(__FILE__),'..')
|
32
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
33
33
|
|
34
34
|
require 'visit_raw_data_directory'
|
35
35
|
require 'pathname'
|
36
36
|
require 'rdoc/usage'
|
37
|
-
|
37
|
+
require 'logger'
|
38
38
|
|
39
39
|
# == Function
|
40
40
|
# Imports imaging data collected during a single visit into the WADRC Data Tools web application database.
|
@@ -46,17 +46,17 @@ require 'rdoc/usage'
|
|
46
46
|
# import_visit('/Data/vtrak1/raw/alz_2000/alz001','johnson.alz.visit1','/path/to/the/rails/db/production.sqlite3')
|
47
47
|
#
|
48
48
|
def import_visit(raw_directory, scan_procedure_codename, database)
|
49
|
+
log = Logger.new(File.basename(raw_directory))
|
49
50
|
v = VisitRawDataDirectory.new(raw_directory, scan_procedure_codename)
|
50
51
|
puts "+++ Importing #{v.visit_directory} as part of #{v.scan_procedure_name} +++"
|
51
52
|
begin
|
52
53
|
v.scan
|
53
|
-
puts v
|
54
54
|
v.db_insert!(database)
|
55
55
|
rescue Exception => e
|
56
|
-
puts "There was a problem scanning a dataset in #{
|
56
|
+
puts "There was a problem scanning a dataset in #{v.visit_directory}... skipping."
|
57
57
|
puts "Exception message: #{e.message}"
|
58
|
-
|
59
|
-
|
58
|
+
log.error "There was a problem scanning a dataset in #{v.visit_directory}... skipping."
|
59
|
+
log.error "Exception message: #{e.message}"
|
60
60
|
ensure
|
61
61
|
v = nil
|
62
62
|
end
|
data/lib/raw_image_file.rb
CHANGED
@@ -69,15 +69,18 @@ unzip a file to a temporary location, be sure to keep the same filename for the
|
|
69
69
|
temporary file.
|
70
70
|
=end
|
71
71
|
def initialize(pathtofile)
|
72
|
-
|
73
72
|
# raise an error if the file doesn't exist
|
74
73
|
absfilepath = File.expand_path(pathtofile)
|
75
74
|
raise(IOError, "File not found.") if not File.exists?(absfilepath)
|
76
75
|
@filename = File.basename(absfilepath)
|
77
76
|
|
78
77
|
# try to read the header, raise an ioerror if unsuccessful
|
79
|
-
|
80
|
-
|
78
|
+
begin
|
79
|
+
@hdr_data, @hdr_reader = read_header(absfilepath)
|
80
|
+
#puts "@hdr_data: #{@hdr_data}; @hdr_reader: #{@hdr_reader}"
|
81
|
+
rescue Exception => e
|
82
|
+
raise(IOError, "Header not readable. #{e}")
|
83
|
+
end
|
81
84
|
|
82
85
|
# file type is based on file name but only if the header was read successfully
|
83
86
|
@file_type = determine_file_type
|
@@ -86,8 +89,8 @@ temporary file.
|
|
86
89
|
# are not found
|
87
90
|
begin
|
88
91
|
import_hdr
|
89
|
-
rescue
|
90
|
-
raise(IOError, "Header import failed.")
|
92
|
+
rescue Exception => e
|
93
|
+
raise(IOError, "Header import failed. #{e}")
|
91
94
|
end
|
92
95
|
|
93
96
|
# deallocate the header data to save memory space.
|
@@ -242,15 +245,19 @@ private
|
|
242
245
|
Reads the file header using one of the available header reading utilities.
|
243
246
|
Returns both the header data as a one big string, and the name of the utility
|
244
247
|
used to read it.
|
248
|
+
|
249
|
+
Note: The rdgehdr is a binary file; the correct version for your architecture must be installed in the path.
|
245
250
|
=end
|
246
251
|
def read_header(absfilepath)
|
247
252
|
header = `#{DICOM_HDR} #{absfilepath} 2> /dev/null`
|
253
|
+
#header = `#{DICOM_HDR} #{absfilepath}`
|
248
254
|
if ( header.index("ERROR") == nil and
|
249
255
|
header.chomp != "" and
|
250
256
|
header.length > MIN_HDR_LENGTH )
|
251
257
|
return [ header, DICOM_HDR ]
|
252
258
|
end
|
253
259
|
header = `#{RDGEHDR} #{absfilepath} 2> /dev/null`
|
260
|
+
#header = `#{RDGEHDR} #{absfilepath}`
|
254
261
|
if ( header.chomp != "" and
|
255
262
|
header.length > MIN_HDR_LENGTH )
|
256
263
|
return [ header, RDGEHDR ]
|
@@ -277,7 +284,7 @@ Parses the header data and extracts a collection of instance variables. If
|
|
277
284
|
@hdr_data and @hdr_reader are not already availables, this function does nothing.
|
278
285
|
=end
|
279
286
|
def import_hdr
|
280
|
-
|
287
|
+
raise(IndexError, "No Header Data Available.") if @hdr_data == nil
|
281
288
|
dicom_hdr_import if (@hdr_reader == "dicom_hdr")
|
282
289
|
rdgehdr_import if (@hdr_reader == "rdgehdr")
|
283
290
|
end
|
@@ -68,13 +68,22 @@ class VisitRawDataDirectory
|
|
68
68
|
flash "Scanning visit raw data directory #{@visit_directory}"
|
69
69
|
d = Pathname.new(@visit_directory)
|
70
70
|
d.each_subdirectory do |dd|
|
71
|
-
|
72
|
-
|
71
|
+
begin
|
72
|
+
dd.each_pfile { |pf| @datasets << import_dataset(pf, dd) }
|
73
|
+
dd.first_dicom { |fd| @datasets << import_dataset(fd, dd) }
|
74
|
+
rescue Exception => e
|
75
|
+
raise(IndexError, "There was an error scaning dataset #{dd}: #{e}")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
unless @datasets.size == 0
|
80
|
+
@timestamp = get_visit_timestamp
|
81
|
+
@rmr_number = get_rmr_number
|
82
|
+
@scanner_source = get_scanner_source
|
83
|
+
flash "Completed scanning #{@visit_directory}"
|
84
|
+
else
|
85
|
+
raise(IndexError, "No datasets could be scanned for directory #{@visit_directory}")
|
73
86
|
end
|
74
|
-
@timestamp = get_visit_timestamp
|
75
|
-
@rmr_number = get_rmr_number
|
76
|
-
@scanner_source = get_scanner_source
|
77
|
-
flash "Completed scanning #{@visit_directory}"
|
78
87
|
end
|
79
88
|
|
80
89
|
# use this to initialize Visit objects in the rails app
|
@@ -219,12 +228,19 @@ class VisitRawDataDirectory
|
|
219
228
|
enter_info_in_db, conference, compile_folder, dicom_dvd, user_id, path, scanner_source, created_at, updated_at)
|
220
229
|
VALUES
|
221
230
|
('#{@timestamp.to_s}', '#{scan_procedure_id.to_s}', '', '', '#{@rmr_number}', 'no', '', 'no', 'no',
|
222
|
-
'no', 'no', 'no', 'no', 'no', 'no', 'no', 'no', 'no', 'no', 'no', NULL, '#{@visit_directory}', #{@scanner_source}, '#{DateTime.now}', '#{DateTime.now}')"
|
231
|
+
'no', 'no', 'no', 'no', 'no', 'no', 'no', 'no', 'no', 'no', 'no', NULL, '#{@visit_directory}', '#{@scanner_source}', '#{DateTime.now}', '#{DateTime.now}')"
|
223
232
|
end
|
224
233
|
|
225
234
|
def import_dataset(rawfile, original_parent_directory)
|
226
235
|
puts "Importing scan session: #{original_parent_directory.to_s} using raw data file: #{rawfile.basename}"
|
227
|
-
|
236
|
+
|
237
|
+
begin
|
238
|
+
rawimagefile = RawImageFile.new(rawfile.to_s)
|
239
|
+
rescue Exception => e
|
240
|
+
raise(IOError, "Trouble reading raw image file #{rawfile}. #{e}")
|
241
|
+
end
|
242
|
+
|
243
|
+
return RawImageDataset.new(original_parent_directory.to_s, [rawimagefile])
|
228
244
|
end
|
229
245
|
|
230
246
|
def get_visit_timestamp
|
@@ -340,8 +356,8 @@ class Pathname
|
|
340
356
|
lc = branch.local_copy
|
341
357
|
begin
|
342
358
|
yield lc
|
343
|
-
rescue
|
344
|
-
#
|
359
|
+
rescue Exception => e
|
360
|
+
puts "#{e}"
|
345
361
|
ensure
|
346
362
|
lc.delete
|
347
363
|
end
|
@@ -356,8 +372,8 @@ class Pathname
|
|
356
372
|
lc = branch.local_copy
|
357
373
|
begin
|
358
374
|
yield lc
|
359
|
-
rescue
|
360
|
-
#
|
375
|
+
rescue Exception => e
|
376
|
+
puts "#{e}"
|
361
377
|
ensure
|
362
378
|
lc.delete
|
363
379
|
end
|
data/metamri.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brainmap-metamri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kristopher J. Kosmatka
|
@@ -49,7 +49,6 @@ files:
|
|
49
49
|
- metamri.gemspec
|
50
50
|
has_rdoc: true
|
51
51
|
homepage: http://github.com/brainmap/metamri
|
52
|
-
licenses:
|
53
52
|
post_install_message:
|
54
53
|
rdoc_options:
|
55
54
|
- --line-numbers
|
@@ -75,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
74
|
requirements: []
|
76
75
|
|
77
76
|
rubyforge_project: metamri
|
78
|
-
rubygems_version: 1.
|
77
|
+
rubygems_version: 1.2.0
|
79
78
|
signing_key:
|
80
79
|
specification_version: 2
|
81
80
|
summary: Extraction of MRI metadata and insertion into compatible sqlite3 databases.
|