dcm2nii-ruby 0.0.1
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/.gitignore +17 -0
 - data/Gemfile +4 -0
 - data/LICENSE.txt +22 -0
 - data/README.md +37 -0
 - data/Rakefile +1 -0
 - data/dcm2nii-ruby.gemspec +19 -0
 - data/lib/dcm2nii-ruby.rb +84 -0
 - data/lib/dcm2nii-ruby/version.rb +5 -0
 - metadata +53 -0
 
    
        data/.gitignore
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/LICENSE.txt
    ADDED
    
    | 
         @@ -0,0 +1,22 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            Copyright (c) 2012 Simon Rascovsky
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            MIT License
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            Permission is hereby granted, free of charge, to any person obtaining
         
     | 
| 
      
 6 
     | 
    
         
            +
            a copy of this software and associated documentation files (the
         
     | 
| 
      
 7 
     | 
    
         
            +
            "Software"), to deal in the Software without restriction, including
         
     | 
| 
      
 8 
     | 
    
         
            +
            without limitation the rights to use, copy, modify, merge, publish,
         
     | 
| 
      
 9 
     | 
    
         
            +
            distribute, sublicense, and/or sell copies of the Software, and to
         
     | 
| 
      
 10 
     | 
    
         
            +
            permit persons to whom the Software is furnished to do so, subject to
         
     | 
| 
      
 11 
     | 
    
         
            +
            the following conditions:
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            The above copyright notice and this permission notice shall be
         
     | 
| 
      
 14 
     | 
    
         
            +
            included in all copies or substantial portions of the Software.
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         
     | 
| 
      
 17 
     | 
    
         
            +
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         
     | 
| 
      
 18 
     | 
    
         
            +
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         
     | 
| 
      
 19 
     | 
    
         
            +
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         
     | 
| 
      
 20 
     | 
    
         
            +
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         
     | 
| 
      
 21 
     | 
    
         
            +
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         
     | 
| 
      
 22 
     | 
    
         
            +
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         
     | 
    
        data/README.md
    ADDED
    
    | 
         @@ -0,0 +1,37 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Dcm2nii::Ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            A Ruby wrapper for the dcm2nii DICOM to NIFTI file conversion utility
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            ## Installation
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            Add this line to your application's Gemfile:
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                gem 'dcm2nii-ruby'
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            And then execute:
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                $ bundle
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            Or install it yourself as:
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                $ gem install dcm2nii-ruby
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            ## Usage
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            dn = Dcm2nii::Runner.new(input_directory,{options hash})
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            eg:
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            dn = Dcm2nii::Runner.new('/Users/simonmd/code/rubycamppus/input/samples/dicom',{reorient_crop:false, reorient:false}) # creates an instance of the DCM2NII runner
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            dn.command # runs the utility
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            resulting_file = dn.get_nii # Returns the generated nifti file
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            ## Contributing
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
            1. Fork it
         
     | 
| 
      
 34 
     | 
    
         
            +
            2. Create your feature branch (`git checkout -b my-new-feature`)
         
     | 
| 
      
 35 
     | 
    
         
            +
            3. Commit your changes (`git commit -am 'Add some feature'`)
         
     | 
| 
      
 36 
     | 
    
         
            +
            4. Push to the branch (`git push origin my-new-feature`)
         
     | 
| 
      
 37 
     | 
    
         
            +
            5. Create new Pull Request
         
     | 
    
        data/Rakefile
    ADDED
    
    | 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "bundler/gem_tasks"
         
     | 
| 
         @@ -0,0 +1,19 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # -*- encoding: utf-8 -*-
         
     | 
| 
      
 2 
     | 
    
         
            +
            lib = File.expand_path('../lib', __FILE__)
         
     | 
| 
      
 3 
     | 
    
         
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'dcm2nii-ruby/version'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            Gem::Specification.new do |gem|
         
     | 
| 
      
 7 
     | 
    
         
            +
              gem.name          = "dcm2nii-ruby"
         
     | 
| 
      
 8 
     | 
    
         
            +
              gem.version       = Dcm2nii::Runner::VERSION
         
     | 
| 
      
 9 
     | 
    
         
            +
              gem.authors       = ["Simon Rascovsky"]
         
     | 
| 
      
 10 
     | 
    
         
            +
              gem.email         = ["investigacion@iatm.com.co"]
         
     | 
| 
      
 11 
     | 
    
         
            +
              gem.description   = %q{dcm2nii wrapper}
         
     | 
| 
      
 12 
     | 
    
         
            +
              gem.summary       = %q{Ruby wrapper for the dcm2nii dicom to nifti conversion utility}
         
     | 
| 
      
 13 
     | 
    
         
            +
              gem.homepage      = ""
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              gem.files         = `git ls-files`.split($/)
         
     | 
| 
      
 16 
     | 
    
         
            +
              gem.executables   = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
         
     | 
| 
      
 17 
     | 
    
         
            +
              gem.test_files    = gem.files.grep(%r{^(test|spec|features)/})
         
     | 
| 
      
 18 
     | 
    
         
            +
              gem.require_paths = ["lib"]
         
     | 
| 
      
 19 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/dcm2nii-ruby.rb
    ADDED
    
    | 
         @@ -0,0 +1,84 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "dcm2nii-ruby/version"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Dcm2nii
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            	class Runner
         
     | 
| 
      
 6 
     | 
    
         
            +
            		@@command_path = '/Applications/mricro/dcm2nii'
         
     | 
| 
      
 7 
     | 
    
         
            +
            		@@options_map = { anonymize: '-a',
         
     | 
| 
      
 8 
     | 
    
         
            +
            							settings_file: '-b',
         
     | 
| 
      
 9 
     | 
    
         
            +
            							collapse_folders: '-c',
         
     | 
| 
      
 10 
     | 
    
         
            +
            							date_in_filename: '-d',
         
     | 
| 
      
 11 
     | 
    
         
            +
            							events_in_filename: '-e',
         
     | 
| 
      
 12 
     | 
    
         
            +
            							source_filename: '-f',
         
     | 
| 
      
 13 
     | 
    
         
            +
            							gzip: '-g',
         
     | 
| 
      
 14 
     | 
    
         
            +
            							id_in_filename: '-i',
         
     | 
| 
      
 15 
     | 
    
         
            +
            							nifti: '-n',
         
     | 
| 
      
 16 
     | 
    
         
            +
            							output_dir: '-o',
         
     | 
| 
      
 17 
     | 
    
         
            +
            							protocol_in_filename: 'p',
         
     | 
| 
      
 18 
     | 
    
         
            +
            							reorient: '-r',
         
     | 
| 
      
 19 
     | 
    
         
            +
            							spm2_analyze: '-s',
         
     | 
| 
      
 20 
     | 
    
         
            +
            							convert_images: '-v',
         
     | 
| 
      
 21 
     | 
    
         
            +
            							reorient_crop: '-x'
         
     | 
| 
      
 22 
     | 
    
         
            +
            						}
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
            		def self.command_path=(path)
         
     | 
| 
      
 25 
     | 
    
         
            +
            			@@command_path = path
         
     | 
| 
      
 26 
     | 
    
         
            +
            		end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
            		def self.command_path
         
     | 
| 
      
 29 
     | 
    
         
            +
            			@@command_path
         
     | 
| 
      
 30 
     | 
    
         
            +
            		end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
            		def self.options_map
         
     | 
| 
      
 33 
     | 
    
         
            +
            			@@options_map
         
     | 
| 
      
 34 
     | 
    
         
            +
            		end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            		def initialize(input_dir, opt = {})
         
     | 
| 
      
 37 
     | 
    
         
            +
            			@input_dir = input_dir
         
     | 
| 
      
 38 
     | 
    
         
            +
            			@opt = opt
         
     | 
| 
      
 39 
     | 
    
         
            +
            		end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
            		def map_vals(val)
         
     | 
| 
      
 42 
     | 
    
         
            +
            			if val == true || val == false
         
     | 
| 
      
 43 
     | 
    
         
            +
            				val ? 'Y' : 'N'
         
     | 
| 
      
 44 
     | 
    
         
            +
            			else
         
     | 
| 
      
 45 
     | 
    
         
            +
            				val
         
     | 
| 
      
 46 
     | 
    
         
            +
            			end
         
     | 
| 
      
 47 
     | 
    
         
            +
            		end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
            		def map_options(opt ={})
         
     | 
| 
      
 50 
     | 
    
         
            +
            			opt.inject({}) { |h, (k, v)| h[k] = (self.class.options_map[k] + ' ' + map_vals(v)); h }
         
     | 
| 
      
 51 
     | 
    
         
            +
            		end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
            		def argument_list
         
     | 
| 
      
 54 
     | 
    
         
            +
            			map_options(@opt).collect {|k,v| v}.join(' ')
         
     | 
| 
      
 55 
     | 
    
         
            +
            		end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
            		def command
         
     | 
| 
      
 58 
     | 
    
         
            +
            			command_str = "#{self.class.command_path} #{argument_list} #{@input_dir}"
         
     | 
| 
      
 59 
     | 
    
         
            +
            			puts "Running DCM2NII with command #{command_str}"
         
     | 
| 
      
 60 
     | 
    
         
            +
            			result = `#{command_str}`
         
     | 
| 
      
 61 
     | 
    
         
            +
            			exit_code = $?
         
     | 
| 
      
 62 
     | 
    
         
            +
            			case exit_code
         
     | 
| 
      
 63 
     | 
    
         
            +
            				when 0
         
     | 
| 
      
 64 
     | 
    
         
            +
            					puts "Done running DCM2NII."
         
     | 
| 
      
 65 
     | 
    
         
            +
            					return result
         
     | 
| 
      
 66 
     | 
    
         
            +
            				else
         
     | 
| 
      
 67 
     | 
    
         
            +
            					puts "An error ocurred while running DCM2NII"
         
     | 
| 
      
 68 
     | 
    
         
            +
            			        #   exit_error = Dcm2nii::Runner::UnexpectedExitError.new
         
     | 
| 
      
 69 
     | 
    
         
            +
            			        #   exit_error.exit_code = exit_code
         
     | 
| 
      
 70 
     | 
    
         
            +
            			        #   raise exit_error
         
     | 
| 
      
 71 
     | 
    
         
            +
            			        # end
         
     | 
| 
      
 72 
     | 
    
         
            +
            			end
         
     | 
| 
      
 73 
     | 
    
         
            +
            		end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
            		def get_nii
         
     | 
| 
      
 76 
     | 
    
         
            +
            			if @opt[:output_dir]
         
     | 
| 
      
 77 
     | 
    
         
            +
            				lookup_dir = @opt[:output_dir]
         
     | 
| 
      
 78 
     | 
    
         
            +
            			else
         
     | 
| 
      
 79 
     | 
    
         
            +
            				lookup_dir = @input_dir
         
     | 
| 
      
 80 
     | 
    
         
            +
            			end
         
     | 
| 
      
 81 
     | 
    
         
            +
            			return `find #{lookup_dir} -name *.nii*`.chomp
         
     | 
| 
      
 82 
     | 
    
         
            +
            		end
         
     | 
| 
      
 83 
     | 
    
         
            +
            	end
         
     | 
| 
      
 84 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,53 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: dcm2nii-ruby
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.1
         
     | 
| 
      
 5 
     | 
    
         
            +
              prerelease: 
         
     | 
| 
      
 6 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 7 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 8 
     | 
    
         
            +
            - Simon Rascovsky
         
     | 
| 
      
 9 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 10 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 11 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2012-11-21 00:00:00.000000000 Z
         
     | 
| 
      
 13 
     | 
    
         
            +
            dependencies: []
         
     | 
| 
      
 14 
     | 
    
         
            +
            description: dcm2nii wrapper
         
     | 
| 
      
 15 
     | 
    
         
            +
            email:
         
     | 
| 
      
 16 
     | 
    
         
            +
            - investigacion@iatm.com.co
         
     | 
| 
      
 17 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 18 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 19 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 20 
     | 
    
         
            +
            files:
         
     | 
| 
      
 21 
     | 
    
         
            +
            - .gitignore
         
     | 
| 
      
 22 
     | 
    
         
            +
            - Gemfile
         
     | 
| 
      
 23 
     | 
    
         
            +
            - LICENSE.txt
         
     | 
| 
      
 24 
     | 
    
         
            +
            - README.md
         
     | 
| 
      
 25 
     | 
    
         
            +
            - Rakefile
         
     | 
| 
      
 26 
     | 
    
         
            +
            - dcm2nii-ruby.gemspec
         
     | 
| 
      
 27 
     | 
    
         
            +
            - lib/dcm2nii-ruby.rb
         
     | 
| 
      
 28 
     | 
    
         
            +
            - lib/dcm2nii-ruby/version.rb
         
     | 
| 
      
 29 
     | 
    
         
            +
            homepage: ''
         
     | 
| 
      
 30 
     | 
    
         
            +
            licenses: []
         
     | 
| 
      
 31 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 32 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 33 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 34 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 35 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 36 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 37 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 38 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 39 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 40 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 41 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 42 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 43 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 44 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 45 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 46 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 47 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 48 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 49 
     | 
    
         
            +
            rubygems_version: 1.8.23
         
     | 
| 
      
 50 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 51 
     | 
    
         
            +
            specification_version: 3
         
     | 
| 
      
 52 
     | 
    
         
            +
            summary: Ruby wrapper for the dcm2nii dicom to nifti conversion utility
         
     | 
| 
      
 53 
     | 
    
         
            +
            test_files: []
         
     |