OpenMS
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-2023.
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 
40 
41 #include <QtCore/QJsonArray> // for JSON export
42 
43 namespace SQLite
44 {
45  class Database;
46 } // namespace SQLite
47 
48 namespace OpenMS
49 {
50  class FeatureMap;
51  class ConsensusMap;
52 
53  namespace Internal
54  {
61  {
62  public:
64 
75  OMSFileLoad(const String& filename, LogType log_type);
76 
83 
85  void load(IdentificationData& id_data);
86 
88  void load(FeatureMap& features);
89 
91  void load(ConsensusMap& consensus);
92 
94  void exportToJSON(std::ostream& output);
95 
96  private:
98  static bool isEmpty_(const SQLite::Statement& query);
99 
101  static DataValue makeDataValue_(const SQLite::Statement& query);
102 
103  // static CVTerm loadCVTerm_(int id);
104 
107 
110 
113 
116 
119 
122 
125 
128 
131 
134 
137 
140 
142  template <class MapType> String loadMapMetaDataTemplate_(MapType& features);
143 
145  void loadMapMetaData_(FeatureMap& features);
146 
148  void loadMapMetaData_(ConsensusMap& consensus);
149 
151  void loadDataProcessing_(std::vector<DataProcessing>& data_processing);
152 
154  void loadFeatures_(FeatureMap& features);
155 
157  Feature loadFeatureAndSubordinates_(SQLite::Statement& query_feat,
158  SQLite::Statement& query_meta,
159  SQLite::Statement& query_match,
160  SQLite::Statement& query_hull);
161 
164 
167 
169  BaseFeature makeBaseFeature_(int id, SQLite::Statement& query_feat,
170  SQLite::Statement& query_meta,
171  SQLite::Statement& query_match);
172 
174  void prepareQueriesBaseFeature_(SQLite::Statement& query_meta,
175  SQLite::Statement& query_match);
176 
178  bool prepareQueryMetaInfo_(SQLite::Statement& query, const String& parent_table);
179 
181  void handleQueryMetaInfo_(SQLite::Statement& query, MetaInfoInterface& info,
182  Key parent_id);
183 
185  bool prepareQueryAppliedProcessingStep_(SQLite::Statement& query,
186  const String& parent_table);
187 
190  SQLite::Statement& query,
192  Key parent_id);
193 
196  SQLite::Statement& query, IdentificationData::ParentMatches& parent_matches,
197  Key molecule_id);
198 
201  SQLite::Statement& query, IdentificationData::ObservationMatch& match,
202  Key parent_id);
203 
205  QJsonArray exportTableToJSON_(const QString& table, const QString& order_by);
206 
208  std::unique_ptr<SQLite::Database> db_;
209 
211 
212  QString subquery_score_;
213 
214  // mappings between database keys and loaded data:
215  std::unordered_map<Key, IdentificationData::ScoreTypeRef> score_type_refs_;
216  std::unordered_map<Key, IdentificationData::InputFileRef> input_file_refs_;
217  std::unordered_map<Key, IdentificationData::ProcessingSoftwareRef> processing_software_refs_;
218  std::unordered_map<Key, IdentificationData::ProcessingStepRef> processing_step_refs_;
219  std::unordered_map<Key, IdentificationData::SearchParamRef> search_param_refs_;
220  std::unordered_map<Key, IdentificationData::ObservationRef> observation_refs_;
221  std::unordered_map<Key, IdentificationData::ParentSequenceRef> parent_sequence_refs_;
222  std::unordered_map<Key, IdentificationData::IdentifiedMolecule> identified_molecule_vars_;
223  std::unordered_map<Key, IdentificationData::ObservationMatchRef> observation_match_refs_;
224  std::unordered_map<Key, IdentificationData::AdductRef> adduct_refs_;
225 
226  // mapping: table name -> ordering critera (for JSON export)
227  // @TODO: could use 'unordered_map' here, but would need to specify hash function for 'QString'
228  static std::map<QString, QString> export_order_by_;
229  };
230  }
231 }
A basic LC-MS feature.
Definition: BaseFeature.h:59
A container for consensus elements.
Definition: ConsensusMap.h:92
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:59
A container for features.
Definition: FeatureMap.h:106
An LC-MS feature.
Definition: Feature.h:72
Definition: IdentificationData.h:113
IdentificationDataInternal::ParentMatches ParentMatches
Definition: IdentificationData.h:164
Helper class for loading .oms files (SQLite format)
Definition: OMSFileLoad.h:61
String loadMapMetaDataTemplate_(MapType &features)
Helper function for loading meta data on feature/consensus maps from the database.
void loadConsensusFeatures_(ConsensusMap &consensus)
Load information on consensus features from the database into a consensus map.
std::unordered_map< Key, IdentificationData::IdentifiedMolecule > identified_molecule_vars_
Definition: OMSFileLoad.h:222
void loadParentSequences_(IdentificationData &id_data)
Load information on parent sequences (e.g. proteins) from the database into IdentificationData.
void loadIdentifiedSequences_(IdentificationData &id_data)
Load information on identified sequences (peptides or oligonucleotides) from the database into Identi...
std::unordered_map< Key, IdentificationData::ProcessingSoftwareRef > processing_software_refs_
Definition: OMSFileLoad.h:217
void load(IdentificationData &id_data)
Load data from database and populate an IdentificationData object.
void loadProcessingSoftwares_(IdentificationData &id_data)
Load information on data processing software from the database into IdentificationData.
void loadScoreTypes_(IdentificationData &id_data)
Load information on score type from the database into IdentificationData.
std::unordered_map< Key, IdentificationData::ParentSequenceRef > parent_sequence_refs_
Definition: OMSFileLoad.h:221
void loadDataProcessing_(std::vector< DataProcessing > &data_processing)
Load information on data processing for feature/consensus maps from the database.
std::unordered_map< Key, IdentificationData::InputFileRef > input_file_refs_
Definition: OMSFileLoad.h:216
void loadObservationMatches_(IdentificationData &id_data)
Load information on observation matches (e.g. PSMs) from the database into IdentificationData.
OMSFileStore::Key Key
Type used for database keys.
Definition: OMSFileLoad.h:63
static DataValue makeDataValue_(const SQLite::Statement &query)
Generate a DataValue with information returned by an SQL query.
void loadMapMetaData_(FeatureMap &features)
Load feature map meta data from the database.
QJsonArray exportTableToJSON_(const QString &table, const QString &order_by)
Export the contents of a database table to JSON.
int version_number_
schema version number
Definition: OMSFileLoad.h:210
void loadFeatures_(FeatureMap &features)
Load information on features from the database into a feature map.
void loadParentGroupSets_(IdentificationData &id_data)
Load information on parent group sets (e.g. protein groups) from the database into IdentificationData...
Feature loadFeatureAndSubordinates_(SQLite::Statement &query_feat, SQLite::Statement &query_meta, SQLite::Statement &query_match, SQLite::Statement &query_hull)
Generate a feature (incl. subordinate features) from data returned by SQL queries.
void handleQueryAppliedProcessingStep_(SQLite::Statement &query, IdentificationDataInternal::ScoredProcessingResult &result, Key parent_id)
Store results from an SQL query on processing metadata in a ScoredProcessingResult(-derived) object.
void exportToJSON(std::ostream &output)
Export database contents in JSON format, write to stream.
std::unordered_map< Key, IdentificationData::ObservationRef > observation_refs_
Definition: OMSFileLoad.h:220
void load(ConsensusMap &consensus)
Load data from database and populate a ConsensusMap object.
std::unordered_map< Key, IdentificationData::SearchParamRef > search_param_refs_
Definition: OMSFileLoad.h:219
void load(FeatureMap &features)
Load data from database and populate a FeatureMap object.
QString subquery_score_
query for score types used in JSON export
Definition: OMSFileLoad.h:212
bool prepareQueryMetaInfo_(SQLite::Statement &query, const String &parent_table)
Prepare SQL query for loading meta values associated with a particular class (stored in parent_table)
bool prepareQueryAppliedProcessingStep_(SQLite::Statement &query, const String &parent_table)
Prepare SQL query for loading processing metadata associated with a particular class (stored in paren...
void handleQueryParentMatch_(SQLite::Statement &query, IdentificationData::ParentMatches &parent_matches, Key molecule_id)
Store results from an SQL query on parent matches.
void loadProcessingSteps_(IdentificationData &id_data)
Load information on data processing steps from the database into IdentificationData.
std::unordered_map< Key, IdentificationData::ObservationMatchRef > observation_match_refs_
Definition: OMSFileLoad.h:223
BaseFeature makeBaseFeature_(int id, SQLite::Statement &query_feat, SQLite::Statement &query_meta, SQLite::Statement &query_match)
Generate a BaseFeature (parent class) from data returned by SQL queries.
void loadAdducts_(IdentificationData &id_data)
Load information on adducts from the database into IdentificationData.
void handleQueryPeakAnnotation_(SQLite::Statement &query, IdentificationData::ObservationMatch &match, Key parent_id)
Store results from an SQL query on peak annotations in an observation match.
void loadConsensusColumnHeaders_(ConsensusMap &consensus)
Load consensus map column headers from the database.
void loadObservations_(IdentificationData &id_data)
Load information on observations (e.g. spectra) from the database into IdentificationData.
OMSFileLoad(const String &filename, LogType log_type)
Constructor.
std::unordered_map< Key, IdentificationData::ScoreTypeRef > score_type_refs_
Definition: OMSFileLoad.h:215
void loadInputFiles_(IdentificationData &id_data)
Load information on input files from the database into IdentificationData.
std::unique_ptr< SQLite::Database > db_
The database connection (read)
Definition: OMSFileLoad.h:208
void loadDBSearchParams_(IdentificationData &id_data)
Load information on sequence database search parameters from the database into IdentificationData.
std::unordered_map< Key, IdentificationData::ProcessingStepRef > processing_step_refs_
Definition: OMSFileLoad.h:218
void prepareQueriesBaseFeature_(SQLite::Statement &query_meta, SQLite::Statement &query_match)
Prepare SQL queries for loading (meta) data on BaseFeatures from the database.
std::unordered_map< Key, IdentificationData::AdductRef > adduct_refs_
Definition: OMSFileLoad.h:224
void loadMapMetaData_(ConsensusMap &consensus)
Load consensus map meta data from the database.
void handleQueryMetaInfo_(SQLite::Statement &query, MetaInfoInterface &info, Key parent_id)
Store results from an SQL query on meta values in a MetaInfoInterface(-derived) object.
static bool isEmpty_(const SQLite::Statement &query)
Does the query contain an empty SQL statement (signifying that it shouldn't be executed)?
static std::map< QString, QString > export_order_by_
Definition: OMSFileLoad.h:228
void loadIdentifiedCompounds_(IdentificationData &id_data)
Load information on identified compounds from the database into IdentificationData.
int64_t Key
< Type used for database keys
Definition: OMSFileStore.h:88
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:72
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:61
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:53
LogType
Possible log types.
Definition: ProgressLogger.h:69
A more convenient string class.
Definition: String.h:60
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
Definition: OMSFileLoad.h:44
Representation of a search hit (e.g. peptide-spectrum match).
Definition: ObservationMatch.h:74
Base class for ID data with scores and processing steps (and meta info)
Definition: ScoredProcessingResult.h:45