Class: Bio::FlatFileIndex::BDB_1::BDBMappingFile
- Defined in:
- lib/bio/io/flatfile/bdb.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#flag ⇒ Object
Returns the value of attribute flag.
-
#permission ⇒ Object
Returns the value of attribute permission.
Class Method Summary collapse
Instance Method Summary collapse
-
#add(key, val) ⇒ Object
methods for writing.
- #add_exclusive(key, val) ⇒ Object
- #add_nr(key, val) ⇒ Object
- #add_overwrite(key, val) ⇒ Object
- #close ⇒ Object
-
#initialize(filename, flag = BDBdefault.flag_read, permission = BDBdefault.permission) ⇒ BDBMappingFile
constructor
A new instance of BDBMappingFile.
- #open ⇒ Object
- #records ⇒ Object (also: #size)
-
#search(key) ⇒ Object
methods for searching.
Constructor Details
#initialize(filename, flag = BDBdefault.flag_read, permission = BDBdefault.permission) ⇒ BDBMappingFile
Returns a new instance of BDBMappingFile.
110 111 112 113 114 115 116 |
# File 'lib/bio/io/flatfile/bdb.rb', line 110 def initialize(filename, flag = BDBdefault.flag_read, = BDBdefault.) @filename = filename @flag = flag @permission = #@bdb = BDB::Btree.open(@filename, nil, @flag, @permission) end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
117 118 119 |
# File 'lib/bio/io/flatfile/bdb.rb', line 117 def filename @filename end |
#flag ⇒ Object
Returns the value of attribute flag.
118 119 120 |
# File 'lib/bio/io/flatfile/bdb.rb', line 118 def flag @flag end |
#permission ⇒ Object
Returns the value of attribute permission.
118 119 120 |
# File 'lib/bio/io/flatfile/bdb.rb', line 118 def @permission end |
Class Method Details
.open(*arg) ⇒ Object
106 107 108 |
# File 'lib/bio/io/flatfile/bdb.rb', line 106 def self.open(*arg) self.new(*arg) end |
Instance Method Details
#add(key, val) ⇒ Object
methods for writing
145 146 147 148 149 150 151 152 153 154 155 156 157 |
# 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) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 |
# 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) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# 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) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 |
# 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 ⇒ Object
130 131 132 133 134 135 136 137 |
# 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 ⇒ Object
120 121 122 123 124 125 126 127 128 |
# 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 ⇒ Object Also known as: size
139 140 141 |
# File 'lib/bio/io/flatfile/bdb.rb', line 139 def records @bdb.size end |
#search(key) ⇒ Object
methods for searching
201 202 203 204 205 206 207 208 209 210 |
# 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 |