| Class | Bio::FlatFileIndex::BDB_1::BDBMappingFile |
| In: |
lib/bio/io/flatfile/bdb.rb
|
| Parent: | Object |
| filename | [R] | |
| flag | [RW] | |
| permission | [RW] |
# 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
methods for writing
# 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
# 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
# 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
# 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
# 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
# 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