OpenMS
FileHandler.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- 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>
17 
18 namespace OpenMS
19 {
20  class PeakFileOptions;
21  class MSSpectrum;
22  class MSExperiment;
23  class FeatureMap;
24  class ConsensusMap;
25  class TargetedExperiment;
26 
40  class OPENMS_DLLAPI FileHandler
41  {
42 public:
51  static FileTypes::Type getType(const String& filename);
52 
53 
55  static FileTypes::Type getTypeByFileName(const String& filename);
56 
63  static bool hasValidExtension(const String& filename, const FileTypes::Type type);
64 
65 
73  static String stripExtension(const String& filename);
74 
82  static String swapExtension(const String& filename, const FileTypes::Type new_type);
83 
84 
97  static FileTypes::Type getConsistentOutputfileType(const String& output_filename, const String& requested_type);
98 
99 
105  static FileTypes::Type getTypeByContent(const String& filename);
106 
108  static bool isSupported(FileTypes::Type type);
109 
112 
114  const PeakFileOptions& getOptions() const;
115 
118 
134  bool loadExperiment(const String& filename, MSExperiment& exp, FileTypes::Type force_type = FileTypes::UNKNOWN, ProgressLogger::LogType log = ProgressLogger::NONE, const bool rewrite_source_file = true, const bool compute_hash = true);
135 
148 
161  bool loadFeatures(const String& filename, FeatureMap& map, FileTypes::Type force_type = FileTypes::UNKNOWN);
162 
173  bool storeFeatures(const String& filename, const FeatureMap& map);
174 
185  bool storeConsensusFeatures(const String& filename, const ConsensusMap& map);
186 
198  bool loadConsensusFeatures(const String& filename, ConsensusMap& map);
199 
200  bool loadIdentifications(const String& filename, std::vector<ProteinIdentification> additional_proteins, std::vector<PeptideIdentification> additional_peptides);
201 
212  bool storeTransitions(const String& filename, const TargetedExperiment& library);
213 
219  static String computeFileHash(const String& filename);
220 
221 private:
223 
224  };
225 
226 } //namespace
227 
A container for consensus elements.
Definition: ConsensusMap.h:66
A container for features.
Definition: FeatureMap.h:80
Facilitates file handling by file type recognition.
Definition: FileHandler.h:41
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 setOptions(const PeakFileOptions &)
set options for loading/storing
void storeExperiment(const String &filename, const MSExperiment &exp, ProgressLogger::LogType log=ProgressLogger::NONE)
Stores an MSExperiment to a file.
bool storeConsensusFeatures(const String &filename, const ConsensusMap &map)
Store a ConsensFeatureMap.
bool loadConsensusFeatures(const String &filename, ConsensusMap &map)
Loads a file into a ConsensMap.
static String computeFileHash(const String &filename)
Computes a SHA-1 hash value for the content of the given 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:222
PeakFileOptions & getOptions()
Mutable access to the 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)
Determines the file type from a file name.
bool loadExperiment(const String &filename, MSExperiment &exp, FileTypes::Type force_type=FileTypes::UNKNOWN, ProgressLogger::LogType log=ProgressLogger::NONE, const bool rewrite_source_file=true, const bool compute_hash=true)
Loads a file into an MSExperiment.
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...
static String stripExtension(const String &filename)
If filename contains an extension, it will be removed (including the '.'). Special extensions,...
bool loadFeatures(const String &filename, FeatureMap &map, FileTypes::Type force_type=FileTypes::UNKNOWN)
Loads a file into a FeatureMap.
bool storeFeatures(const String &filename, const FeatureMap &map)
Store a FeatureMap.
bool loadIdentifications(const String &filename, std::vector< ProteinIdentification > additional_proteins, std::vector< PeptideIdentification > additional_peptides)
bool storeTransitions(const String &filename, const TargetedExperiment &library)
Store transitions of a spectral library.
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:46
Options for loading files containing peak data.
Definition: PeakFileOptions.h:22
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
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22
Type
Actual file types enum.
Definition: FileTypes.h:31
@ UNKNOWN
Unknown file extension.
Definition: FileTypes.h:32