Class: MzID::ParserSax::PeptideHandler

Inherits:
Ox::Sax
  • Object
show all
Defined in:
lib/mzid/parser_sax.rb

Overview

handler for Peptide elements

Constant Summary collapse

ATTR =
[:Peptide, :PeptideSequence, :Modification]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(num_pep = nil) ⇒ PeptideHandler

Returns a new instance of PeptideHandler.



79
80
81
82
83
# File 'lib/mzid/parser_sax.rb', line 79

def initialize(num_pep=nil)
  @pbar = num_pep.nil? ? nil : ProgressBar.new("Peptides", num_pep)
  @pep_h = Hash.new
  @mod_h = Hash.new
end

Instance Attribute Details

#mod_hObject

Returns the value of attribute mod_h.



85
86
87
# File 'lib/mzid/parser_sax.rb', line 85

def mod_h
  @mod_h
end

#pbarObject

Returns the value of attribute pbar.



85
86
87
# File 'lib/mzid/parser_sax.rb', line 85

def pbar
  @pbar
end

#pep_hObject

Returns the value of attribute pep_h.



85
86
87
# File 'lib/mzid/parser_sax.rb', line 85

def pep_h
  @pep_h
end

Instance Method Details

#attr(name, value) ⇒ Object



93
94
95
96
97
# File 'lib/mzid/parser_sax.rb', line 93

def attr(name, value)
  return unless ATTR.include?(@curr_node)
  @h[name] = value if @curr_node != :Modification
  @mh.push(value) if @curr_node == :Modification
end

#end_element(name) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
# File 'lib/mzid/parser_sax.rb', line 104

def end_element(name)
  return unless name == :Peptide
  @pbar.inc if !@pbar.nil?
  @pep_h[@h[:id].to_sym] = @h[:PeptideSequence]
  if !@mh.empty? then
    @mod_h[@h[:id].to_sym] = {}
    (1..@mh.size-1).step(2) do |i|
      @mod_h[@h[:id].to_sym][@mh[i].to_i] = @mh[i-1]
    end
  end
end

#start_element(name) ⇒ Object



87
88
89
90
91
# File 'lib/mzid/parser_sax.rb', line 87

def start_element(name)
  @h = {} if name == :Peptide
  @mh = [] if name == :Peptide
  @curr_node = name
end

#text(value) ⇒ Object



99
100
101
102
# File 'lib/mzid/parser_sax.rb', line 99

def text(value)
  return unless ATTR.include?(@curr_node)
  @h[@curr_node] = value
end