OpenMS
|
Facilitates file handling by file type recognition. More...
#include <OpenMS/FORMAT/FileHandler.h>
Public Member Functions | |
PeakFileOptions & | getOptions () |
Mutable access to the options for loading/storing. More... | |
const PeakFileOptions & | getOptions () const |
Non-mutable access to the options for loading/storing. More... | |
void | setOptions (const PeakFileOptions &) |
set options for loading/storing More... | |
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. More... | |
void | storeExperiment (const String &filename, const MSExperiment &exp, ProgressLogger::LogType log=ProgressLogger::NONE) |
Stores an MSExperiment to a file. More... | |
bool | loadFeatures (const String &filename, FeatureMap &map, FileTypes::Type force_type=FileTypes::UNKNOWN) |
Loads a file into a FeatureMap. More... | |
bool | storeFeatures (const String &filename, const FeatureMap &map) |
Store a FeatureMap. More... | |
bool | storeConsensusFeatures (const String &filename, const ConsensusMap &map) |
Store a ConsensFeatureMap. More... | |
bool | loadConsensusFeatures (const String &filename, ConsensusMap &map) |
Loads a file into a ConsensMap. More... | |
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. More... | |
Static Public Member Functions | |
static FileTypes::Type | getType (const String &filename) |
Tries to determine the file type (by name or content) More... | |
static FileTypes::Type | getTypeByFileName (const String &filename) |
Determines the file type from a file name. More... | |
static bool | hasValidExtension (const String &filename, const FileTypes::Type type) |
Check if filename has the extension type . More... | |
static String | stripExtension (const String &filename) |
If filename contains an extension, it will be removed (including the '.'). Special extensions, known to OpenMS, e.g. '.mzML.gz' will be recognized as well. More... | |
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. More... | |
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 to write. This function makes sure that the type derived from output_filename and requested_type are consistent, i.e. are either identical or one of them is UNKNOWN. Upon conflict, an error message is printed and the UNKNOWN type is returned. More... | |
static FileTypes::Type | getTypeByContent (const String &filename) |
Determines the file type of a file by parsing the first few lines. More... | |
static bool | isSupported (FileTypes::Type type) |
Returns if the file type is supported in this build of the library. More... | |
static String | computeFileHash (const String &filename) |
Computes a SHA-1 hash value for the content of the given file. More... | |
Private Attributes | |
PeakFileOptions | options_ |
Facilitates file handling by file type recognition.
This class provides file type recognition from the file name and from the file content.
It also offer a common interface to load MSExperiment data and allows querying for supported file types.
Computes a SHA-1 hash value for the content of the given file.
|
static |
Useful function for TOPP tools which have an 'out_type' parameter and want to know what output format to write. This function makes sure that the type derived from output_filename
and requested_type
are consistent, i.e. are either identical or one of them is UNKNOWN. Upon conflict, an error message is printed and the UNKNOWN type is returned.
output_filename | A full filename (with none, absolute or relative paths) whose type is determined using FileHandler::getTypeByFileName() internally |
requested_type | A type as string, usually obtained from '-out_type', e.g. "FASTA" (case insensitive). The string can be empty (yields UNKNOWN for this type) |
PeakFileOptions& getOptions | ( | ) |
Mutable access to the options for loading/storing.
Referenced by TOPPViewBase::metadataFileDialog().
const PeakFileOptions& getOptions | ( | ) | const |
Non-mutable access to the options for loading/storing.
|
static |
Tries to determine the file type (by name or content)
First the type is determined from the file name. If this fails, the type is determined from the file content.
Exception::FileNotFound | is thrown if the file is not present |
Referenced by TOPPViewBase::addDataFile(), and TOPPOpenSwathBase::performCalibration().
|
static |
Determines the file type of a file by parsing the first few lines.
Exception::FileNotFound | is thrown if the file is not present |
Referenced by InspectOutfile::getExperiment().
|
static |
Determines the file type from a file name.
Referenced by TOPPOpenSwathBase::loadSwathFiles_().
|
static |
Check if filename
has the extension type
.
If the extension is not known (e.g. '.tmp') this is also allowed. However, if the extension is another one (neither type
nor unknown), false is returned.
|
static |
Returns if the file type is supported in this build of the library.
bool loadConsensusFeatures | ( | const String & | filename, |
ConsensusMap & | map | ||
) |
Loads a file into a ConsensMap.
filename | the file name of the file to load. |
map | The ConsensMap to load the data into. |
Exception::FileNotFound | is thrown if the file could not be opened |
Exception::ParseError | is thrown if an error occurs during parsing |
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.
filename | The file name of the file to load. |
exp | The experiment to load the data into. |
force_type | Forces to load the file with that file type. If no type is forced, it is determined from the extension (or from the content if that fails). |
log | Progress logging mode |
rewrite_source_file | Set's the SourceFile name and path to the current file. Note that this looses the link to the primary MS run the file originated from. |
compute_hash | If source files are rewritten, this flag triggers a recomputation of hash values. A SHA1 string gets stored in the checksum member of SourceFile. |
Exception::FileNotFound | is thrown if the file could not be opened |
Exception::ParseError | is thrown if an error occurs during parsing |
Referenced by TOPPViewBase::addDataFile(), TOPPViewBase::fileChanged_(), InspectOutfile::getExperiment(), and TOPPViewBase::metadataFileDialog().
bool loadFeatures | ( | const String & | filename, |
FeatureMap & | map, | ||
FileTypes::Type | force_type = FileTypes::UNKNOWN |
||
) |
Loads a file into a FeatureMap.
filename | the file name of the file to load. |
map | The FeatureMap to load the data into. |
force_type | Forces to load the file with that file type. If no type is forced, it is determined from the extension (or from the content if that fails). |
Exception::FileNotFound | is thrown if the file could not be opened |
Exception::ParseError | is thrown if an error occurs during parsing |
Referenced by TOPPViewBase::fileChanged_().
bool loadIdentifications | ( | const String & | filename, |
std::vector< ProteinIdentification > | additional_proteins, | ||
std::vector< PeptideIdentification > | additional_peptides | ||
) |
void setOptions | ( | const PeakFileOptions & | ) |
set options for loading/storing
bool storeConsensusFeatures | ( | const String & | filename, |
const ConsensusMap & | map | ||
) |
Store a ConsensFeatureMap.
filename | the file name of the file to write. |
map | The ConsensusMap to store. |
Exception::UnableToCreateFile | is thrown if the file could not be written |
void storeExperiment | ( | const String & | filename, |
const MSExperiment & | exp, | ||
ProgressLogger::LogType | log = ProgressLogger::NONE |
||
) |
Stores an MSExperiment to a file.
The file type to store the data in is determined by the file name. Supported formats for storing are mzML, mzXML, mzData and DTA2D. If the file format cannot be determined from the file name, the mzML format is used.
filename | The name of the file to store the data in. |
exp | The experiment to store. |
log | Progress logging mode |
Exception::UnableToCreateFile | is thrown if the file could not be written |
bool storeFeatures | ( | const String & | filename, |
const FeatureMap & | map | ||
) |
Store a FeatureMap.
filename | the file name of the file to write. |
map | The FeatureMap to store. |
Exception::UnableToCreateFile | is thrown if the file could not be written |
bool storeTransitions | ( | const String & | filename, |
const TargetedExperiment & | library | ||
) |
Store transitions of a spectral library.
filename | the file name of the file to write. |
map | The TargetedExperiment to store. |
Exception::UnableToCreateFile | is thrown if the file could not be written |
If filename contains an extension, it will be removed (including the '.'). Special extensions, known to OpenMS, e.g. '.mzML.gz' will be recognized as well.
E.g. 'experiment.featureXML' becomes 'experiment' and 'c:\files\data.mzML.gz' becomes 'c:\files\data' If the extension is unknown, the everything in the basename of the file after the last '.' is removed. E.g. 'future.newEnding' becomes 'future' If the filename does not contain '.', but the path (if any) does, nothing is removed, e.g. '/my.dotted.dir/filename' is returned unchanged.
Referenced by TOPPViewBase::addDataFile().
|
static |
Tries to find and remove a known file extension, and append the new one.
Internally calls 'stripExtension()' and adds the new suffix to the result. E.g. 'experiment.featureXML'+ FileTypes::TRAFOXML becomes 'experiment.trafoXML' and 'c:\files\data.mzML.gz' + FileTypes::FEATUREXML becomes 'c:\files\data.featureXML' If the existing extension is unknown, the everything after the last '.' is removed, e.g. 'exp.tmp'+FileTypes::IDXML becomes 'exp.idXML'
Referenced by TOPPViewBase::addDataFile().
|
private |