Class: Ms::Ident::Pepxml::SpectrumQuery

Inherits:
Object
  • Object
show all
Includes:
Merge
Defined in:
lib/ms/ident/pepxml/spectrum_query.rb

Overview

search_specification is a search constraint applied specifically to this query (a String)

Constant Summary collapse

DEFAULT_MEMBERS =
[:spectrum, :start_scan, :end_scan, :precursor_neutral_mass, :index, :assumed_charge, :retention_time_sec, :search_specification, :search_results, :pepxml_version]
Required =
Set.new([:spectrum, :start_scan, :end_scan, :precursor_neutral_mass, :index, :assumed_charge])
Optional =
[:retention_time_sec, :search_specification]

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Merge

#merge!

Constructor Details

#initialize(*args, &block) ⇒ SpectrumQuery

takes either a hash or an ordered list of values to set yeilds an empty search_results array if given a block



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ms/ident/pepxml/spectrum_query.rb', line 30

def initialize(*args, &block)
  @search_results = [] 
  if args.first.is_a?(Hash)
    merge!(args.first)
  else
    self.class.members.zip(args) do |k,v|
      send("#{k}=", v)
    end
  end
  block.call(@search_results) if block
end

Class Attribute Details

.membersObject



18
19
20
# File 'lib/ms/ident/pepxml/spectrum_query.rb', line 18

def members
  @members || DEFAULT_MEMBERS
end

Class Method Details

.calc_precursor_neutral_mass(m_plus_h, deltamass, h_plus = Ms::Mass::H_PLUS) ⇒ Object



80
81
82
# File 'lib/ms/ident/pepxml/spectrum_query.rb', line 80

def self.calc_precursor_neutral_mass(m_plus_h, deltamass, h_plus=Ms::Mass::H_PLUS)
  m_plus_h - h_plus + deltamass
end

.from_pepxml_node(node) ⇒ Object



66
67
68
# File 'lib/ms/ident/pepxml/spectrum_query.rb', line 66

def self.from_pepxml_node(node)
  self.new.from_pepxml_node(node)
end

Instance Method Details

#from_pepxml_node(node) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/ms/ident/pepxml/spectrum_query.rb', line 70

def from_pepxml_node(node)
  @spectrum = node['spectrum']
  @start_scan = node['start_scan'].to_i
  @end_scan = node['end_scan'].to_i
  @precursor_neutral_mass = node['precursor_neutral_mass'].to_f
  @index = node['index'].to_i
  @assumed_charge = node['assumed_charge'].to_i
  self
end

#membersObject



42
43
44
# File 'lib/ms/ident/pepxml/spectrum_query.rb', line 42

def members
  self.class.members
end

#to_xml(builder = nil) ⇒ Object

FOR PEPXML:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ms/ident/pepxml/spectrum_query.rb', line 49

def to_xml(builder=nil)
  xmlb = builder || Nokogiri::XML::Builder.new
  # all through search_specification
  attrs = members[0, 8].map {|at| v=send(at) ; [at, v] if v }
  attrs_hash = Hash[attrs]
  case pepxml_version
  when 18
    attrs_hash.delete(:retention_time_sec)
  end
  xmlb.spectrum_query(attrs_hash) do |xmlb|
    search_results.each do |search_result|
      search_result.to_xml(xmlb) 
    end
  end
  builder || xmlb.doc.root.to_xml
end