bpp-seq  2.2.0
IoSequenceFactory.cpp
Go to the documentation of this file.
1 //
2 // File IOSequenceFactory.cpp
3 // Created by: Julien Dutheil
4 // Created on: Tue 18/04/06 10:24
5 //
6 
7 /*
8 Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
9 
10 This software is a computer program whose purpose is to provide classes
11 for sequences 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 
40 #include "IoSequenceFactory.h"
41 #include "Fasta.h"
42 #include "Mase.h"
43 #include "Clustal.h"
44 #include "Dcse.h"
45 #include "Phylip.h"
46 #include "GenBank.h"
47 #include "NexusIoSequence.h"
48 
49 using namespace bpp;
50 using namespace std;
51 
52 const string IoSequenceFactory::FASTA_FORMAT = "Fasta";
53 const string IoSequenceFactory::MASE_FORMAT = "Mase";
54 const string IoSequenceFactory::CLUSTAL_FORMAT = "Clustal";
55 const string IoSequenceFactory::DCSE_FORMAT = "DCSE";
56 const string IoSequenceFactory::PHYLIP_FORMAT_INTERLEAVED = "Phylip I";
57 const string IoSequenceFactory::PHYLIP_FORMAT_SEQUENTIAL = "Phylip S";
58 const string IoSequenceFactory::PAML_FORMAT_INTERLEAVED = "PAML I";
59 const string IoSequenceFactory::PAML_FORMAT_SEQUENTIAL = "PAML S";
60 const string IoSequenceFactory::GENBANK_FORMAT = "GenBank";
61 const string IoSequenceFactory::NEXUS_FORMAT = "Nexus";
62 
63 ISequence* IoSequenceFactory::createReader(const string& format) throw (Exception)
64 {
65  if(format == FASTA_FORMAT) return new Fasta();
66  else if(format == MASE_FORMAT) return new Mase();
67  else if(format == CLUSTAL_FORMAT) return new Clustal();
68  else if(format == DCSE_FORMAT) return new DCSE();
69  else if(format == PHYLIP_FORMAT_INTERLEAVED) return new Phylip(false, false);
70  else if(format == PHYLIP_FORMAT_SEQUENTIAL) return new Phylip(false, true);
71  else if(format == PAML_FORMAT_INTERLEAVED) return new Phylip(true, false);
72  else if(format == PAML_FORMAT_SEQUENTIAL) return new Phylip(true, true);
73  else if(format == GENBANK_FORMAT) return new GenBank();
74  else if(format == NEXUS_FORMAT) return new NexusIOSequence();
75  else throw Exception("Format " + format + " is not supported for sequences input.");
76 }
77 
78 IAlignment* IoSequenceFactory::createAlignmentReader(const string& format) throw (Exception)
79 {
80  if(format == FASTA_FORMAT) return new Fasta();
81  else if(format == MASE_FORMAT) return new Mase();
82  else if(format == CLUSTAL_FORMAT) return new Clustal();
83  else if(format == DCSE_FORMAT) return new DCSE();
84  else if(format == PHYLIP_FORMAT_INTERLEAVED) return new Phylip(false, false);
85  else if(format == PHYLIP_FORMAT_SEQUENTIAL) return new Phylip(false, true);
86  else if(format == PAML_FORMAT_INTERLEAVED) return new Phylip(true, false);
87  else if(format == PAML_FORMAT_SEQUENTIAL) return new Phylip(true, true);
88  else if(format == NEXUS_FORMAT) return new NexusIOSequence();
89  else throw Exception("Format " + format + " is not supported for alignment input.");
90 }
91 
92 OSequence* IoSequenceFactory::createWriter(const string& format) throw (Exception)
93 {
94  if(format == FASTA_FORMAT) return new Fasta();
95  else if(format == MASE_FORMAT) return new Mase();
96  else throw Exception("Format " + format + " is not supported for output.");
97 }
98 
99 OAlignment* IoSequenceFactory::createAlignmentWriter(const string& format) throw (Exception)
100 {
101  if (format == FASTA_FORMAT) return new Fasta();
102  else if (format == MASE_FORMAT) return new Mase();
103  else if (format == PHYLIP_FORMAT_INTERLEAVED) return new Phylip(false, false);
104  else if (format == PHYLIP_FORMAT_SEQUENTIAL) return new Phylip(false, true);
105  else if (format == PAML_FORMAT_INTERLEAVED) return new Phylip(true, false);
106  else if (format == PAML_FORMAT_SEQUENTIAL) return new Phylip(true, true);
107  else throw Exception("Format " + format + " is not supported for output.");
108 }
109 
virtual IAlignment * createAlignmentReader(const std::string &format)
Get a new dynamically created IAlignment object.
The OAlignment interface.
Definition: OSequence.h:95
virtual OSequence * createWriter(const std::string &format)
Get a new dynamically created OSequence object.
The OSequence interface.
Definition: OSequence.h:58
The fasta sequence file format.
Definition: Fasta.h:63
static const std::string PAML_FORMAT_INTERLEAVED
static const std::string FASTA_FORMAT
This alphabet is used to deal NumericAlphabet.
static const std::string MASE_FORMAT
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.
static const std::string PAML_FORMAT_SEQUENTIAL
static const std::string PHYLIP_FORMAT_SEQUENTIAL
Support for the Dedicated Comparative Sequence Editor format.
Definition: Dcse.h:60
The Phylip & co format.
Definition: Phylip.h:64
static const std::string GENBANK_FORMAT
virtual 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
The GenBank sequence file format.
Definition: GenBank.h:56
virtual ISequence * createReader(const std::string &format)
Get a new dynamically created ISequence object.
The IAlignment interface.
Definition: ISequence.h:99
static const std::string CLUSTAL_FORMAT
static const std::string DCSE_FORMAT
The ISequence interface.
Definition: ISequence.h:64