All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
11 #include <OpenMS/config.h>
21 
22 
23 namespace OpenMS
24 {
25  class PeakFileOptions;
26  class MSSpectrum;
27  class MSExperiment;
28  class FeatureMap;
29  class ConsensusMap;
30  class TargetedExperiment;
31 
45  class OPENMS_DLLAPI FileHandler
46  {
47 public:
60  static FileTypes::Type getType(const String& filename);
61 
62 
72  static FileTypes::Type getTypeByFileName(const String& filename);
73 
74 
81  static bool hasValidExtension(const String& filename, const FileTypes::Type type);
82 
83 
96  static String stripExtension(const String& filename);
97 
98 
112  static String swapExtension(const String& filename, const FileTypes::Type new_type);
113 
114 
127  static FileTypes::Type getConsistentOutputfileType(const String& output_filename, const String& requested_type);
128 
129 
135  static FileTypes::Type getTypeByContent(const String& filename);
136 
138  static bool isSupported(FileTypes::Type type);
139 
142 
144  const PeakFileOptions& getOptions() const;
145 
148 
151 
154 
157 
171  void loadExperiment(const String& filename, PeakMap& exp, const std::vector<FileTypes::Type> allowed_types = std::vector<FileTypes::Type>(),
172  ProgressLogger::LogType log = ProgressLogger::NONE, const bool rewrite_source_file = false,
173  const bool compute_hash = false);
174 
187  void storeExperiment(const String& filename, const PeakMap& exp, const std::vector<FileTypes::Type> allowed_types = {}, ProgressLogger::LogType log = ProgressLogger::NONE);
188 
199  void loadSpectrum(const String& filename, MSSpectrum& spec, const std::vector<FileTypes::Type> allowed_types = {});
200 
210  void storeSpectrum(const String& filename, MSSpectrum& spec, const std::vector<FileTypes::Type> allowed_types = {});
211 
223  void loadFeatures(const String& filename, FeatureMap& map, const std::vector<FileTypes::Type> allowed_types = {}, ProgressLogger::LogType log = ProgressLogger::NONE);
224 
235  void storeFeatures(const String& filename, const FeatureMap& map, const std::vector<FileTypes::Type> allowed_types = {}, ProgressLogger::LogType log = ProgressLogger::NONE);
236 
248  void loadConsensusFeatures(const String& filename, ConsensusMap& map, const std::vector<FileTypes::Type> allowed_types = {}, ProgressLogger::LogType log = ProgressLogger::NONE);
249 
260  void storeConsensusFeatures(const String& filename, const ConsensusMap& map, const std::vector<FileTypes::Type> allowed_types = {}, ProgressLogger::LogType log = ProgressLogger::NONE);
261 
274  void loadIdentifications(const String& filename, std::vector<ProteinIdentification>& additional_proteins, PeptideIdentificationList& additional_peptides, const std::vector<FileTypes::Type> allowed_types = {}, ProgressLogger::LogType log = ProgressLogger::NONE);
275 
287  void storeIdentifications(const String& filename, const std::vector<ProteinIdentification>& additional_proteins, const PeptideIdentificationList& additional_peptides, const std::vector<FileTypes::Type> allowed_types = {}, ProgressLogger::LogType log = ProgressLogger::NONE);
288 
300  void loadTransitions(const String& filename, TargetedExperiment& library, const std::vector<FileTypes::Type> allowed_types = {}, ProgressLogger::LogType log = ProgressLogger::NONE);
301 
312  void storeTransitions(const String& filename, const TargetedExperiment& library, const std::vector<FileTypes::Type> allowed_types = {}, ProgressLogger::LogType log = ProgressLogger::NONE);
313 
326  void loadTransformations(const String& filename, TransformationDescription& map, bool fit_model=true, const std::vector<FileTypes::Type> allowed_types = {});
327 
337  void storeTransformations(const String& filename, const TransformationDescription& map, const std::vector<FileTypes::Type> allowed_types = {});
338 
359  void storeQC(const String& input_file,
360  const String& filename,
361  const MSExperiment& exp,
362  const FeatureMap& feature_map,
363  std::vector<ProteinIdentification>& prot_ids,
364  PeptideIdentificationList& pep_ids,
365  const ConsensusMap& consensus_map = ConsensusMap(),
366  const String& contact_name = "",
367  const String& contact_address = "",
368  const String& description = "",
369  const String& label = "label",
370  const bool remove_duplicate_features = false,
371  const std::vector<FileTypes::Type> allowed_types = {});
372 
378  static String computeFileHash(const String& filename);
379 
380 private:
383  };
384 
385 } //namespace
386 
A container for consensus elements.
Definition: ConsensusMap.h:68
Options for loading files containing features.
Definition: FeatureFileOptions.h:21
A container for features.
Definition: FeatureMap.h:82
Facilitates file handling by file type recognition.
Definition: FileHandler.h:46
static String swapExtension(const String &filename, const FileTypes::Type new_type)
Tries to find and remove a known file extension, and append the new one.
static bool isSupported(FileTypes::Type type)
Returns if the file type is supported in this build of the library.
void loadConsensusFeatures(const String &filename, ConsensusMap &map, const std::vector< FileTypes::Type > allowed_types={}, ProgressLogger::LogType log=ProgressLogger::NONE)
Loads a file into a ConsensusMap.
FeatureFileOptions & getFeatOptions()
Mutable access to the feature file options for loading/storing.
void loadSpectrum(const String &filename, MSSpectrum &spec, const std::vector< FileTypes::Type > allowed_types={})
Loads a single MSSpectrum from a file.
void storeFeatures(const String &filename, const FeatureMap &map, const std::vector< FileTypes::Type > allowed_types={}, ProgressLogger::LogType log=ProgressLogger::NONE)
Store a FeatureMap.
void setOptions(const PeakFileOptions &)
set options for loading/storing
void storeTransformations(const String &filename, const TransformationDescription &map, const std::vector< FileTypes::Type > allowed_types={})
Store Transformations.
static String computeFileHash(const String &filename)
Computes a SHA-1 hash value for the content of the given file.
void storeSpectrum(const String &filename, MSSpectrum &spec, const std::vector< FileTypes::Type > allowed_types={})
Stores a single MSSpectrum to a file.
static bool hasValidExtension(const String &filename, const FileTypes::Type type)
Check if filename has the extension type.
const PeakFileOptions & getOptions() const
Non-mutable access to the options for loading/storing.
static FileTypes::Type getTypeByContent(const String &filename)
Determines the file type of a file by parsing the first few lines.
PeakFileOptions options_
Definition: FileHandler.h:381
void storeExperiment(const String &filename, const PeakMap &exp, const std::vector< FileTypes::Type > allowed_types={}, ProgressLogger::LogType log=ProgressLogger::NONE)
Stores an MSExperiment to a file.
PeakFileOptions & getOptions()
Mutable access to the options for loading/storing.
const FeatureFileOptions & getFeatOptions() const
Non-mutable access to the feature file options for loading/storing.
static FileTypes::Type getType(const String &filename)
Tries to determine the file type (by name or content)
static FileTypes::Type getTypeByFileName(const String &filename)
Try to get the file type from the filename.
void storeIdentifications(const 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.
static FileTypes::Type getConsistentOutputfileType(const String &output_filename, const String &requested_type)
Useful function for TOPP tools which have an 'out_type' parameter and want to know what output format...
void loadTransformations(const String &filename, TransformationDescription &map, bool fit_model=true, const std::vector< FileTypes::Type > allowed_types={})
Loads a file into Transformations.
static String stripExtension(const String &filename)
If filename contains an extension, it will be removed (including the '.'). Special extensions,...
void storeQC(const String &input_file, const String &filename, const MSExperiment &exp, const FeatureMap &feature_map, std::vector< ProteinIdentification > &prot_ids, PeptideIdentificationList &pep_ids, const ConsensusMap &consensus_map=ConsensusMap(), const String &contact_name="", const String &contact_address="", const String &description="", const String &label="label", const bool remove_duplicate_features=false, const std::vector< FileTypes::Type > allowed_types={})
Store QC info.
void storeConsensusFeatures(const String &filename, const ConsensusMap &map, const std::vector< FileTypes::Type > allowed_types={}, ProgressLogger::LogType log=ProgressLogger::NONE)
Store a ConsensusFeatureMap.
void storeTransitions(const String &filename, const TargetedExperiment &library, const std::vector< FileTypes::Type > allowed_types={}, ProgressLogger::LogType log=ProgressLogger::NONE)
Store transitions of a spectral library.
void loadExperiment(const 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 loadIdentifications(const 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.
void loadFeatures(const String &filename, FeatureMap &map, const std::vector< FileTypes::Type > allowed_types={}, ProgressLogger::LogType log=ProgressLogger::NONE)
Loads a file into a FeatureMap.
void setFeatOptions(const FeatureFileOptions &)
set feature file options for loading/storing
FeatureFileOptions f_options_
Definition: FileHandler.h:382
void loadTransitions(const String &filename, TargetedExperiment &library, const std::vector< FileTypes::Type > allowed_types={}, ProgressLogger::LogType log=ProgressLogger::NONE)
Load transitions of a spectral library.
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
@ NONE
No progress logging.
Definition: ProgressLogger.h:46
A more convenient string class.
Definition: String.h:34
A description of a targeted experiment containing precursor and production ions.
Definition: TargetedExperiment.h:39
Generic description of a coordinate transformation.
Definition: TransformationDescription.h:37
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Type
Actual file types enum.
Definition: FileTypes.h:31