42 #include "../SitePatterns.h" 45 #include <Bpp/Seq/Container/AlignedSequenceContainer.h> 54 nodeData_(data.nodeData_),
55 leafData_(data.leafData_),
56 rootBitsets_(data.rootBitsets_),
57 rootScores_(data.rootScores_),
59 nbSites_(data.nbSites_),
60 nbStates_(data.nbStates_),
61 nbDistinctSites_(data.nbDistinctSites_)
92 nbStates_ = stateMap.getNumberOfModelStates();
93 nbSites_ = sites.getNumberOfSites();
98 nbDistinctSites_ = shrunkData_->getNumberOfSites();
102 const SiteContainer* sequences =
new AlignedSequenceContainer(*shrunkData_);
103 init(getTreeP_()->getRootNode(), *sequences, stateMap);
107 rootBitsets_.resize(nbDistinctSites_);
108 rootScores_.resize(nbDistinctSites_);
114 const Alphabet* alphabet = sites.getAlphabet();
120 seq = &sites.getSequence(node->getName());
122 catch (SequenceNotFoundException& snfe)
124 throw SequenceNotFoundException(
"DRTreeParsimonyData:init(node, sites). Leaf name in tree not found in site container: ", (node->getName()));
130 leafData_bitsets->resize(nbDistinctSites_);
132 for (
unsigned int i = 0; i < nbDistinctSites_; i++)
134 Bitset* leafData_bitsets_i = &(*leafData_bitsets)[i];
135 for (
unsigned int s = 0; s < nbStates_; s++)
139 int state = seq->getValue(i);
140 vector<int> states = alphabet->getAlias(state);
141 for (
size_t j = 0; j < states.size(); j++)
143 if (stateMap.getAlphabetStateAsInt(s) == states[j])
144 (*leafData_bitsets_i)[s].flip();
155 int nbSons =
static_cast<int>(node->getNumberOfSons());
157 for (
int n = (node->hasFather() ? -1 : 0); n < nbSons; n++)
159 const Node* neighbor = (*node)[n];
163 neighborData_bitsets->resize(nbDistinctSites_);
164 neighborData_scores->resize(nbDistinctSites_);
169 size_t nbSonNodes = node->getNumberOfSons();
170 for (
unsigned int l = 0; l < nbSonNodes; l++)
173 init(node->getSon(l), sites, stateMap);
196 int nbSons =
static_cast<int>(node->getNumberOfSons());
198 for (
int n = (node->hasFather() ? -1 : 0); n < nbSons; n++)
200 const Node* neighbor = (*node)[n];
204 neighborData_bitsets->resize(nbDistinctSites_);
205 neighborData_scores->resize(nbDistinctSites_);
210 size_t nbSonNodes = node->getNumberOfSons();
211 for (
unsigned int l = 0; l < nbSonNodes; l++)
214 reInit(node->getSon(l));
Parsimony data structure for a node.
std::vector< Bitset > & getBitsetsArrayForNeighbor(int neighborId)
const std::vector< size_t > & getIndices() const
const std::vector< unsigned int > & getWeights() const
void setNode(const Node *node)
Set the node associated to this data.
std::vector< unsigned int > & getScoresArrayForNeighbor(int neighborId)
Parsimony data structure for a leaf.
SiteContainer * shrunkData_
AbstractTreeParsimonyData & operator=(const AbstractTreeParsimonyData &atpd)
std::map< int, DRTreeParsimonyLeafData > leafData_
virtual int getId() const
Get the node's id.
const TreeTemplate< Node > * getTreeP_() const
void init(const SiteContainer &sites, const StateMap &stateMap)
std::vector< unsigned int > rootScores_
SiteContainer * getSites() const
The phylogenetic node class.
DRTreeParsimonyData & operator=(const DRTreeParsimonyData &data)
std::map< int, DRTreeParsimonyNodeData > nodeData_
Parsimony data structure for double-recursive (DR) algorithm.
DRTreeParsimonyData(const TreeTemplate< Node > *tree)
Partial implementation of the TreeParsimonyData interface.
Data structure for site patterns.
std::vector< Bitset > & getBitsetsArray()
std::vector< Bitset > rootBitsets_
void eraseNeighborArrays()
Map the states of a given alphabet which have a model state.
void setNode(const Node *node)
Set the node associated to this data.