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, Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
41 
42 #include <QtCore/QJsonArray> // for JSON export
43 
44 namespace SQLite
45 {
46  class Database;
47 } // namespace SQLite
48 
49 namespace OpenMS
50 {
51  namespace Internal
52  {
59  {
60  public:
62 
73  OMSFileLoad(const String& filename, LogType log_type);
74 
80  ~OMSFileLoad();
81 
83  void load(IdentificationData& id_data);
84 
86  void load(FeatureMap& features);
87 
89  void exportToJSON(std::ostream& output);
90 
91  private:
92  // static CVTerm loadCVTerm_(int id);
93 
94  void loadScoreTypes_(IdentificationData& id_data);
95 
96  void loadInputFiles_(IdentificationData& id_data);
97 
99 
101 
103 
104  void loadObservations_(IdentificationData& id_data);
105 
107 
109 
111 
113 
114  void loadAdducts_(IdentificationData& id_data);
115 
117 
118  void loadMapMetaData_(FeatureMap& features);
119 
120  void loadDataProcessing_(FeatureMap& features);
121 
122  void loadFeatures_(FeatureMap& features);
123 
124  Feature loadFeatureAndSubordinates_(SQLite::Statement& query_feat,
125  std::optional<SQLite::Statement>& query_meta,
126  std::optional<SQLite::Statement>& query_hull,
127  std::optional<SQLite::Statement>& query_match);
128 
129  static DataValue makeDataValue_(const SQLite::Statement& query);
130 
131  bool prepareQueryMetaInfo_(SQLite::Statement& query, const String& parent_table);
132 
133  void handleQueryMetaInfo_(SQLite::Statement& query, MetaInfoInterface& info,
134  Key parent_id);
135 
136  bool prepareQueryAppliedProcessingStep_(SQLite::Statement& query,
137  const String& parent_table);
138 
140  SQLite::Statement& query,
142  Key parent_id);
143 
145  SQLite::Statement& query, IdentificationData::ParentMatches& parent_matches,
146  Key molecule_id);
147 
149  SQLite::Statement& query, IdentificationData::ObservationMatch& match,
150  Key parent_id);
151 
152  void createView_(const String& name, const String& select);
153 
154  QJsonArray exportTableToJSON_(const QString& table, const QString& order_by);
155 
157  std::unique_ptr<SQLite::Database> db_;
158 
160 
161  QString subquery_score_;
162 
163  // mappings between database keys and loaded data:
164  std::unordered_map<Key, IdentificationData::ScoreTypeRef> score_type_refs_;
165  std::unordered_map<Key, IdentificationData::InputFileRef> input_file_refs_;
166  std::unordered_map<Key, IdentificationData::ProcessingSoftwareRef> processing_software_refs_;
167  std::unordered_map<Key, IdentificationData::ProcessingStepRef> processing_step_refs_;
168  std::unordered_map<Key, IdentificationData::SearchParamRef> search_param_refs_;
169  std::unordered_map<Key, IdentificationData::ObservationRef> observation_refs_;
170  std::unordered_map<Key, IdentificationData::ParentSequenceRef> parent_sequence_refs_;
171  std::unordered_map<Key, IdentificationData::IdentifiedMolecule> identified_molecule_vars_;
172  std::unordered_map<Key, IdentificationData::ObservationMatchRef> observation_match_refs_;
173  std::unordered_map<Key, IdentificationData::AdductRef> adduct_refs_;
174 
175  // mapping: table name -> ordering critera (for JSON export)
176  // @TODO: could use 'unordered_map' here, but would need to specify hash function for 'QString'
177  static std::map<QString, QString> export_order_by_;
178  };
179  }
180 }
void handleQueryMetaInfo_(SQLite::Statement &query, MetaInfoInterface &info, Key parent_id)
Helper class for loading .oms files (SQLite format)
Definition: OMSFileLoad.h:58
A more convenient string class.
Definition: String.h:58
void exportToJSON(std::ostream &output)
Export database contents in JSON format, write to stream.
void load(IdentificationData &id_data)
Load data from database and populate an IdentificationData object.
LogType
Possible log types.
Definition: ProgressLogger.h:68
OMSFileStore::Key Key
Type used for database keys.
Definition: OMSFileLoad.h:61
A container for features.
Definition: FeatureMap.h:98
void loadInputFiles_(IdentificationData &id_data)
void loadParentGroupSets_(IdentificationData &id_data)
int64_t Key
< Type used for database keys
Definition: OMSFileStore.h:81
std::unordered_map< Key, IdentificationData::ScoreTypeRef > score_type_refs_
Definition: OMSFileLoad.h:164
IdentificationDataInternal::ParentMatches ParentMatches
Definition: IdentificationData.h:164
Definition: IdentificationData.h:112
void loadObservationMatches_(IdentificationData &id_data)
std::unordered_map< Key, IdentificationData::ProcessingStepRef > processing_step_refs_
Definition: OMSFileLoad.h:167
std::unordered_map< Key, IdentificationData::ObservationMatchRef > observation_match_refs_
Definition: OMSFileLoad.h:172
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
bool prepareQueryAppliedProcessingStep_(SQLite::Statement &query, const String &parent_table)
int version_number_
schema version number
Definition: OMSFileLoad.h:159
void loadProcessingSoftwares_(IdentificationData &id_data)
std::unordered_map< Key, IdentificationData::IdentifiedMolecule > identified_molecule_vars_
Definition: OMSFileLoad.h:171
void loadAdducts_(IdentificationData &id_data)
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:58
void loadScoreTypes_(IdentificationData &id_data)
void handleQueryAppliedProcessingStep_(SQLite::Statement &query, IdentificationDataInternal::ScoredProcessingResult &result, Key parent_id)
std::unordered_map< Key, IdentificationData::ObservationRef > observation_refs_
Definition: OMSFileLoad.h:169
QString subquery_score_
query for score types used in JSON export
Definition: OMSFileLoad.h:161
void createView_(const String &name, const String &select)
void handleQueryPeakAnnotation_(SQLite::Statement &query, IdentificationData::ObservationMatch &match, Key parent_id)
void loadDataProcessing_(FeatureMap &features)
std::unordered_map< Key, IdentificationData::SearchParamRef > search_param_refs_
Definition: OMSFileLoad.h:168
OMSFileLoad(const String &filename, LogType log_type)
Constructor.
static std::map< QString, QString > export_order_by_
Definition: OMSFileLoad.h:177
void loadIdentifiedSequences_(IdentificationData &id_data)
Feature loadFeatureAndSubordinates_(SQLite::Statement &query_feat, std::optional< SQLite::Statement > &query_meta, std::optional< SQLite::Statement > &query_hull, std::optional< SQLite::Statement > &query_match)
std::unordered_map< Key, IdentificationData::ProcessingSoftwareRef > processing_software_refs_
Definition: OMSFileLoad.h:166
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 handleQueryParentMatch_(SQLite::Statement &query, IdentificationData::ParentMatches &parent_matches, Key molecule_id)
void loadFeatures_(FeatureMap &features)
QJsonArray exportTableToJSON_(const QString &table, const QString &order_by)
Definition: OMSFileLoad.h:44
void loadObservations_(IdentificationData &id_data)
std::unordered_map< Key, IdentificationData::AdductRef > adduct_refs_
Definition: OMSFileLoad.h:173
Representation of a search hit (e.g. peptide-spectrum match).
Definition: ObservationMatch.h:73
void loadParentSequences_(IdentificationData &id_data)
static DataValue makeDataValue_(const SQLite::Statement &query)
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:52
std::unique_ptr< SQLite::Database > db_
The database connection (read)
Definition: OMSFileLoad.h:157
void loadDBSearchParams_(IdentificationData &id_data)
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:170
std::unordered_map< Key, IdentificationData::InputFileRef > input_file_refs_
Definition: OMSFileLoad.h:165
bool prepareQueryMetaInfo_(SQLite::Statement &query, const String &parent_table)
void loadIdentifiedCompounds_(IdentificationData &id_data)