metamri 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -36,6 +36,7 @@ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
36
36
  require 'pathname'
37
37
  require 'logger'
38
38
  require 'metamri'
39
+ require 'optparse'
39
40
 
40
41
  def run!
41
42
  options = parse_options
@@ -82,7 +83,7 @@ def list_visit(raw_directory, options = {})
82
83
 
83
84
  raise IOError.new("Could not lookup visit using path #{lookup_path}.") unless visit
84
85
  raise IOError.new("Returned visit's path #{visit.path} does not match path.") unless visit.path == File.expand_path(lookup_path)
85
- rescue ScriptError, IOError => e
86
+ rescue ActiveResource::ConnectionError, ScriptError, IOError => e
86
87
  puts e unless options[:verbose] == false
87
88
  visit = VisitRawDataDirectory.new(raw_directory)
88
89
  begin
@@ -13,6 +13,7 @@ require 'metamri/raw_image_dataset'
13
13
  require 'metamri/visit_raw_data_directory'
14
14
  require 'metamri/raw_image_dataset_resource'
15
15
  require 'metamri/visit_raw_data_directory_resource'
16
+ require 'metamri/image_dataset_quality_check_resource'
16
17
 
17
18
  # require 'metamri/raw_image_dataset_thumbnail'
18
19
  # TODO Move raw_image_dataset_thumbnail out of metamri.
@@ -57,7 +57,7 @@ class Pathname
57
57
  def first_dicom
58
58
  entries.each do |leaf|
59
59
  branch = self + leaf
60
- if leaf.to_s =~ /^I\.(\.bz2)?$|\.dcm(\.bz2)?$|[A-Za-z^P]\.[0-9]+(\.bz2)?$/
60
+ if leaf.to_s =~ /^I\..*(\.bz2)?$|\.dcm(\.bz2)?$|\.[0-9]{2,}(\.bz2)?$/
61
61
  lc = branch.local_copy
62
62
  begin
63
63
  yield lc
@@ -22,5 +22,25 @@ class ImageDatasetQualityCheckResource < ActiveResource::Base
22
22
  self.site = VisitRawDataDirectory::DATAPANDA_SERVER
23
23
  self.element_name = "image_dataset_quality_check"
24
24
 
25
+ PASSING_STATUSES = Set.new(%w(complete pass))
26
+ FAILING_STATUSES = Set.new( ["Incomplete","Mild","Moderate","Severe","Limited Activation","No activation","No pass"] )
25
27
 
28
+ # Returns an array of hashes for failed checks.
29
+ def failed_checks
30
+ failed_checks = Array.new
31
+ self.attribute_names.each_pair do |name, value|
32
+ unless name.blank?
33
+ if FAILING_STATUSES.include?(value)
34
+ comment = instance_values['attributes']["#{name}_comment"]
35
+ failed_checks << {:name => name, :value => value, :comment => comment }
36
+ end
37
+ end
38
+ end
39
+ return failed_checks
40
+ end
41
+
42
+ def attribute_names
43
+ instance_values['attributes']
44
+ end
45
+
26
46
  end
@@ -98,8 +98,30 @@ class RawImageDatasetResource < ActiveResource::Base
98
98
  return relative_dataset_path
99
99
  end
100
100
 
101
- def image_quality_checks
102
-
101
+ # Queries ActiveResource for an array of ImageDatasetQualityCheckResources
102
+ def image_dataset_quality_checks
103
+ @image_dataset_quality_checks ||= ImageDatasetQualityCheckResource.find(:all, :params => {:image_dataset_id => id })
104
+ end
105
+
106
+ def image_dataset_quality_checks_tablerow
107
+ output = []
108
+ unless image_dataset_quality_checks.empty?
109
+ image_dataset_quality_checks.each do |qc|
110
+ qc.failed_checks.each do |check|
111
+ output << "* #{check[:name].capitalize.gsub("_", " ")} (#{check[:value]}): #{check[:comment]}."
112
+ end
113
+
114
+ output << "Concerns: #{qc.other_issues}" if qc.other_issues
115
+
116
+ if output.empty?
117
+ output << "Good"
118
+ end
119
+
120
+ # Add QC date at end.
121
+ output << "[#{qc.attribute_names['created_at'].strftime('%D')}]"
122
+ end
123
+ end
124
+ return output.join(" ")
103
125
  end
104
126
 
105
127
  # Creates an Hirb Table for pretty output of dataset info.
@@ -107,12 +129,12 @@ class RawImageDatasetResource < ActiveResource::Base
107
129
  def self.to_table(datasets)
108
130
  Hirb::Helpers::AutoTable.render(
109
131
  datasets.sort_by{ |ds| [ds.timestamp, File.basename(ds.path)] },
110
- :headers => { :relative_dataset_path => 'Dataset', :series_description => 'Series Details', :file_count => "File Count", },
111
- :fields => [:relative_dataset_path, :series_description, :file_count],
132
+ :headers => { :relative_dataset_path => 'Dataset', :series_description => 'Series Details', :file_count => "File Count", :image_dataset_quality_checks_tablerow => "Quality Checks"},
133
+ :fields => [:relative_dataset_path, :series_description, :file_count, :image_dataset_quality_checks_tablerow],
112
134
  :description => false # Turn off rendering row count description at bottom.
113
135
  )
114
136
  rescue NameError => e
115
- puts e
137
+ raise e
116
138
 
117
139
  # Header Line
118
140
  printf "\t%-15s %-30s [%s]\n", "Directory", "Series Description", "Files"
@@ -125,6 +147,6 @@ class RawImageDatasetResource < ActiveResource::Base
125
147
  # Reminder Line
126
148
  puts "(This would be much prettier if you installed hirb.)"
127
149
  return
128
- end
150
+ end
129
151
 
130
152
  end
@@ -59,7 +59,7 @@ class VisitRawDataDirectory
59
59
 
60
60
  PREPROCESS_REPOSITORY_DIRECTORY = '/Data/vtrak1/preprocessed/visits'
61
61
  # DATAPANDA_SERVER = 'http://localhost:3000'
62
- DATAPANDA_SERVER = 'http://144.92.151.228'
62
+ DATAPANDA_SERVER = 'http://nelson'
63
63
 
64
64
 
65
65
  # A new Visit instance needs to know the path to its raw data and scan_procedure name. The scan_procedure
@@ -95,7 +95,7 @@ class VisitRawDataDirectory
95
95
  begin
96
96
  matches = options[:ignore_patterns].collect {|pat| dd.to_s =~ pat ? dd : nil }.compact
97
97
  next unless matches.empty?
98
- dd.each_pfile { |pf| @datasets << import_dataset(pf, dd); (print "."; STDOUT.flush) if $LOG.level == Logger::INFO }
98
+ dd.each_pfile { |pf| @datasets << import_dataset(pf, dd); (print "."; STDOUT.flush) if $LOG.level == Logger::INFO }
99
99
  dd.first_dicom { |fd| @datasets << import_dataset(fd, dd); (print "."; STDOUT.flush) if $LOG.level == Logger::INFO }
100
100
  rescue StandardError => e
101
101
  raise(e, "There was an error scaning dataset #{dd}: #{e}")
@@ -39,6 +39,7 @@ class VisitRawDataDirectoryResource < ActiveResource::Base
39
39
  # puts "#{@scan_procedure_name}"
40
40
  puts RawImageDatasetResource.to_table(datasets)
41
41
  puts "Notes: " + notes unless notes.nil? or notes.empty?
42
+ puts "#{VisitRawDataDirectory::DATAPANDA_SERVER}/visits/#{id}"
42
43
  end
43
44
 
44
45
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{metamri}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
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-11-19}
12
+ s.date = %q{2010-11-22}
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 = ["convert_visit.rb", "import_visit.rb", "import_respiratory_files.rb", "import_study.rb", "list_visit"]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristopher J. Kosmatka
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-19 00:00:00 -06:00
17
+ date: 2010-11-22 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency