]> git.donarmstrong.com Git - biopieces.git/commitdiff
finished refactoring s/has_key?/[]/
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Thu, 28 Feb 2013 14:34:26 +0000 (14:34 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Thu, 28 Feb 2013 14:34:26 +0000 (14:34 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@2109 74ccb610-7750-0410-82ae-013aeee3265d

code_ruby/lib/maasha/align.rb
code_ruby/lib/maasha/biopieces.rb
code_ruby/lib/maasha/embl.rb
code_ruby/lib/maasha/fastq.rb
code_ruby/lib/maasha/genbank.rb
code_ruby/lib/maasha/sam.rb
code_ruby/lib/maasha/seq/digest.rb
code_ruby/lib/maasha/usearch.rb

index ffa41c4e41e8107d4fe828ef6b81c529b320741f..c139fe8d89c30a773df458f23e730d2a73e992c4 100755 (executable)
@@ -102,7 +102,7 @@ class Align
 
     Open3.popen3("muscle", "-quiet") do |stdin, stdout, stderr|
       entries.each do |entry|
-        raise AlignError, "Duplicate sequence name: #{entry.seq_name}" if index.has_key? entry.seq_name
+        raise AlignError, "Duplicate sequence name: #{entry.seq_name}" if index[entry.seq_name]
 
         index[entry.seq_name] = entry.dup
 
@@ -270,14 +270,14 @@ class Align
     # NArrays.
     def consensus_calc
       if @has_qual
-        if @options.has_key? :quality_min
+        if @options[:quality_min]
           mask = mask_quality_min
 
           @na_seq  *= mask
           @na_qual *= mask
         end
 
-        if @options.has_key? :quality_mean
+        if @options[:quality_mean]
           mask = mask_quality_mean
 
           @na_seq  *= mask
@@ -285,21 +285,21 @@ class Align
         end
       end
 
-      if @options.has_key? :sequence_min
+      if @options[:sequence_min]
         mask = mask_sequence_min
 
         @na_seq  *= mask
         @na_qual *= mask if @has_qual
       end
 
-      if @options.has_key? :gap_max
+      if @options[:gap_max]
         mask = mask_gap_max
 
         @na_seq  *= mask
         @na_qual *= mask if @has_qual
       end
 
-      if @options.has_key? :residue_min
+      if @options[:residue_min]
         mask = mask_residue_min
 
         @na_seq  *= mask
index bd85afb0f4a86c02eaaa8a0dc07324489d8ed6f0..1797d9211ed4e16ddcc1101b86d1170437ae314f 100644 (file)
@@ -233,7 +233,7 @@ class Casts < Array
   def check_keys
     @cast_list.each do |cast|
       MANDATORY.each do |mandatory|
-        raise CastError, "Missing symbol in cast: '#{mandatory.to_sym}'" unless cast.has_key? mandatory.to_sym
+        raise CastError, "Missing symbol in cast: '#{mandatory}'" unless cast.has_key? mandatory.to_sym
       end
     end
   end
@@ -272,7 +272,7 @@ class Casts < Array
       type_hash[type] = true
     end
 
-    unless type_hash.has_key? cast[:type]
+    unless type_hash[cast[:type]]
       raise CastError, "Illegal cast of type: '#{cast[:type]}'"
     end
   end
@@ -312,8 +312,8 @@ class Casts < Array
   def check_duplicates
     check_hash = {}
     @cast_list.each do |cast|
-      raise CastError, "Duplicate argument: '--#{cast[:long]}'" if check_hash.has_key? cast[:long]
-      raise CastError, "Duplicate argument: '-#{cast[:short]}'" if check_hash.has_key? cast[:short]
+      raise CastError, "Duplicate argument: '--#{cast[:long]}'" if check_hash[cast[:long]]
+      raise CastError, "Duplicate argument: '-#{cast[:short]}'" if check_hash[cast[:short]]
       check_hash[cast[:long]]  = true
       check_hash[cast[:short]] = true
     end
@@ -446,7 +446,7 @@ class OptionHandler
   def options_default
     @casts.each do |cast|
       if cast[:default]
-        unless @options.has_key? cast[:long]
+        unless @options[cast[:long]]
           if cast[:type] == 'list'
             @options[cast[:long]] = cast[:default].split ','
           else
@@ -462,7 +462,7 @@ class OptionHandler
   def options_glob
     @casts.each do |cast|
       if cast[:type] == 'files' or cast[:type] == 'files!'
-        if @options.has_key? cast[:long]
+        if @options[cast[:long]]
           files = []
         
           @options[cast[:long]].each do |path|
@@ -498,13 +498,13 @@ class OptionHandler
   # Check if a mandatory option is set and raise if it isn't.
   def options_check_mandatory(cast)
     if cast[:mandatory]
-      raise ArgumentError, "Mandatory argument: --#{cast[:long]}" unless @options.has_key? cast[:long]
+      raise ArgumentError, "Mandatory argument: --#{cast[:long]}" unless @options[cast[:long]]
     end
   end
 
   # Check int type option and raise if not an integer.
   def options_check_int(cast)
-    if cast[:type] == 'int' and @options.has_key? cast[:long]
+    if cast[:type] == 'int' and @options[cast[:long]]
       unless @options[cast[:long]].is_a? Integer
         raise ArgumentError, "Argument to --#{cast[:long]} must be an integer, not '#{@options[cast[:long]]}'"
       end
@@ -513,7 +513,7 @@ class OptionHandler
   
   # Check uint type option and raise if not an unsinged integer.
   def options_check_uint(cast)
-    if cast[:type] == 'uint' and @options.has_key? cast[:long]
+    if cast[:type] == 'uint' and @options[cast[:long]]
       unless @options[cast[:long]].is_a? Integer and @options[cast[:long]] >= 0
         raise ArgumentError, "Argument to --#{cast[:long]} must be an unsigned integer, not '#{@options[cast[:long]]}'"
       end
@@ -522,14 +522,14 @@ class OptionHandler
 
   # Check file! type argument and raise if file don't exists.
   def options_check_file(cast)
-    if cast[:type] == 'file!' and @options.has_key? cast[:long]
+    if cast[:type] == 'file!' and @options[cast[:long]]
       raise ArgumentError, "No such file: '#{@options[cast[:long]]}'" unless File.file? @options[cast[:long]]
     end
   end
 
   # Check files! type argument and raise if files don't exists.
   def options_check_files(cast)
-    if cast[:type] == 'files!' and @options.has_key? cast[:long]
+    if cast[:type] == 'files!' and @options[cast[:long]]
       @options[cast[:long]].each do |path|
         next if path == "-"
         raise ArgumentError, "File not readable: '#{path}'" unless File.readable? path
@@ -539,24 +539,24 @@ class OptionHandler
   
   # Check dir! type argument and raise if directory don't exist.
   def options_check_dir(cast)
-    if cast[:type] == 'dir!' and @options.has_key? cast[:long]
+    if cast[:type] == 'dir!' and @options[cast[:long]]
       raise ArgumentError, "No such directory: '#{@options[cast[:long]]}'" unless File.directory? @options[cast[:long]]
     end
   end
   
   # Check options and raise unless allowed.
   def options_check_allowed(cast)
-    if cast[:allowed] and @options.has_key? cast[:long]
+    if cast[:allowed] and @options[cast[:long]]
       allowed_hash = {}
       cast[:allowed].split(',').each { |a| allowed_hash[a.to_s] = 1 }
   
-      raise ArgumentError, "Argument '#{@options[cast[:long]]}' to --#{cast[:long]} not allowed" unless allowed_hash.has_key? @options[cast[:long]].to_s
+      raise ArgumentError, "Argument '#{@options[cast[:long]]}' to --#{cast[:long]} not allowed" unless allowed_hash[@options[cast[:long]].to_s]
     end
   end
   
   # Check disallowed argument values and raise if disallowed.
   def options_check_disallowed(cast)
-    if cast[:disallowed] and @options.has_key? cast[:long]
+    if cast[:disallowed] and @options[cast[:long]]
       cast[:disallowed].split(',').each do |val|
         raise ArgumentError, "Argument '#{@options[cast[:long]]}' to --#{cast[:long]} is disallowed" if val.to_s == @options[cast[:long]].to_s
       end
index d3532ae31edc50c00c4b4547166909ff33cefca5..d08dce56e97d5e02392491bd49f18d4150d234ac 100644 (file)
@@ -114,7 +114,7 @@ class EMBL < Filesys
             end
           end
 
-          if keys.has_key? key.to_sym
+          if keys[key.to_sym]
             keys[key.to_sym] << " " + val
           else
             keys[key.to_sym] = val
index c57f4eb9165bb3423fccc22590f89550a8125c69..4ac44aa70cb84045158fc775f782be7719fdbbbd 100644 (file)
@@ -83,7 +83,7 @@ class FastqIndex
   # Method to read from file a Fastq entry from an indexed position,
   # and return the entry as a Seq object.
   def get(seq_name)
-    raise FastqError, "Sequence name: #{seq_name} not found in index." unless @index.has_key? seq_name
+    raise FastqError, "Sequence name: #{seq_name} not found in index." unless @index[seq_name]
 
     elem = @index[seq_name]
     @ios.sysseek(elem.offset_seq)
index fe08263446379e749fc89094b66338e55421af3d..c3515ecbe326c03e65abb834b1ff84b5413dc0e2 100644 (file)
@@ -109,7 +109,7 @@ class Genbank < Filesys
             j += 1
           end
 
-          if keys.has_key? key.to_sym
+          if keys[key.to_sym]
             keys[key.to_sym] << ";" + val
           else
             keys[key.to_sym] = val
index 5ef7de5fbd99a134bff197070402c5fc7b2b5af8..074b999aa58589ea962356655c7f3262ab3b05a3 100644 (file)
@@ -79,7 +79,7 @@ class Sam < Filesys
       bp[:SCORES] = sam[:SEQ].convert_phred2illumina!.qual
     end
 
-    if sam.has_key? :NM and sam[:NM].to_i > 0
+    if sam[:NM] and sam[:NM].to_i > 0
       bp[:NM] = sam[:NM]
       bp[:MD] = sam[:MD]
       bp[:ALIGN] = self.align_descriptors(sam)
@@ -264,7 +264,7 @@ class Sam < Filesys
 
     @header[:SQ][:SN] = Hash.new unless @header[:SQ][:SN].is_a? Hash
 
-    if @header[:SQ][:SN].has_key? seq_name
+    if @header[:SQ][:SN][seq_name]
       raise SamError, "Non-unique sequence name: #{seq_name}"
     else
       @header[:SQ][:SN][seq_name] = hash
@@ -292,13 +292,13 @@ class Sam < Filesys
       end
     end
 
-    if hash.has_key? :FO
+    if hash[:FO]
       unless hash[:FO] =~ /^\*|[ACMGRSVTWYHKDBN]+$/
         raise SamError, "Bad flow order: #{hash[:FO]}"
       end
     end
 
-    if hash.has_key? :PL
+    if hash[:PL]
       unless hash[:PL] =~ /^(CAPILLARY|LS454|ILLUMINA|SOLID|HELICOS|IONTORRENT|PACBIO)$/
         raise SamError, "Bad platform: #{hash[:PL]}"
       end
@@ -306,7 +306,7 @@ class Sam < Filesys
 
     @header[:RG][:ID] = Hash.new unless @header[:RG][:ID].is_a? Hash
 
-    if @header[:RG][:ID].has_key? id
+    if @header[:RG][:ID][id]
       raise SamError, "Non-unique read group identifier: #{id}"
     else
       @header[:RG][:ID][id] = hash
@@ -336,7 +336,7 @@ class Sam < Filesys
 
     @header[:PG][:ID] = Hash.new unless @header[:PG][:ID].is_a? Hash
 
-    if @header[:PG][:ID].has_key? id
+    if @header[:PG][:ID][id]
       raise SamError, "Non-unique program record identifier: #{id}"
     else
       @header[:PG][:ID][id] = hash
@@ -401,7 +401,7 @@ class Sam < Filesys
     fields[11 .. -1].each do |field|
       tag, type, val = field.split(':')
 
-      raise SamError, "Non-unique optional tag: #{tag}" if entry.has_key? tag.to_sym
+      raise SamError, "Non-unique optional tag: #{tag}" if entry[tag.to_sym]
 
       # A [!-~] Printable character
 
@@ -439,7 +439,7 @@ class Sam < Filesys
     raise SamError, "Bad rname: #{rname}" unless rname =~ /^(\*|[!-()+-<>-~][!-~]*)$/
 
     unless @header.empty? or rname == '*'
-      unless @header[:SQ][:SN].has_key? rname.to_sym
+      unless @header[:SQ][:SN][rname.to_sym]
         raise SamError, "rname not found in header hash: #{rname}"
       end
     end
@@ -462,7 +462,7 @@ class Sam < Filesys
     raise SamError, "Bad rnext: #{rnext}" unless rnext =~ /^(\*|=|[!-()+-<>-~][!-~]*)$/
 
     unless @header.empty? or rnext == '*' or rnext == '='
-      unless @header[:SQ][:SN].has_key? rnext.to_sym
+      unless @header[:SQ][:SN][rnext.to_sym]
         raise SamError, "rnext not found in header hash: #{rnext}"
       end
     end
index 835e8c0a115a68054a56ef40ba47a3ad82342cfc..a64aaa57d6dfcc189d2d22db37defc22f6c8f4dc 100644 (file)
@@ -85,7 +85,7 @@ module Digest
     new_pattern = ""
 
     pattern.upcase.each_char do |char|
-      if ambiguity.has_key? char
+      if ambiguity[char]
         new_pattern << ambiguity[char]
       else
         raise DigestError, "Could not disambiguate residue: #{char}"
index 2a3365b73cec139ace7e204cd1779867a6befae1..837585010f41fda3d18ea91292bdef452ba3076d 100644 (file)
@@ -78,8 +78,8 @@ class Usearch
   def usearch
     @command << "usearch --query #{@infile} --db #{@options[:database]} --userout #{@outfile}"
     @command << "--userfields target+tloz+thiz+query+bits+strand"
-    @command << "--id #{@options[:identity]}"  if @options.has_key? :identity
-    @command << "--evalue #{@options[:e_val]}" if @options.has_key? :e_val
+    @command << "--id #{@options[:identity]}"  if @options[:identity]
+    @command << "--evalue #{@options[:e_val]}" if @options[:e_val]
     @command << "--rev"
 
                execute