+ //you want to remove a percentage of OTUs
+ set<string> removeLabels;
+ if (rarePercent != -0.01) {
+ vector<spearmanRank> otus;
+ //rank otus by abundance
+ for (int i = 0; i < thislookup[0]->getNumBins(); i++) {
+ float otuTotal = 0.0;
+ for (int j = 0; j < thislookup.size(); j++) {
+ otuTotal += thislookup[j]->getAbundance(i);
+ }
+ spearmanRank temp(saveBinLabels[i], otuTotal);
+ otus.push_back(temp);
+ }
+
+ //sort by abundance
+ sort(otus.begin(), otus.end(), compareSpearman);
+
+ //find index of cutoff
+ int indexFirstNotRare = ceil(rarePercent * (float)thislookup[0]->getNumBins());
+
+ //handle ties
+ if (keepties) { //adjust indexFirstNotRare if needed
+ if (indexFirstNotRare != 0) { //not out of bounds
+ if (otus[indexFirstNotRare].score == otus[indexFirstNotRare-1].score) { //you have a tie
+ bool tie = true;
+ for (int i = indexFirstNotRare-1; i >=0; i--) {
+ if (otus[indexFirstNotRare].score != otus[i].score) { //found value below tie
+ indexFirstNotRare = i+1; tie = false; break;
+ }
+ }
+ if (tie) { if (m->debug) { m->mothurOut("For distance " + thislookup[0]->getLabel() + " all rare OTUs abundance tie with first 'non rare' OTU, not removing any for rarepercent parameter.\n"); }indexFirstNotRare = 0; }
+ }
+ }
+ }
+
+ //saved labels for OTUs above rarepercent
+ for (int i = 0; i < indexFirstNotRare; i++) { removeLabels.insert(otus[i].name); }
+ }
+