bpp-seq3  3.0.0
Stockholm.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 <Bpp/Io/FileTools.h>
7 #include <Bpp/Text/TextTools.h>
8 
9 #include "../StringSequenceTools.h"
10 #include "Stockholm.h"
11 
12 using namespace bpp;
13 using namespace std;
14 
15 /******************************************************************************/
16 
17 void Stockholm::writeAlignment(ostream& output, const SiteContainerInterface& sc) const
18 {
19  if (!output)
20  throw IOException("Stockholm::writeAlignment: can't write to ostream output");
21 
22  output << "# STOCKHOLM 1.0" << endl;
23  // Loop for all general comments
24  for (size_t i = 0; i < sc.getComments().size(); ++i)
25  {
26  output << "#=GF CC " << sc.getComments()[i] << endl;
27  }
28 
29  // Main loop : for all sequences in vector container
30  vector<string> names = sc.getSequenceNames();
31  size_t maxSize = 0;
32  for (size_t i = 0; i < names.size(); ++i)
33  {
34  names[i] = TextTools::removeWhiteSpaces(names[i]);
35  if (names[i].size() > maxSize)
36  maxSize = names[i].size();
37  }
38  if (maxSize > 255)
39  maxSize = 255;
40  for (size_t i = 0; i < sc.getNumberOfSequences(); ++i)
41  {
42  output << TextTools::resizeRight(names[i], maxSize) << " " << sc.sequence(i).toString() << endl;
43  }
44  output << "//" << endl;
45 }
46 
47 /******************************************************************************/
virtual const Comments & getComments() const =0
Get the comments.
void writeAlignment(std::ostream &output, const SiteContainerInterface &sc) const override
Write a container to a stream.
Definition: Stockholm.cpp:17
virtual const SequenceType & sequence(const HashType &sequenceKey) const override=0
Retrieve a sequence object from the container.
virtual std::vector< std::string > getSequenceNames() const =0
virtual size_t getNumberOfSequences() const =0
Get the number of sequences in the container.
std::string removeWhiteSpaces(const std::string &s)
std::string resizeRight(const std::string &s, std::size_t newSize, char fill)
This alphabet is used to deal NumericAlphabet.