bpp-seq  2.2.0
AbstractISequence.h
Go to the documentation of this file.
1 //
2 // File: AbstractISequence.h
3 // Created by: Julien Dutheil
4 // Created on: ?
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 _ABSTRACTISEQUENCE_H_
41 #define _ABSTRACTISEQUENCE_H_
42 
43 #include "ISequence.h"
44 #include "../Container/VectorSequenceContainer.h"
45 #include "../Alphabet/Alphabet.h"
46 
47 // From the STL:
48 #include <string>
49 #include <iostream>
50 #include <fstream>
51 
52 namespace bpp
53 {
54 
59  public virtual ISequence
60 {
61 
62  public:
64  virtual ~AbstractISequence() {}
65 
66  public:
67 
74  public:
82  virtual void readSequences(std::istream& input, SequenceContainer& sc) const throw (Exception)
83  {
84  appendSequencesFromStream(input, sc);
85  }
86 
94  virtual void readSequences(const std::string& path, SequenceContainer& sc) const throw (Exception)
95  {
96  appendSequencesFromFile(path, sc);
97  }
98 
99  virtual
100 #if defined(NO_VIRTUAL_COV)
102 #else
104 #endif
105  readSequences(std::istream& input, const Alphabet* alpha) const throw (Exception)
106  {
107  return readSequencesFromStream(input, alpha);
108  }
109 
110  virtual
111 #if defined(NO_VIRTUAL_COV)
113 #else
115 #endif
116  readSequences(const std::string& path , const Alphabet* alpha) const throw (Exception)
117  {
118  return readSequencesFromFile(path, alpha);
119  }
123  protected:
133  virtual void appendSequencesFromStream(std::istream& input, SequenceContainer& sc) const throw (Exception) = 0;
134 
142  virtual void appendSequencesFromFile(const std::string& path, SequenceContainer& sc) const throw (Exception)
143  {
144  std::ifstream input(path.c_str(), std::ios::in);
145  appendSequencesFromStream(input, sc);
146  input.close();
147  }
148 
157  virtual VectorSequenceContainer* readSequencesFromStream(std::istream& input, const Alphabet* alpha) const throw (Exception)
158  {
160  appendSequencesFromStream(input, *vsc);
161  return vsc;
162  }
163 
171  virtual VectorSequenceContainer* readSequencesFromFile(const std::string& path , const Alphabet* alpha) const throw (Exception)
172  {
174  appendSequencesFromFile(path, *vsc);
175  return vsc;
176  }
177 };
178 
179 } //end of namespace bpp.
180 
181 #endif //_ABSTRACTISEQUENCE_H_
182 
virtual VectorSequenceContainer * readSequences(const std::string &path, const Alphabet *alpha) const
Create a new container from a file.
This alphabet is used to deal NumericAlphabet.
virtual VectorSequenceContainer * readSequencesFromFile(const std::string &path, const Alphabet *alpha) const
Append sequences to a container from a file.
The VectorSequenceContainer class.
The Alphabet interface.
Definition: Alphabet.h:130
virtual VectorSequenceContainer * readSequences(std::istream &input, const Alphabet *alpha) const
Create a new container from a stream.
virtual VectorSequenceContainer * readSequencesFromStream(std::istream &input, const Alphabet *alpha) const
Read sequences from a stream.
virtual void appendSequencesFromFile(const std::string &path, SequenceContainer &sc) const
Append sequences to a container from a file.
virtual void readSequences(std::istream &input, SequenceContainer &sc) const
Add sequences to a container from a stream.
virtual void readSequences(const std::string &path, SequenceContainer &sc) const
Add sequences to a container from a file.
Partial implementation of the ISequence interface.
The SequenceContainer interface.
The ISequence interface.
Definition: ISequence.h:64
virtual void appendSequencesFromStream(std::istream &input, SequenceContainer &sc) const =0
Append sequences to a container from a stream.