+ int start = time(NULL);
+
+ //set or check size
+ if (subsample) {
+ //user has not set size, set size = smallest samples size
+ if (subsampleSize == -1) {
+ vector<string> temp; temp.push_back(Groups[0]);
+ subsampleSize = (tmap->getNamesSeqs(temp)).size(); //num in first group
+ for (int i = 1; i < Groups.size(); i++) {
+ temp.clear(); temp.push_back(Groups[i]);
+ int thisSize = (tmap->getNamesSeqs(temp)).size();
+ if (thisSize < subsampleSize) { subsampleSize = thisSize; }
+ }
+ m->mothurOut("\nSetting subsample size to " + toString(subsampleSize) + ".\n\n");
+ }else { //eliminate any too small groups
+ vector<string> newGroups = Groups;
+ Groups.clear();
+ for (int i = 0; i < newGroups.size(); i++) {
+ vector<string> thisGroup; thisGroup.push_back(newGroups[i]);
+ vector<string> thisGroupsSeqs = tmap->getNamesSeqs(thisGroup);
+ int thisSize = thisGroupsSeqs.size();
+
+ if (thisSize >= subsampleSize) { Groups.push_back(newGroups[i]); }
+ else { m->mothurOut("You have selected a size that is larger than "+newGroups[i]+" number of sequences, removing "+newGroups[i]+".\n"); }
+ }
+ m->setGroups(Groups);
+ }
+ }
+
+ //here in case some groups are removed by subsample
+ util.getCombos(groupComb, Groups, numComp);
+
+ if (numComp < processors) { processors = numComp; }
+
+ if (consensus && (numComp < 2)) { m->mothurOut("consensus can only be used with numComparisions greater than 1, setting consensus=f.\n"); consensus=false; }
+
+ //get weighted scores for users trees
+ for (int i = 0; i < T.size(); i++) {
+
+ if (m->control_pressed) { delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; } outSum.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
+
+ counter = 0;
+ rScores.resize(numComp); //data[0] = weightedscore AB, data[1] = weightedscore AC...
+ uScores.resize(numComp); //data[0] = weightedscore AB, data[1] = weightedscore AC...
+
+ vector<double> userData; userData.resize(numComp,0); //weighted score info for user tree. data[0] = weightedscore AB, data[1] = weightedscore AC...
+ vector<double> randomData; randomData.resize(numComp,0); //weighted score info for random trees. data[0] = weightedscore AB, data[1] = weightedscore AC...
+
+ if (random) {
+ output = new ColumnFile(outputDir + m->getSimpleName(treefile) + toString(i+1) + ".weighted", itersString);
+ outputNames.push_back(outputDir + m->getSimpleName(treefile) + toString(i+1) + ".weighted");
+ outputTypes["weighted"].push_back(outputDir + m->getSimpleName(treefile) + toString(i+1) + ".weighted");
+ }
+
+ userData = weighted.getValues(T[i], processors, outputDir); //userData[0] = weightedscore
+ if (m->control_pressed) { delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; } if (random) { delete output; } outSum.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
+
+ //save users score
+ for (int s=0; s<numComp; s++) {
+ //add users score to vector of user scores
+ uScores[s].push_back(userData[s]);
+ //save users tree score for summary file
+ utreeScores.push_back(userData[s]);
+ }
+
+ if (random) { runRandomCalcs(T[i], userData); }
+
+ //clear data
+ rScores.clear();
+ uScores.clear();
+ validScores.clear();
+
+ //subsample loop
+ vector< vector<double> > calcDistsTotals; //each iter, each groupCombos dists. this will be used to make .dist files
+ for (int thisIter = 0; thisIter < subsampleIters; thisIter++) { //subsampleIters=0, if subsample=f.
+
+ if (m->control_pressed) { break; }
+
+ //copy to preserve old one - would do this in subsample but memory cleanup becomes messy.
+ TreeMap* newTmap = new TreeMap();
+ //newTmap->getCopy(*tmap);
+
+ //SubSample sample;
+ //Tree* subSampleTree = sample.getSample(T[i], newTmap, nameMap, subsampleSize);
+
+ //uses method of setting groups to doNotIncludeMe
+ SubSample sample;
+ Tree* subSampleTree = sample.getSample(T[i], tmap, newTmap, subsampleSize, unique2Dup);
+
+ //call new weighted function
+ vector<double> iterData; iterData.resize(numComp,0);
+ Weighted thisWeighted(includeRoot);
+ iterData = thisWeighted.getValues(subSampleTree, processors, outputDir); //userData[0] = weightedscore
+
+ //save data to make ave dist, std dist
+ calcDistsTotals.push_back(iterData);
+
+ delete newTmap;
+ delete subSampleTree;
+
+ if((thisIter+1) % 100 == 0){ m->mothurOut(toString(thisIter+1)); m->mothurOutEndLine(); }
+ }
+
+ if (m->control_pressed) { delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; } if (random) { delete output; } outSum.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
+
+ if (subsample) { getAverageSTDMatrices(calcDistsTotals, i); }
+ if (consensus) { getConsensusTrees(calcDistsTotals, i); }
+ }
+
+
+ if (m->control_pressed) { delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; } outSum.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }