metamri 0.2.3 → 0.2.4
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/VERSION +1 -1
 - data/bin/list_visit +7 -2
 - data/lib/metamri/raw_image_dataset.rb +13 -7
 - data/lib/metamri/raw_image_dataset_thumbnail.rb +2 -0
 - data/lib/metamri/raw_image_file.rb +7 -2
 - data/metamri.gemspec +2 -2
 - metadata +4 -4
 
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            0.2. 
     | 
| 
      
 1 
     | 
    
         
            +
            0.2.4
         
     | 
    
        data/bin/list_visit
    CHANGED
    
    | 
         @@ -51,7 +51,12 @@ def run! 
     | 
|
| 
       51 
51 
     | 
    
         | 
| 
       52 
52 
     | 
    
         
             
              unless input_directories.empty?
         
     | 
| 
       53 
53 
     | 
    
         
             
                input_directories.each do |raw_directory|
         
     | 
| 
       54 
     | 
    
         
            -
                   
     | 
| 
      
 54 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 55 
     | 
    
         
            +
                    list_visit raw_directory, options
         
     | 
| 
      
 56 
     | 
    
         
            +
                  rescue StandardError => e
         
     | 
| 
      
 57 
     | 
    
         
            +
                    puts e
         
     | 
| 
      
 58 
     | 
    
         
            +
                    next
         
     | 
| 
      
 59 
     | 
    
         
            +
                  end
         
     | 
| 
       55 
60 
     | 
    
         
             
                end
         
     | 
| 
       56 
61 
     | 
    
         
             
              else
         
     | 
| 
       57 
62 
     | 
    
         
             
                raise IOError, "No input directories specified."
         
     | 
| 
         @@ -79,7 +84,7 @@ def list_visit(raw_directory, options = {}) 
     | 
|
| 
       79 
84 
     | 
    
         
             
                raise ScriptError, "Scaning filesystem directly..." if options[:force_scan]
         
     | 
| 
       80 
85 
     | 
    
         | 
| 
       81 
86 
     | 
    
         
             
                lookup_path = File.dirname(raw_directory).split(File::Separator).last == "dicoms" ?  File.join(raw_directory, '..') : raw_directory
         
     | 
| 
       82 
     | 
    
         
            -
                visit = VisitRawDataDirectoryResource.find(:first, :params => {:search => {: 
     | 
| 
      
 87 
     | 
    
         
            +
                visit = VisitRawDataDirectoryResource.find(:first, :params => {:search => {:path_contains => File.expand_path(lookup_path)}})
         
     | 
| 
       83 
88 
     | 
    
         | 
| 
       84 
89 
     | 
    
         
             
                raise IOError.new("Could not lookup visit using path #{lookup_path}.") unless visit
         
     | 
| 
       85 
90 
     | 
    
         
             
                raise IOError.new("Returned visit's path #{visit.path} does not match path.") unless visit.path == File.expand_path(lookup_path)
         
     | 
| 
         @@ -164,11 +164,18 @@ class RawImageDataset 
     | 
|
| 
       164 
164 
     | 
    
         
             
              # Returns a hash of attributes used for insertion into active record.
         
     | 
| 
       165 
165 
     | 
    
         
             
              # Options:  :thumb => FileHandle to thumbnail includes a thumbnail.
         
     | 
| 
       166 
166 
     | 
    
         
             
              def attributes_for_active_record(options = {})
         
     | 
| 
       167 
     | 
    
         
            -
                 
     | 
| 
      
 167 
     | 
    
         
            +
                attrs = {}
         
     | 
| 
       168 
168 
     | 
    
         | 
| 
       169 
     | 
    
         
            -
                 
     | 
| 
       170 
     | 
    
         
            -
             
     | 
| 
      
 169 
     | 
    
         
            +
                # If the thumbnail is present and valid, add it to the hash.
         
     | 
| 
      
 170 
     | 
    
         
            +
                # Otherwise don't add the key, or paperclip will delete the attachments (it deletes when given nil)
         
     | 
| 
      
 171 
     | 
    
         
            +
                if options.has_key?(:thumb)
         
     | 
| 
      
 172 
     | 
    
         
            +
                  thumbnail = options[:thumb]
         
     | 
| 
      
 173 
     | 
    
         
            +
                  unless (thumbnail.class == File || thumbnail == nil)
         
     | 
| 
      
 174 
     | 
    
         
            +
                    raise(IOError, "Thumbnail #{options[:thumb]} must be a #File instead of #{thumbnail.class}.")
         
     | 
| 
      
 175 
     | 
    
         
            +
                  end
         
     | 
| 
      
 176 
     | 
    
         
            +
                  attrs[:thumbnail] = thumbnail
         
     | 
| 
       171 
177 
     | 
    
         
             
                end
         
     | 
| 
      
 178 
     | 
    
         
            +
             
     | 
| 
       172 
179 
     | 
    
         
             
                { :rmr => @rmr_number,
         
     | 
| 
       173 
180 
     | 
    
         
             
                  :series_description => @series_description,
         
     | 
| 
       174 
181 
     | 
    
         
             
                  :path => @directory,
         
     | 
| 
         @@ -178,10 +185,9 @@ class RawImageDataset 
     | 
|
| 
       178 
185 
     | 
    
         
             
                  :bold_reps => @raw_image_files.first.bold_reps,
         
     | 
| 
       179 
186 
     | 
    
         
             
                  :slices_per_volume => @raw_image_files.first.num_slices,
         
     | 
| 
       180 
187 
     | 
    
         
             
                  :scanned_file => @scanned_file,
         
     | 
| 
       181 
     | 
    
         
            -
                  :thumbnail => thumbnail,
         
     | 
| 
       182 
188 
     | 
    
         
             
                  :dicom_series_uid => @dicom_series_uid,
         
     | 
| 
       183 
189 
     | 
    
         
             
                  :dicom_taghash => @dicom_taghash
         
     | 
| 
       184 
     | 
    
         
            -
                }
         
     | 
| 
      
 190 
     | 
    
         
            +
                }.merge attrs
         
     | 
| 
       185 
191 
     | 
    
         
             
              end
         
     | 
| 
       186 
192 
     | 
    
         | 
| 
       187 
193 
     | 
    
         
             
              def create_thumbnail
         
     | 
| 
         @@ -272,7 +278,7 @@ Returns a path to the created dataset as a string if successful. 
     | 
|
| 
       272 
278 
     | 
    
         | 
| 
       273 
279 
     | 
    
         
             
              def file_count
         
     | 
| 
       274 
280 
     | 
    
         
             
                unless @file_count
         
     | 
| 
       275 
     | 
    
         
            -
                  if @raw_image_files.first.dicom?
         
     | 
| 
      
 281 
     | 
    
         
            +
                  if @raw_image_files.first.dicom? or @raw_image_files.first.geifile?
         
     | 
| 
       276 
282 
     | 
    
         
             
                    @file_count = Dir.open(@directory).reject{ |branch| /(^\.|.yaml$)/.match(branch) }.length
         
     | 
| 
       277 
283 
     | 
    
         
             
                  elsif @raw_image_files.first.pfile?
         
     | 
| 
       278 
284 
     | 
    
         
             
                    @file_count = 1
         
     | 
| 
         @@ -305,7 +311,7 @@ Returns a path to the created dataset as a string if successful. 
     | 
|
| 
       305 
311 
     | 
    
         
             
              def relative_dataset_path(visit_dir = nil)
         
     | 
| 
       306 
312 
     | 
    
         
             
                image_file = @raw_image_files.first
         
     | 
| 
       307 
313 
     | 
    
         
             
                case image_file.file_type
         
     | 
| 
       308 
     | 
    
         
            -
                  when 'dicom'
         
     | 
| 
      
 314 
     | 
    
         
            +
                  when 'dicom', 'geifile'
         
     | 
| 
       309 
315 
     | 
    
         
             
                    relative_dataset_path = File.basename(directory)
         
     | 
| 
       310 
316 
     | 
    
         
             
                  when 'pfile'
         
     | 
| 
       311 
317 
     | 
    
         
             
                    full_dataset_path = Pathname.new(File.join(directory, image_file.filename))
         
     | 
| 
         @@ -19,6 +19,8 @@ class RawImageDatasetThumbnail 
     | 
|
| 
       19 
19 
     | 
    
         
             
              attr_reader :path
         
     | 
| 
       20 
20 
     | 
    
         
             
              # The processor for creating the thumbnail (:rubydicom or :slicer)
         
     | 
| 
       21 
21 
     | 
    
         
             
              attr_reader :processor
         
     | 
| 
      
 22 
     | 
    
         
            +
              # An array of errors encountered during the reading process.
         
     | 
| 
      
 23 
     | 
    
         
            +
              attr_reader :errors
         
     | 
| 
       22 
24 
     | 
    
         | 
| 
       23 
25 
     | 
    
         
             
              # Creates a RawImageDatasetThumbnail instance by passing in a parent dataset to thumbnail.
         
     | 
| 
       24 
26 
     | 
    
         
             
              def initialize(dataset)
         
     | 
| 
         @@ -143,6 +143,10 @@ class RawImageFile 
     | 
|
| 
       143 
143 
     | 
    
         
             
                return @file_type == "dicom"
         
     | 
| 
       144 
144 
     | 
    
         
             
              end
         
     | 
| 
       145 
145 
     | 
    
         | 
| 
      
 146 
     | 
    
         
            +
              def geifile?
         
     | 
| 
      
 147 
     | 
    
         
            +
                return @file_type == "geifile"
         
     | 
| 
      
 148 
     | 
    
         
            +
              end
         
     | 
| 
      
 149 
     | 
    
         
            +
              
         
     | 
| 
       146 
150 
     | 
    
         | 
| 
       147 
151 
     | 
    
         
             
              # Returns a yaml string based on a subset of the attributes.  Specifically,
         
     | 
| 
       148 
152 
     | 
    
         
             
              # the @hdr_data is not included.  This is used to generate .yaml files that are 
         
     | 
| 
         @@ -294,8 +298,9 @@ private 
     | 
|
| 
       294 
298 
     | 
    
         
             
              # file a "pfile" if it is an image and the file name is of the form P*.7
         
     | 
| 
       295 
299 
     | 
    
         
             
              # All other images are called "dicom".
         
     | 
| 
       296 
300 
     | 
    
         
             
              def determine_file_type
         
     | 
| 
       297 
     | 
    
         
            -
                return "pfile" 
     | 
| 
       298 
     | 
    
         
            -
                return " 
     | 
| 
      
 301 
     | 
    
         
            +
                return "pfile"    if image? and (@filename =~ /^P.....\.7/) != nil
         
     | 
| 
      
 302 
     | 
    
         
            +
                return "geifile"  if image? and (@filename =~ /^I\.\d*/) != nil
         
     | 
| 
      
 303 
     | 
    
         
            +
                return "dicom"    if image? and (@filename =~ /^P.....\.7/) == nil
         
     | 
| 
       299 
304 
     | 
    
         
             
                return nil
         
     | 
| 
       300 
305 
     | 
    
         
             
              end
         
     | 
| 
       301 
306 
     | 
    
         | 
    
        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.2. 
     | 
| 
      
 8 
     | 
    
         
            +
              s.version = "0.2.4"
         
     | 
| 
       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{2011- 
     | 
| 
      
 12 
     | 
    
         
            +
              s.date = %q{2011-03-07}
         
     | 
| 
       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
    
    | 
         @@ -1,13 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: metamri
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
     | 
    
         
            -
              hash:  
     | 
| 
      
 4 
     | 
    
         
            +
              hash: 31
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
              segments: 
         
     | 
| 
       7 
7 
     | 
    
         
             
              - 0
         
     | 
| 
       8 
8 
     | 
    
         
             
              - 2
         
     | 
| 
       9 
     | 
    
         
            -
              -  
     | 
| 
       10 
     | 
    
         
            -
              version: 0.2. 
     | 
| 
      
 9 
     | 
    
         
            +
              - 4
         
     | 
| 
      
 10 
     | 
    
         
            +
              version: 0.2.4
         
     | 
| 
       11 
11 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       12 
12 
     | 
    
         
             
            authors: 
         
     | 
| 
       13 
13 
     | 
    
         
             
            - Kristopher J. Kosmatka
         
     | 
| 
         @@ -15,7 +15,7 @@ autorequire: 
     | 
|
| 
       15 
15 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       16 
16 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
            date: 2011- 
     | 
| 
      
 18 
     | 
    
         
            +
            date: 2011-03-07 00:00:00 -06:00
         
     | 
| 
       19 
19 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       20 
20 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       21 
21 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     |