bpp-phyl3  3.0.0
BppOTreeReaderFormat.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #include <Bpp/Text/KeyvalTools.h>
6 #include <memory>
7 #include <string>
8 
9 #include "BppOTreeReaderFormat.h"
10 #include "Newick.h"
11 #include "NexusIoTree.h"
12 #include "Nhx.h"
13 
14 using namespace bpp;
15 using namespace std;
16 
17 unique_ptr<ITree> BppOTreeReaderFormat::readITree(const std::string& description)
18 {
19  unparsedArguments_.clear();
20  string format = "";
21  KeyvalTools::parseProcedure(description, format, unparsedArguments_);
22  unique_ptr<ITree> iTree;
23  if (format == "Newick")
24  {
25  bool allowComments = ApplicationTools::getBooleanParameter("allow_comments", unparsedArguments_, false, "", true, warningLevel_);
26  iTree.reset(new Newick(allowComments));
27  }
28  else if (format == "Nhx")
29  {
30  iTree.reset(new Nhx());
31  }
32  else if (format == "Nexus")
33  {
34  iTree.reset(new NexusIOTree());
35  }
36  else
37  {
38  throw Exception("Tree format '" + format + "' unknown.");
39  }
40 
41  return iTree;
42 }
static bool getBooleanParameter(const std::string &parameterName, const std::map< std::string, std::string > &params, bool defaultValue, const std::string &suffix="", bool suffixIsOptional=true, int warn=0)
std::unique_ptr< ITree > readITree(const std::string &description)
Read a ITree object from a string.
static void parseProcedure(const std::string &desc, std::string &name, std::map< std::string, std::string > &args)
The so-called 'newick' parenthetic format.
Definition: Newick.h:58
a simple parser for reading trees from a Nexus file.
Definition: NexusIoTree.h:36
The so-called 'Nhx - New Hampshire eXtended' parenthetic format.
Definition: Nhx.h:62
Defines the basic types of data flow nodes.