127 if (nnodes < 3) nnodes = 3;
130 for (
int i=0;
i<nnodes; ++
i) {
158 if (idmin == jdmin) {
159 cerr <<
"Error: You cannot join node " << idmin <<
" to itself.\n";
163 if (idmin < 0 || idmin > maxIndex || jdmin < 0 || jdmin > maxIndex || m_nextNode < 0 || m_nextNode > maxIndex) {
167 cerr <<
"Warning: Out of range index in Join: " << idmin <<
" "
168 << jdmin <<
" " <<
m_nextNode <<
" Max allowed index: " << maxIndex << endl;
180 while (tmpi == idmin || tmpi == jdmin) {
184 cit->distance = tmpd;
188 tmpi = -(idmin+jdmin);
189 cerr <<
"Error: iterator found (id= " << cit->rowID <<
") not attached to hub.\n";
192 m_items[tmpi]->distance = tmpd;
196 tmpi = (tmpi==idmin) ? jdmin : -(idmin+jdmin);
205 int* indexMap =
new int[
m_nseqs];
209 for (it=1; it<=
m_nseqs-3; ++it) {
232 int idmin, jdmin,
tmp;
233 int imin = 0, jmin = 0;
237 double normalization;
247 string newickStr =
"";
264 double* internalDistCorrection =
new double[
m_nseqs];
269 int* indexMap =
new int[
m_nseqs];
273 if (indexMap == 0 || internalDistCorrection == 0) {
280 internalDistCorrection[
i] = 0.0;
289 ppDists =
new double*[
m_nseqs];
305 sum_d += ppDists[
i][k];
313 for (
int it=1; it<=
m_nseqs-3; ++it) {
316 normalization = 1.0/((double)(
m_nseqs - it + 1) - 2.0);
321 for (
i=0;
i<j; ++
i) {
324 double Sum = pSums[
i] + pSums[j];
325 sum_ij = ppDists[j][
i]/normalization - Sum;
326 if (sum_ij < minval) {
337 idmin = indexMap[imin];
338 jdmin = indexMap[jmin];
351 sum_d += ppDists[imin][k] - ppDists[jmin][k];
353 sum_d *= normalization;
354 ilen = 0.5*(ppDists[imin][jmin] + sum_d) - internalDistCorrection[imin];
355 jlen = 0.5*(ppDists[imin][jmin] - sum_d) - internalDistCorrection[jmin];
372 Join(idmin, jdmin, ilen, jlen);
374 internalDistCorrection[imin] = 0.5*ppDists[imin][jmin];
382 tmp_d = 0.5*(ppDists[imin][k] + ppDists[jmin][k]);
383 pSums[imin] -= ppDists[imin][k];
384 pSums[imin] += tmp_d;
385 ppDists[imin][k] = tmp_d;
386 pSums[k] -= ppDists[k][imin];
388 ppDists[k][imin] = tmp_d;
391 pSums[imin] -= ppDists[imin][imin];
392 ppDists[imin][imin] = 0.0;
394 pSums[jmin] -= ppDists[jmin][k];
395 ppDists[jmin][k] = 0.0;
396 pSums[k] -= ppDists[k][jmin];
397 ppDists[k][jmin] = 0.0;
410 double finalLen[3] = {0.0, 0.0, 0.0};
425 for (
int l=0;
l<
tmp; ++
l) {
427 j = finalNodes[(
l+1)%3];
428 k = finalNodes[(
l+2)%3];
432 finalLen[
l] = 0.5*(d0 + d1 - d2);
438 m_items[indexMap[
i]]->distance = finalLen[
l];
461 delete [] internalDistCorrection;
double FastGet(const int RowIndex, const int ColIndex) const
static std::string toNestedString(const SeqTree &seqTree)
static const int USED_ROW
static const double REPLACE_NEG_DIST
virtual string toString()
virtual void ComputeTree(SeqTree *tree, pProgressFunction pFunc)
static const DistanceMatrix::TMatType INIT_MINIMA
virtual void SetDistMat(DistanceMatrix *dm)
virtual long GetNumLoopsForTreeCalc()
static const Rootedness MY_ROOTEDNESS
void Join(int inode1, int inode2, double len1, double len2)
virtual ~NJ_TreeAlgorithm()
vector< SeqItem * > m_items
static const int BAD_INDEX
int numChildren(const TSeqIt &sit)
static const ETreeMethod MY_TREE_METHOD
void midpointRootIfNeeded()
iter append_child(iter position)
pre_order_iterator begin() const
iter insert(iter position, const T &x)
unsigned int number_of_children(const iterator_base &) const
iter reparent(iter position, sibling_iterator begin, sibling_iterator end)
static bool is_valid(const char *num, int type, CONV_RESULT *cr)
void(* pProgressFunction)(int Num, int Total)
const string TREE_ALGORITHM_NAMES[]
string GetTreeAlgorithmName(ETreeMethod algorithm)
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define END_SCOPE(ns)
End the previously defined scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
#define BEGIN_SCOPE(ns)
Define a new scope.
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
static SLJIT_INLINE sljit_ins l(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)