Class: Mspire::Ident::Pepxml
- Inherits:
-
Object
- Object
- Mspire::Ident::Pepxml
- Defined in:
- lib/mspire/ident/pepxml.rb,
lib/mspire/ident/pepxml/parameters.rb,
lib/mspire/ident/pepxml/search_hit.rb,
lib/mspire/ident/pepxml/modifications.rb,
lib/mspire/ident/pepxml/sample_enzyme.rb,
lib/mspire/ident/pepxml/search_result.rb,
lib/mspire/ident/pepxml/search_summary.rb,
lib/mspire/ident/pepxml/spectrum_query.rb,
lib/mspire/ident/pepxml/search_database.rb,
lib/mspire/ident/pepxml/msms_run_summary.rb,
lib/mspire/ident/pepxml/msms_pipeline_analysis.rb,
lib/mspire/ident/pepxml/search_hit/modification_info.rb
Defined Under Namespace
Classes: AminoacidModification, EnzymaticSearchConstraint, MsmsPipelineAnalysis, MsmsRunSummary, Parameters, SampleEnzyme, SearchDatabase, SearchHit, SearchResult, SearchSummary, SpectrumQuery, TerminalModification
Constant Summary collapse
- XML_STYLESHEET_LOCATION =
'/tools/bin/TPP/tpp/schema/pepXML_std.xsl'
- DEFAULT_PEPXML_VERSION =
MsmsPipelineAnalysis::PEPXML_VERSION
- XML_ENCODING =
'UTF-8'
Instance Attribute Summary collapse
-
#msms_pipeline_analysis ⇒ Object
Returns the value of attribute msms_pipeline_analysis.
Class Method Summary collapse
-
.simple_search_hits(file, &block) ⇒ Object
returns an array of Mspire::Ident::Pepxml::SearchHit::Simple structs will only process last result if duplicate search scores are included.
Instance Method Summary collapse
-
#add_stylesheet(doc, location) ⇒ Object
takes an xml document object and sets it with the xml stylesheet.
-
#initialize(&block) ⇒ Pepxml
constructor
yields a new Msms_Pipeline_Analysis object if given a block.
- #pepxml_version ⇒ Object
-
#spectrum_queries ⇒ Object
returns an array of spectrum queries.
-
#to_xml(opts = {}) ⇒ Object
if no options are given, an xml string is returned.
Constructor Details
#initialize(&block) ⇒ Pepxml
yields a new Msms_Pipeline_Analysis object if given a block
73 74 75 |
# File 'lib/mspire/ident/pepxml.rb', line 73 def initialize(&block) block.call(@msms_pipeline_analysis=MsmsPipelineAnalysis.new) if block end |
Instance Attribute Details
#msms_pipeline_analysis ⇒ Object
Returns the value of attribute msms_pipeline_analysis.
25 26 27 |
# File 'lib/mspire/ident/pepxml.rb', line 25 def msms_pipeline_analysis @msms_pipeline_analysis end |
Class Method Details
.simple_search_hits(file, &block) ⇒ Object
returns an array of Mspire::Ident::Pepxml::SearchHit::Simple structs will only process last result if duplicate search scores are included. Score keys returned as symbols and values cast as Floats while analysis results are all returned as strings.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/mspire/ident/pepxml.rb', line 31 def self.simple_search_hits(file, &block) 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 nodes_by_name = search_hit.children.group_by(&:name) search_scores = {} nodes_by_name['search_score'].each do |node| search_scores[node['name'].to_sym] = node['value'].to_f end analysis_results = {} nodes_by_name['analysis_result'].each do |node| analysis_results[node['analysis']] = node.children.map do |atnode| atnode.attribute_nodes.each_with_object({}) do |attribute, hash| hash[attribute.name] = attribute.value end end end hit = Mspire::Ident::Pepxml::SearchHit::Simple.new("hit_#{i}", Mspire::Ident::Search.new(file.chomp(File.extname(file))), aaseq, charge, search_scores, analysis_results) if block block.call(search_hit_n.parent.parent) end hit end end end |
Instance Method Details
#add_stylesheet(doc, location) ⇒ Object
takes an xml document object and sets it with the xml stylesheet
78 79 80 81 82 |
# File 'lib/mspire/ident/pepxml.rb', line 78 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 ⇒ Object
63 64 65 |
# File 'lib/mspire/ident/pepxml.rb', line 63 def pepxml_version msms_pipeline_analysis.pepxml_version end |
#spectrum_queries ⇒ Object
returns an array of spectrum queries
68 69 70 |
# File 'lib/mspire/ident/pepxml.rb', line 68 def spectrum_queries msms_pipeline_analysis.msms_run_summary.spectrum_queries end |
#to_xml(opts = {}) ⇒ Object
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.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/mspire/ident/pepxml.rb', line 99 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.(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, Mspire::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 |