[BioRuby-cvs] bioruby/lib/bio/io/flatfile bdb.rb, 1.5, 1.6 index.rb, 1.9, 1.10 indexer.rb, 1.17, 1.18

Katayama Toshiaki k at pub.open-bio.org
Wed Sep 7 21:22:14 EDT 2005


Update of /home/repository/bioruby/bioruby/lib/bio/io/flatfile
In directory pub.open-bio.org:/tmp/cvs-serv9021/lib/bio/io/flatfile

Modified Files:
	bdb.rb index.rb indexer.rb 
Log Message:
* expanded tab at the line head


Index: bdb.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/io/flatfile/bdb.rb,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** bdb.rb	28 Feb 2003 10:29:40 -0000	1.5
--- bdb.rb	8 Sep 2005 01:22:12 -0000	1.6
***************
*** 31,50 ****
      module BDBdefault
        def permission
! 	(0666 & (0777 ^ File.umask))
        end
        module_function :permission
  
        def flag_read
! 	BDB::RDONLY
        end
        module_function :flag_read
  
        def flag_write
! 	(BDB::CREATE | BDB::TRUNCATE)
        end
        module_function :flag_write
  
        def flag_append
! 	'r+'
        end
        module_function :flag_append
--- 31,50 ----
      module BDBdefault
        def permission
!         (0666 & (0777 ^ File.umask))
        end
        module_function :permission
  
        def flag_read
!         BDB::RDONLY
        end
        module_function :flag_read
  
        def flag_write
!         (BDB::CREATE | BDB::TRUNCATE)
        end
        module_function :flag_write
  
        def flag_append
!         'r+'
        end
        module_function :flag_append
***************
*** 53,112 ****
      class BDBwrapper
        def initialize(name, filename, *arg)
! 	@dbname = name
! 	@file = nil
! 	@filename = filename
! 	#self.open(*arg)
        end
  
        def filename
! 	File.join(@dbname, @filename)
        end
  
        def open(flag = BDBdefault.flag_read,
! 	       permission = BDBdefault.permission)
! 	unless @file then
! 	  DEBUG.print "BDBwrapper: open #{filename}\n"
! 	  @file = BDB::Btree.open(filename, nil, flag, permission)
! 	end
! 	true
        end
  
        def close
! 	if @file
! 	  DEBUG.print "BDBwrapper: close #{filename}\n"
! 	  @file.close
! 	  @file = nil
! 	end
! 	nil
        end
  
        def [](arg)
! 	#self.open
! 	if @file then
! 	  @file[arg]
! 	else
! 	  nil
! 	end
        end
  
        def []=(key, val)
! 	#self.open
! 	@file[key.to_s] = val.to_s
        end
  
        def writeback_array(prefix, array, *arg)
! 	self.close
! 	self.open(*arg)
! 	array.each_with_index do |val, key|
! 	  @file["#{prefix}#{key}"] = val.to_s
! 	end
        end
  
        def keys
! 	if @file then
! 	  @file.keys
! 	else
! 	  []
! 	end
        end
      end #class BDBwrapper
--- 53,112 ----
      class BDBwrapper
        def initialize(name, filename, *arg)
!         @dbname = name
!         @file = nil
!         @filename = filename
!         #self.open(*arg)
        end
  
        def filename
!         File.join(@dbname, @filename)
        end
  
        def open(flag = BDBdefault.flag_read,
!                permission = BDBdefault.permission)
!         unless @file then
!           DEBUG.print "BDBwrapper: open #{filename}\n"
!           @file = BDB::Btree.open(filename, nil, flag, permission)
!         end
!         true
        end
  
        def close
!         if @file
!           DEBUG.print "BDBwrapper: close #{filename}\n"
!           @file.close
!           @file = nil
!         end
!         nil
        end
  
        def [](arg)
!         #self.open
!         if @file then
!           @file[arg]
!         else
!           nil
!         end
        end
  
        def []=(key, val)
!         #self.open
!         @file[key.to_s] = val.to_s
        end
  
        def writeback_array(prefix, array, *arg)
!         self.close
!         self.open(*arg)
!         array.each_with_index do |val, key|
!           @file["#{prefix}#{key}"] = val.to_s
!         end
        end
  
        def keys
!         if @file then
!           @file.keys
!         else
!           []
!         end
        end
      end #class BDBwrapper
***************
*** 114,254 ****
      module BDB_1
        class BDBMappingFile
! 	def self.open(*arg)
! 	  self.new(*arg)
! 	end
  
! 	def initialize(filename, flag = BDBdefault.flag_read,
! 		       permission = BDBdefault.permission)
! 	  @filename = filename
! 	  @flag = flag
! 	  @permission = permission
! 	  #@bdb = BDB::Btree.open(@filename, nil, @flag, @permission)
! 	end
! 	attr_reader :filename
! 	attr_accessor :flag, :permission
  
! 	def open
! 	  unless @bdb then
! 	    DEBUG.print "BDBMappingFile: open #{@filename}\n"
! 	    @bdb = BDB::Btree.open(@filename, nil, @flag, @permission)
! 	    true
! 	  else
! 	    nil
! 	  end
! 	end
  
! 	def close
! 	  if @bdb then
! 	    DEBUG.print "BDBMappingFile: close #{@filename}\n"
! 	    @bdb.close
              @bdb = nil
! 	  end
! 	  nil
! 	end
  
! 	def records
! 	  @bdb.size
! 	end
! 	alias :size :records
  
! 	# methods for writing
! 	def add(key, val)
! 	  open
! 	  val = val.to_a.join("\t")
! 	  s = @bdb[key]
! 	  if s then
! 	    s << "\t"
! 	    s << val
! 	    val = s
! 	  end
! 	  @bdb[key] = val
! 	  #DEBUG.print "add: key=#{key.inspect}, val=#{val.inspect}\n"
! 	  val
! 	end
  
! 	def add_exclusive(key, val)
! 	  open
! 	  val = val.to_a.join("\t")
! 	  s = @bdb[key]
! 	  if s then
! 	    raise RuntimeError, "keys must be unique, but key #{key.inspect} already exists"
! 	  end
! 	  @bdb[key] = val
! 	  #DEBUG.print "add_exclusive: key=#{key.inspect}, val=#{val.inspect}\n"
! 	  val
! 	end
  
! 	def add_overwrite(key, val)
! 	  open
! 	  val = val.to_a.join("\t")
! 	  s = @bdb[key]
! 	  if s then
! 	    DEBUG.print "Warining: overwrote unique id #{key.inspect}\n"
! 	  end
! 	  @bdb[key] = val
! 	  #DEBUG.print "add_overwrite: key=#{key.inspect}, val=#{val.inspect}\n"
! 	  val
! 	end
  
! 	def add_nr(key, val)
! 	  open
! 	  s = @bdb[key]
! 	  if s then
! 	    a = s.split("\t")
! 	  else
! 	    a = []
! 	  end
! 	  a.concat val.to_a
! 	  a.sort!
! 	  a.uniq!
! 	  str = a.join("\t")
! 	  @bdb[key] = str
! 	  #DEBUG.print "add_nr: key=#{key.inspect}, val=#{str.inspect}\n"
! 	  str
! 	end
! 	    
! 	# methods for searching
! 	def search(key)
! 	  open
! 	  s = @bdb[key]
! 	  if s then
! 	    a = s.split("\t")
! 	    a
! 	  else
! 	    []
! 	  end
! 	end
        end #class BDBMappingFile
  
        class PrimaryNameSpace < Template::NameSpace
! 	def mapping(filename)
! 	  BDBMappingFile.new(filename)
! 	end
! 	def filename
! 	  File.join(dbname, "key_#{name}")
! 	end
! 	def search(key)
! 	  r = super(key)
! 	  unless r.empty? then
! 	    [ r ]
! 	  else
! 	    r
! 	  end
! 	end
        end #class PrimaryNameSpace
  
        class SecondaryNameSpace < Template::NameSpace
! 	def mapping(filename)
! 	  BDBMappingFile.new(filename)
! 	end
! 	def filename
! 	  File.join(dbname, "id_#{name}")
! 	end #class SecondaryNameSpaces
        
! 	def search(key)
! 	  r = super(key)
! 	  file.close
! 	  r
! 	end
        end #class SecondaryNameSpace
      end #module BDB_1
--- 114,254 ----
      module BDB_1
        class BDBMappingFile
!         def self.open(*arg)
!           self.new(*arg)
!         end
  
!         def initialize(filename, flag = BDBdefault.flag_read,
!                        permission = BDBdefault.permission)
!           @filename = filename
!           @flag = flag
!           @permission = permission
!           #@bdb = BDB::Btree.open(@filename, nil, @flag, @permission)
!         end
!         attr_reader :filename
!         attr_accessor :flag, :permission
  
!         def open
!           unless @bdb then
!             DEBUG.print "BDBMappingFile: open #{@filename}\n"
!             @bdb = BDB::Btree.open(@filename, nil, @flag, @permission)
!             true
!           else
!             nil
!           end
!         end
  
!         def close
!           if @bdb then
!             DEBUG.print "BDBMappingFile: close #{@filename}\n"
!             @bdb.close
              @bdb = nil
!           end
!           nil
!         end
  
!         def records
!           @bdb.size
!         end
!         alias :size :records
  
!         # methods for writing
!         def add(key, val)
!           open
!           val = val.to_a.join("\t")
!           s = @bdb[key]
!           if s then
!             s << "\t"
!             s << val
!             val = s
!           end
!           @bdb[key] = val
!           #DEBUG.print "add: key=#{key.inspect}, val=#{val.inspect}\n"
!           val
!         end
  
!         def add_exclusive(key, val)
!           open
!           val = val.to_a.join("\t")
!           s = @bdb[key]
!           if s then
!             raise RuntimeError, "keys must be unique, but key #{key.inspect} already exists"
!           end
!           @bdb[key] = val
!           #DEBUG.print "add_exclusive: key=#{key.inspect}, val=#{val.inspect}\n"
!           val
!         end
  
!         def add_overwrite(key, val)
!           open
!           val = val.to_a.join("\t")
!           s = @bdb[key]
!           if s then
!             DEBUG.print "Warining: overwrote unique id #{key.inspect}\n"
!           end
!           @bdb[key] = val
!           #DEBUG.print "add_overwrite: key=#{key.inspect}, val=#{val.inspect}\n"
!           val
!         end
  
!         def add_nr(key, val)
!           open
!           s = @bdb[key]
!           if s then
!             a = s.split("\t")
!           else
!             a = []
!           end
!           a.concat val.to_a
!           a.sort!
!           a.uniq!
!           str = a.join("\t")
!           @bdb[key] = str
!           #DEBUG.print "add_nr: key=#{key.inspect}, val=#{str.inspect}\n"
!           str
!         end
!             
!         # methods for searching
!         def search(key)
!           open
!           s = @bdb[key]
!           if s then
!             a = s.split("\t")
!             a
!           else
!             []
!           end
!         end
        end #class BDBMappingFile
  
        class PrimaryNameSpace < Template::NameSpace
!         def mapping(filename)
!           BDBMappingFile.new(filename)
!         end
!         def filename
!           File.join(dbname, "key_#{name}")
!         end
!         def search(key)
!           r = super(key)
!           unless r.empty? then
!             [ r ]
!           else
!             r
!           end
!         end
        end #class PrimaryNameSpace
  
        class SecondaryNameSpace < Template::NameSpace
!         def mapping(filename)
!           BDBMappingFile.new(filename)
!         end
!         def filename
!           File.join(dbname, "id_#{name}")
!         end #class SecondaryNameSpaces
        
!         def search(key)
!           r = super(key)
!           file.close
!           r
!         end
        end #class SecondaryNameSpace
      end #module BDB_1

Index: index.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/io/flatfile/index.rb,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** index.rb	27 Aug 2003 17:25:21 -0000	1.9
--- index.rb	8 Sep 2005 01:22:12 -0000	1.10
***************
*** 50,56 ****
      def closed?
        if @db then
! 	false
        else
! 	true
        end
      end
--- 50,56 ----
      def closed?
        if @db then
[...1963 lines suppressed...]
!         else
!           n2 = names
!           p = nil
!         end
!         s = secondary.search_names(key, *n2)
!         s.push p if p
!         s.sort!
!         s.uniq!
!         s
        end
  
        def search_namespaces(key, *names)
!         s = search_namespaces_get_unique_id(key, *names)
!         search_primary(*s)
        end
  
        def check_consistency
!         fileids.check_all
        end
      end #class DataBank

Index: indexer.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/io/flatfile/indexer.rb,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** indexer.rb	27 Aug 2003 17:25:21 -0000	1.17
--- indexer.rb	8 Sep 2005 01:22:12 -0000	1.18
***************
*** 27,702 ****
  
        class NameSpace
! 	def initialize(name, method)
! 	  @name = name
! 	  @proc = method
! 	end
! 	attr_reader :name, :proc
        end #class NameSpace
  
        class NameSpaces < Hash
[...1427 lines suppressed...]
!         Indexer::makeindexFlat(dbname, parser, options, *files)
        end
      end #def makeindex
***************
*** 752,758 ****
      def self.update_index(dbname, format, options, *files)
        if format then
! 	parser = Indexer::Parser.new(dbclass)
        else
! 	parser = nil
        end
        Indexer::update_index(dbname, parser, options, *files)
--- 752,758 ----
      def self.update_index(dbname, format, options, *files)
        if format then
!         parser = Indexer::Parser.new(dbclass)
        else
!         parser = nil
        end
        Indexer::update_index(dbname, parser, options, *files)



More information about the bioruby-cvs mailing list