bpp-seq  2.2.0
BppOSequenceReaderFormat.cpp
Go to the documentation of this file.
1 //
2 // File: BppOSequenceReaderFormat.cpp
3 // Created by: Julien Dutheil
4 // Created on: Friday September 14th, 14:08
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 "GenBank.h"
47 #include "NexusIoSequence.h"
48 
49 #include <Bpp/Text/KeyvalTools.h>
50 
51 #include <string>
52 #include <memory>
53 
54 using namespace bpp;
55 using namespace std;
56 
57 ISequence* BppOSequenceReaderFormat::read(const std::string& description) throw (Exception)
58 {
59  unparsedArguments_.clear();
60  string format = "";
61  KeyvalTools::parseProcedure(description, format, unparsedArguments_);
62  auto_ptr<ISequence> iSeq;
63  if (format == "Mase")
64  {
65  iSeq.reset(new Mase());
66  }
67  else if (format == "Phylip")
68  {
69  bool sequential = true, extended = true;
70  string split = " ";
71  string order = ApplicationTools::getStringParameter("order", unparsedArguments_, "sequential", "", true, warningLevel_);
72  if (order == "sequential")
73  sequential = true;
74  else if (order == "interleaved")
75  sequential = false;
76  else
77  throw Exception("BppOAlignmentReaderFormat::read. Invalid argument 'order' for phylip format: " + order);
78 
79  string type = ApplicationTools::getStringParameter("type", unparsedArguments_, "extended", "", true, warningLevel_);
80  if (type == "extended")
81  {
82  extended = true;
83  split = ApplicationTools::getStringParameter("split", unparsedArguments_, "spaces", "", true, warningLevel_);
84  if (split == "spaces")
85  split = " ";
86  else if (split == "tab")
87  split = "\t";
88  else
89  throw Exception("BppOAlignmentReaderFormat::read. Invalid argument 'split' for phylip format: " + split);
90  }
91  else if (type == "classic")
92  extended = false;
93  else
94  throw Exception("BppOAlignmentReaderFormat::read. Invalid argument 'type' for phylip format: " + type);
95 
96  iSeq.reset(new Phylip(extended, sequential, 100, true, split));
97  }
98  else if (format == "Fasta")
99  {
100  bool strictNames = ApplicationTools::getBooleanParameter("strict_names", unparsedArguments_, false, "", true, warningLevel_);
101  bool extended = ApplicationTools::getBooleanParameter("extended", unparsedArguments_, false, "", true, warningLevel_);
102  iSeq.reset(new Fasta(100, true, extended, strictNames));
103  }
104  else if (format == "Clustal")
105  {
106  unsigned int extraSpaces = ApplicationTools::getParameter<unsigned int>("extraSpaces", unparsedArguments_, 0, "", true, warningLevel_);
107  iSeq.reset(new Clustal(true, extraSpaces));
108  }
109  else if (format == "Dcse")
110  {
111  iSeq.reset(new DCSE());
112  }
113  else if (format == "GenBank")
114  {
115  iSeq.reset(new GenBank()); // This is required to remove a strict-aliasing warning in gcc 4.4
116  }
117  else if (format == "Nexus")
118  {
119  iSeq.reset(new NexusIOSequence());
120  }
121  else
122  {
123  throw Exception("Sequence format '" + format + "' unknown.");
124  }
125 
126  return iSeq.release();
127 }
128 
ISequence * read(const std::string &description)
Read a ISequence object from a string.
The fasta sequence file format.
Definition: Fasta.h:63
This alphabet is used to deal NumericAlphabet.
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 GenBank sequence file format.
Definition: GenBank.h:56
The ISequence interface.
Definition: ISequence.h:64