bpp-seq  2.2.0
BppOAlignmentReaderFormat.cpp
Go to the documentation of this file.
1 //
2 // File: BppOAlignmentReaderFormat.cpp
3 // Created by: Julien Dutheil
4 // Created on: Friday September 15th, 22:06
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
9 
10  This software is a computer program whose purpose is to provide classes
11  for phylogenetic data analysis.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38 */
39 
41 #include "Mase.h"
42 #include "Phylip.h"
43 #include "Fasta.h"
44 #include "Clustal.h"
45 #include "Dcse.h"
46 #include "NexusIoSequence.h"
47 
48 #include <Bpp/Text/KeyvalTools.h>
49 
50 #include <string>
51 #include <memory>
52 
53 using namespace bpp;
54 using namespace std;
55 
56 IAlignment* BppOAlignmentReaderFormat::read(const std::string& description) throw (Exception)
57 {
58  unparsedArguments_.clear();
59  string format = "";
60  KeyvalTools::parseProcedure(description, format, unparsedArguments_);
61  auto_ptr<IAlignment> iAln;
62  if (format == "Mase")
63  {
64  iAln.reset(new Mase());
65  }
66  else if (format == "Phylip")
67  {
68  bool sequential = true, extended = true;
69  string split = " ";
70  string order = ApplicationTools::getStringParameter("order", unparsedArguments_, "sequential", "", true, warningLevel_);
71  if (order == "sequential")
72  sequential = true;
73  else if (order == "interleaved")
74  sequential = false;
75  else
76  throw Exception("BppOAlignmentReaderFormat::read. Invalid argument 'order' for phylip format: " + order);
77 
78  string type = ApplicationTools::getStringParameter("type", unparsedArguments_, "extended", "", true, warningLevel_);
79  if (type == "extended")
80  {
81  extended = true;
82  split = ApplicationTools::getStringParameter("split", unparsedArguments_, "spaces", "", true, warningLevel_);
83  if (split == "spaces")
84  split = " ";
85  else if (split == "tab")
86  split = "\t";
87  else
88  throw Exception("BppOAlignmentReaderFormat::read. Invalid argument 'split' for phylip format: " + split);
89  }
90  else if (type == "classic")
91  extended = false;
92  else
93  throw Exception("BppOAlignmentReaderFormat::read. Invalid argument 'type' for phylip format: " + type);
94 
95  iAln.reset(new Phylip(extended, sequential, 100, true, split));
96  }
97  else if (format == "Fasta")
98  {
99  bool strictNames = ApplicationTools::getBooleanParameter("strict_names", unparsedArguments_, false, "", true, warningLevel_);
100  bool extended = ApplicationTools::getBooleanParameter("extended", unparsedArguments_, false, "", true, warningLevel_);
101  iAln.reset(new Fasta(100, true, extended, strictNames));
102  }
103  else if (format == "Clustal")
104  {
105  unsigned int extraSpaces = ApplicationTools::getParameter<unsigned int>("extraSpaces", unparsedArguments_, 0, "", true, warningLevel_);
106  iAln.reset(new Clustal(true, extraSpaces));
107  }
108  else if (format == "Dcse")
109  {
110  iAln.reset(new DCSE());
111  }
112  else if (format == "Nexus")
113  {
114  iAln.reset(new NexusIOSequence());
115  }
116  else
117  {
118  throw Exception("Sequence format '" + format + "' unknown.");
119  }
120 
121  return iAln.release();
122 }
123 
The fasta sequence file format.
Definition: Fasta.h:63
This alphabet is used to deal NumericAlphabet.
IAlignment * read(const std::string &description)
Read a IAlignment object from a string.
STL namespace.
The clustal sequence file format.
Definition: Clustal.h:57
The mase sequence file format.
Definition: Mase.h:125
The Nexus format reader for sequences.
Support for the Dedicated Comparative Sequence Editor format.
Definition: Dcse.h:60
The Phylip & co format.
Definition: Phylip.h:64
The IAlignment interface.
Definition: ISequence.h:99