43 #include <Bpp/Text/TextTools.h> 62 for (
unsigned int i = 0; i < osc.getNumberOfSequences(); i++)
64 addSequence(osc.getSequence(i),
true);
67 if (osc.getNumberOfSequences() > 0)
68 length_ = getSequence(0).size();
73 sites_.resize(length_);
74 setGeneralComments(osc.getGeneralComments());
86 sites_.resize(length_);
100 sites_.resize(length_);
114 sites_.resize(length_);
124 for (
unsigned int i = 0; i < sites_.size(); i++)
136 throw IndexOutOfBoundsException(
"AlignedSequenceContainer::getSite", i, 0, getNumberOfSites() - 1);
139 size_t n = getNumberOfSequences();
140 std::vector<int> site(n);
141 for (
size_t j = 0; j < n; j++)
143 site[j] = getSequence(j)[i];
148 sites_[i] =
new Site(site, getAlphabet(), positions_[i]);
157 if (pos >= getNumberOfSites())
158 throw IndexOutOfBoundsException(
"AlignedSequenceContainer::setSite", pos, 0, getNumberOfSites() - 1);
159 if (site.getAlphabet()->getAlphabetType() != getAlphabet()->getAlphabetType())
162 std::vector<int> s = site.getContent();
165 if (s.size() != getNumberOfSequences())
166 throw SiteException(
"AlignedSequenceContainer::setSite, site does not have the appropriate length", &site);
169 int position = site.getPosition();
173 for (
size_t i = 0; i < positions_.size(); i++)
175 if (positions_[i] == position)
176 throw SiteException(
"AlignedSequenceContainer::setSite: Site position already exists in container", &site);
181 for (
size_t j = 0; j < getNumberOfSequences(); j++)
183 getSequence_(j).setElement(pos, s[j]);
185 positions_[pos] = site.getPosition();
192 if (pos >= getNumberOfSites())
193 throw IndexOutOfBoundsException(
"AlignedSequenceContainer::removeSite", pos, 0, getNumberOfSites() - 1);
197 Site* old = sites_[pos];
200 for (
size_t j = 0; j < getNumberOfSequences(); j++)
206 positions_.erase(positions_.begin() +
static_cast<ptrdiff_t
>(pos));
212 sites_.erase(sites_.begin() +
static_cast<ptrdiff_t
>(pos));
222 if (pos >= getNumberOfSites())
223 throw IndexOutOfBoundsException(
"AlignedSequenceContainer::deleteSite", pos, 0, getNumberOfSites() - 1);
226 for (
size_t j = 0; j < getNumberOfSequences(); j++)
228 getSequence_(j).deleteElement(pos);
232 positions_.erase(positions_.begin() +
static_cast<ptrdiff_t
>(pos));
238 sites_.erase(sites_.begin() +
static_cast<ptrdiff_t
>(pos));
245 if (siteIndex + length > getNumberOfSites())
246 throw IndexOutOfBoundsException(
"AlignedSequenceContainer::deleteSites", siteIndex + length, 0, getNumberOfSites() - 1);
249 for (
size_t j = 0; j < getNumberOfSequences(); j++)
251 getSequence_(j).deleteElements(siteIndex, length);
255 positions_.erase(positions_.begin() +
static_cast<ptrdiff_t
>(siteIndex),
256 positions_.begin() +
static_cast<ptrdiff_t
>(siteIndex + length));
260 for (
size_t i = siteIndex; i < siteIndex + length; ++i)
265 sites_.erase(sites_.begin() +
static_cast<ptrdiff_t
>(siteIndex),
266 sites_.begin() +
static_cast<ptrdiff_t
>(siteIndex + length));
274 if (site.getAlphabet()->getAlphabetType() != getAlphabet()->getAlphabetType())
278 std::vector<int> s = site.getContent();
281 if (s.size() != getNumberOfSequences())
282 throw SiteException(
"AlignedSequenceContainer::addSite, site does not have the appropriate length", &site);
286 int position = site.getPosition();
290 for (
unsigned int i = 0; i < positions_.size(); i++)
292 if (positions_[i] == position)
293 throw SiteException(
"AlignedSequenceContainer::addSite: Site position already exists in container", &site);
298 for (
unsigned int j = 0; j < getNumberOfSequences(); j++)
300 getSequence_(j).addElement(s[j]);
304 positions_.push_back(position);
315 if (site.getAlphabet()->getAlphabetType() != getAlphabet()->getAlphabetType())
319 std::vector<int> s = site.getContent();
322 if (s.size() != getNumberOfSequences())
323 throw SiteException(
"AlignedSequenceContainer::addSite, site does not have the appropriate length", &site);
330 for (
unsigned int i = 0; i < positions_.size(); i++)
332 if (positions_[i] == position)
333 throw SiteException(
"AlignedSequenceContainer::addSite: Site position already exists in container", &site);
338 for (
unsigned int j = 0; j < getNumberOfSequences(); j++)
340 getSequence_(j).addElement(s[j]);
344 positions_.push_back(position);
354 if (siteIndex >= getNumberOfSites())
355 throw IndexOutOfBoundsException(
"AlignedSequenceContainer::addSite", siteIndex, 0, getNumberOfSites() - 1);
358 if (site.getAlphabet()->getAlphabetType() != getAlphabet()->getAlphabetType())
361 std::vector<int> s = site.getContent();
364 if (s.size() != getNumberOfSequences())
365 throw SiteException(
"AlignedSequenceContainer::addSite, site does not have the appropriate length", &site);
368 int position = site.getPosition();
372 for (
size_t i = 0; i < positions_.size(); i++)
374 if (positions_[i] == position)
375 throw SiteException(
"AlignedSequenceContainer::addSite: Site position already exists in container", &site);
380 for (
size_t j = 0; j < getNumberOfSequences(); j++)
382 getSequence_(j).addElement(siteIndex, site[j]);
386 positions_.insert(positions_.begin() +
static_cast<ptrdiff_t
>(siteIndex), position);
389 sites_.insert(sites_.begin() +
static_cast<ptrdiff_t
>(siteIndex), 0);
396 if (siteIndex >= getNumberOfSites())
397 throw IndexOutOfBoundsException(
"AlignedSequenceContainer::addSite", siteIndex, 0, getNumberOfSites() - 1);
400 if (site.getAlphabet()->getAlphabetType() != getAlphabet()->getAlphabetType())
403 std::vector<int> s = site.getContent();
406 if (s.size() != getNumberOfSequences())
407 throw SiteException(
"AlignedSequenceContainer::addSite, site does not have the appropriate length", &site);
413 for (
size_t i = 0; i < positions_.size(); i++)
415 if (positions_[i] == position)
416 throw SiteException(
"AlignedSequenceContainer::addSite: Site position already exists in container", &site);
421 for (
size_t j = 0; j < getNumberOfSequences(); j++)
423 getSequence_(j).addElement(siteIndex, site[j]);
427 positions_.insert(positions_.begin() +
static_cast<ptrdiff_t
>(siteIndex), position);
430 sites_.insert(sites_.begin() +
static_cast<ptrdiff_t
>(siteIndex), 0);
437 positions_.resize(length_);
438 for (
size_t i = 0; i < length_; i++)
440 positions_[i] =
static_cast<int>(i + 1);
448 if (i >= getNumberOfSequences())
449 throw IndexOutOfBoundsException(
"AlignedSequenceContainer::setSequence", i, 0, getNumberOfSequences() - 1);
451 if (getNumberOfSequences() == 1)
452 length_ = sequence.size();
453 if (checkSize_(sequence))
464 if (getNumberOfSequences() == 1)
465 length_ = sequence.size();
466 if (checkSize_(sequence))
479 length_ = sequence.size();
480 sites_.resize(length_);
483 if (checkSize_(sequence))
493 if (i >= getNumberOfSequences())
494 throw IndexOutOfBoundsException(
"AlignedSequenceContainer::addSequence", i, 0, getNumberOfSequences() - 1);
497 length_ = sequence.size();
498 if (checkSize_(sequence))
Vint getSitePositions() const
Get all position attributes of sites.
const Site & getSite(size_t siteIndex) const
Get a site from the container.
VectorSequenceContainer & operator=(const VectorSequenceContainer &vsc)
Assign from a VectorSequenceContainer.
void addSite(const Site &site, bool checkPosition=true)
Add a site in the container.
virtual ~AlignedSequenceContainer()
The SiteContainer interface.
The OrderedSequenceContainer interface.
Aligned sequences container.
This alphabet is used to deal NumericAlphabet.
The site exception base class.
void deleteSite(size_t siteIndex)
Delete a site in the container.
The VectorSequenceContainer class.
void deleteSites(size_t siteIndex, size_t length)
Delete a continuous range of sites in the container.
size_t getNumberOfSites() const
Get the number of sites in the container.
AlignedSequenceContainer & operator=(const AlignedSequenceContainer &asc)
void setSequence(const std::string &name, const Sequence &sequence, bool checkName=true)
Replace a sequence in the container.
virtual void addSequence(const Sequence &sequence, bool checkName=true)
Add a sequence at the end of the container.
void setSequence(const std::string &name, const Sequence &sequence, bool checkName=true)
Replace a sequence in the container.
void clear()
Delete all sequences in the container.
void setSite(size_t siteIndex, const Site &site, bool checkPosition=true)
Set a site in the container.
void addSequence(const Sequence &sequence, bool checkName=true)
Add a sequence at the end of the container.
Site * removeSite(size_t siteIndex)
Remove a site from the container.
AlignedSequenceContainer * createEmptyContainer() const
Return a copy of this container, but with no sequence inside.
AlignedSequenceContainer(const Alphabet *alpha)
Build a new empty container with the specified alphabet.
virtual size_t getNumberOfSites() const =0
Get the number of sites in the container.
virtual Vint getSitePositions() const =0
Get all position attributes of sites.
void clear()
Delete all sequences in the container.
Exception thrown when two alphabets do not match.
void reindexSites()
Set all positions attributes.
virtual void deleteElement(size_t pos)
Delete the element at position 'pos'.
Exception thrown when a sequence is not align with others.
void setGeneralComments(const Comments &comments)
Set the comments of this container.