Class Bio::FlatFileIndex::BDB_1::BDBMappingFile
In: lib/bio/io/flatfile/bdb.rb  (CVS)
Parent: Object

Methods

add   add_exclusive   add_nr   add_overwrite   close   new   open   open   records   search   size  

Attributes

filename  [R] 
flag  [RW] 
permission  [RW] 

Public Class methods

[Source]

# File lib/bio/io/flatfile/bdb.rb, line 110
        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

[Source]

# File lib/bio/io/flatfile/bdb.rb, line 106
        def self.open(*arg)
          self.new(*arg)
        end

Public Instance methods

methods for writing

[Source]

# File lib/bio/io/flatfile/bdb.rb, line 145
        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

[Source]

# File lib/bio/io/flatfile/bdb.rb, line 159
        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

[Source]

# File lib/bio/io/flatfile/bdb.rb, line 183
        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

[Source]

# File lib/bio/io/flatfile/bdb.rb, line 171
        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

[Source]

# File lib/bio/io/flatfile/bdb.rb, line 130
        def close
          if @bdb then
            DEBUG.print "BDBMappingFile: close #{@filename}\n"
            @bdb.close
            @bdb = nil
          end
          nil
        end

[Source]

# File lib/bio/io/flatfile/bdb.rb, line 120
        def open
          unless @bdb then
            DEBUG.print "BDBMappingFile: open #{@filename}\n"
            @bdb = BDB::Btree.open(@filename, nil, @flag, @permission)
            true
          else
            nil
          end
        end

[Source]

# File lib/bio/io/flatfile/bdb.rb, line 139
        def records
          @bdb.size
        end

methods for searching

[Source]

# File lib/bio/io/flatfile/bdb.rb, line 201
        def search(key)
          open
          s = @bdb[key]
          if s then
            a = s.split("\t")
            a
          else
            []
          end
        end
size()

Alias for records

[Validate]