bpp-popgen  2.2.0
PopgenlibIO.h
Go to the documentation of this file.
1 //
2 // File PopgenlibIO.h
3 // Created by: Sylvain Gaillard
4 // Created on: Thursday July 29 2004
5 //
6 
7 /*
8  Copyright or © or Copr. CNRS, (November 17, 2004)
9 
10  This software is a computer program whose purpose is to provide classes
11  for population genetics 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 _POPULIBIO_H_
41 #define _POPULIBIO_H_
42 
43 #include <Bpp/Exceptions.h>
44 #include <Bpp/Text/TextTools.h>
45 #include <Bpp/Io/FileTools.h>
46 
47 // From Seq
48 #include <Bpp/Seq/Io/Fasta.h>
49 #include <Bpp/Seq/Container/VectorSequenceContainer.h>
50 
51 // From local Pop
52 #include "AbstractIDataSet.h"
53 #include "AbstractODataSet.h"
54 #include "BasicAlleleInfo.h"
55 
56 namespace bpp
57 {
63 class PopgenlibIO :
64  public AbstractIDataSet,
65  public AbstractODataSet
66 {
67 public:
68  // Constantes
69  static const std::string WHITESPACE;
70  static const std::string TAB;
71  static const std::string COMA;
72  static const std::string SEMICOLON;
73 
74  static const std::string DIPLOID;
75  static const std::string HAPLOID;
76  static const std::string HAPLODIPLOID;
77  static const std::string UNKNOWN;
78 
79 private:
82 
83  std::vector<std::string> getValues_(std::string& param_line, const std::string& delim);
84  void parseGeneral_(const std::vector<std::string>& in, DataSet& data_set);
85  void parseLocality_(const std::vector<std::string>& in, DataSet& data_set);
86  void parseSequence_(const std::vector<std::string>& in, VectorSequenceContainer& vsc);
87  void parseLoci_(const std::vector<std::string>& in, std::vector<LocusInfo>& locus_info);
88  void parseIndividual_(const std::vector<std::string>& in, DataSet& data_set, const VectorSequenceContainer& vsc);
89 
90 public:
91  // Constructor and destructor
92  PopgenlibIO();
93  PopgenlibIO(const std::string& missing_data_symbol, const std::string& data_separator) throw (Exception);
94  ~PopgenlibIO();
95 
96 public:
100  std::string getMissingDataSymbol() const;
101 
105  std::string getDataSeparator() const;
106 
110  char getMissingDataChar() const;
111 
115  char getDataSeparatorChar() const;
116 
128  void setMissingDataSymbol(const std::string& missing_data_symbol)
129  throw (Exception);
130 
146  void setDataSeparator(const std::string& data_separator)
147  throw (Exception);
148 
153  void read(std::istream& is, DataSet& data_set) throw (Exception);
154  void read(const std::string& path, DataSet& data_set) throw (Exception);
155  DataSet* read(std::istream& is) throw (Exception);
156  DataSet* read(const std::string& path) throw (Exception);
165  void write(std::ostream& os, const DataSet& data_set) const throw (Exception);
166 
167  void write(const std::string& path, const DataSet& data_set, bool overwrite) const throw (Exception);
176  const std::string getFormatName() const
177  {
178  return "PopgenlibIO ver 0.1";
179  }
180  const std::string getFormatDescription() const
181  {
182  return "IO format used to store DataSets inspired from Arlequin and Fasta";
183  }
187 };
188 } // end of namespace bpp;
189 
190 #endif // _POPULIBIO_H_
void parseGeneral_(const std::vector< std::string > &in, DataSet &data_set)
char missing_data_symbol_
Definition: PopgenlibIO.h:81
The native I/O format for popgenlib.
Definition: PopgenlibIO.h:63
static const std::string SEMICOLON
Definition: PopgenlibIO.h:72
char getMissingDataChar() const
Get the character for missing data.
void parseLocality_(const std::vector< std::string > &in, DataSet &data_set)
const std::string getFormatDescription() const
Definition: PopgenlibIO.h:180
static const std::string UNKNOWN
Definition: PopgenlibIO.h:77
Partial implementation of the DataSet Output interface.
std::string getDataSeparator() const
Get the code for data separator.
void parseIndividual_(const std::vector< std::string > &in, DataSet &data_set, const VectorSequenceContainer &vsc)
static const std::string HAPLODIPLOID
Definition: PopgenlibIO.h:76
char getDataSeparatorChar() const
Get the data separator char.
void setDataSeparator(const std::string &data_separator)
Set the code for data separator.
Definition: PopgenlibIO.cpp:87
const std::string getFormatName() const
Definition: PopgenlibIO.h:176
Partial implementation of the DataSet Input interface.
std::string getMissingDataSymbol() const
Get the code for missing data.
void parseSequence_(const std::vector< std::string > &in, VectorSequenceContainer &vsc)
std::vector< std::string > getValues_(std::string &param_line, const std::string &delim)
static const std::string HAPLOID
Definition: PopgenlibIO.h:75
void write(std::ostream &os, const DataSet &data_set) const
Write a DataSet on ostream.
static const std::string TAB
Definition: PopgenlibIO.h:70
static const std::string COMA
Definition: PopgenlibIO.h:71
void setMissingDataSymbol(const std::string &missing_data_symbol)
Set the code for missing data.
Definition: PopgenlibIO.cpp:76
void parseLoci_(const std::vector< std::string > &in, std::vector< LocusInfo > &locus_info)
static const std::string WHITESPACE
Definition: PopgenlibIO.h:69
void read(std::istream &is, DataSet &data_set)
Read a DataSet on istream.
static const std::string DIPLOID
Definition: PopgenlibIO.h:74
The DataSet class.
Definition: DataSet.h:73