]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_ruby/lib/maasha/genbank.rb
fixed grave bug in genbank.rb
[biopieces.git] / code_ruby / lib / maasha / genbank.rb
index a6ec292621a91f4259d25689a4606aeccac9b05a..dcdfbe32593ec5c883f2ae9036e555ebe3963c52 100644 (file)
@@ -24,6 +24,7 @@
 
 require 'maasha/seq'
 require 'maasha/filesys'
+require 'pp'
 
 # Error class for all exceptions to do with Genbank.
 class GenbankError < StandardError; end
@@ -135,28 +136,27 @@ class Genbank < Filesys
 end
 
 class GenbankFeatures
-  @@i = 0
-  @@j = 0
-
   def initialize(entry, hash_feats, hash_quals)
     @entry      = entry
     @hash_feats = hash_feats
     @hash_quals = hash_quals
+       @i          = 0
+       @j          = 0
   end
 
   def each
-    while @entry[@@i] and @entry[@@i] !~ /^ORIGIN/
-      if @entry[@@i] =~ /^\s{5}([A-Za-z_-]+)/
+    while @entry[@i] and @entry[@i] !~ /^ORIGIN/
+      if @entry[@i] =~ /^\s{5}([A-Za-z_-]+)/
         if want_feat? $1
           record = {}
 
-          feat, loc = @entry[@@i].lstrip.split(/\s+/, 2)
+          feat, loc = @entry[@i].lstrip.split(/\s+/, 2)
 
-          @@j = @@i + 1
+          @j = @i + 1
 
-          while @entry[@@j] and @entry[@@j] !~ /^(\s{21}\/|\s{5}[A-Za-z_-]|[A-Z])/
-            loc << @entry[@@j].lstrip
-            @@j += 1
+          while @entry[@j] and @entry[@j] !~ /^(\s{21}\/|\s{5}[A-Za-z_-]|[A-Z])/
+            loc << @entry[@j].lstrip
+            @j += 1
           end
 
           get_quals.each_pair { |k,v|
@@ -170,7 +170,7 @@ class GenbankFeatures
         end
       end
 
-      @@j > @@i ? @@i = @@j : @@i += 1
+      @j > @i ? @i = @j : @i += 1
     end
   end
 
@@ -180,13 +180,13 @@ class GenbankFeatures
     quals = {}
     k     = 0
 
-    while @entry[@@j] and @entry[@@j] !~ /^\s{5}[A-Za-z_-]|^[A-Z]/
-      if @entry[@@j] =~ /^\s{21}\/([^=]+)="([^"]+)/
+    while @entry[@j] and @entry[@j] !~ /^\s{5}[A-Za-z_-]|^[A-Z]/
+      if @entry[@j] =~ /^\s{21}\/([^=]+)="([^"]+)/
         qual = $1
         val  = $2
 
         if want_qual? qual
-          k = @@j + 1
+          k = @j + 1
 
           while @entry[k] and @entry[k] !~ /^(\s{21}\/|\s{5}[A-Za-z_-]|[A-Z])/
             val << @entry[k].lstrip.chomp('"')
@@ -201,7 +201,7 @@ class GenbankFeatures
         end
       end
 
-      k > @@j ? @@j = k : @@j += 1
+      k > @j ? @j = k : @j += 1
     end
 
     quals