lib/ms/ident/pepxml.rb in ms-ident-0.0.20 vs lib/ms/ident/pepxml.rb in ms-ident-0.0.21

- old
+ new

@@ -20,10 +20,39 @@ DEFAULT_PEPXML_VERSION = MsmsPipelineAnalysis::PEPXML_VERSION XML_ENCODING = 'UTF-8' attr_accessor :msms_pipeline_analysis + def self.search_hits(file) + fields = [:aaseq, :charge] + ss_names = [] + have_ss_names = false + # begin with aaseq, charge + hit_values = File.open(file) do |io| + doc = Nokogiri::XML.parse(io, nil, nil, Nokogiri::XML::ParseOptions::DEFAULT_XML | Nokogiri::XML::ParseOptions::NOBLANKS) + # we can work with namespaces, or just remove them ... + doc.remove_namespaces! + root = doc.root + search_hits = root.xpath('//search_hit') + search_hits.map do |search_hit| + aaseq = search_hit['peptide'] + charge = search_hit.parent.parent['assumed_charge'].to_i + search_score_nodes = search_hit.children.select {|node| node.name == 'search_score' } + ss_values = [] + search_score_nodes.each do |node| + ss_names << node['name'].to_sym unless have_ss_names + ss_values << node['value'].to_f + end + have_ss_names = true + [aaseq, charge, *ss_values] + end + end + fields.push(*ss_names) + peptide_hit_class = Struct.new(*fields) + hit_values.map {|ar| peptide_hit_class.new(*ar) } + end + def pepxml_version msms_pipeline_analysis.pepxml_version end # returns an array of spectrum queries @@ -40,10 +69,10 @@ def add_stylesheet(doc, location) xml_stylesheet = Nokogiri::XML::ProcessingInstruction.new(doc, "xml-stylesheet", %Q{type="text/xsl" href="#{location}"}) doc.root.add_previous_sibling xml_stylesheet doc end - + # if no options are given, an xml string is returned. If either :outdir or # :outfile is given, the xml is written to file and the output filename is returned. # A single string argument will be interpreted as :outfile if it ends in # '.xml' and the :outdir otherwise. In this case, update_summary_xml is still true #