OpenMS  2.8.0
MzIdentMLDOMHandler.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2021.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Mathias Walzer $
32 // $Authors: Mathias Walzer$
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
38 
46 
47 #include <xercesc/dom/DOM.hpp>
48 #include <xercesc/dom/DOMDocument.hpp>
49 #include <xercesc/dom/DOMDocumentType.hpp>
50 #include <xercesc/dom/DOMElement.hpp>
51 #include <xercesc/dom/DOMImplementation.hpp>
52 #include <xercesc/dom/DOMImplementationLS.hpp>
53 #include <xercesc/dom/DOMNodeIterator.hpp>
54 #include <xercesc/dom/DOMNodeList.hpp>
55 #include <xercesc/dom/DOMText.hpp>
56 #include <xercesc/util/OutOfMemoryException.hpp>
57 #include <xercesc/util/XMLString.hpp>
58 #include <xercesc/util/PlatformUtils.hpp>
59 #include <xercesc/framework/LocalFileFormatTarget.hpp>
60 
61 #include <xercesc/parsers/XercesDOMParser.hpp>
62 #include <xercesc/util/XMLUni.hpp>
63 #include <xercesc//framework/psvi/XSValue.hpp>
64 
65 #include <string>
66 #include <stdexcept>
67 #include <vector>
68 #include <map>
69 
70 // Error codes
71 //enum {
72 // ERROR_ARGS = 1,
73 // ERROR_XERCES_INIT,
74 // ERROR_PARSE,
75 // ERROR_EMPTY_DOCUMENT
76 //};
77 
78 namespace OpenMS
79 {
80  class ProgressLogger;
81 
82  namespace Internal
83  {
95  class OPENMS_DLLAPI MzIdentMLDOMHandler
96  {
97 public:
101  MzIdentMLDOMHandler(const std::vector<ProteinIdentification>& pro_id, const std::vector<PeptideIdentification>& pep_id, const String& version, const ProgressLogger& logger);
102 
104  MzIdentMLDOMHandler(std::vector<ProteinIdentification>& pro_id, std::vector<PeptideIdentification>& pep_id, const String& version, const ProgressLogger& logger);
105 
109 
111  void readMzIdentMLFile(const std::string& mzid_file);
113  void writeMzIdentMLFile(const std::string& mzid_file);
114 
115 protected:
118 
123 
125  std::vector<ProteinIdentification>* pro_id_;
127  std::vector<PeptideIdentification>* pep_id_;
128 
130  const std::vector<ProteinIdentification>* cpro_id_;
132  const std::vector<PeptideIdentification>* cpep_id_;
133 
136 
138  ControlledVocabulary::CVTerm getChildWithName_(const String& parent_accession, const String& name) const;
139 
142  std::pair<CVTermList, std::map<String, DataValue> > parseParamGroup_(xercesc::DOMNodeList* paramGroup);
143  CVTerm parseCvParam_(xercesc::DOMElement* param);
144  std::pair<String, DataValue> parseUserParam_(xercesc::DOMElement* param);
145  void parseAnalysisSoftwareList_(xercesc::DOMNodeList* analysisSoftwareElements);
146  void parseDBSequenceElements_(xercesc::DOMNodeList* dbSequenceElements);
147  void parsePeptideElements_(xercesc::DOMNodeList* peptideElements);
148  //AASequence parsePeptideSiblings_(xercesc::DOMNodeList* peptideSiblings);
149  AASequence parsePeptideSiblings_(xercesc::DOMElement* peptide);
150  void parsePeptideEvidenceElements_(xercesc::DOMNodeList* peptideEvidenceElements);
151  void parseSpectrumIdentificationElements_(xercesc::DOMNodeList* spectrumIdentificationElements);
152  void parseSpectrumIdentificationProtocolElements_(xercesc::DOMNodeList* spectrumIdentificationProtocolElements);
153  void parseInputElements_(xercesc::DOMNodeList* inputElements);
154  void parseSpectrumIdentificationListElements_(xercesc::DOMNodeList* spectrumIdentificationListElements);
155  void parseSpectrumIdentificationItemSetXLMS(std::set<String>::const_iterator set_it, std::multimap<String, int> xl_val_map, xercesc::DOMElement* element_res, String spectrumID);
156  void parseSpectrumIdentificationItemElement_(xercesc::DOMElement* spectrumIdentificationItemElement, PeptideIdentification& spectrum_identification, String& spectrumIdentificationList_ref);
157  void parseProteinDetectionHypothesisElement_(xercesc::DOMElement* proteinDetectionHypothesisElement, ProteinIdentification& protein_identification);
158  void parseProteinAmbiguityGroupElement_(xercesc::DOMElement* proteinAmbiguityGroupElement, ProteinIdentification& protein_identification);
159  void parseProteinDetectionListElements_(xercesc::DOMNodeList* proteinDetectionListElements);
160  static ProteinIdentification::SearchParameters findSearchParameters_(std::pair<CVTermList, std::map<String, DataValue> > as_params);
162 
164  void buildCvList_(xercesc::DOMElement* cvElements);
165  void buildAnalysisSoftwareList_(xercesc::DOMElement* analysisSoftwareElements);
166  void buildSequenceCollection_(xercesc::DOMElement* sequenceCollectionElements);
167  void buildAnalysisCollection_(xercesc::DOMElement* analysisCollectionElements);
168  void buildAnalysisProtocolCollection_(xercesc::DOMElement* protocolElements);
169  void buildInputDataCollection_(xercesc::DOMElement* inputElements);
170  void buildEnclosedCV_(xercesc::DOMElement* parentElement, const String& encel, const String& acc, const String& name, const String& cvref);
171  void buildAnalysisDataCollection_(xercesc::DOMElement* analysisElements);
173 
174 
175 private:
179 
182  {
185  };
188  {
189  int start;
190  int stop;
191  char pre;
192  char post;
193  bool idec;
194  };
196  struct DBSequence
197  {
202  };
205  {
210  };
213  {
215  long double mass_delta;
219  };
222  {
226  std::map<String, DataValue> parameter_ups;
227 // std::vector<ModificationParam> modification_parameter;
229  long double precursor_tolerance;
230  long double fragment_tolerance;
232  std::map<String, DataValue> threshold_ups;
233  };
236  {
241  };
242 
246 
247  xercesc::XercesDOMParser mzid_parser_;
248 
249  //from AnalysisSoftware
252  //mapping from AnalysisSoftware
253  std::map<String, AnalysisSoftware> as_map_;
254 
255  //mapping from DataCollection Inputs
256  std::map<String, String> sr_map_;
257  std::map<String, String> sd_map_;
258  std::map<String, DatabaseInput> db_map_;
259 
260  //mapping from SpectrumIdentification - SpectrumIdentification will be the new IdentificationRuns
261  std::map<String, SpectrumIdentification> si_map_;
262  std::map<String, size_t> si_pro_map_;
263 
264  //mapping from SpectrumIdentificationProtocol
265  std::map<String, SpectrumIdentificationProtocol> sp_map_;
266 
267  //mapping from SequenceCollection
268  std::map<String, AASequence> pep_map_;
269  std::map<String, PeptideEvidence> pe_ev_map_;
270  std::map<String, String> pv_db_map_;
271  std::multimap<String, String> p_pv_map_;
272  std::map<String, DBSequence> db_sq_map_;
273 
274  std::list<std::list<String> > hit_pev_;
275 
277  std::map<String, String> xl_id_donor_map_;
278  //std::map<String, String> xl_id_acceptor_map_; ///< mapping Peptide id -> cross-link acceptor value
279  std::map<String, String> xl_id_acceptor_map_;
280  std::map<String, SignedSize> xl_donor_pos_map_;
281  std::map<String, SignedSize> xl_acceptor_pos_map_;
282  std::map<String, double> xl_mass_map_;
283  std::map<String, String> xl_mod_map_;
284 
285  };
286  } // namespace Internal
287 } // namespace OpenMS
288 
Representation of a peptide/protein sequence.
Definition: AASequence.h:112
Representation of controlled vocabulary term list.
Definition: CVTermList.h:54
Representation of controlled vocabulary term.
Definition: CVTerm.h:53
Representation of a controlled vocabulary.
Definition: ControlledVocabulary.h:55
DateTime Class.
Definition: DateTime.h:55
XML DOM handler for MzIdentMLFile.
Definition: MzIdentMLDOMHandler.h:96
ControlledVocabulary::CVTerm getChildWithName_(const String &parent_accession, const String &name) const
Looks up a child CV term of parent_accession with the name name. If no such term is found,...
void readMzIdentMLFile(const std::string &mzid_file)
Provides the functionality of reading a mzid with a handler object.
std::map< String, SpectrumIdentification > si_map_
mapping SpectrumIdentification id -> SpectrumIdentification (id refs)
Definition: MzIdentMLDOMHandler.h:261
void buildAnalysisSoftwareList_(xercesc::DOMElement *analysisSoftwareElements)
std::map< String, DatabaseInput > db_map_
mapping database id -> DatabaseInput
Definition: MzIdentMLDOMHandler.h:258
CVTermList parameter_cvs
Definition: MzIdentMLDOMHandler.h:225
String search_database_ref
Definition: MzIdentMLDOMHandler.h:207
bool xl_ms_search_
is true when reading a file containing Cross-Linking MS search results
Definition: MzIdentMLDOMHandler.h:276
void parseSpectrumIdentificationItemElement_(xercesc::DOMElement *spectrumIdentificationItemElement, PeptideIdentification &spectrum_identification, String &spectrumIdentificationList_ref)
DateTime date
Definition: MzIdentMLDOMHandler.h:240
std::map< String, double > xl_mass_map_
mapping Peptide id -> cross-link mass
Definition: MzIdentMLDOMHandler.h:282
std::map< String, String > sd_map_
mapping spectradata id -> spectradata location
Definition: MzIdentMLDOMHandler.h:257
CVTerm parseCvParam_(xercesc::DOMElement *param)
void parseSpectrumIdentificationItemSetXLMS(std::set< String >::const_iterator set_it, std::multimap< String, int > xl_val_map, xercesc::DOMElement *element_res, String spectrumID)
std::map< String, DBSequence > db_sq_map_
mapping DBSequence id -> Sequence
Definition: MzIdentMLDOMHandler.h:272
XMLCh * xml_root_tag_ptr_
Definition: MzIdentMLDOMHandler.h:243
int start
Definition: MzIdentMLDOMHandler.h:189
String sequence
Definition: MzIdentMLDOMHandler.h:198
std::map< String, String > sr_map_
mapping sourcefile id -> sourcefile location
Definition: MzIdentMLDOMHandler.h:256
void parseProteinDetectionListElements_(xercesc::DOMNodeList *proteinDetectionListElements)
long double precursor_tolerance
Definition: MzIdentMLDOMHandler.h:229
void parseInputElements_(xercesc::DOMNodeList *inputElements)
std::pair< String, DataValue > parseUserParam_(xercesc::DOMElement *param)
String location
Definition: MzIdentMLDOMHandler.h:238
const std::vector< ProteinIdentification > * cpro_id_
Internal -w Identification Item for proteins.
Definition: MzIdentMLDOMHandler.h:130
void parseProteinDetectionHypothesisElement_(xercesc::DOMElement *proteinDetectionHypothesisElement, ProteinIdentification &protein_identification)
std::map< String, SignedSize > xl_acceptor_pos_map_
mapping acceptor value -> cross-link modification location
Definition: MzIdentMLDOMHandler.h:281
const ProgressLogger & logger_
Progress logger.
Definition: MzIdentMLDOMHandler.h:117
ControlledVocabulary cv_
Controlled vocabulary (psi-ms from OpenMS/share/OpenMS/CV/psi-ms.obo)
Definition: MzIdentMLDOMHandler.h:120
String search_engine_
Definition: MzIdentMLDOMHandler.h:250
void buildAnalysisCollection_(xercesc::DOMElement *analysisCollectionElements)
std::map< String, PeptideEvidence > pe_ev_map_
mapping PeptideEvidence id -> PeptideEvidence
Definition: MzIdentMLDOMHandler.h:269
long double mass_delta
Definition: MzIdentMLDOMHandler.h:215
CVTermList modification_param_cvs
Definition: MzIdentMLDOMHandler.h:217
String version
Definition: MzIdentMLDOMHandler.h:184
static ProteinIdentification::SearchParameters findSearchParameters_(std::pair< CVTermList, std::map< String, DataValue > > as_params)
XMLCh * xml_cvparam_tag_ptr_
Definition: MzIdentMLDOMHandler.h:244
long double fragment_tolerance
Definition: MzIdentMLDOMHandler.h:230
String spectrum_identification_list_ref
Definition: MzIdentMLDOMHandler.h:209
int stop
Definition: MzIdentMLDOMHandler.h:190
std::map< String, size_t > si_pro_map_
mapping SpectrumIdentificationList id -> index to ProteinIdentification in pro_id_
Definition: MzIdentMLDOMHandler.h:262
MzIdentMLDOMHandler & operator=(const MzIdentMLDOMHandler &rhs)
String database_ref
Definition: MzIdentMLDOMHandler.h:199
std::vector< ProteinIdentification > * pro_id_
Internal +w Identification Item for proteins.
Definition: MzIdentMLDOMHandler.h:125
void parseProteinAmbiguityGroupElement_(xercesc::DOMElement *proteinAmbiguityGroupElement, ProteinIdentification &protein_identification)
void parseSpectrumIdentificationElements_(xercesc::DOMNodeList *spectrumIdentificationElements)
void parsePeptideEvidenceElements_(xercesc::DOMNodeList *peptideEvidenceElements)
CVTerm searchtype
Definition: MzIdentMLDOMHandler.h:223
std::map< String, String > pv_db_map_
mapping PeptideEvidence id -> DBSequence id
Definition: MzIdentMLDOMHandler.h:270
void buildAnalysisDataCollection_(xercesc::DOMElement *analysisElements)
String search_engine_version_
Definition: MzIdentMLDOMHandler.h:251
std::map< String, AnalysisSoftware > as_map_
mapping AnalysisSoftware id -> AnalysisSoftware
Definition: MzIdentMLDOMHandler.h:253
std::vector< PeptideIdentification > * pep_id_
Internal +w Identification Item for peptides.
Definition: MzIdentMLDOMHandler.h:127
void buildEnclosedCV_(xercesc::DOMElement *parentElement, const String &encel, const String &acc, const String &name, const String &cvref)
bool idec
Definition: MzIdentMLDOMHandler.h:193
ControlledVocabulary unimod_
Controlled vocabulary for modifications (unimod from OpenMS/share/OpenMS/CV/unimod....
Definition: MzIdentMLDOMHandler.h:122
std::map< String, String > xl_mod_map_
mapping peptide id -> cross-linking reagent name
Definition: MzIdentMLDOMHandler.h:283
std::map< String, String > xl_id_donor_map_
mapping Peptide id -> cross-link donor value
Definition: MzIdentMLDOMHandler.h:277
void parseSpectrumIdentificationProtocolElements_(xercesc::DOMNodeList *spectrumIdentificationProtocolElements)
AASequence parsePeptideSiblings_(xercesc::DOMElement *peptide)
String name
Definition: MzIdentMLDOMHandler.h:183
std::multimap< String, String > p_pv_map_
mapping Peptide id -> PeptideEvidence id, multiple PeptideEvidences can have equivalent Peptides.
Definition: MzIdentMLDOMHandler.h:271
void buildInputDataCollection_(xercesc::DOMElement *inputElements)
void writeMzIdentMLFile(const std::string &mzid_file)
Provides the functionality to write a mzid with a handler object.
xercesc::XercesDOMParser mzid_parser_
Definition: MzIdentMLDOMHandler.h:247
CVTermList threshold_cvs
Definition: MzIdentMLDOMHandler.h:231
String fixed_mod
Definition: MzIdentMLDOMHandler.h:214
String accession
Definition: MzIdentMLDOMHandler.h:200
CVTermList specificities
Definition: MzIdentMLDOMHandler.h:218
char pre
Definition: MzIdentMLDOMHandler.h:191
String residues
Definition: MzIdentMLDOMHandler.h:216
std::map< String, DataValue > threshold_ups
Definition: MzIdentMLDOMHandler.h:232
std::pair< CVTermList, std::map< String, DataValue > > parseParamGroup_(xercesc::DOMNodeList *paramGroup)
CVTermList cvs
Definition: MzIdentMLDOMHandler.h:201
std::map< String, AASequence > pep_map_
mapping Peptide id -> Sequence
Definition: MzIdentMLDOMHandler.h:268
void parseAnalysisSoftwareList_(xercesc::DOMNodeList *analysisSoftwareElements)
MzIdentMLDOMHandler(const std::vector< ProteinIdentification > &pro_id, const std::vector< PeptideIdentification > &pep_id, const String &version, const ProgressLogger &logger)
Constructor for a write-only handler for internal identification structures.
MzIdentMLDOMHandler(std::vector< ProteinIdentification > &pro_id, std::vector< PeptideIdentification > &pep_id, const String &version, const ProgressLogger &logger)
Constructor for a read-only handler for internal identification structures.
std::list< std::list< String > > hit_pev_
writing help only
Definition: MzIdentMLDOMHandler.h:274
const std::vector< PeptideIdentification > * cpep_id_
Internal -w Identification Item for peptides.
Definition: MzIdentMLDOMHandler.h:132
MzIdentMLDOMHandler(const MzIdentMLDOMHandler &rhs)
std::map< String, SignedSize > xl_donor_pos_map_
mapping donor value -> cross-link modification location
Definition: MzIdentMLDOMHandler.h:280
std::map< String, SpectrumIdentificationProtocol > sp_map_
mapping SpectrumIdentificationProtocol id -> SpectrumIdentificationProtocol
Definition: MzIdentMLDOMHandler.h:265
CVTermList modification_parameter
Definition: MzIdentMLDOMHandler.h:228
void buildCvList_(xercesc::DOMElement *cvElements)
std::map< String, DataValue > parameter_ups
Definition: MzIdentMLDOMHandler.h:226
void buildSequenceCollection_(xercesc::DOMElement *sequenceCollectionElements)
void parseSpectrumIdentificationListElements_(xercesc::DOMNodeList *spectrumIdentificationListElements)
void parseDBSequenceElements_(xercesc::DOMNodeList *dbSequenceElements)
char post
Definition: MzIdentMLDOMHandler.h:192
void buildAnalysisProtocolCollection_(xercesc::DOMElement *protocolElements)
std::map< String, String > xl_id_acceptor_map_
mapping peptide id of acceptor peptide -> cross-link acceptor value
Definition: MzIdentMLDOMHandler.h:279
String spectrum_identification_protocol_ref
Definition: MzIdentMLDOMHandler.h:208
XMLCh * xml_name_attr_ptr_
Definition: MzIdentMLDOMHandler.h:245
virtual ~MzIdentMLDOMHandler()
Destructor.
String spectra_data_ref
Definition: MzIdentMLDOMHandler.h:206
const String schema_version_
Internal version keeping.
Definition: MzIdentMLDOMHandler.h:135
void parsePeptideElements_(xercesc::DOMNodeList *peptideElements)
Struct to hold the used analysis software for that file.
Definition: MzIdentMLDOMHandler.h:182
Struct to hold the information from the DBSequence xml tag.
Definition: MzIdentMLDOMHandler.h:197
Struct to hold the information from the DatabaseInput xml tag.
Definition: MzIdentMLDOMHandler.h:236
Struct to hold the information from the ModificationParam xml tag.
Definition: MzIdentMLDOMHandler.h:213
Struct to hold the PeptideEvidence information.
Definition: MzIdentMLDOMHandler.h:188
Struct to hold the information from the SpectrumIdentification xml tag.
Definition: MzIdentMLDOMHandler.h:205
Struct to hold the information from the SpectrumIdentificationProtocol xml tag.
Definition: MzIdentMLDOMHandler.h:222
Represents the peptide hits for a spectrum.
Definition: PeptideIdentification.h:65
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:53
Representation of a protein identification run.
Definition: ProteinIdentification.h:72
A more convenient string class.
Definition: String.h:60
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Representation of a CV term.
Definition: ControlledVocabulary.h:61
Search parameters of the DB search.
Definition: ProteinIdentification.h:260