FormatHandling::FormatManager Class Reference

Class to handle Format Handlers .
It serves as a proxy to the handlers, so the code outside the FormatManager is format-agnostic. More...

#include <FormatManager.h>

Public Member Functions

 FormatManager ()
 
 ~FormatManager ()
 
AlignmentloadAlignment (const std::string &inFile)
 Function that loads an alignment given a file path. It automatically detects the format of the file. More...
 
std::string replaceINtag (const Alignment &alignment, const std::string &outPattern)
 
bool saveAlignment (const std::string &outPattern, const std::vector< std::string > &outFormats, Alignment &alignment)
 Function to save an alignment to a file. It searches among the available_states one that can write the alignment in the specified format. More...
 
bool saveAlignments (const std::string &outPattern, const std::vector< std::string > &outFormats, const std::vector< Alignment *> &alignmentVector)
 Function to save an alignment to a file. It searches among the available_states one that can write the alignment in the specified format. More...
 
void loadAndSaveMultipleAlignments (const std::vector< std::string > &inFiles, const std::string &outPattern, const std::vector< std::string > &outFormats)
 Function that takes multiple files, loads them and saves in a cumulus of formats, using an outPattern. More...
 
std::string getFileFormatName (const std::string &inFile)
 Function to obtain the format name of a given file. More...
 
std::string getInputFormatsAvailable ()
 Function to obtain all format names available by this object that can load an alignment. More...
 
std::string getOutputFormatsAvailable ()
 Function to obtain all format names available by this object that can save an alignment. More...
 
std::vector< Alignment * > splitAlignmentKeeping (const Alignment &alignment)
 Function to divide an alignment into different alignments, each one with a sequence from the original.
This function does a deep copy of each sequence, so the original alignment can be deleted after being splitted. More...
 
FormatHandling::BaseFormatHandlergetFormatFromToken (const std::string &token)
 
std::ifstream * getNonEmptyFile (const std::string &filename)
 
FormatHandling::BaseFormatHandlergetFormatFromFile (const std::string &filename)
 

Public Attributes

bool hasOutputFile = true
 Tag to know if the machine has an output file or it has to output to console. More...
 
bool keepHeader = false
 Tag to know if the machine should keep original headers. More...
 
bool reverse = false
 Tag to know if sequences should be reversed before saving them. More...
 
bool format = false
 Tag to know if the machine should output the format information about the alignment. More...
 
bool type = false
 Tag to know if the machine should output the type of the alignment. More...
 
bool info = false
 Tag to know if the machine should output the information of the alignment. More...
 
std::ios_base::openmode openmode = std::ofstream::out
 

Private Member Functions

void addState (BaseFormatHandler *newState)
 Function that adds a newState to the FormatManager::available_states vector.
This should be called on the constructor function foreach format existent. More...
 

Private Attributes

std::vector< FormatHandling::BaseFormatHandler * > available_states
 Vector that contains the available formats to load/save from.
They are loaded into the format in the constructor function. More...
 

Detailed Description

Class to handle Format Handlers .
It serves as a proxy to the handlers, so the code outside the FormatManager is format-agnostic.

Note
The Format Handlers are added automatically by CMake, on CMake configuration.
This is achieved by creating the file include/FormatHandling/formats_header.h , which implements the FormatManager constructor.

Definition at line 64 of file FormatManager.h.

Constructor & Destructor Documentation

◆ FormatManager()

FormatHandling::FormatManager::FormatManager ( )

Definition at line 29 of file formats_header.h.

References addState().

Referenced by main(), and menu().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ~FormatManager()

FormatHandling::FormatManager::~FormatManager ( )

Definition at line 43 of file BaseFormatHandler.cpp.

References available_states.

Member Function Documentation

◆ addState()

void FormatHandling::FormatManager::addState ( FormatHandling::BaseFormatHandler newState)
private

Function that adds a newState to the FormatManager::available_states vector.
This should be called on the constructor function foreach format existent.

Parameters
newStatePointer to the newState we want to instantiate.

Definition at line 50 of file BaseFormatHandler.cpp.

References available_states.

Referenced by FormatManager().

+ Here is the caller graph for this function:

◆ getFileFormatName()

std::string FormatHandling::FormatManager::getFileFormatName ( const std::string &  inFile)

Function to obtain the format name of a given file.

Parameters
inFileFile path of the file which we want to obtain it's format.

Definition at line 239 of file BaseFormatHandler.cpp.

References getFormatFromFile(), and FormatHandling::BaseFormatHandler::name.

Referenced by trimAlManager::check_output_format(), main(), and statistics::Consistency::perform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFormatFromFile()

FormatHandling::BaseFormatHandler * FormatHandling::FormatManager::getFormatFromFile ( const std::string &  filename)

Definition at line 302 of file BaseFormatHandler.cpp.

References AlignmentFormatNotRecognized, available_states, FormatHandling::BaseFormatHandler::CheckAlignment(), debug, getNonEmptyFile(), and reporting::reportManager::report().

Referenced by getFileFormatName(), and loadAlignment().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFormatFromToken()

FormatHandling::BaseFormatHandler * FormatHandling::FormatManager::getFormatFromToken ( const std::string &  token)

Definition at line 291 of file BaseFormatHandler.cpp.

References available_states, and FormatHandling::BaseFormatHandler::RecognizeOutputFormat().

Referenced by trimAlManager::out_format_arguments(), trimAlManager::perform(), and saveAlignments().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInputFormatsAvailable()

std::string FormatHandling::FormatManager::getInputFormatsAvailable ( )

Function to obtain all format names available by this object that can load an alignment.

Definition at line 245 of file BaseFormatHandler.cpp.

References available_states, FormatHandling::BaseFormatHandler::canLoad, and FormatHandling::BaseFormatHandler::name.

Referenced by trimAlManager::help_arguments(), menu(), and trimAlManager::menu().

+ Here is the caller graph for this function:

◆ getNonEmptyFile()

std::ifstream * FormatHandling::FormatManager::getNonEmptyFile ( const std::string &  filename)

Definition at line 349 of file BaseFormatHandler.cpp.

References CantOpenFile, debug, FileIsEmpty, and reporting::reportManager::report().

Referenced by getFormatFromFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getOutputFormatsAvailable()

std::string FormatHandling::FormatManager::getOutputFormatsAvailable ( )

Function to obtain all format names available by this object that can save an alignment.

Definition at line 256 of file BaseFormatHandler.cpp.

References available_states, FormatHandling::BaseFormatHandler::canSave, and FormatHandling::BaseFormatHandler::name.

Referenced by trimAlManager::help_arguments(), menu(), and trimAlManager::menu().

+ Here is the caller graph for this function:

◆ loadAlignment()

Alignment * FormatHandling::FormatManager::loadAlignment ( const std::string &  inFile)

Function that loads an alignment given a file path. It automatically detects the format of the file.

Parameters
inFileFile path of the alignment to load.
Returns
Pointer to the alignment if it could be loaded.
Null if not.

Definition at line 55 of file BaseFormatHandler.cpp.

References AlignmentFormatNotRecognized, debug, getFormatFromFile(), FormatHandling::BaseFormatHandler::LoadAlignment(), and reporting::reportManager::report().

Referenced by trimAlManager::back_trans_argument(), trimAlManager::force_select_argument(), trimAlManager::in_argument(), loadAndSaveMultipleAlignments(), main(), and statistics::Consistency::perform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadAndSaveMultipleAlignments()

void FormatHandling::FormatManager::loadAndSaveMultipleAlignments ( const std::vector< std::string > &  inFiles,
const std::string &  outPattern,
const std::vector< std::string > &  outFormats 
)

Function that takes multiple files, loads them and saves in a cumulus of formats, using an outPattern.

Parameters
inFilesVector of files to load, reformat and save.
outPatternPath and name of the new files.
The function changes some optional tokens on the original string to obtain multiple versions:
  • [in] Token that is changed with the original filename without extension.
  • [format] Token that is changed with the new format name.
  • [extension] Token that is changed with the format file extensions.
Note
This method should be used in combination of the output tag system, which allows to reuse the name of the original alignment, in the new output, along the new format and extension. Otherwise, the system would overwrite the same file over and over.
Parameters
outFormatsOutput formats that original files should reformat to.

Definition at line 215 of file BaseFormatHandler.cpp.

References loadAlignment(), and saveAlignments().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ replaceINtag()

std::string FormatHandling::FormatManager::replaceINtag ( const Alignment alignment,
const std::string &  outPattern 
)

Definition at line 68 of file BaseFormatHandler.cpp.

References Alignment::filename, and utils::ReplaceString().

Referenced by trimAlManager::perform(), and saveAlignments().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveAlignment()

bool FormatHandling::FormatManager::saveAlignment ( const std::string &  outPattern,
const std::vector< std::string > &  outFormats,
Alignment alignment 
)

Function to save an alignment to a file. It searches among the available_states one that can write the alignment in the specified format.

Parameters
outPatternFile path to save the alignment.
outFormatsFormat in which save the alignment.
alignmentAlignment

Definition at line 90 of file BaseFormatHandler.cpp.

References saveAlignments().

Referenced by main(), and trimAlManager::save_alignment().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveAlignments()

bool FormatHandling::FormatManager::saveAlignments ( const std::string &  outPattern,
const std::vector< std::string > &  outFormats,
const std::vector< Alignment *> &  alignmentVector 
)

Function to save an alignment to a file. It searches among the available_states one that can write the alignment in the specified format.

Parameters
outPatternFile path to save the alignment.
outFormatsFormat in which save the alignment.
alignmentVectorAlignment

Definition at line 99 of file BaseFormatHandler.cpp.

References AlignmentIsEmpty, AlignmentNotSaved, debug, FormatHandling::BaseFormatHandler::extension, utils::fileExists(), getFormatFromToken(), FormatHandling::BaseFormatHandler::name, Alignment::numberOfResidues, Alignment::numberOfSequences, OnlyOneFormatOnConsoleOutput, OutputFormatNotRecognized, RenamingOutputPreventOverride, replaceINtag(), utils::ReplaceString(), utils::ReplaceStringInPlace(), reporting::reportManager::report(), FormatHandling::BaseFormatHandler::SaveAlignment(), and TriedRenamingOutputPreventOverride.

Referenced by loadAndSaveMultipleAlignments(), and saveAlignment().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ splitAlignmentKeeping()

std::vector< Alignment * > FormatHandling::FormatManager::splitAlignmentKeeping ( const Alignment alignment)

Function to divide an alignment into different alignments, each one with a sequence from the original.
This function does a deep copy of each sequence, so the original alignment can be deleted after being splitted.

Definition at line 267 of file BaseFormatHandler.cpp.

References Alignment::Alignment(), Alignment::filename, Alignment::numberOfResidues, Alignment::numberOfSequences, Alignment::originalNumberOfResidues, Alignment::originalNumberOfSequences, Alignment::seqsName, and Alignment::sequences.

Referenced by trimAlManager::perform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ available_states

std::vector<FormatHandling::BaseFormatHandler*> FormatHandling::FormatManager::available_states
private

Vector that contains the available formats to load/save from.
They are loaded into the format in the constructor function.

Note
The formats (BaseFormatHandler) are hard-coded loaded, and thus so when a new format is implemented, it has to be added 'manually'. There is a workaround for this, done on CMake, which creates the constructor of the class. This on-the-fly constructor implements all states found, using some rules.

This file includes all States found, and also defines the ReadWriteMS constructor.
To be able to be automatically recognized, the new state should:
  1. Have the same Class Name as File Name (without the extension)
  2. Name must end with '_state'
  3. Be placed on ReadWriteMS folder

Definition at line 86 of file FormatManager.h.

Referenced by addState(), getFormatFromFile(), getFormatFromToken(), getInputFormatsAvailable(), getOutputFormatsAvailable(), and ~FormatManager().

◆ format

bool FormatHandling::FormatManager::format = false

Tag to know if the machine should output the format information about the alignment.

Definition at line 108 of file FormatManager.h.

Referenced by checkArguments(), main(), and parseArguments().

◆ hasOutputFile

bool FormatHandling::FormatManager::hasOutputFile = true

Tag to know if the machine has an output file or it has to output to console.

Definition at line 99 of file FormatManager.h.

Referenced by checkArguments().

◆ info

bool FormatHandling::FormatManager::info = false

Tag to know if the machine should output the information of the alignment.

Definition at line 114 of file FormatManager.h.

Referenced by checkArguments(), main(), and parseArguments().

◆ keepHeader

bool FormatHandling::FormatManager::keepHeader = false

Tag to know if the machine should keep original headers.

Definition at line 101 of file FormatManager.h.

Referenced by trimAlManager::keep_header_argument(), and parseArguments().

◆ openmode

std::ios_base::openmode FormatHandling::FormatManager::openmode = std::ofstream::out

Definition at line 212 of file FormatManager.h.

◆ reverse

bool FormatHandling::FormatManager::reverse = false

Tag to know if sequences should be reversed before saving them.

Definition at line 103 of file FormatManager.h.

Referenced by main(), and parseArguments().

◆ type

bool FormatHandling::FormatManager::type = false

Tag to know if the machine should output the type of the alignment.

Definition at line 111 of file FormatManager.h.

Referenced by checkArguments(), main(), and parseArguments().


The documentation for this class was generated from the following files: