//**********************************************************************************************************************
vector<string> SummarySharedCommand::setParameters(){
try {
- CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared);
- CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel);
- CommandParameter psubsample("subsample", "String", "", "", "", "", "",false,false); parameters.push_back(psubsample);
- CommandParameter pdistance("distance", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pdistance);
- CommandParameter pcalc("calc", "Multiple", "sharedchao-sharedsobs-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-kstest-whittaker-sharednseqs-ochiai-anderberg-kulczynski-kulczynskicody-lennon-morisitahorn-braycurtis-odum-canberra-structeuclidean-structchord-hellinger-manhattan-structpearson-soergel-spearman-structkulczynski-speciesprofile-structchi2-hamming-gower-memchi2-memchord-memeuclidean-mempearson", "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan", "", "", "",true,false); parameters.push_back(pcalc);
- CommandParameter poutput("output", "Multiple", "lt-square", "lt", "", "", "",false,false); parameters.push_back(poutput);
- CommandParameter pall("all", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pall);
- CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters);
- CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors);
- CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups);
- CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
- CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
+ CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none","summary",false,true,true); parameters.push_back(pshared);
+ CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel);
+ CommandParameter psubsample("subsample", "String", "", "", "", "", "","phylip",false,false); parameters.push_back(psubsample);
+ CommandParameter pdistance("distance", "Boolean", "", "F", "", "", "","phylip",false,false); parameters.push_back(pdistance);
+ CommandParameter pcalc("calc", "Multiple", "sharedchao-sharedsobs-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-kstest-whittaker-sharednseqs-ochiai-anderberg-kulczynski-kulczynskicody-lennon-morisitahorn-braycurtis-odum-canberra-structeuclidean-structchord-hellinger-manhattan-structpearson-soergel-spearman-structkulczynski-speciesprofile-structchi2-hamming-gower-memchi2-memchord-memeuclidean-mempearson", "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan", "", "", "","",true,false,true); parameters.push_back(pcalc);
+ CommandParameter poutput("output", "Multiple", "lt-square", "lt", "", "", "","",false,false); parameters.push_back(poutput);
+ CommandParameter pall("all", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pall);
+ CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters);
+ CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors);
+ CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups);
+ CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
+ CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
vector<string> myArray;
for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
}
}
//**********************************************************************************************************************
+string SummarySharedCommand::getOutputPattern(string type) {
+ try {
+ string pattern = "";
+
+ if (type == "summary") { pattern = "[filename],summary-[filename],[tag],summary"; }
+ else if (type == "phylip") { pattern = "[filename],[calc],[distance],[outputtag],[tag2],dist"; }
+ else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; }
+
+ return pattern;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "SummarySharedCommand", "getOutputPattern");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
SummarySharedCommand::SummarySharedCommand(){
try {
abort = true; calledHelp = true;
setParameters();
vector<string> tempOutNames;
outputTypes["summary"] = tempOutNames;
+ outputTypes["phylip"] = tempOutNames;
}
catch(exception& e) {
m->errorOut(e, "SummarySharedCommand", "SummarySharedCommand");
//initialize outputTypes
vector<string> tempOutNames;
outputTypes["summary"] = tempOutNames;
+ outputTypes["phylip"] = tempOutNames;
//if the user changes the input directory command factory will send this info to us in the output parameter
string inputDir = validParameter.validFile(parameters, "inputdir", false);
temp = validParameter.validFile(parameters, "iters", false); if (temp == "not found") { temp = "1000"; }
m->mothurConvert(temp, iters);
- output = validParameter.validFile(parameters, "output", false); if(output == "not found"){ output = "lt"; }
+ output = validParameter.validFile(parameters, "output", false);
+ if(output == "not found"){ output = "lt"; }
+ else { createPhylip = true; }
if ((output != "lt") && (output != "square")) { m->mothurOut(output + " is not a valid output form. Options are lt and square. I will use lt."); m->mothurOutEndLine(); output = "lt"; }
temp = validParameter.validFile(parameters, "subsample", false); if (temp == "not found") { temp = "F"; }
else { subsample = false; }
}
- if (subsample == false) { iters = 1; }
+ if (subsample == false) { iters = 0; }
temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); }
m->setProcessors(temp);
if (abort == true) { if (calledHelp) { return 0; } return 2; }
ofstream outputFileHandle, outAll;
- string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "shared.summary";
+ map<string, string> variables;
+ variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile));
+ string outputFileName = getOutputFileName("summary",variables);
//if the users entered no valid calculators don't execute command
if (sumCalculators.size() == 0) { return 0; }
outputFileHandle.close();
//create file and put column headers for multiple groups file
- string outAllFileName = ((m->getRootName(sharedfile)) + "sharedmultiple.summary");
+ variables["[tag]"]= "multiple";
+ string outAllFileName = getOutputFileName("summary",variables);
if (mult == true) {
m->openOutputFile(outAllFileName, outAll);
outputNames.push_back(outAllFileName);
vector<summarySharedData*> pDataArray;
DWORD dwThreadIdArray[processors-1];
- HANDLE hThreadArray[processors-1];
+ HANDLE hThreadArray[processors-1];
//Create processor worker threads.
for( int i=1; i<processors; i++ ){
temp->setGroup(thisLookup[k]->getGroup());
newLookup.push_back(temp);
}
+
//for each bin
for (int k = 0; k < thisLookup[0]->getNumBins(); k++) {
//Close all thread handles and free memory allocations.
for(int i=0; i < pDataArray.size(); i++){
+ if (pDataArray[i]->count != (pDataArray[i]->end-pDataArray[i]->start)) {
+ m->mothurOut("[ERROR]: process " + toString(i) + " only processed " + toString(pDataArray[i]->count) + " of " + toString(pDataArray[i]->end-pDataArray[i]->start) + " groups assigned to it, quitting. \n"); m->control_pressed = true;
+ }
m->appendFiles((sumFileName + toString(processIDS[i]) + ".temp"), sumFileName);
m->mothurRemove((sumFileName + toString(processIDS[i]) + ".temp"));
//clean up memory
for (int i = 0; i < thisItersLookup.size(); i++) { delete thisItersLookup[i]; }
thisItersLookup.clear();
- for (int i = 0; i < calcDists.size(); i++) { calcDists[i].clear(); }
}else {
if (createPhylip) {
for (int i = 0; i < calcDists.size(); i++) {
matrix[column][row] = dist;
}
- string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + sumCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".dist";
+ map<string, string> variables;
+ variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile));
+ variables["[calc]"] = sumCalculators[i]->getName();
+ variables["[distance]"] = thisLookup[0]->getLabel();
+ variables["[outputtag]"] = output;
+ variables["[tag2]"] = "";
+ string distFileName = getOutputFileName("phylip",variables);
outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName);
ofstream outDist;
m->openOutputFile(distFileName, outDist);
}
}
}
+ for (int i = 0; i < calcDists.size(); i++) { calcDists[i].clear(); }
}
- if (iters != 1) {
+ if (iters != 0) {
//we need to find the average distance and standard deviation for each groups distance
-
- vector< vector<seqDist> > calcAverages; calcAverages.resize(sumCalculators.size());
- for (int i = 0; i < calcAverages.size(); i++) { //initialize sums to zero.
- calcAverages[i].resize(calcDistsTotals[0][i].size());
-
- for (int j = 0; j < calcAverages[i].size(); j++) {
- calcAverages[i][j].seq1 = calcDists[i][j].seq1;
- calcAverages[i][j].seq2 = calcDists[i][j].seq2;
- calcAverages[i][j].dist = 0.0;
- }
- }
-
- for (int thisIter = 0; thisIter < iters; thisIter++) { //sum all groups dists for each calculator
- for (int i = 0; i < calcAverages.size(); i++) { //initialize sums to zero.
- for (int j = 0; j < calcAverages[i].size(); j++) {
- calcAverages[i][j].dist += calcDistsTotals[thisIter][i][j].dist;
- }
- }
- }
-
- for (int i = 0; i < calcAverages.size(); i++) { //finds average.
- for (int j = 0; j < calcAverages[i].size(); j++) {
- calcAverages[i][j].dist /= (float) iters;
- }
- }
+ vector< vector<seqDist> > calcAverages = m->getAverages(calcDistsTotals);
//find standard deviation
- vector< vector<seqDist> > stdDev; stdDev.resize(sumCalculators.size());
- for (int i = 0; i < stdDev.size(); i++) { //initialize sums to zero.
- stdDev[i].resize(calcDistsTotals[0][i].size());
-
- for (int j = 0; j < stdDev[i].size(); j++) {
- stdDev[i][j].seq1 = calcDists[i][j].seq1;
- stdDev[i][j].seq2 = calcDists[i][j].seq2;
- stdDev[i][j].dist = 0.0;
- }
- }
-
- for (int thisIter = 0; thisIter < iters; thisIter++) { //compute the difference of each dist from the mean, and square the result of each
- for (int i = 0; i < stdDev.size(); i++) {
- for (int j = 0; j < stdDev[i].size(); j++) {
- stdDev[i][j].dist += ((calcDistsTotals[thisIter][i][j].dist - calcAverages[i][j].dist) * (calcDistsTotals[thisIter][i][j].dist - calcAverages[i][j].dist));
- }
- }
- }
-
- for (int i = 0; i < stdDev.size(); i++) { //finds average.
- for (int j = 0; j < stdDev[i].size(); j++) {
- stdDev[i][j].dist /= (float) iters;
- stdDev[i][j].dist = sqrt(stdDev[i][j].dist);
- }
- }
+ vector< vector<seqDist> > stdDev = m->getStandardDeviation(calcDistsTotals, calcAverages);
//print results
for (int i = 0; i < calcDists.size(); i++) {
stdmatrix[column][row] = stdDist;
}
- string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + sumCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".ave.dist";
+ map<string, string> variables;
+ variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile));
+ variables["[calc]"] = sumCalculators[i]->getName();
+ variables["[distance]"] = thisLookup[0]->getLabel();
+ variables["[outputtag]"] = output;
+ variables["[tag2]"] = "ave";
+ string distFileName = getOutputFileName("phylip",variables);
outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName);
ofstream outAve;
m->openOutputFile(distFileName, outAve);
outAve.close();
- distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + sumCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".std.dist";
+ variables["[tag2]"] = "std";
+ distFileName = getOutputFileName("phylip",variables);
outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName);
ofstream outSTD;
m->openOutputFile(distFileName, outSTD);