class Ms::Ident::Peptide::Db::IO
an object for on disk retrieval of db entries proteins are returned as an array. behaves much like a hash once it is opened.
Attributes
index[RW]
io[RW]
Public Class Methods
new(io)
click to toggle source
# File lib/ms/ident/peptide/db.rb, line 199 def initialize(io) @io = io @index = {} re = /^(\w+)#{Regexp.escape(KEY_VALUE_DELIMITER)}/ prev_io_pos = io.pos triplets = io.each_line.map do |line| key = re.match(line)[1] [key, prev_io_pos + key.bytesize+KEY_VALUE_DELIMITER.bytesize, prev_io_pos=io.pos] end triplets.each do |key, start, end_pos| @index[key] = [start, end_pos-start] end end
open(filename, &block)
click to toggle source
# File lib/ms/ident/peptide/db.rb, line 189 def self.open(filename, &block) raise ArgumentError unless block File.open(filename) do |io| block.call(self.new(io)) end end
Public Instance Methods
[](key)
click to toggle source
returns an array of proteins for the given key (peptide aaseq)
# File lib/ms/ident/peptide/db.rb, line 214 def [](key) (start, length) = @index[key] return nil unless start @io.seek(start) string = @io.read(length) string.chomp! string.split("\t") end
each(&block)
click to toggle source
yields a pair of aaseq and protein array
# File lib/ms/ident/peptide/db.rb, line 237 def each(&block) @index.each do |key, start_length| block.call([key, self[key]]) end end
keys()
click to toggle source
# File lib/ms/ident/peptide/db.rb, line 227 def keys @index.keys end
size()
click to toggle source
number of entries
# File lib/ms/ident/peptide/db.rb, line 224 def size ; @index.size end
Also aliased as: length
values()
click to toggle source
all the protein lists
# File lib/ms/ident/peptide/db.rb, line 232 def values keys.map {|key| self[key] } end