bpp-seq3  3.0.0
Pasta.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_SEQ_IO_PASTA_H
6 #define BPP_SEQ_IO_PASTA_H
7 
8 #include <Bpp/Numeric/Table.h>
9 
10 #include "../Container/VectorSiteContainer.h"
11 #include "../ProbabilisticSequence.h"
12 #include "../Container/AlignmentData.h"
13 #include "AbstractIAlignment.h"
14 #include "AbstractISequence.h"
15 #include "AbstractOAlignment.h"
16 #include "AbstractOSequence.h"
17 
18 namespace bpp
19 {
30 class Pasta :
33  public AbstractOSequence2
34 {
35 protected:
39  unsigned int charsByLine_; // Number of chars by line (output only)
40 
41  bool extended_; // If using HUPO-PSI extensions
42  bool strictNames_; // If name is between '>' and first space
43 
44 public:
46 
54  Pasta(unsigned int charsByLine = 100, bool extended = false, bool strictSequenceNames = false) : charsByLine_(charsByLine), extended_(extended), strictNames_(strictSequenceNames) {}
55 
56  // class destructor
57  virtual ~Pasta() {}
58 
59 public:
65  const std::string getFormatName() const override { return "PASTA file"; }
66  const std::string getFormatDescription() const override
67  {
68  return "By rows: alphabet, then Sequence name (preceded by >) in one line, and rows of sequence content.";
69  }
70 
76  bool nextSequence(std::istream& input, ProbabilisticSequence& seq, bool hasLabels, const std::vector<size_t>& permutationMap) const;
77 
82  void writeSequence(std::ostream& output, const ProbabilisticSequence& seq, bool header) const;
83 
84  void writeSequence(std::ostream& output, const Sequence& seq, bool header) const;
85 
91  void writeSequences(std::ostream& output, const SequenceContainerInterface& sc) const override
92  {
93  for (size_t i = 0; i < sc.getNumberOfSequences(); ++i)
94  {
95  writeSequence(output, sc.sequence(i), i == 0);
96  }
97  }
98 
100 
110  void appendAlignmentFromStream(std::istream& input, ProbabilisticSequenceContainerInterface& psc) const override;
111 
112  void writeAlignment(std::ostream& output, const ProbabilisticSiteContainerInterface& psc) const override
113  {
114  if (!output)
115  throw IOException("Pasta::write: can't write to ostream output");
116 
117  // Main loop : for all sequences in vector container
118 
119  bool first = true;
120  for (size_t i = 0; i < psc.getNumberOfSequences(); ++i)
121  {
122  writeSequence(output, psc.sequence(i), first);
123  first = false;
124  }
125  }
130 
131  const std::string getDataType() const override { return "(Probabilistic) sequence container"; }
132 };
133 } // end of namespace bpp
134 #endif // BPP_SEQ_IO_PASTA_H
Partial implementation of the OProbabilisticAlignment interface.
Partial implementation of the OAlignment interface.
void writeAlignment(std::ostream &output, const SiteContainerInterface &sc) const override
Write a container to a stream.
void writeSequences(std::ostream &output, const SequenceContainerInterface &sc) const override=0
Write a container to a stream.
The Pasta sequence file format.
Definition: Pasta.h:34
Table< double > DataTable
Definition: Pasta.h:45
const std::string getFormatName() const override
Get the format name.
Definition: Pasta.h:65
bool strictNames_
Definition: Pasta.h:42
void writeSequence(std::ostream &output, const ProbabilisticSequence &seq, bool header) const
Definition: Pasta.cpp:276
void appendAlignmentFromStream(std::istream &input, ProbabilisticSequenceContainerInterface &psc) const override
Append sequences to a container from a stream.
Definition: Pasta.cpp:156
virtual ~Pasta()
Definition: Pasta.h:57
bool extended_
Definition: Pasta.h:41
Pasta(unsigned int charsByLine=100, bool extended=false, bool strictSequenceNames=false)
Build a new Pasta object.
Definition: Pasta.h:54
void writeAlignment(std::ostream &output, const ProbabilisticSiteContainerInterface &psc) const override
Write a container to a stream.
Definition: Pasta.h:112
void writeSequences(std::ostream &output, const SequenceContainerInterface &sc) const override
Write a container to a stream.
Definition: Pasta.h:91
const std::string getDataType() const override
Definition: Pasta.h:131
bool nextSequence(std::istream &input, ProbabilisticSequence &seq, bool hasLabels, const std::vector< size_t > &permutationMap) const
Definition: Pasta.cpp:19
unsigned int charsByLine_
The maximum number of chars to be written on a line.
Definition: Pasta.h:39
const std::string getFormatDescription() const override
Definition: Pasta.h:66
A basic implementation of the ProbabilisticSequence interface.
A basic implementation of the Sequence interface.
Definition: Sequence.h:117
The SequenceContainer interface.
virtual const SequenceType & sequence(const HashType &sequenceKey) const override=0
Retrieve a sequence object from the container.
virtual size_t getNumberOfSequences() const =0
Get the number of sequences in the container.
The SiteContainer interface.
Definition: SiteContainer.h:29
This alphabet is used to deal NumericAlphabet.