OpenMS
Loading...
Searching...
No Matches
FileHandler.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg $
6// $Authors: Marc Sturm $
7// --------------------------------------------------------------------------
8
9#pragma once
10
12
13#include <OpenMS/config.h>
18
19// Forward declarations instead of full includes — all these types appear only
20// as references/pointers in method signatures, so full definitions are not needed.
21namespace OpenMS
22{
23 class TransformationDescription;
24 class PeakFileOptions;
25 class MSSpectrum;
26 class MSExperiment;
27 class FeatureMap;
28 class ConsensusMap;
29 class TargetedExperiment;
30 class ProteinIdentification;
31 class PeptideIdentificationList;
32
46 class OPENMS_DLLAPI FileHandler
47 {
48public:
61 static FileTypes::Type getType(const std::string& filename);
62
63
73 static FileTypes::Type getTypeByFileName(const std::string& filename);
74
75
85 static bool hasValidExtension(const std::string& filename, const FileTypes::Type type);
86
87
100 static std::string stripExtension(const std::string& filename);
101
102
116 static std::string swapExtension(const std::string& filename, const FileTypes::Type new_type);
117
118
131 static FileTypes::Type getConsistentOutputfileType(const std::string& output_filename, const std::string& requested_type);
132
133
141 static FileTypes::Type getTypeByContent(const std::string& filename);
142
144 static bool isSupported(FileTypes::Type type);
145
148
151
154
157
160
163
177 void loadExperiment(const std::string& filename, PeakMap& exp, const std::vector<FileTypes::Type> allowed_types = std::vector<FileTypes::Type>(),
178 ProgressLogger::LogType log = ProgressLogger::NONE, const bool rewrite_source_file = false,
179 const bool compute_hash = false);
180
193 void storeExperiment(const std::string& filename, const PeakMap& exp, const std::vector<FileTypes::Type> allowed_types = {}, ProgressLogger::LogType log = ProgressLogger::NONE);
194
205 void loadSpectrum(const std::string& filename, MSSpectrum& spec, const std::vector<FileTypes::Type> allowed_types = {});
206
216 void storeSpectrum(const std::string& filename, MSSpectrum& spec, const std::vector<FileTypes::Type> allowed_types = {});
217
229 void loadFeatures(const std::string& filename, FeatureMap& map, const std::vector<FileTypes::Type> allowed_types = {}, ProgressLogger::LogType log = ProgressLogger::NONE);
230
250 void storeFeatures(const std::string& filename, const FeatureMap& map, const std::vector<FileTypes::Type> allowed_types = {}, ProgressLogger::LogType log = ProgressLogger::NONE);
251
263 void loadConsensusFeatures(const std::string& filename, ConsensusMap& map, const std::vector<FileTypes::Type> allowed_types = {}, ProgressLogger::LogType log = ProgressLogger::NONE);
264
284 void storeConsensusFeatures(const std::string& filename, const ConsensusMap& map, const std::vector<FileTypes::Type> allowed_types = {}, ProgressLogger::LogType log = ProgressLogger::NONE);
285
298 void loadIdentifications(const std::string& filename, std::vector<ProteinIdentification>& additional_proteins, PeptideIdentificationList& additional_peptides, const std::vector<FileTypes::Type> allowed_types = {}, ProgressLogger::LogType log = ProgressLogger::NONE);
299
320 void storeIdentifications(const std::string& filename, const std::vector<ProteinIdentification>& additional_proteins, const PeptideIdentificationList& additional_peptides, const std::vector<FileTypes::Type> allowed_types = {}, ProgressLogger::LogType log = ProgressLogger::NONE);
321
333 void loadTransitions(const std::string& filename, TargetedExperiment& library, const std::vector<FileTypes::Type> allowed_types = {}, ProgressLogger::LogType log = ProgressLogger::NONE);
334
345 void storeTransitions(const std::string& filename, const TargetedExperiment& library, const std::vector<FileTypes::Type> allowed_types = {}, ProgressLogger::LogType log = ProgressLogger::NONE);
346
359 void loadTransformations(const std::string& filename, TransformationDescription& map, bool fit_model=true, const std::vector<FileTypes::Type> allowed_types = {});
360
370 void storeTransformations(const std::string& filename, const TransformationDescription& map, const std::vector<FileTypes::Type> allowed_types = {});
371
392 void storeQC(const std::string& input_file,
393 const std::string& filename,
394 const MSExperiment& exp,
395 const FeatureMap& feature_map,
396 std::vector<ProteinIdentification>& prot_ids,
398 const ConsensusMap& consensus_map,
399 const std::string& contact_name = "",
400 const std::string& contact_address = "",
401 const std::string& description = "",
402 const std::string& label = "label",
403 const bool remove_duplicate_features = false,
404 const std::vector<FileTypes::Type> allowed_types = {});
405
411 static std::string computeFileHash(const std::string& filename);
412
413private:
424
427 };
428
429} //namespace
A container for consensus elements.
Definition ConsensusMap.h:67
Options for loading files containing features.
Definition FeatureFileOptions.h:35
A container for features.
Definition FeatureMap.h:78
Facilitates file handling by file type recognition.
Definition FileHandler.h:47
static bool isSupported(FileTypes::Type type)
Returns if the file type is supported in this build of the library.
void applyPostLoadOptions_(MSExperiment &exp) const
Applies the current PeakFileOptions filters to an already-loaded experiment.
void storeQC(const std::string &input_file, const std::string &filename, const MSExperiment &exp, const FeatureMap &feature_map, std::vector< ProteinIdentification > &prot_ids, PeptideIdentificationList &pep_ids, const ConsensusMap &consensus_map, const std::string &contact_name="", const std::string &contact_address="", const std::string &description="", const std::string &label="label", const bool remove_duplicate_features=false, const std::vector< FileTypes::Type > allowed_types={})
Store QC info.
void setOptions(const PeakFileOptions &)
set options for loading/storing
void storeSpectrum(const std::string &filename, MSSpectrum &spec, const std::vector< FileTypes::Type > allowed_types={})
Stores a single MSSpectrum to a file.
void storeIdentifications(const std::string &filename, const std::vector< ProteinIdentification > &additional_proteins, const PeptideIdentificationList &additional_peptides, const std::vector< FileTypes::Type > allowed_types={}, ProgressLogger::LogType log=ProgressLogger::NONE)
Stores proteins and peptides into an Identification File.
const FeatureFileOptions & getFeatOptions() const
Non-mutable access to the feature file options for loading/storing.
void loadIdentifications(const std::string &filename, std::vector< ProteinIdentification > &additional_proteins, PeptideIdentificationList &additional_peptides, const std::vector< FileTypes::Type > allowed_types={}, ProgressLogger::LogType log=ProgressLogger::NONE)
Loads an identification file into a proteinIdentifications and peptideIdentifications.
static FileTypes::Type getTypeByContent(const std::string &filename)
Determines the file type of a file by parsing the first few lines.
static FileTypes::Type getTypeByFileName(const std::string &filename)
Try to get the file type from the filename.
const PeakFileOptions & getOptions() const
Non-mutable access to the options for loading/storing.
void loadConsensusFeatures(const std::string &filename, ConsensusMap &map, const std::vector< FileTypes::Type > allowed_types={}, ProgressLogger::LogType log=ProgressLogger::NONE)
Loads a file into a ConsensusMap.
void storeExperiment(const std::string &filename, const PeakMap &exp, const std::vector< FileTypes::Type > allowed_types={}, ProgressLogger::LogType log=ProgressLogger::NONE)
Stores an MSExperiment to a file.
void storeConsensusFeatures(const std::string &filename, const ConsensusMap &map, const std::vector< FileTypes::Type > allowed_types={}, ProgressLogger::LogType log=ProgressLogger::NONE)
Store a ConsensusFeatureMap.
void loadTransformations(const std::string &filename, TransformationDescription &map, bool fit_model=true, const std::vector< FileTypes::Type > allowed_types={})
Loads a file into Transformations.
void storeTransitions(const std::string &filename, const TargetedExperiment &library, const std::vector< FileTypes::Type > allowed_types={}, ProgressLogger::LogType log=ProgressLogger::NONE)
Store transitions of a spectral library.
PeakFileOptions options_
Definition FileHandler.h:425
static bool hasValidExtension(const std::string &filename, const FileTypes::Type type)
Check if filename has the extension type.
static FileTypes::Type getType(const std::string &filename)
Tries to determine the file type (by name or content)
void storeFeatures(const std::string &filename, const FeatureMap &map, const std::vector< FileTypes::Type > allowed_types={}, ProgressLogger::LogType log=ProgressLogger::NONE)
Store a FeatureMap.
FeatureFileOptions & getFeatOptions()
Mutable access to the feature file options for loading/storing.
PeakFileOptions & getOptions()
Mutable access to the options for loading/storing.
static std::string swapExtension(const std::string &filename, const FileTypes::Type new_type)
Tries to find and remove a known file extension, and append the new one.
void loadSpectrum(const std::string &filename, MSSpectrum &spec, const std::vector< FileTypes::Type > allowed_types={})
Loads a single MSSpectrum from a file.
static std::string stripExtension(const std::string &filename)
If filename contains an extension, it will be removed (including the '.'). Special extensions,...
void setFeatOptions(const FeatureFileOptions &)
set feature file options for loading/storing
void loadTransitions(const std::string &filename, TargetedExperiment &library, const std::vector< FileTypes::Type > allowed_types={}, ProgressLogger::LogType log=ProgressLogger::NONE)
Load transitions of a spectral library.
static std::string computeFileHash(const std::string &filename)
Computes a SHA-1 hash value for the content of the given file.
FeatureFileOptions f_options_
Definition FileHandler.h:426
void loadExperiment(const std::string &filename, PeakMap &exp, const std::vector< FileTypes::Type > allowed_types=std::vector< FileTypes::Type >(), ProgressLogger::LogType log=ProgressLogger::NONE, const bool rewrite_source_file=false, const bool compute_hash=false)
Loads a file into an MSExperiment.
void loadFeatures(const std::string &filename, FeatureMap &map, const std::vector< FileTypes::Type > allowed_types={}, ProgressLogger::LogType log=ProgressLogger::NONE)
Loads a file into a FeatureMap.
static FileTypes::Type getConsistentOutputfileType(const std::string &output_filename, const std::string &requested_type)
Useful function for TOPP tools which have an 'out_type' parameter and want to know what output format...
void storeTransformations(const std::string &filename, const TransformationDescription &map, const std::vector< FileTypes::Type > allowed_types={})
Store Transformations.
In-Memory representation of a mass spectrometry run.
Definition MSExperiment.h:49
The representation of a 1D spectrum.
Definition MSSpectrum.h:44
Options for loading files containing peak data.
Definition PeakFileOptions.h:22
Container for peptide identifications from multiple spectra.
Definition PeptideIdentificationList.h:66
LogType
Possible log types.
Definition ProgressLogger.h:43
A description of a targeted experiment containing precursor and production ions.
Definition TargetedExperiment.h:40
Generic description of a coordinate transformation.
Definition TransformationDescription.h:38
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Type
Actual file types enum.
Definition FileTypes.h:31