27 return getSequenceSubset(siteContainer, node);
29 catch (std::bad_cast& e)
35 return getSequenceSubset(siteContainer, node);
37 catch (std::bad_cast& e)
40 throw Exception(
"PatternTools::getSequenceSubset : unsupported sequence type.");
49 auto sequenceSubset = std::make_unique<VectorSiteContainer>(alphabet);
60 auto newSeq = std::make_unique<Sequence>(sequenceSet.
sequence(i->getName()));
61 sequenceSubset->addSequence(i->getName(), newSeq);
63 catch (std::exception& e)
65 ApplicationTools::displayWarning(
"PatternTools::getSequenceSubset : Leaf name not found in sequence file: " + i->getName() +
" : Replaced with unknown sequence");
67 auto seq = std::make_unique<Sequence>(i->getName(),
"", alphabet);
68 seq->setToSizeR(nbSites);
70 sequenceSubset->addSequence(i->getName(), seq);
75 return sequenceSubset;
84 auto sequenceSubset = std::make_unique<ProbabilisticVectorSiteContainer>(alphabet);
95 auto newSeq = std::make_unique<ProbabilisticSequence>(sequenceSet.
sequence(i->getName()));
96 sequenceSubset->addSequence(i->getName(), newSeq);
98 catch (std::exception
const& e)
100 ApplicationTools::displayWarning(
"PatternTools::getSequenceSubset : Leaf name not found in sequence file: " + i->getName() +
" : Replaced with unknown sequence");
102 auto newSeq = std::make_unique<ProbabilisticSequence>(i->getName(),
Table<double>(alphabet->getSize(), 0), alphabet);
103 newSeq->setToSizeR(nbSites);
105 sequenceSubset->addSequence(i->getName(), newSeq);
110 return sequenceSubset;
117 const std::vector<std::string>& names)
124 return getSequenceSubset(siteContainer, names);
126 catch (std::bad_cast& e)
132 return getSequenceSubset(siteContainer, names);
134 catch (std::bad_cast& e)
137 throw Exception(
"PatternTools::getSequenceSubset : unsupported sequence type.");
143 const std::vector<std::string>& names)
146 auto sequenceSubset = std::make_unique<VectorSiteContainer>(alphabet);
148 for (
auto& i : names)
152 auto newSeq = std::make_unique<Sequence>(sequenceSet.
sequence(i));
153 sequenceSubset->addSequence(i, newSeq);
159 return std::move(sequenceSubset);
164 const std::vector<std::string>& names)
167 auto sequenceSubset = std::make_unique<ProbabilisticVectorSiteContainer>(alphabet);
169 for (
auto& i : names)
173 auto newSeq = std::make_unique<ProbabilisticSequence>(sequenceSet.
sequence(i));
174 sequenceSubset->addSequence(i, newSeq);
180 return std::move(sequenceSubset);
191 return shrinkSiteSet(sc);
193 catch (std::bad_cast& e)
199 return shrinkSiteSet(psc);
201 catch (std::bad_cast& e)
204 throw Exception(
"PatternTools::shrinkSiteSet : unsupported sequence type.");
213 throw Exception(
"PatternTools::shrinkSiteSet siteSet is void.");
215 vector<std::unique_ptr<Site>> sites;
219 const auto& currentSite = siteSet.
site(i);
220 bool siteExists =
false;
221 for (
unsigned int j = 0; !siteExists && j < sites.size(); ++j)
227 sites.push_back(make_unique<Site>(currentSite));
229 auto result = make_unique<VectorSiteContainer>(sites, alphabet,
false);
240 throw Exception(
"PatternTools::shrinkSiteSet siteSet is void.");
242 vector<unique_ptr<ProbabilisticSite>> sites;
246 const auto& currentSite = siteSet.
site(i);
247 bool siteExists =
false;
248 for (
unsigned int j = 0; !siteExists && j < sites.size(); ++j)
254 sites.push_back(make_unique<ProbabilisticSite>(currentSite));
256 auto result = make_unique<ProbabilisticVectorSiteContainer>(sites, alphabet,
false);
268 Vint indexes(nbSites);
275 for (
size_t i = 0; i < nbSites; ++i)
279 const auto& site1 =
dynamic_cast<const Site&
>(sc1.site(i));
282 const auto& site2 =
dynamic_cast<const Site&
>(sc2.site(i));
285 indexes[i] =
static_cast<int>(j);
292 catch (std::bad_cast& e)
300 for (
size_t i = 0; i < nbSites; ++i)
310 indexes[i] =
static_cast<int>(j);
317 catch (std::bad_cast& e)
320 throw Exception(
"PatternTools::shrinkSiteSet : unsupported sequence type.");
The phylogenetic node class.
virtual size_t getNumberOfSites() const=0
virtual Vint getSiteCoordinates() const=0
virtual bool hasSequence(const std::string &sequenceKey) const =0
virtual std::vector< std::string > getSequenceNames() const =0
virtual const CoreSequenceInterface & sequence(const std::string &sequenceKey) const =0
virtual std::shared_ptr< const Alphabet > getAlphabet() const =0
virtual const Site & site(size_t sitePosition) const override=0
virtual size_t getNumberOfSites() const override=0
Defines the basic types of data flow nodes.