class Ms::Ident::Pepxml
Constants
- DEFAULT_PEPXML_VERSION
- XML_ENCODING
- XML_STYLESHEET_LOCATION
Attributes
msms_pipeline_analysis[RW]
Public Class Methods
new(&block)
click to toggle source
yields a new Msms_Pipeline_Analysis object if given a block
# File lib/ms/ident/pepxml.rb, line 58 def initialize(&block) block.call(@msms_pipeline_analysis=MsmsPipelineAnalysis.new) if block end
simple_search_hits(file)
click to toggle source
returns an array of Ms::Ident::Pepxml::SearchHit::Simple structs
# File lib/ms/ident/pepxml.rb, line 28 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 | Nokogiri::XML::ParseOptions::STRICT) # we can work with namespaces, or just remove them ... doc.remove_namespaces! root = doc.root search_hits = root.xpath('//search_hit') search_hits.each_with_index.map do |search_hit,i| 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' } search_scores = {} search_score_nodes.each do |node| search_scores[node['name'].to_sym] = node['value'].to_f end Ms::Ident::Pepxml::SearchHit::Simple.new("hit_#{i}", Ms::Ident::Search.new(file.chomp(File.extname(file))), aaseq, charge, search_scores) end end end
Public Instance Methods
add_stylesheet(doc, location)
click to toggle source
takes an xml document object and sets it with the xml stylesheet
# File lib/ms/ident/pepxml.rb, line 63 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
pepxml_version()
click to toggle source
# File lib/ms/ident/pepxml.rb, line 48 def pepxml_version msms_pipeline_analysis.pepxml_version end
spectrum_queries()
click to toggle source
returns an array of spectrum queries
# File lib/ms/ident/pepxml.rb, line 53 def spectrum_queries msms_pipeline_analysis.msms_run_summary.spectrum_queries end
to_xml(opts={})
click to toggle source
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
options:
arg default :outdir => nil write to disk using this outdir with summary_xml basename :outfile => nil write to this filename (overrides outdir) :update_summary_xml => true update summary_xml attribute to point to the output file true/false
set outdir to File.dirname(pepxml_obj.msms_pipeline_analysis.msms_run_summary.base_name) to write to the same directory as the input search file.
# File lib/ms/ident/pepxml.rb, line 84 def to_xml(opts={}) opts ||= {} if opts.is_a?(String) opts = ( opts.match(/\.xml$/) ? {:outfile => opts} : {:outdir => opts } ) end opt = {:update_summary_xml => true, :outdir => nil, :outfile => nil}.merge(opts) if opt[:outfile] outfile = opt[:outfile] elsif opt[:outdir] outfile = File.join(opt[:outdir], msms_pipeline_analysis.summary_xml.split(/[\/\\]/).last) end self.msms_pipeline_analysis.summary_xml = File.expand_path(outfile) if (opt[:update_summary_xml] && outfile) builder = Nokogiri::XML::Builder.new(:encoding => XML_ENCODING) msms_pipeline_analysis.to_xml(builder) add_stylesheet(builder.doc, Ms::Ident::Pepxml::XML_STYLESHEET_LOCATION) string = builder.doc.to_xml if outfile File.open(outfile,'w') {|out| out.print(string) } outfile else string end end