bpp-seq3  3.0.0
BppOAlignmentWriterFormat.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 
10 #include "Clustal.h"
11 #include "Fasta.h"
12 #include "Mase.h"
13 #include "Phylip.h"
14 #include "Stockholm.h"
15 
16 using namespace bpp;
17 using namespace std;
18 
19 unique_ptr<OAlignment> BppOAlignmentWriterFormat::read(const std::string& description)
20 {
21  unparsedArguments_.clear();
22  string format = "";
23  KeyvalTools::parseProcedure(description, format, unparsedArguments_);
24  unsigned int ncol = ApplicationTools::getParameter<unsigned int>("length", unparsedArguments_, 100, "", true, warningLevel_);
25  unique_ptr<OAlignment> oAln;
26  if (format == "Fasta")
27  {
28  oAln.reset(new Fasta(ncol));
29  }
30  else if (format == "Mase")
31  {
32  oAln.reset(new Mase(ncol));
33  }
34  else if (format == "Clustal")
35  {
36  oAln.reset(new Clustal(ncol));
37  }
38  else if (format == "Phylip")
39  {
40  bool sequential = true, extended = true;
41  string split = " ";
42  string order = ApplicationTools::getStringParameter("order", unparsedArguments_, "sequential", "", true, warningLevel_);
43  if (order == "sequential")
44  sequential = true;
45  else if (order == "interleaved")
46  sequential = false;
47  else
48  throw Exception("BppOAlignmentWriterFormat::read. Invalid argument 'order' for phylip format: " + order);
49 
50  string type = ApplicationTools::getStringParameter("type", unparsedArguments_, "extended", "", true, warningLevel_);
51  if (type == "extended")
52  {
53  extended = true;
54  split = ApplicationTools::getStringParameter("split", unparsedArguments_, "spaces", "", true, warningLevel_);
55  if (split == "spaces")
56  split = " ";
57  else if (split == "tab")
58  split = "\t";
59  else
60  throw Exception("BppOAlignmentWriterFormat::read. Invalid argument 'split' for phylip format: " + split);
61  }
62  else if (type == "classic")
63  extended = false;
64  else
65  throw Exception("BppOAlignmentWriterFormat::read. Invalid argument 'type' for phylip format: " + type);
66 
67  oAln.reset(new Phylip(extended, sequential, ncol, split));
68  }
69  else if (format == "Stockholm")
70  {
71  oAln.reset(new Stockholm());
72  }
73  else
74  {
75  throw IOException("Sequence format '" + format + "' unknown.");
76  }
77 
78  return oAln;
79 }
static std::string getStringParameter(const std::string &parameterName, const std::map< std::string, std::string > &params, const std::string &defaultValue, const std::string &suffix="", bool suffixIsOptional=true, int warn=0)
std::unique_ptr< OAlignment > read(const std::string &description)
Read a OAlignment object from a string.
The clustal sequence file format.
Definition: Clustal.h:26
The fasta sequence file format.
Definition: Fasta.h:32
static void parseProcedure(const std::string &desc, std::string &name, std::map< std::string, std::string > &args)
The mase sequence file format.
Definition: Mase.h:107
The Phylip & co format.
Definition: Phylip.h:31
The Stockholm alignment file format.
Definition: Stockholm.h:24
std::vector< std::string > split(const std::string &s, std::size_t n)
This alphabet is used to deal NumericAlphabet.