OpenMS  2.4.0
Public Member Functions | Static Public 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...
 
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...
 

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 the file extension of. 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_
 

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

◆ computeFileHash()

static String computeFileHash ( const String filename)
static

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

Returns
The SHA-1 hash of the given file.

◆ getOptions() [1/2]

PeakFileOptions& getOptions ( )

Mutable access to the options for loading/storing.

Referenced by TOPPViewBase::metadataFileDialog().

◆ getOptions() [2/2]

const PeakFileOptions& getOptions ( ) const

Non-mutable access to the options for loading/storing.

◆ getType()

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(), and TOPPViewBase::annotateWithID().

◆ getTypeByContent()

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

◆ getTypeByFileName()

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

Determines the file type from a file name.

◆ hasValidExtension()

static bool hasValidExtension ( const String filename,
const FileTypes::Type  type 
)
static

Check if the file extension of.

Parameters
typematches no other known FileType

This means that may match the extension of or any other unknown extension (e.g., '.tmp')

◆ isSupported()

static bool isSupported ( FileTypes::Type  type)
static

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

◆ loadExperiment()

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.

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
rewrite_source_fileSet'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_hashIf source files are rewritten, this flag triggers a recomputation of hash values. A SHA1 string gets stored in the checksum member of 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

Referenced by TOPPViewBase::addDataFile(), TOPPViewBase::fileChanged_(), InspectOutfile::getExperiment(), and TOPPViewBase::metadataFileDialog().

◆ loadFeatures()

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_().

◆ setOptions()

void setOptions ( const PeakFileOptions )

set options for loading/storing

◆ storeExperiment()

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.

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

Member Data Documentation

◆ options_

PeakFileOptions options_
private