bpp-phyl3  3.0.0
BppOTreeWriterFormat.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 "BppOTreeWriterFormat.h"
10 #include "Newick.h"
11 #include "NexusIoTree.h"
12 #include "Nhx.h"
13 
14 using namespace bpp;
15 using namespace std;
16 
17 OTree* BppOTreeWriterFormat::readOTree(const std::string& description)
18 {
19  unparsedArguments_.clear();
20  string format = "";
21  KeyvalTools::parseProcedure(description, format, unparsedArguments_);
22  unique_ptr<OTree> oTree;
23  if (format == "Newick")
24  {
25  bool allowComments = ApplicationTools::getBooleanParameter("allow_comments", unparsedArguments_, false, "", true, warningLevel_);
26  oTree.reset(new Newick(allowComments));
27  }
28  else if (format == "Nhx")
29  {
30  oTree.reset(new Nhx());
31  }
32  else if (format == "Nexus")
33  {
34  oTree.reset(new NexusIOTree());
35  }
36  else
37  {
38  throw Exception("Tree format '" + format + "' unknown.");
39  }
40 
41  return oTree.release();
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)
OTree * readOTree(const std::string &description)
Read a OTree 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
General interface for tree writers.
Definition: IoTree.h:125
Defines the basic types of data flow nodes.