bpp-seq3  3.0.0
SequenceWithAnnotationTools.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
7 
8 using namespace bpp;
9 using namespace std;
10 
11 const string SequenceMask::MASK = "Boolean mask";
12 
13 /******************************************************************************/
14 
16 {
17  mask_.clear();
18  mask_.insert(mask_.begin(), event.getCoreSymbolList()->size(), false);
19 }
20 
21 /******************************************************************************/
22 
24 {
25  mask_.insert(mask_.begin() + static_cast<ptrdiff_t>(event.getPosition()),
26  event.getLength(), false);
27 }
28 
29 /******************************************************************************/
30 
32 {
33  mask_.erase(mask_.begin() + static_cast<ptrdiff_t>(event.getPosition()),
34  mask_.begin() + static_cast<ptrdiff_t>(event.getPosition() + event.getLength()));
35 }
36 
37 /******************************************************************************/
38 
39 unique_ptr<SequenceWithAnnotation> SequenceWithAnnotationTools::createMaskAnnotation(const Sequence& seq)
40 {
41  auto cma = dynamic_pointer_cast<const CaseMaskedAlphabet>(seq.getAlphabet());
42  if (cma)
43  {
44  auto alphaPtr = seq.getAlphabet();
45  auto seqa = make_unique<SequenceWithAnnotation>(seq.getName(), seq.toString(), seq.getComments(), alphaPtr);
46  vector<bool> mask(seq.size());
47  for (size_t i = 0; i < seq.size(); ++i)
48  {
49  mask[i] = cma->isMasked(seq[i]);
50  }
51  seqa->addAnnotation(make_shared<SequenceMask>(mask));
52  return seqa;
53  }
54  else
55  {
56  throw AlphabetException("SequenceWithAnnotationTools::createMaskAnnotation. Alphabet should be a CaseMaskedAlphabet.", seq.getAlphabet());
57  }
58 }
59 
60 /******************************************************************************/
const std::string & getName() const override
Get the name of this sequence.
Definition: CoreSequence.h:170
std::shared_ptr< const Alphabet > getAlphabet() const override
Get the alphabet associated to the list.
Definition: SymbolList.h:120
size_t size() const override
Get the number of elements in the list.
Definition: SymbolList.h:124
The alphabet exception base class.
virtual size_t getPosition() const
virtual size_t getLength() const
virtual TemplateCoreSymbolListInterface< T > * getCoreSymbolList()
virtual size_t getPosition() const
virtual size_t getLength() const
void afterSequenceChanged(const IntSymbolListEditionEvent &event) override
void afterSequenceInserted(const IntSymbolListInsertionEvent &event) override
static const std::string MASK
void afterSequenceDeleted(const IntSymbolListDeletionEvent &event) override
std::unique_ptr< SequenceWithAnnotation > createMaskAnnotation(const Sequence &seq)
Parse a sequence with a CaseMaskedAlphabet and creates a new SequenceWithAnnotation object with origi...
A basic implementation of the Sequence interface.
Definition: Sequence.h:117
std::string toString() const override
Convert the list as a string.
Definition: Sequence.h:341
const Comments & getComments() const override
Get the comments.
Definition: Commentable.h:79
This alphabet is used to deal NumericAlphabet.