OpenMS  3.0.0
OMSFileLoad.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-2022.
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: Hendrik Weisser $
32 // $Authors: Hendrik Weisser $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
40 
41 #include <QtCore/QJsonArray> // for JSON export
42 #include <QString>
43 #include <QStringList> // avoid compiler error on initialization using init. list
44 
45 class QSqlQuery;
46 
47 namespace OpenMS
48 {
49  namespace Internal
50  {
57  {
58  public:
59  using Key = qint64;
60 
71  OMSFileLoad(const String& filename, LogType log_type);
72 
78  ~OMSFileLoad();
79 
81  void load(IdentificationData& id_data);
82 
84  void load(FeatureMap& features);
85 
87  void exportToJSON(std::ostream& output);
88 
89  private:
90  // static CVTerm loadCVTerm_(int id);
91 
92  void loadScoreTypes_(IdentificationData& id_data);
93 
94  void loadInputFiles_(IdentificationData& id_data);
95 
97 
99 
101 
102  void loadObservations_(IdentificationData& id_data);
103 
105 
107 
109 
111 
112  void loadAdducts_(IdentificationData& id_data);
113 
115 
116  void loadMapMetaData_(FeatureMap& features);
117 
118  void loadDataProcessing_(FeatureMap& features);
119 
120  void loadFeatures_(FeatureMap& features);
121 
122  Feature loadFeatureAndSubordinates_(QSqlQuery& query_feat,
123  std::optional<QSqlQuery>& query_meta,
124  std::optional<QSqlQuery>& query_hull,
125  std::optional<QSqlQuery>& query_match);
126 
127  static DataValue makeDataValue_(const QSqlQuery& query);
128 
129  bool prepareQueryMetaInfo_(QSqlQuery& query, const String& parent_table);
130 
131  void handleQueryMetaInfo_(QSqlQuery& query, MetaInfoInterface& info,
132  Key parent_id);
133 
134  bool prepareQueryAppliedProcessingStep_(QSqlQuery& query,
135  const String& parent_table);
136 
138  QSqlQuery& query,
140  Key parent_id);
141 
143  QSqlQuery& query, IdentificationData::ParentMatches& parent_matches,
144  Key molecule_id);
145 
147  QSqlQuery& query, IdentificationData::ObservationMatch& match,
148  Key parent_id);
149 
150  void createView_(const QString& name, const QString& select);
151 
152  QJsonArray exportTableToJSON_(const QString& table, const QString& order_by);
153 
154  // store name, not database connection itself (see https://stackoverflow.com/a/55200682):
155  QString db_name_;
156 
158 
159  QString subquery_score_;
160 
161  // mappings between database keys and loaded data:
162  std::unordered_map<Key, IdentificationData::ScoreTypeRef> score_type_refs_;
163  std::unordered_map<Key, IdentificationData::InputFileRef> input_file_refs_;
164  std::unordered_map<Key, IdentificationData::ProcessingSoftwareRef> processing_software_refs_;
165  std::unordered_map<Key, IdentificationData::ProcessingStepRef> processing_step_refs_;
166  std::unordered_map<Key, IdentificationData::SearchParamRef> search_param_refs_;
167  std::unordered_map<Key, IdentificationData::ObservationRef> observation_refs_;
168  std::unordered_map<Key, IdentificationData::ParentSequenceRef> parent_sequence_refs_;
169  std::unordered_map<Key, IdentificationData::IdentifiedMolecule> identified_molecule_vars_;
170  std::unordered_map<Key, IdentificationData::ObservationMatchRef> observation_match_refs_;
171  std::unordered_map<Key, IdentificationData::AdductRef> adduct_refs_;
172 
173  // mapping: table name -> ordering critera (for JSON export)
174  // @TODO: could use 'unordered_map' here, but would need to specify hash function for 'QString'
175  static std::map<QString, QString> export_order_by_;
176  };
177  }
178 }
static DataValue makeDataValue_(const QSqlQuery &query)
Helper class for loading .oms files (SQLite format)
Definition: OMSFileLoad.h:56
A more convenient string class.
Definition: String.h:58
void exportToJSON(std::ostream &output)
Export database contents in JSON format, write to stream.
void handleQueryParentMatch_(QSqlQuery &query, IdentificationData::ParentMatches &parent_matches, Key molecule_id)
void load(IdentificationData &id_data)
Load data from database and populate an IdentificationData object.
bool prepareQueryAppliedProcessingStep_(QSqlQuery &query, const String &parent_table)
LogType
Possible log types.
Definition: ProgressLogger.h:68
void handleQueryMetaInfo_(QSqlQuery &query, MetaInfoInterface &info, Key parent_id)
void createView_(const QString &name, const QString &select)
A container for features.
Definition: FeatureMap.h:98
void loadInputFiles_(IdentificationData &id_data)
QString db_name_
Definition: OMSFileLoad.h:155
void loadParentGroupSets_(IdentificationData &id_data)
std::unordered_map< Key, IdentificationData::ScoreTypeRef > score_type_refs_
Definition: OMSFileLoad.h:162
IdentificationDataInternal::ParentMatches ParentMatches
Definition: IdentificationData.h:146
Representation of spectrum identification results and associated data.
Definition: IdentificationData.h:94
void loadObservationMatches_(IdentificationData &id_data)
std::unordered_map< Key, IdentificationData::ProcessingStepRef > processing_step_refs_
Definition: OMSFileLoad.h:165
std::unordered_map< Key, IdentificationData::ObservationMatchRef > observation_match_refs_
Definition: OMSFileLoad.h:170
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
int version_number_
schema version number
Definition: OMSFileLoad.h:157
void loadProcessingSoftwares_(IdentificationData &id_data)
std::unordered_map< Key, IdentificationData::IdentifiedMolecule > identified_molecule_vars_
Definition: OMSFileLoad.h:169
void loadAdducts_(IdentificationData &id_data)
bool prepareQueryMetaInfo_(QSqlQuery &query, const String &parent_table)
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:58
void loadScoreTypes_(IdentificationData &id_data)
std::unordered_map< Key, IdentificationData::ObservationRef > observation_refs_
Definition: OMSFileLoad.h:167
QString subquery_score_
query for score types used in JSON export
Definition: OMSFileLoad.h:159
void loadDataProcessing_(FeatureMap &features)
std::unordered_map< Key, IdentificationData::SearchParamRef > search_param_refs_
Definition: OMSFileLoad.h:166
OMSFileLoad(const String &filename, LogType log_type)
Constructor.
static std::map< QString, QString > export_order_by_
Definition: OMSFileLoad.h:175
void loadIdentifiedSequences_(IdentificationData &id_data)
qint64 Key
Type used for database keys.
Definition: OMSFileLoad.h:59
std::unordered_map< Key, IdentificationData::ProcessingSoftwareRef > processing_software_refs_
Definition: OMSFileLoad.h:164
void loadMapMetaData_(FeatureMap &features)
An LC-MS feature.
Definition: Feature.h:70
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:60
void loadFeatures_(FeatureMap &features)
QJsonArray exportTableToJSON_(const QString &table, const QString &order_by)
void handleQueryPeakAnnotation_(QSqlQuery &query, IdentificationData::ObservationMatch &match, Key parent_id)
void loadObservations_(IdentificationData &id_data)
std::unordered_map< Key, IdentificationData::AdductRef > adduct_refs_
Definition: OMSFileLoad.h:171
Representation of a search hit (e.g. peptide-spectrum match).
Definition: ObservationMatch.h:73
void loadParentSequences_(IdentificationData &id_data)
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:52
void loadDBSearchParams_(IdentificationData &id_data)
void handleQueryAppliedProcessingStep_(QSqlQuery &query, IdentificationDataInternal::ScoredProcessingResult &result, Key parent_id)
void loadProcessingSteps_(IdentificationData &id_data)
Base class for ID data with scores and processing steps (and meta info)
Definition: ScoredProcessingResult.h:44
std::unordered_map< Key, IdentificationData::ParentSequenceRef > parent_sequence_refs_
Definition: OMSFileLoad.h:168
std::unordered_map< Key, IdentificationData::InputFileRef > input_file_refs_
Definition: OMSFileLoad.h:163
void loadIdentifiedCompounds_(IdentificationData &id_data)
Feature loadFeatureAndSubordinates_(QSqlQuery &query_feat, std::optional< QSqlQuery > &query_meta, std::optional< QSqlQuery > &query_hull, std::optional< QSqlQuery > &query_match)