bpp-popgen  3.0.0
DarwinDon.cpp
Go to the documentation of this file.
1 //
2 // File DarwinDon.cpp
3 // Authors : Sylvain Gaillard
4 // Last modification : April 7, 2008
5 //
6 
7 /*
8  Copyright or © or Copr. CNRS, (April 7, 2008)
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 #include "DarwinDon.h"
41 
42 #include <Bpp/Io/OutputStream.h>
43 
44 using namespace bpp;
45 using namespace std;
46 
48 
50 
51 void DarwinDon::write(ostream& os, const DataSet& data_set) const
52 {
53  if (!os)
54  throw IOException("DarwinDon::write: fail to open stream.");
55  StlOutputStreamWrapper out(&os);
56  (out << "@DARwin 5.0 - DON").endLine();
57  size_t ind_nbr = 0;
58  for (size_t i = 0; i < data_set.getNumberOfGroups(); i++)
59  {
60  ind_nbr += data_set.getNumberOfIndividualsInGroup(i);
61  }
62  vector<string> header;
63  header.push_back("N°");
64  header.push_back("Name");
65  (out << ind_nbr << "\t" << header.size() - 1).endLine();
66  VectorTools::print(header, out, "\t");
67  // size_t ind_index = 0;
68  for (size_t i = 0; i < data_set.getNumberOfGroups(); i++)
69  {
70  size_t ind_nbr_ig = data_set.getNumberOfIndividualsInGroup(i);
71  for (size_t j = 0; j < ind_nbr_ig; j++)
72  {
73  (out << j + (i * ind_nbr_ig) + 1 << "\t" << data_set.getIndividualAtPositionFromGroup(i, j)->getId()).endLine();
74  }
75  }
76 }
77 
78 void DarwinDon::write(const string& path, const DataSet& data_set, bool overwrite) const
79 {
80  AbstractODataSet::write(path, data_set, overwrite);
81 }
82 
virtual void write(std::ostream &os, const DataSet &data_set) const =0
Write a DataSet on ostream.
void write(std::ostream &os, const DataSet &data_set) const
Write a DataSet on ostream.
Definition: DarwinDon.cpp:51
The DataSet class.
Definition: DataSet.h:73
size_t getNumberOfGroups() const
Get the number of Groups.
Definition: DataSet.cpp:300
size_t getNumberOfIndividualsInGroup(size_t group_position) const
Get the number of Individuals in a Group.
Definition: DataSet.cpp:439
const Individual * getIndividualAtPositionFromGroup(size_t group_position, size_t individual_position) const
Get an Individual from a Group.
Definition: DataSet.cpp:464
const std::string & getId() const
Get the id of the Individual.
Definition: Individual.h:146
static void print(const std::vector< T > &v1, OutputStream &out=*ApplicationTools::message, const std::string &delim=" ")