Class | Bio::FlatFileIndex::BDB_1::BDBMappingFile
In: | lib/bio/io/flatfile/bdb.rb
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

new(filename, flag = BDBdefault.flag_read, permission = BDBdefault.permission)

[Source]

         # File lib/bio/io/flatfile/bdb.rb, line 110
    110:         def initialize(filename, flag = BDBdefault.flag_read,
    111:                        permission = BDBdefault.permission)
    112:           @filename = filename
    113:           @flag = flag
    114:           @permission = permission
    115:           #@bdb = BDB::Btree.open(@filename, nil, @flag, @permission)
    116:         end

open(*arg)

[Source]

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

### Public Instance methods

add(key, val)

methods for writing

[Source]

         # File lib/bio/io/flatfile/bdb.rb, line 145
    145:         def add(key, val)
    146:           open
    147:           val = val.to_a.join("\t")
    148:           s = @bdb[key]
    149:           if s then
    150:             s << "\t"
    151:             s << val
    152:             val = s
    153:           end
    154:           @bdb[key] = val
    155:           #DEBUG.print "add: key=#{key.inspect}, val=#{val.inspect}\n"
    156:           val
    157:         end

add_exclusive(key, val)

[Source]

         # File lib/bio/io/flatfile/bdb.rb, line 159
    159:         def add_exclusive(key, val)
    160:           open
    161:           val = val.to_a.join("\t")
    162:           s = @bdb[key]
    163:           if s then
    164:             raise RuntimeError, "keys must be unique, but key #{key.inspect} already exists"
    165:           end
    166:           @bdb[key] = val
    167:           #DEBUG.print "add_exclusive: key=#{key.inspect}, val=#{val.inspect}\n"
    168:           val
    169:         end

add_nr(key, val)

[Source]

         # File lib/bio/io/flatfile/bdb.rb, line 183
    183:         def add_nr(key, val)
    184:           open
    185:           s = @bdb[key]
    186:           if s then
    187:             a = s.split("\t")
    188:           else
    189:             a = []
    190:           end
    191:           a.concat val.to_a
    192:           a.sort!
    193:           a.uniq!
    194:           str = a.join("\t")
    195:           @bdb[key] = str
    196:           #DEBUG.print "add_nr: key=#{key.inspect}, val=#{str.inspect}\n"
    197:           str
    198:         end

add_overwrite(key, val)

[Source]

         # File lib/bio/io/flatfile/bdb.rb, line 171
    171:         def add_overwrite(key, val)
    172:           open
    173:           val = val.to_a.join("\t")
    174:           s = @bdb[key]
    175:           if s then
    176:             DEBUG.print "Warining: overwrote unique id #{key.inspect}\n"
    177:           end
    178:           @bdb[key] = val
    179:           #DEBUG.print "add_overwrite: key=#{key.inspect}, val=#{val.inspect}\n"
    180:           val
    181:         end

close()

[Source]

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

open()

[Source]

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

records()

[Source]

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

search(key)

methods for searching

[Source]

         # File lib/bio/io/flatfile/bdb.rb, line 201
    201:         def search(key)
    202:           open
    203:           s = @bdb[key]
    204:           if s then
    205:             a = s.split("\t")
    206:             a
    207:           else
    208:             []
    209:           end
    210:         end

size()

Alias for records

[Validate]