class Bio::FlatFileIndex::BDB_1::BDBMappingFile

Attributes

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

Public Class Methods

new(filename, flag = BDBdefault.flag_read, permission = BDBdefault.permission) click to toggle 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
open(*arg) click to toggle source
# File lib/bio/io/flatfile/bdb.rb, line 106
def self.open(*arg)
  self.new(*arg)
end

Public Instance Methods

add(key, val) click to toggle source

methods for writing

# 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
add_exclusive(key, val) click to toggle 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
add_nr(key, val) click to toggle 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
add_overwrite(key, val) click to toggle 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
close() click to toggle 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
open() click to toggle 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
records() click to toggle source
# File lib/bio/io/flatfile/bdb.rb, line 139
def records
  @bdb.size
end
Also aliased as: size
size()
Alias for: records