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

- old
+ new

@@ -1,9 +1,11 @@ require 'nokogiri' require 'ms/ident' require 'ms/ident/pepxml/msms_pipeline_analysis' +require 'ostruct' + module Ms ; module Ident ; end ; end class Numeric # returns a string with a + or - on the front def to_plus_minus_string @@ -20,36 +22,28 @@ 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 + # returns an array of Ms::Ident::Pepxml::SearchHit::Simple structs + def self.simple_search_hits(file) 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_scores = {} search_score_nodes.each do |node| - ss_names << node['name'].to_sym unless have_ss_names - ss_values << node['value'].to_f + search_scores[node['name'].to_sym] = node['value'].to_f end - have_ss_names = true - [aaseq, charge, *ss_values] + Ms::Ident::Pepxml::SearchHit::Simple.new(aaseq, charge, search_scores) 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