[BioRuby] Indexing fasta file with Ruby 1.9.1

MISHIMA, Hiroyuki missy at be.to
Fri Aug 6 02:53:15 UTC 2010


Hi Raoul and all,

Raoul Bonnal wrote (2010/07/30 20:28):
> Caught error: #<NoMethodError: undefined method `each' for
> "bta-miR-3596":String> in "mature.fa" position 1178667

The following patch seems to work...

--- ./indexer-orig.rb   2010-08-06 11:40:52.000000000 +0900
+++ 
/usr/local/lib/ruby/gems/1.9.1/gems/bio-1.4.0/lib/bio/io/flatfile/indexer.rb 
        2010-08-06 11:38:53.000000000 +0900
@@ -155,8 +155,15 @@
            def parse_secondary
              self.secondary.each do |x|
                p = x.proc.call(@entry)
-              p.each do |y|
-                yield x.name, y if y.length > 0
+
+              if p.respond_to? :each
+                p.each do |y|
+                  yield x.name, y if y.length > 0
+                end
+              else
+                p.each_line do |y|
+                  yield x.name, y if y.length > 0
+                end
                end
              end
            end

This is typical incompatibility between Ruby-1.8 and -1.9. In Ruby-1.9,
String#each should be replaced by String#each_line.

irb-1.8> "abc\ndef".each {|l| p l}
"abc\n"
"def"
=> "abc\ndef"

irb-1.9> "abc\ndef".each {|l| p l}
NoMethodError: undefined method `each' for "abc\ndef":String
from (irb):1
from /usr/local/bin/irb-1.9:12:in `<main>'
irb-1.9> "abc\ndef".each_line {|l| p l}
"abc\n"
"def"
=> "abc\ndef"

Because the "p" variable can be String or Array in the "parse_secondary"
method, I used "respond_to?". I do not know this instant patch is right
way or no.

Sincerely yours,
Hiro
-- 
MISHIMA, Hiroyuki, DDS, Ph.D.
COE Research Fellow
Department of Human Genetics
Nagasaki University Graduate School of Biomedical Sciences



More information about the BioRuby mailing list