Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
FileHandler Class Reference

Facilitates file handling by file type recognition. More...

#include <OpenMS/FORMAT/FileHandler.h>

Public Member Functions

PeakFileOptionsgetOptions ()
 Mutable access to the options for loading/storing. More...
 
const PeakFileOptionsgetOptions () const
 Non-mutable access to the options for loading/storing. More...
 
void setOptions (const PeakFileOptions &)
 set options for loading/storing More...
 
template<class PeakType >
bool loadExperiment (const String &filename, MSExperiment< PeakType > &exp, FileTypes::Type force_type=FileTypes::UNKNOWN, ProgressLogger::LogType log=ProgressLogger::NONE, const bool compute_hash=true)
 Loads a file into an MSExperiment. More...
 
template<class PeakType >
void storeExperiment (const String &filename, const MSExperiment< PeakType > &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...
 

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 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...
 

Private Member Functions

String computeFileHash_ (const String &filename) const
 Computes a SHA-1 hash value for the content of the given file. More...
 

Private Attributes

PeakFileOptions options_
 

Detailed Description

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.

See also
FileTypes

Member Function Documentation

String computeFileHash_ ( const String filename) const
private

Computes a SHA-1 hash value for the content of the given file.

Returns
The SHA-1 hash of the given file.
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 FileTypes::Type getType ( const String filename)
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.

Exceptions
Exception::FileNotFoundis thrown if the file is not present

Referenced by TOPPViewBase::addDataFile(), TOPPViewBase::annotateWithID(), and IDEvaluationBase::loadCurve().

static FileTypes::Type getTypeByContent ( const String filename)
static

Determines the file type of a file by parsing the first few lines.

Exceptions
Exception::FileNotFoundis thrown if the file is not present

Referenced by InspectOutfile::getExperiment().

static FileTypes::Type getTypeByFileName ( const String filename)
static

Determines the file type from a file name.

static bool isSupported ( FileTypes::Type  type)
static

Returns if the file type is supported in this build of the library.

bool loadExperiment ( const String filename,
MSExperiment< PeakType > &  exp,
FileTypes::Type  force_type = FileTypes::UNKNOWN,
ProgressLogger::LogType  log = ProgressLogger::NONE,
const bool  compute_hash = true 
)
inline

Loads a file into an MSExperiment.

Parameters
filenameThe file name of the file to load.
expThe experiment to load the data into.
force_typeForces 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).
logProgress logging mode
compute_hashComputes a hash value for the loaded file and stores it in the SourceFile
Returns
true if the file could be loaded, false otherwise
Exceptions
Exception::FileNotFoundis thrown if the file could not be opened
Exception::ParseErroris thrown if an error occurs during parsing

References File::basename(), ChromatogramTools::convertSpectraToChromatograms(), FileTypes::DTA, FileTypes::DTA2D, MzXMLFile::getOptions(), MzDataFile::getOptions(), MzMLFile::getOptions(), DTA2DFile::getOptions(), ExperimentalSettings::getSourceFiles(), XMassFile::importExperimentalSettings(), MS2File::load(), MzXMLFile::load(), MzDataFile::load(), DTAFile::load(), MzMLFile::load(), XMassFile::load(), MascotGenericFile::load(), DTA2DFile::load(), FileTypes::MGF, FileTypes::MS2, FileTypes::MZDATA, FileTypes::MZML, FileTypes::MZXML, File::path(), MSExperiment< PeakT, ChromatogramPeakT >::reset(), MSExperiment< PeakT, ChromatogramPeakT >::resize(), SourceFile::setChecksum(), SourceFile::setFileType(), ProgressLogger::setLogType(), SourceFile::setNameOfFile(), SourceFile::setPathToFile(), SourceFile::SHA1, FileTypes::typeToMZML(), FileTypes::UNKNOWN, and FileTypes::XMASS.

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.

Parameters
filenamethe file name of the file to load.
mapThe FeatureMap to load the data into.
force_typeForces 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).
Returns
true if the file could be loaded, false otherwise
Exceptions
Exception::FileNotFoundis thrown if the file could not be opened
Exception::ParseErroris thrown if an error occurs during parsing

Referenced by TOPPViewBase::fileChanged_().

void setOptions ( const PeakFileOptions )

set options for loading/storing

void storeExperiment ( const String filename,
const MSExperiment< PeakType > &  exp,
ProgressLogger::LogType  log = ProgressLogger::NONE 
)
inline

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.

Parameters
filenameThe name of the file to store the data in.
expThe experiment to store.
logProgress logging mode
Exceptions
Exception::UnableToCreateFileis thrown if the file could not be written

References ChromatogramTools::convertChromatogramsToSpectra(), FileTypes::DTA2D, MSExperiment< PeakT, ChromatogramPeakT >::getChromatograms(), MzDataFile::getOptions(), MzXMLFile::getOptions(), MzMLFile::getOptions(), DTA2DFile::getOptions(), FileTypes::MZDATA, FileTypes::MZXML, ProgressLogger::setLogType(), MzXMLFile::store(), MzDataFile::store(), MzMLFile::store(), and DTA2DFile::store().

Member Data Documentation

PeakFileOptions options_
private

OpenMS / TOPP release 2.0.0 Documentation generated on Sat May 16 2015 16:13:51 using doxygen 1.8.9.1