bpp-seq  2.2.0
AbstractIAlignment.h
Go to the documentation of this file.
1 //
2 // File: AbstractIAlignment.h
3 // Created by: Julien Dutheil
4 // Created on: mon 27 jun 16:30 2005
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 #ifndef _ABSTRACTIALIGNMENT_H_
41 #define _ABSTRACTIALIGNMENT_H_
42 
43 #include "../Container/AlignedSequenceContainer.h"
44 #include "../Alphabet/Alphabet.h"
45 #include "ISequence.h"
46 
47 // From the STL:
48 #include <string>
49 #include <iostream>
50 #include <fstream>
51 
52 namespace bpp
53 {
54 
59  public virtual IAlignment
60 {
61 
62  public:
64  virtual ~AbstractIAlignment() {}
65 
66  public:
67 
81  virtual void readAlignment(std::istream& input, SiteContainer& sc) const throw (Exception)
82  {
83  appendAlignmentFromStream(input, sc);
84  }
85 
93  virtual void readAlignment(const std::string& path, SiteContainer& sc) const throw (Exception)
94  {
95  appendAlignmentFromFile(path, sc);
96  }
97 
98  virtual
99 #if defined(NO_VIRTUAL_COV)
101 #else
103 #endif
104  readAlignment(const std::string& path , const Alphabet* alpha) const throw (Exception)
105  {
106  return readAlignmentFromFile(path, alpha);
107  }
108 
109  virtual
110 #if defined(NO_VIRTUAL_COV)
112 #else
114 #endif
115  readAlignment(std::istream& input, const Alphabet* alpha) const throw (Exception)
116  {
117  return readAlignmentFromStream(input, alpha);
118  }
124  protected:
134  virtual void appendAlignmentFromStream(std::istream& input, SiteContainer& sc) const throw (Exception) = 0;
135 
143  virtual void appendAlignmentFromFile(const std::string& path, SiteContainer& sc) const throw (Exception)
144  {
145  std::ifstream input(path.c_str(), std::ios::in);
146  appendAlignmentFromStream(input, sc);
147  input.close();
148  }
149 
158  virtual AlignedSequenceContainer* readAlignmentFromStream(std::istream& input, const Alphabet* alpha) const throw (Exception)
159  {
161  appendAlignmentFromStream(input, *asc);
162  return asc;
163  }
164 
173  virtual AlignedSequenceContainer* readAlignmentFromFile(const std::string& path, const Alphabet* alpha) const throw (Exception)
174  {
176  appendAlignmentFromFile(path, *asc);
177  return asc;
178  }
179 
180 };
181 
182 } //end of namespace bpp.
183 
184 #endif // _ABSTRACTIALIGNMENT_H_
185 
virtual void readAlignment(const std::string &path, SiteContainer &sc) const
Add sequences to a container from a file.
virtual AlignedSequenceContainer * readAlignment(const std::string &path, const Alphabet *alpha) const
Create a new container from a file.
The SiteContainer interface.
Definition: SiteContainer.h:63
Aligned sequences container.
This alphabet is used to deal NumericAlphabet.
Partial implementation of the IAlignment interface, dedicated to alignment readers.
virtual void appendAlignmentFromStream(std::istream &input, SiteContainer &sc) const =0
Append sequences to a container from a stream.
The Alphabet interface.
Definition: Alphabet.h:130
virtual AlignedSequenceContainer * readAlignmentFromStream(std::istream &input, const Alphabet *alpha) const
Read sequences from a stream.
virtual AlignedSequenceContainer * readAlignment(std::istream &input, const Alphabet *alpha) const
Create a new container from a stream.
The IAlignment interface.
Definition: ISequence.h:99
virtual void appendAlignmentFromFile(const std::string &path, SiteContainer &sc) const
Append sequences to a container from a file.
virtual void readAlignment(std::istream &input, SiteContainer &sc) const
Add sequences to a container from a stream.
virtual AlignedSequenceContainer * readAlignmentFromFile(const std::string &path, const Alphabet *alpha) const
Read sequences from a file.