Class: Bio::FlatFileIndex::BDB_1::BDBMappingFile

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/io/flatfile/bdb.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (BDBMappingFile) initialize(filename, flag = BDBdefault.flag_read, permission = BDBdefault.permission)

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,
               permission = BDBdefault.permission)
  @filename = filename
  @flag = flag
  @permission = permission
  #@bdb = BDB::Btree.open(@filename, nil, @flag, @permission)
end

Instance Attribute Details

- (Object) filename (readonly)

Returns the value of attribute filename



117
118
119
# File 'lib/bio/io/flatfile/bdb.rb', line 117

def filename
  @filename
end

- (Object) flag

Returns the value of attribute flag



118
119
120
# File 'lib/bio/io/flatfile/bdb.rb', line 118

def flag
  @flag
end

- (Object) permission

Returns the value of attribute permission



118
119
120
# File 'lib/bio/io/flatfile/bdb.rb', line 118

def permission
  @permission
end

Class Method Details

+ (Object) open(*arg)



106
107
108
# File 'lib/bio/io/flatfile/bdb.rb', line 106

def self.open(*arg)
  self.new(*arg)
end

Instance Method Details

- (Object) add(key, val)

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

- (Object) add_exclusive(key, val)



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

- (Object) add_nr(key, val)



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

- (Object) add_overwrite(key, val)



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

- (Object) close



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

- (Object) open



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

- (Object) records Also known as: size



139
140
141
# File 'lib/bio/io/flatfile/bdb.rb', line 139

def records
  @bdb.size
end

- (Object) search(key)

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