X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=sparsedistancematrix.cpp;h=417e24ae94e4242db9a56db14fd2987714ab1712;hp=8035e138c261ae427f02c17eeeb60a5db7e8d12f;hb=d1c97b8c04bb75faca1e76ffad60b37a4d789d3d;hpb=0cefb55a2616975bd4a144fc345693695ffc9bb6 diff --git a/sparsedistancematrix.cpp b/sparsedistancematrix.cpp index 8035e13..417e24a 100644 --- a/sparsedistancematrix.cpp +++ b/sparsedistancematrix.cpp @@ -39,8 +39,10 @@ int SparseDistanceMatrix::updateCellCompliment(ull row, ull col){ ull vcol = 0; //find the columns entry for this cell as well - for (int i = 0; i < seqVec[vrow].size(); i++) { if (seqVec[vrow][i].index == row) { vcol = i; break; } } - + for (int i = 0; i < seqVec[vrow].size(); i++) { + if (seqVec[vrow][i].index == row) { vcol = i; break; } + } + seqVec[vrow][vcol].dist = seqVec[row][col].dist; return 0; @@ -87,6 +89,30 @@ void SparseDistanceMatrix::addCell(ull row, PDistCell cell){ exit(1); } } +/***********************************************************************/ +int SparseDistanceMatrix::addCellSorted(ull row, PDistCell cell){ + try { + numNodes+=2; + if(cell.dist < smallDist){ smallDist = cell.dist; } + + seqVec[row].push_back(cell); + PDistCell temp(row, cell.dist); + seqVec[cell.index].push_back(temp); + + sortSeqVec(row); + sortSeqVec(cell.index); + + int location = -1; //find location of new cell when sorted + for (int i = 0; i < seqVec[row].size(); i++) { if (seqVec[row][i].index == cell.index) { location = i; break; } } + + return location; + } + catch(exception& e) { + m->errorOut(e, "SparseDistanceMatrix", "addCellSorted"); + exit(1); + } +} + /***********************************************************************/ ull SparseDistanceMatrix::getSmallestCell(ull& row){ @@ -98,7 +124,9 @@ ull SparseDistanceMatrix::getSmallestCell(ull& row){ for (int i = 0; i < seqVec.size(); i++) { for (int j = 0; j < seqVec[i].size(); j++) { - + + if (m->control_pressed) { return smallDist; } + //already checked everyone else in row if (i < seqVec[i][j].index) { @@ -118,7 +146,7 @@ ull SparseDistanceMatrix::getSmallestCell(ull& row){ } } - random_shuffle(mins.begin(), mins.end()); //randomize the order of the iterators in the mins vector + //random_shuffle(mins.begin(), mins.end()); //randomize the order of the iterators in the mins vector row = mins[0].row; ull col = mins[0].col; @@ -126,7 +154,7 @@ ull SparseDistanceMatrix::getSmallestCell(ull& row){ return col; } catch(exception& e) { - m->errorOut(e, "SparseMatrix", "getSmallestCell"); + m->errorOut(e, "SparseDistanceMatrix", "getSmallestCell"); exit(1); } } @@ -141,7 +169,22 @@ int SparseDistanceMatrix::sortSeqVec(){ return 0; } catch(exception& e) { - m->errorOut(e, "SparseMatrix", "getSmallestCell"); + m->errorOut(e, "SparseDistanceMatrix", "sortSeqVec"); + exit(1); + } +} +/***********************************************************************/ + +int SparseDistanceMatrix::sortSeqVec(int index){ + try { + + //saves time in getSmallestCell, by making it so you dont search the repeats + sort(seqVec[index].begin(), seqVec[index].end(), compareIndexes); + + return 0; + } + catch(exception& e) { + m->errorOut(e, "SparseDistanceMatrix", "sortSeqVec"); exit(1); } }