bpp-seq3  3.0.0
IoSequenceFactory.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 "Clustal.h"
6 #include "Dcse.h"
7 #include "Fasta.h"
8 #include "GenBank.h"
9 #include "IoSequenceFactory.h"
10 #include "Mase.h"
11 #include "NexusIoSequence.h"
12 #include "Phylip.h"
13 
14 using namespace bpp;
15 using namespace std;
16 
17 const string IoSequenceFactory::FASTA_FORMAT = "Fasta";
18 const string IoSequenceFactory::MASE_FORMAT = "Mase";
19 const string IoSequenceFactory::CLUSTAL_FORMAT = "Clustal";
20 const string IoSequenceFactory::DCSE_FORMAT = "DCSE";
21 const string IoSequenceFactory::PHYLIP_FORMAT_INTERLEAVED = "Phylip I";
22 const string IoSequenceFactory::PHYLIP_FORMAT_SEQUENTIAL = "Phylip S";
23 const string IoSequenceFactory::PAML_FORMAT_INTERLEAVED = "PAML I";
24 const string IoSequenceFactory::PAML_FORMAT_SEQUENTIAL = "PAML S";
25 const string IoSequenceFactory::GENBANK_FORMAT = "GenBank";
26 const string IoSequenceFactory::NEXUS_FORMAT = "Nexus";
27 
28 unique_ptr<ISequence> IoSequenceFactory::createReader(const string& format)
29 {
30  if (format == FASTA_FORMAT)
31  return make_unique<Fasta>();
32  else if (format == MASE_FORMAT)
33  return make_unique<Mase>();
34  else if (format == CLUSTAL_FORMAT)
35  return make_unique<Clustal>();
36  else if (format == DCSE_FORMAT)
37  return make_unique<DCSE>();
38  else if (format == PHYLIP_FORMAT_INTERLEAVED)
39  return make_unique<Phylip>(false, false);
40  else if (format == PHYLIP_FORMAT_SEQUENTIAL)
41  return make_unique<Phylip>(false, true);
42  else if (format == PAML_FORMAT_INTERLEAVED)
43  return make_unique<Phylip>(true, false);
44  else if (format == PAML_FORMAT_SEQUENTIAL)
45  return make_unique<Phylip>(true, true);
46  else if (format == GENBANK_FORMAT)
47  return make_unique<GenBank>();
48  else if (format == NEXUS_FORMAT)
49  return make_unique<NexusIOSequence>();
50  else
51  throw Exception("Format " + format + " is not supported for sequences input.");
52 }
53 
54 unique_ptr<IAlignment> IoSequenceFactory::createAlignmentReader(const string& format)
55 {
56  if (format == FASTA_FORMAT)
57  return make_unique<Fasta>();
58  else if (format == MASE_FORMAT)
59  return make_unique<Mase>();
60  else if (format == CLUSTAL_FORMAT)
61  return make_unique<Clustal>();
62  else if (format == DCSE_FORMAT)
63  return make_unique<DCSE>();
64  else if (format == PHYLIP_FORMAT_INTERLEAVED)
65  return make_unique<Phylip>(false, false);
66  else if (format == PHYLIP_FORMAT_SEQUENTIAL)
67  return make_unique<Phylip>(false, true);
68  else if (format == PAML_FORMAT_INTERLEAVED)
69  return make_unique<Phylip>(true, false);
70  else if (format == PAML_FORMAT_SEQUENTIAL)
71  return make_unique<Phylip>(true, true);
72  else if (format == NEXUS_FORMAT)
73  return make_unique<NexusIOSequence>();
74  else
75  throw Exception("Format " + format + " is not supported for alignment input.");
76 }
77 
78 unique_ptr<OSequence> IoSequenceFactory::createWriter(const string& format)
79 {
80  if (format == FASTA_FORMAT)
81  return make_unique<Fasta>();
82  else if (format == MASE_FORMAT)
83  return make_unique<Mase>();
84  else
85  throw Exception("Format " + format + " is not supported for output.");
86 }
87 
88 unique_ptr<OAlignment> IoSequenceFactory::createAlignmentWriter(const string& format)
89 {
90  if (format == FASTA_FORMAT)
91  return make_unique<Fasta>();
92  else if (format == MASE_FORMAT)
93  return make_unique<Mase>();
94  else if (format == PHYLIP_FORMAT_INTERLEAVED)
95  return make_unique<Phylip>(false, false);
96  else if (format == PHYLIP_FORMAT_SEQUENTIAL)
97  return make_unique<Phylip>(false, true);
98  else if (format == PAML_FORMAT_INTERLEAVED)
99  return make_unique<Phylip>(true, false);
100  else if (format == PAML_FORMAT_SEQUENTIAL)
101  return make_unique<Phylip>(true, true);
102  else
103  throw Exception("Format " + format + " is not supported for output.");
104 }
static const std::string DCSE_FORMAT
static const std::string PHYLIP_FORMAT_SEQUENTIAL
static const std::string GENBANK_FORMAT
virtual std::unique_ptr< IAlignment > createAlignmentReader(const std::string &format)
Get a new dynamically created IAlignment object.
static const std::string PAML_FORMAT_INTERLEAVED
static const std::string CLUSTAL_FORMAT
virtual std::unique_ptr< OSequence > createWriter(const std::string &format)
Get a new dynamically created OSequence object.
virtual std::unique_ptr< OAlignment > createAlignmentWriter(const std::string &format)
Get a new dynamically created OAlignment object.
static const std::string NEXUS_FORMAT
static const std::string PHYLIP_FORMAT_INTERLEAVED
static const std::string MASE_FORMAT
static const std::string FASTA_FORMAT
static const std::string PAML_FORMAT_SEQUENTIAL
virtual std::unique_ptr< ISequence > createReader(const std::string &format)
Get a new dynamically created ISequence object.
This alphabet is used to deal NumericAlphabet.