bpp-phyl3  3.0.0
bpp::LegacyPhylogeneticsApplicationTools Class Reference

This class provides some common tools for applications. More...

#include <Bpp/Phyl/Legacy/App/PhylogeneticsApplicationTools.h>

Public Member Functions

 LegacyPhylogeneticsApplicationTools ()
 
virtual ~LegacyPhylogeneticsApplicationTools ()
 

Static Public Member Functions

static std::map< size_t, std::shared_ptr< Tree > > getTrees (const std::map< std::string, std::string > &params, const std::map< size_t, std::shared_ptr< AlignmentDataInterface >> &mSeq, std::map< std::string, std::string > &unparsedParams, const std::string &prefix="input.", const std::string &suffix="", bool suffixIsOptional=true, bool verbose=true, int warn=1)
 Build a list ofTree objects according to options. More...
 
static void setSubstitutionModelParametersInitialValuesWithAliases (BranchModelInterface &model, std::map< std::string, std::string > &unparsedParameterValues, size_t modelNumber, std::shared_ptr< const AlignmentDataInterface > data, std::map< std::string, std::string > &sharedParams, bool verbose)
 Set parameter initial values of a given model in a set according to options. More...
 
static std::unique_ptr< SubstitutionModelSetgetSubstitutionModelSet (std::shared_ptr< const Alphabet > alphabet, std::shared_ptr< const GeneticCode > gcode, std::shared_ptr< const AlignmentDataInterface > data, const std::map< std::string, std::string > &params, const std::string &suffix="", bool suffixIsOptional=true, bool verbose=true, int warn=1)
 Gets a SubstitutionModelSet object according to options. More...
 
static void setSubstitutionModelSet (SubstitutionModelSet &modelSet, std::shared_ptr< const Alphabet > alphabet, std::shared_ptr< const GeneticCode > gcode, std::shared_ptr< const AlignmentDataInterface > data, const std::map< std::string, std::string > &params, const std::string &suffix="", bool suffixIsOptional=true, bool verbose=true, int warn=1)
 Sets a SubstitutionModelSet object according to options. More...
 
static void completeMixedSubstitutionModelSet (MixedSubstitutionModelSet &mixedModelSet, std::shared_ptr< const Alphabet > alphabet, std::shared_ptr< const AlignmentDataInterface > data, const std::map< std::string, std::string > &params, const std::string &suffix="", bool suffixIsOptional=true, bool verbose=true, int warn=1)
 Complete a MixedSubstitutionModelSet object according to options, given this model has already been filled through setSubstitutionModelSet method. More...
 
static std::shared_ptr< TreeLikelihoodInterfaceoptimizeParameters (std::shared_ptr< TreeLikelihoodInterface > tl, const ParameterList &parameters, const std::map< std::string, std::string > &params, const std::string &suffix="", bool suffixIsOptional=true, bool verbose=true, int warn=1)
 Optimize parameters according to options. More...
 
static void writeTrees (const std::vector< const Tree * > &trees, const std::map< std::string, std::string > &params, const std::string &prefix="output.", const std::string &suffix="", bool suffixIsOptional=true, bool verbose=true, bool checkOnly=false, int warn=1)
 Write a tree according to options. More...
 
static void writeTrees (const std::vector< const TreeTemplate< Node > * > &trees, const std::map< std::string, std::string > &params, const std::string &prefix="output.", const std::string &suffix="", bool suffixIsOptional=true, bool verbose=true, bool checkOnly=false, int warn=1)
 
static void printParameters (const SubstitutionModelSet &modelSet, OutputStream &out, int warn=1, bool withAlias=true)
 Output a SubstitutionModelSet description to a file. More...
 

Detailed Description

This class provides some common tools for applications.

The functions parse some option file, create corresponding objects and send a pointer toward it.

The option files are supposed to follow this simple format:

parameterName = parameterContent

with one parameter per line.

See also
ApplicationTools

Definition at line 50 of file PhylogeneticsApplicationTools.h.

Constructor & Destructor Documentation

◆ LegacyPhylogeneticsApplicationTools()

bpp::LegacyPhylogeneticsApplicationTools::LegacyPhylogeneticsApplicationTools ( )

◆ ~LegacyPhylogeneticsApplicationTools()

virtual bpp::LegacyPhylogeneticsApplicationTools::~LegacyPhylogeneticsApplicationTools ( )
virtual

Member Function Documentation

◆ completeMixedSubstitutionModelSet()

void LegacyPhylogeneticsApplicationTools::completeMixedSubstitutionModelSet ( MixedSubstitutionModelSet mixedModelSet,
std::shared_ptr< const Alphabet alphabet,
std::shared_ptr< const AlignmentDataInterface data,
const std::map< std::string, std::string > &  params,
const std::string &  suffix = "",
bool  suffixIsOptional = true,
bool  verbose = true,
int  warn = 1 
)
static

Complete a MixedSubstitutionModelSet object according to options, given this model has already been filled through setSubstitutionModelSet method.

In addition, this method builds the allowed combinations of submodels of the different mixed models.

If none combination is given, then all possible submodels combinations will be considered.

The submodels dependencies are given a sets of combinations of the mixed variables of the mixed models. For instance, if we have:

model1=MixedModel(model=T92(kappa=Gamma(n=4), theta=0.5))
model2=MixedModel(model=T92(kappa=Gaussian(n=5), theta=Beta(n=3)))

In this case model1 is a mixture of 4 T92 submodels and model2 a mixture of 15 T92 submodels. These submodels are denoted with the parameter name and the class number. For example, the submodels of model1 are denoted model1[kappa_1], ..., model1[kappa_4], and the submodels of model2 are denoted model2[kappa_1,theta_1], ..., model2[kappa_5, theta_3]. Additionally, for instance, model2[kappa_2] denotes all the submodels whose description has kappa_2.

By default, when switching from model1 to model2, a site is allowed to switch between any submodel of model1 and any submodel of model2. If the only allowed combination is that a site follows submodels model1(kappa_1) and model2(kappa_3,theta_2), it is denoted:

site.allowedpaths= model1[kappa_1] & model2[kappa_3,theta_2]

With additional co()mbination saying that a site can follow submodels model1[kappa_2] and any submodel of model2[kappa_3] is denoted:

site.allowedpaths= model1[kappa_1] & model2[kappa_3,theta_2] |
model1[kappa_2] & model2[kappa_3]

See MixedSubstitutionModelSet description for further information.

Parameters
mixedModelSetThe modified MixedSubstitutionModelSet object according to options specified.
alphabetThe alphabet to use in all models.
dataA pointer toward the AlignedValuesContainer for which the substitution model is designed. The alphabet associated to the data must be of the same type as the one specified for the model. May be equal to NULL, but in this cas use_observed_freq option will be unavailable.
paramsThe attribute map where options may be found.
suffixA suffix to be applied to each attribute name.
suffixIsOptionalTell if the suffix is absolutely required.
verbosePrint some info to the 'message' output stream.
warnSet the warning level (0: always display warnings, >0 display warnings on demand).

Definition at line 616 of file PhylogeneticsApplicationTools.cpp.

References bpp::MixedSubstitutionModelSet::addEmptyHyperNode(), bpp::MixedSubstitutionModelSet::addToHyperNode(), bpp::MixedSubstitutionModelSet::complete(), bpp::MixedSubstitutionModelSet::computeHyperNodesProbabilities(), bpp::ApplicationTools::displayResult(), bpp::MixedSubstitutionModelSet::getHyperNode(), bpp::SubstitutionModelSet::getModel(), bpp::MixedSubstitutionModelSet::getNumberOfHyperNodes(), bpp::ApplicationTools::getStringParameter(), bpp::MixedSubstitutionModelSet::hasExclusivePaths(), bpp::StringTokenizer::hasMoreToken(), bpp::MixedSubstitutionModelSet::HyperNode::isComplete(), bpp::StringTokenizer::nextToken(), bpp::ApplicationTools::parameterExists(), bpp::TextTools::toInt(), and bpp::TextTools::toString().

◆ getSubstitutionModelSet()

unique_ptr< SubstitutionModelSet > LegacyPhylogeneticsApplicationTools::getSubstitutionModelSet ( std::shared_ptr< const Alphabet alphabet,
std::shared_ptr< const GeneticCode gcode,
std::shared_ptr< const AlignmentDataInterface data,
const std::map< std::string, std::string > &  params,
const std::string &  suffix = "",
bool  suffixIsOptional = true,
bool  verbose = true,
int  warn = 1 
)
static

Gets a SubstitutionModelSet object according to options.

See setSubstitutionModelSet and setMixedSubstitutionModelSet methods.

Definition at line 432 of file PhylogeneticsApplicationTools.cpp.

References bpp::ApplicationTools::getStringParameter(), bpp::ApplicationTools::parameterExists(), and bpp::TextTools::toString().

◆ getTrees()

map< size_t, shared_ptr< Tree > > LegacyPhylogeneticsApplicationTools::getTrees ( const std::map< std::string, std::string > &  params,
const std::map< size_t, std::shared_ptr< AlignmentDataInterface >> &  mSeq,
std::map< std::string, std::string > &  unparsedParams,
const std::string &  prefix = "input.",
const std::string &  suffix = "",
bool  suffixIsOptional = true,
bool  verbose = true,
int  warn = 1 
)
static

Build a list ofTree objects according to options.

See the Bio++ Program Suite manual for a description of available options.

Parameters
paramsThe attribute map where options may be found.
mSeqA map of pointers of AlignedValuesContainers, necessary in case of random trees
unparsedParamsA map of parameters (BrLen) that will be aliased after.
prefixA prefix to be applied to each attribute name.
suffixA suffix to be applied to each attribute name.
suffixIsOptionalTell if the suffix is absolutely required.
verbosePrint some info to the 'message' output stream.
warnSet the warning level (0: always display warnings, >0 display warnings on demand).
Returns
A new vector of Tree objects according to the specified options.

Definition at line 66 of file PhylogeneticsApplicationTools.cpp.

References bpp::TreeTools::computeBranchLengthsGrafen(), bpp::TreeTools::constrainedMidPointRooting(), bpp::TreeTools::convertToClockTree(), bpp::ApplicationTools::displayMessage(), bpp::ApplicationTools::displayResult(), bpp::ApplicationTools::displayWarning(), bpp::ApplicationTools::getAFilePath(), bpp::ApplicationTools::getDoubleParameter(), bpp::TreeTools::getHeight(), bpp::TreeTemplateTools::getRandomTree(), bpp::ApplicationTools::getStringParameter(), bpp::TextTools::isDecimalInteger(), bpp::ApplicationTools::matchingParameters(), bpp::KeyvalTools::parseProcedure(), bpp::TextTools::toDouble(), bpp::TextTools::toInt(), and bpp::TextTools::toString().

◆ optimizeParameters()

shared_ptr< TreeLikelihoodInterface > LegacyPhylogeneticsApplicationTools::optimizeParameters ( std::shared_ptr< TreeLikelihoodInterface tl,
const ParameterList parameters,
const std::map< std::string, std::string > &  params,
const std::string &  suffix = "",
bool  suffixIsOptional = true,
bool  verbose = true,
int  warn = 1 
)
static

Optimize parameters according to options.

Parameters
tlThe TreeLikelihood function to optimize.
parametersThe initial list of parameters to optimize. Use tl->getIndependentParameters() in order to estimate all parameters.
paramsThe attribute map where options may be found.
suffixA suffix to be applied to each attribute name.
suffixIsOptionalTell if the suffix is absolutely required.
verbosePrint some info to the 'message' output stream.
warnSet the warning level (0: always display warnings, >0 display warnings on demand).
Returns
A pointer toward the final likelihood object. This pointer may be the same as passed in argument (tl), but in some cases the algorithm clone this object. We may change this behavior in the future... You hence should write something like
tl = PhylogeneticsApplicationToolsOld::optimizeParameters(tl, ...);

Definition at line 709 of file PhylogeneticsApplicationTools.cpp.

References bpp::abs(), bpp::NNITopologySearch::BETTER, bpp::Parameter::constraint(), bpp::AutoParameter::CONSTRAINTS_AUTO, bpp::convert(), bpp::ParameterList::deleteParameter(), bpp::ParameterList::deleteParameters(), bpp::VectorTools::diff(), bpp::ApplicationTools::displayMessage(), bpp::ApplicationTools::displayResult(), bpp::ApplicationTools::displayWarning(), bpp::NNITopologySearch::FAST, bpp::FileTools::fileExists(), bpp::ApplicationTools::getAFilePath(), bpp::ApplicationTools::getBooleanParameter(), bpp::Parameter::getConstraint(), bpp::ConstraintInterface::getDescription(), bpp::ApplicationTools::getDoubleParameter(), bpp::Parameter::getName(), bpp::ParameterList::getParameterNames(), bpp::ApplicationTools::getStringParameter(), bpp::Parameter::hasConstraint(), bpp::StringTokenizer::hasMoreToken(), bpp::ParameterList::hasParameter(), bpp::ConstraintInterface::isEmpty(), bpp::TextTools::isEmpty(), bpp::ApplicationTools::matchingParameters(), bpp::ParameterList::matchParametersValues(), bpp::ApplicationTools::message, bpp::StringTokenizer::nextToken(), bpp::StringTokenizer::numberOfRemainingTokens(), bpp::OptimizationTools::OPTIMIZATION_BFGS, bpp::OptimizationTools::OPTIMIZATION_BRENT, bpp::OptimizationTools::OPTIMIZATION_GRADIENT, bpp::OptimizationTools::OPTIMIZATION_NEWTON, bpp::LegacyOptimizationTools::optimizeNumericalParameters(), bpp::LegacyOptimizationTools::optimizeNumericalParameters2(), bpp::LegacyOptimizationTools::optimizeTreeNNI(), bpp::LegacyOptimizationTools::optimizeTreeNNI2(), bpp::LegacyOptimizationTools::optimizeTreeScale(), bpp::ParameterNotFoundException::parameter(), bpp::ParameterList::parameter(), bpp::KeyvalTools::parseProcedure(), bpp::NNITopologySearch::PHYML, bpp::FileTools::putStreamIntoVectorOfStrings(), bpp::ParameterList::reset(), bpp::Parameter::setConstraint(), bpp::ParameterList::setParameter(), bpp::TextTools::toDouble(), bpp::TextTools::toString(), and bpp::ParameterList::whichParameterHasName().

◆ printParameters()

void LegacyPhylogeneticsApplicationTools::printParameters ( const SubstitutionModelSet modelSet,
OutputStream out,
int  warn = 1,
bool  withAlias = true 
)
static

Output a SubstitutionModelSet description to a file.

Parameters
modelSetThe model set to serialize.
outThe stream where to print.
warnSet the warning level (0: always display warnings, >0 display warnings on demand).
withAliasoutputs the alias names of the aliased Parameters instead of the values (default : true).

Definition at line 1184 of file PhylogeneticsApplicationTools.cpp.

References bpp::BppOFrequencySetFormat::ALL, bpp::BppOSubstitutionModelFormat::ALL, bpp::OutputStream::endLine(), bpp::AbstractParameterAliasable::getFrom(), bpp::SubstitutionModelSet::getModel(), bpp::SubstitutionModelSet::getNodesWithModel(), bpp::SubstitutionModelSet::getNumberOfModels(), bpp::SubstitutionModelSet::isStationary(), bpp::SubstitutionModelSet::rootFrequencySet(), bpp::ParameterList::size(), bpp::TextTools::toString(), bpp::BppOSubstitutionModelFormat::write(), and bpp::BppOFrequencySetFormat::writeFrequencySet().

◆ setSubstitutionModelParametersInitialValuesWithAliases()

void LegacyPhylogeneticsApplicationTools::setSubstitutionModelParametersInitialValuesWithAliases ( BranchModelInterface model,
std::map< std::string, std::string > &  unparsedParameterValues,
size_t  modelNumber,
std::shared_ptr< const AlignmentDataInterface data,
std::map< std::string, std::string > &  sharedParams,
bool  verbose 
)
static

Set parameter initial values of a given model in a set according to options.

Parameters actually depends on the model passed as argument. See getSubstitutionModelSet for more information.

This function is mainly for internal usage, you're probably looking for the getSubstitutionModel or getSubstitutionModelSet function.

Parameters
modelThe model to set.
unparsedParameterValuesA map that contains all the model parameters names and their corresponding unparsed value, if they were found.
modelNumberThe number of this model in the SubstitutionModelSet.
dataA pointer toward an AlignedValuesContainer used for the initialization of substitution model when this data is needed (typically use_observed_freq option). The alphabet associated to the data must be of the same type as the one specified for the model. May be equal to NULL, but in this case will be unavailable.
sharedParams(out) remote parameters will be recorded here.
verbosePrint some info to the 'message' output stream.

Definition at line 345 of file PhylogeneticsApplicationTools.cpp.

References bpp::ApplicationTools::displayMessage(), bpp::ApplicationTools::displayResult(), bpp::ApplicationTools::displayWarning(), bpp::ParameterAliasable::getIndependentParameters(), bpp::BranchModelInterface::getName(), bpp::ParameterAliasable::getNamespace(), bpp::ParameterAliasable::getParameterNameWithoutNamespace(), bpp::ApplicationTools::getStringParameter(), bpp::StringTokenizer::hasMoreToken(), bpp::ParameterAliasable::matchParametersValues(), bpp::StringTokenizer::nextToken(), bpp::AutoParameter::setMessageHandler(), bpp::ParameterList::setParameter(), bpp::ParameterList::size(), bpp::TextTools::toDouble(), bpp::TextTools::toString(), and bpp::ApplicationTools::warning.

◆ setSubstitutionModelSet()

void LegacyPhylogeneticsApplicationTools::setSubstitutionModelSet ( SubstitutionModelSet modelSet,
std::shared_ptr< const Alphabet alphabet,
std::shared_ptr< const GeneticCode gcode,
std::shared_ptr< const AlignmentDataInterface data,
const std::map< std::string, std::string > &  params,
const std::string &  suffix = "",
bool  suffixIsOptional = true,
bool  verbose = true,
int  warn = 1 
)
static

Sets a SubstitutionModelSet object according to options.

This model set is meant to be used with non-homogeneous substitution models of sequence evolution.

Recognized options are:

  • number_of_models: the number of distinct SubstitutionModel to use.

Then, for each of the models, the following information must be provided:

  • model1='model name(parameters'='value',...) Model names and parameters follow the same syntax as for the getSubstitutionModel method.
  • model1.nodes='list of nodes id, separated by comas'. And then
  • model2=... etc.

All models must be fully specified, and at the end of the description, all nodes must be attributed to a model, otherwise an exception is thrown.

Finally, this is also allowed for models to share one or several parameters. for instance:

model1=T92(kappa=2.0, theta=0.5)
model2=T92(kappa=model1.kappa, theta=0.5)

In this case model1 and model2 with have their own and independent theta parameter, but only one kappa parameter will be used for both models. Note that

model1=T92(kappa=2.0, theta=0.5)
model1.nodes=1,2,3
model2=T92(kappa= model1.kappa, theta=model1.theta)
model2.nodes=4,5,6

is equivalent to

model1=T92(kappa=2.0, theta=0.5)
model1.nodes=1,2,3,4,5,6

but will require more memory and use more CPU, since some calculations will be performed twice.

Parameters
modelSetThe modified SubstitutionModelSet object according to options specified.
alphabetThe alphabet to use in all models.
gcodeThe genetic code to use (only for codon models, otherwise can be set to 0). If set to NULL and a codon model is requested, an Exception will be thrown.
dataA pointer toward the AlignedValuesContainer for which the substitution model is designed. The alphabet associated to the data must be of the same type as the one specified for the model. May be equal to NULL, but in this cas use_observed_freq option will be unavailable.
paramsThe attribute map where options may be found.
suffixA suffix to be applied to each attribute name.
suffixIsOptionalTell if the suffix is absolutely required.
verbosePrint some info to the 'message' output stream.
warnSet the warning level (0: always display warnings, >0 display warnings on demand).

Definition at line 476 of file PhylogeneticsApplicationTools.cpp.

References bpp::SubstitutionModelSet::addModel(), bpp::AbstractParameterAliasable::aliasParameters(), bpp::BppOSubstitutionModelFormat::ALL, bpp::SubstitutionModelSet::clear(), bpp::ApplicationTools::displayBooleanResult(), bpp::ApplicationTools::displayResult(), bpp::ApplicationTools::getBooleanParameter(), bpp::PhylogeneticsApplicationTools::getRootFrequencySet(), bpp::ApplicationTools::getStringParameter(), bpp::BppOSubstitutionModelFormat::getUnparsedArguments(), bpp::StringTokenizer::hasMoreToken(), bpp::AlphabetTools::isCodonAlphabet(), bpp::AlphabetTools::isWordAlphabet(), bpp::StringTokenizer::nextToken(), bpp::ApplicationTools::parameterExists(), bpp::BppOTransitionModelFormat::readTransitionModel(), bpp::BppOSubstitutionModelFormat::setGeneticCode(), bpp::SubstitutionModelSet::setRootFrequencies(), bpp::BppOSubstitutionModelFormat::setVerbose(), and bpp::TextTools::toString().

◆ writeTrees() [1/2]

void LegacyPhylogeneticsApplicationTools::writeTrees ( const std::vector< const Tree * > &  trees,
const std::map< std::string, std::string > &  params,
const std::string &  prefix = "output.",
const std::string &  suffix = "",
bool  suffixIsOptional = true,
bool  verbose = true,
bool  checkOnly = false,
int  warn = 1 
)
static

Write a tree according to options.

See the Bio++ Program Suite manual for a description of all available options.

Parameters
treesThe trees to write.
paramsThe attribute map where options may be found.
prefixA prefix to be applied to each attribute name.
suffixA suffix to be applied to each attribute name.
suffixIsOptionalTell if the suffix is absolutely required.
verbosePrint some info to the 'message' output stream.
checkOnlyIf this parameter is set to true, then all options are checked and error messages sent, but no file is written.
warnSet the warning level (0: always display warnings, >0 display warnings on demand).

Definition at line 1151 of file PhylogeneticsApplicationTools.cpp.

References bpp::ApplicationTools::displayResult(), bpp::ApplicationTools::getAFilePath(), bpp::ApplicationTools::getStringParameter(), and bpp::OMultiTree::writeTrees().

◆ writeTrees() [2/2]

static void bpp::LegacyPhylogeneticsApplicationTools::writeTrees ( const std::vector< const TreeTemplate< Node > * > &  trees,
const std::map< std::string, std::string > &  params,
const std::string &  prefix = "output.",
const std::string &  suffix = "",
bool  suffixIsOptional = true,
bool  verbose = true,
bool  checkOnly = false,
int  warn = 1 
)
static

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