- float ucumul = 1.0000;
- float rcumul = 1.0000;
- //this loop fills the cumulative maps and put 0.0000 in the score freq map to make it easier to print.
- for (it = validScores.begin(); it != validScores.end(); it++) {
- it2 = uscoreFreq.find(it->first);
- //make uCumul map
- uCumul[it->first] = ucumul;
- //user data has that score
- if (it2 != uscoreFreq.end()) { uscoreFreq[it->first] /= T.size(); ucumul-= it2->second; }
- else { uscoreFreq[it->first] = 0.0000; } //no user trees with that score
-
- //make rscoreFreq map and rCumul
- it2 = totalrscoreFreq.find(it->first);
- rCumul[it->first] = rcumul;
- //get percentage of random trees with that info
- if (it2 != totalrscoreFreq.end()) { totalrscoreFreq[it->first] /= (iters*T.size()); rcumul-= it2->second; }
- else { totalrscoreFreq[it->first] = 0.0000; } //no random trees with that score
+ }
+ catch(exception& e) {
+ m->errorOut(e, "UnifracUnweightedCommand", "UnifracUnweightedCommand");
+ exit(1);
+ }
+}
+
+/***********************************************************/
+int UnifracUnweightedCommand::execute() {
+ try {
+
+ if (abort == true) { if (calledHelp) { return 0; } return 2; }
+
+ m->setTreeFile(treefile);
+
+ TreeReader* reader = new TreeReader(treefile, groupfile, namefile);
+ T = reader->getTrees();
+ tmap = T[0]->getTreeMap();
+ map<string, string> nameMap = reader->getNames();
+ map<string, string> unique2Dup = reader->getNameMap();
+ delete reader;
+
+ sumFile = outputDir + m->getRootName(m->getSimpleName(treefile)) + getOutputFileNameTag("uwsummary");
+ outputNames.push_back(sumFile); outputTypes["uwsummary"].push_back(sumFile);
+ m->openOutputFile(sumFile, outSum);
+
+ SharedUtil util;
+ Groups = m->getGroups();
+ vector<string> namesGroups = tmap->getNamesOfGroups();
+ util.setGroups(Groups, namesGroups, allGroups, numGroups, "unweighted"); //sets the groups the user wants to analyze
+
+ Unweighted unweighted(includeRoot);
+
+ 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);
+ }
+ }
+
+ util.getCombos(groupComb, Groups, numComp);
+ m->setGroups(Groups);
+
+ if (numGroups == 1) { numComp++; groupComb.push_back(allGroups); }
+
+ 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; }
+
+ outSum << "Tree#" << '\t' << "Groups" << '\t' << "UWScore" <<'\t';
+ m->mothurOut("Tree#\tGroups\tUWScore\t");
+ if (random) { outSum << "UWSig"; m->mothurOut("UWSig"); }
+ outSum << endl; m->mothurOutEndLine();
+
+ //get pscores 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;
+
+ if (random) {
+ output = new ColumnFile(outputDir + m->getSimpleName(treefile) + toString(i+1) + "." + getOutputFileNameTag("unweighted"), itersString);
+ outputNames.push_back(outputDir + m->getSimpleName(treefile) + toString(i+1) + "." + getOutputFileNameTag("unweighted"));
+ outputTypes["unweighted"].push_back(outputDir + m->getSimpleName(treefile) + toString(i+1) + "." + getOutputFileNameTag("unweighted"));
+ }
+
+
+ //get unweighted for users tree
+ rscoreFreq.resize(numComp);
+ rCumul.resize(numComp);
+ utreeScores.resize(numComp);
+ UWScoreSig.resize(numComp);
+
+ vector<double> userData; userData.resize(numComp,0); //weighted score info for user tree. data[0] = weightedscore AB, data[1] = weightedscore AC...
+
+ userData = unweighted.getValues(T[i], processors, outputDir); //userData[0] = unweightedscore
+
+ 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; }