class Mspire::Ident::Peptide::Db::IO
Attributes
index[RW]
io[RW]
Public Class Methods
new(io)
click to toggle source
# File lib/mspire/ident/peptide/db/io.rb, line 19 def initialize(io) @io = io @index = {} re = /^(\w+)#{Regexp.escape(Mspire::Ident::Peptide::Db::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+Mspire::Ident::Peptide::Db::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/mspire/ident/peptide/db/io.rb, line 8 def self.open(filename, &block) #p filename 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/mspire/ident/peptide/db/io.rb, line 34 def [](key) (start, length) = @index[key] return nil unless start @io.seek(start) string = @io.read(length) string.chomp! string.split(Mspire::Ident::Peptide::Db::PROTEIN_DELIMITER) end
each(&block)
click to toggle source
yields a pair of aaseq and protein array
# File lib/mspire/ident/peptide/db/io.rb, line 61 def each(&block) @index.each do |key, start_length| block.call([key, self[key]]) end end
key?(key)
click to toggle source
# File lib/mspire/ident/peptide/db/io.rb, line 43 def key?(key) @index[key] end
keys()
click to toggle source
# File lib/mspire/ident/peptide/db/io.rb, line 51 def keys @index.keys end
size()
click to toggle source
number of entries
# File lib/mspire/ident/peptide/db/io.rb, line 48 def size ; @index.size end
Also aliased as: length
values()
click to toggle source
all the protein lists
# File lib/mspire/ident/peptide/db/io.rb, line 56 def values keys.map {|key| self[key] } end