bpp-popgen3  3.0.0
DarwinDon.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #include "DarwinDon.h"
6 
7 #include <Bpp/Io/OutputStream.h>
8 
9 using namespace bpp;
10 using namespace std;
11 
13 
15 
16 void DarwinDon::write(ostream& os, const DataSet& dataset) const
17 {
18  if (!os)
19  throw IOException("DarwinDon::write: fail to open stream.");
20  StlOutputStreamWrapper out(&os);
21  (out << "@DARwin 5.0 - DON").endLine();
22  size_t ind_nbr = 0;
23  for (size_t i = 0; i < dataset.getNumberOfGroups(); i++)
24  {
25  ind_nbr += dataset.getNumberOfIndividualsInGroup(i);
26  }
27  vector<string> header;
28  header.push_back("N°");
29  header.push_back("Name");
30  (out << ind_nbr << "\t" << header.size() - 1).endLine();
31  VectorTools::print(header, out, "\t");
32  // size_t ind_index = 0;
33  for (size_t i = 0; i < dataset.getNumberOfGroups(); i++)
34  {
35  size_t ind_nbr_ig = dataset.getNumberOfIndividualsInGroup(i);
36  for (size_t j = 0; j < ind_nbr_ig; j++)
37  {
38  (out << j + (i * ind_nbr_ig) + 1 << "\t" << dataset.getIndividualAtPositionFromGroup(i, j).getId()).endLine();
39  }
40  }
41 }
42 
43 void DarwinDon::write(const string& path, const DataSet& dataset, bool overwrite) const
44 {
45  AbstractODataSet::write(path, dataset, overwrite);
46 }
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:16
The DataSet class.
Definition: DataSet.h:37
size_t getNumberOfGroups() const
Get the number of Groups.
Definition: DataSet.cpp:251
const Individual & getIndividualAtPositionFromGroup(size_t groupPosition, size_t individualPosition) const
Get an Individual from a Group.
Definition: DataSet.cpp:415
size_t getNumberOfIndividualsInGroup(size_t groupPosition) const
Get the number of Individuals in a Group.
Definition: DataSet.cpp:390
const std::string & getId() const
Get the id of the Individual.
Definition: Individual.h:110
static void print(const std::vector< T > &v1, OutputStream &out=*ApplicationTools::message, const std::string &delim=" ")