metamri 0.1.18 → 0.1.19
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/list_visit +43 -13
- data/lib/metamri/core_additions.rb +19 -0
- data/lib/metamri/raw_image_dataset_resource.rb +0 -2
- data/lib/metamri/visit_raw_data_directory.rb +12 -2
- data/lib/metamri/visit_raw_data_directory_resource.rb +0 -2
- data/lib/metamri.rb +7 -0
- data/metamri.gemspec +4 -4
- metadata +15 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.19
|
data/bin/list_visit
CHANGED
@@ -33,29 +33,42 @@
|
|
33
33
|
|
34
34
|
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
35
35
|
|
36
|
-
require 'metamri'
|
37
36
|
require 'pathname'
|
38
|
-
require '
|
39
|
-
|
37
|
+
require 'logger'
|
38
|
+
require 'metamri'
|
40
39
|
|
41
|
-
def
|
40
|
+
def run!
|
41
|
+
options = parse_options
|
42
|
+
|
43
|
+
# Default to scanning the current directory if no argument was given.
|
44
|
+
raw_directory = ARGV[0] ||= Dir.pwd
|
45
|
+
raw_directory = File.expand_path(raw_directory)
|
46
|
+
|
47
|
+
list_visit raw_directory, options
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
def list_visit(raw_directory, options = {})
|
42
52
|
unless $LOG
|
43
53
|
$LOG = Logger.new(STDOUT)
|
44
|
-
$LOG.level = Logger::INFO
|
54
|
+
$LOG.level = options[:verbose] ? Logger::DEBUG : Logger::INFO
|
45
55
|
end
|
46
56
|
|
47
57
|
# First try to lookup Visit and Datasets through active_resource
|
48
58
|
# Then fall back to scanning them fresh using the metamri classes.
|
49
59
|
|
50
60
|
begin
|
61
|
+
raise ScriptError, "Scaning filesystem directly..." if options[:force_scan]
|
62
|
+
|
51
63
|
visit = VisitRawDataDirectoryResource.find(:first, :params => {:search => {:path => raw_directory}})
|
64
|
+
|
52
65
|
raise IOError.new("Could not lookup visit using path.") unless visit
|
53
66
|
raise IOError.new("Returned visit does not match path.") unless visit.path == raw_directory
|
54
|
-
rescue IOError => e
|
67
|
+
rescue ScriptError, IOError => e
|
55
68
|
puts e
|
56
69
|
visit = VisitRawDataDirectory.new(raw_directory)
|
57
70
|
begin
|
58
|
-
visit.scan
|
71
|
+
visit.scan(options)
|
59
72
|
rescue IndexError => e
|
60
73
|
$LOG.error "Are you sure #{raw_directory} is a valid raw visit directory?"
|
61
74
|
raise e
|
@@ -69,12 +82,29 @@ def list_visit(raw_directory)
|
|
69
82
|
|
70
83
|
end
|
71
84
|
|
72
|
-
|
73
|
-
|
85
|
+
def parse_options
|
86
|
+
options = Hash.new
|
87
|
+
parser = OptionParser.new do |opts|
|
88
|
+
opts.banner = "Usage: #{File.basename(__FILE__)} [options] [directory]"
|
74
89
|
|
75
|
-
|
76
|
-
|
77
|
-
|
90
|
+
opts.on('-s', '--scan', "Scan filesystem directly instead of checking database first.") do
|
91
|
+
options[:force_scan] = true
|
92
|
+
end
|
93
|
+
|
94
|
+
opts.on('-v', '--verbose', "Be wordy.") do
|
95
|
+
options[:verbose] = true
|
96
|
+
end
|
97
|
+
|
98
|
+
opts.on_tail('-h', '--help', "Show this message") { puts(parser); exit }
|
99
|
+
opts.on_tail("If no directory is given, default is the current directory.")
|
100
|
+
opts.on_tail("Example: #{File.basename(__FILE__)} pd006")
|
78
101
|
|
79
|
-
|
102
|
+
end
|
103
|
+
parser.parse!(ARGV)
|
104
|
+
|
105
|
+
return options
|
106
|
+
end
|
107
|
+
|
108
|
+
if File.basename(__FILE__) == File.basename($PROGRAM_NAME)
|
109
|
+
run!
|
80
110
|
end
|
@@ -92,6 +92,25 @@ class Pathname
|
|
92
92
|
return
|
93
93
|
end
|
94
94
|
|
95
|
+
def recursive_local_copy(ignore_patterns = [], &block)
|
96
|
+
tempdir = Dir.mktmpdir('local_orig')
|
97
|
+
|
98
|
+
entries.each do |leaf|
|
99
|
+
branch = self + leaf
|
100
|
+
next if branch.directory?
|
101
|
+
next if ignore_patterns.collect { |pat| leaf.to_s =~ pattern }
|
102
|
+
next if branch.should_be_skipped
|
103
|
+
lc = branch.local_copy(tempdir)
|
104
|
+
lc.chmod(0444 | 0200 | 0020 )
|
105
|
+
end
|
106
|
+
|
107
|
+
return tempdir
|
108
|
+
end
|
109
|
+
|
110
|
+
def should_be_skipped
|
111
|
+
self.to_s =~ /^\./ || self.symlink?
|
112
|
+
end
|
113
|
+
|
95
114
|
=begin
|
96
115
|
Creates a local, unzipped copy of a file for use in scanning.
|
97
116
|
Will return a pathname to the local copy if called directly, or can also be
|
@@ -6,6 +6,7 @@ require 'tmpdir'
|
|
6
6
|
require 'fileutils'
|
7
7
|
require 'sqlite3'
|
8
8
|
require 'logger'
|
9
|
+
require 'pp'
|
9
10
|
require 'metamri/raw_image_file'
|
10
11
|
require 'metamri/raw_image_dataset'
|
11
12
|
|
@@ -81,11 +82,20 @@ class VisitRawDataDirectory
|
|
81
82
|
# pfiles are scanned and imported in addition to one and only one dicom file. After scanning
|
82
83
|
# @datasets will hold an array of ImageDataset instances. Setting the rmr here can raise an
|
83
84
|
# exception if no valid rmr is found in the datasets, be prepared to catch it.
|
84
|
-
|
85
|
+
#
|
86
|
+
# Run a scan with the following options:
|
87
|
+
# - :ignore_patterns - An array of Regular Expressions that will be used to skip heavy directories.
|
88
|
+
def scan(options = {})
|
85
89
|
flash "Scanning visit raw data directory #{@visit_directory}" if $LOG.level <= Logger::INFO
|
90
|
+
default_options = {:ignore_patterns => []}
|
91
|
+
options = default_options.merge(options)
|
92
|
+
puts "Ignoring directories matching: #{options[:ignore_patterns].join(", ")}" unless options[:ignore_patterns].empty?
|
93
|
+
|
86
94
|
d = Pathname.new(@visit_directory)
|
87
95
|
d.each_subdirectory do |dd|
|
88
|
-
begin
|
96
|
+
begin
|
97
|
+
matches = options[:ignore_patterns].collect {|pat| dd.to_s =~ pat ? dd : nil }.compact
|
98
|
+
next unless matches.empty?
|
89
99
|
dd.each_pfile { |pf| @datasets << import_dataset(pf, dd) }
|
90
100
|
dd.first_dicom { |fd| @datasets << import_dataset(fd, dd) }
|
91
101
|
rescue Exception => e
|
data/lib/metamri.rb
CHANGED
data/metamri.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
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.19"
|
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-07-09}
|
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
15
|
s.executables = ["import_study.rb", "import_visit.rb", "import_respiratory_files.rb", "list_visit", "convert_visit.rb"]
|
@@ -50,7 +50,7 @@ Gem::Specification.new do |s|
|
|
50
50
|
s.homepage = %q{http://github.com/brainmap/metamri}
|
51
51
|
s.rdoc_options = ["--charset=UTF-8"]
|
52
52
|
s.require_paths = ["lib"]
|
53
|
-
s.rubygems_version = %q{1.3.
|
53
|
+
s.rubygems_version = %q{1.3.7}
|
54
54
|
s.summary = %q{MRI metadata}
|
55
55
|
s.test_files = [
|
56
56
|
"test/nifti_builder_spec.rb",
|
@@ -65,7 +65,7 @@ Gem::Specification.new do |s|
|
|
65
65
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
66
66
|
s.specification_version = 3
|
67
67
|
|
68
|
-
if Gem::Version.new(Gem::
|
68
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
69
69
|
s.add_runtime_dependency(%q<sqlite3-ruby>, [">= 0"])
|
70
70
|
s.add_runtime_dependency(%q<dicom>, [">= 0"])
|
71
71
|
s.add_development_dependency(%q<rspec>, [">= 0"])
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metamri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 61
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
9
|
+
- 19
|
10
|
+
version: 0.1.19
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Kristopher J. Kosmatka
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-07-09 00:00:00 -05:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: sqlite3-ruby
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
27
30
|
segments:
|
28
31
|
- 0
|
29
32
|
version: "0"
|
@@ -33,9 +36,11 @@ dependencies:
|
|
33
36
|
name: dicom
|
34
37
|
prerelease: false
|
35
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
36
40
|
requirements:
|
37
41
|
- - ">="
|
38
42
|
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
39
44
|
segments:
|
40
45
|
- 0
|
41
46
|
version: "0"
|
@@ -45,9 +50,11 @@ dependencies:
|
|
45
50
|
name: rspec
|
46
51
|
prerelease: false
|
47
52
|
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
48
54
|
requirements:
|
49
55
|
- - ">="
|
50
56
|
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
51
58
|
segments:
|
52
59
|
- 0
|
53
60
|
version: "0"
|
@@ -105,23 +112,27 @@ rdoc_options:
|
|
105
112
|
require_paths:
|
106
113
|
- lib
|
107
114
|
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
108
116
|
requirements:
|
109
117
|
- - ">="
|
110
118
|
- !ruby/object:Gem::Version
|
119
|
+
hash: 3
|
111
120
|
segments:
|
112
121
|
- 0
|
113
122
|
version: "0"
|
114
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
115
125
|
requirements:
|
116
126
|
- - ">="
|
117
127
|
- !ruby/object:Gem::Version
|
128
|
+
hash: 3
|
118
129
|
segments:
|
119
130
|
- 0
|
120
131
|
version: "0"
|
121
132
|
requirements: []
|
122
133
|
|
123
134
|
rubyforge_project:
|
124
|
-
rubygems_version: 1.3.
|
135
|
+
rubygems_version: 1.3.7
|
125
136
|
signing_key:
|
126
137
|
specification_version: 3
|
127
138
|
summary: MRI metadata
|