X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=cluster.cpp;h=6b69e4d5312fcce5db6c084fd42499b64724fb5e;hb=6b32d112bb60e9f7eb6d4407a4eed4c49b67bced;hp=18133a29030cc47d10ab7a1c7f3572cec74e4c29;hpb=5a4ac4f954c4b4445bcee272f1f8220ddcc9c1e4;p=mothur.git diff --git a/cluster.cpp b/cluster.cpp index 18133a2..6b69e4d 100644 --- a/cluster.cpp +++ b/cluster.cpp @@ -13,8 +13,8 @@ /***********************************************************************/ -Cluster::Cluster(RAbundVector* rav, ListVector* lv, SparseDistanceMatrix* dm, float c, string f) : -rabund(rav), list(lv), dMatrix(dm), method(f) +Cluster::Cluster(RAbundVector* rav, ListVector* lv, SparseDistanceMatrix* dm, float c, string f, float cs) : +rabund(rav), list(lv), dMatrix(dm), method(f), adjust(cs) { try { @@ -64,7 +64,7 @@ void Cluster::update(double& cutOFF){ nRowCells = dMatrix->seqVec[smallRow].size(); vector foundCol(nColCells, 0); - //cout << dMatrix->getNNodes() << " small cell: " << smallRow << '\t' << smallCol << endl; + //cout << dMatrix->getNNodes() << " small cell: " << smallRow << '\t' << smallCol << endl; int search; bool changed; @@ -85,13 +85,28 @@ void Cluster::update(double& cutOFF){ changed = updateDistance(dMatrix->seqVec[smallCol][j], dMatrix->seqVec[smallRow][i]); dMatrix->updateCellCompliment(smallCol, j); break; - }else if (dMatrix->seqVec[smallCol][j].index < search) { j+=nColCells; } //we don't have a distance for this cell + }else if (dMatrix->seqVec[smallCol][j].index < search) { //we don't have a distance for this cell + if (adjust != -1.0) { //adjust + merged = true; + PDistCell value(search, adjust); //create a distance for the missing value + int location = dMatrix->addCellSorted(smallCol, value); + changed = updateDistance(dMatrix->seqVec[smallCol][location], dMatrix->seqVec[smallRow][i]); + dMatrix->updateCellCompliment(smallCol, location); + nColCells++; + foundCol.push_back(0); //add a new found column + //adjust value + for (int k = foundCol.size()-1; k > location; k--) { foundCol[k] = foundCol[k-1]; } + foundCol[location] = 1; + } + j+=nColCells; + } } } //if not merged it you need it for warning if ((!merged) && (method == "average" || method == "weighted")) { if (cutOFF > dMatrix->seqVec[smallRow][i].dist) { - cutOFF = dMatrix->seqVec[smallRow][i].dist; + cutOFF = dMatrix->seqVec[smallRow][i].dist; + //cout << "changing cutoff to " << cutOFF << endl; } } @@ -104,14 +119,20 @@ void Cluster::update(double& cutOFF){ // Special handling for singlelinkage case, not sure whether this // could be avoided for (int i=nColCells-1;i>=0;i--) { - if (foundCol[i] == 0) { - if (method == "average" || method == "weighted") { - if (dMatrix->seqVec[smallCol][i].index != smallRow) { //if you are not hte smallest distance - if (cutOFF > dMatrix->seqVec[smallCol][i].dist) { - cutOFF = dMatrix->seqVec[smallCol][i].dist; - } - } - } + if (foundCol[i] == 0) { + if (adjust != -1.0) { //adjust + PDistCell value(smallCol, adjust); //create a distance for the missing value + changed = updateDistance(dMatrix->seqVec[smallCol][i], value); + dMatrix->updateCellCompliment(smallCol, i); + }else { + if (method == "average" || method == "weighted") { + if (dMatrix->seqVec[smallCol][i].index != smallRow) { //if you are not hte smallest distance + if (cutOFF > dMatrix->seqVec[smallCol][i].dist) { + cutOFF = dMatrix->seqVec[smallCol][i].dist; + } + } + } + } dMatrix->rmCell(smallCol, i); } }