2 * summarysharedcommand.cpp
5 * Created by Sarah Westcott on 1/2/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "summarysharedcommand.h"
11 #include "sharedsobscollectsummary.h"
12 #include "sharedchao1.h"
13 #include "sharedace.h"
14 #include "sharednseqs.h"
15 #include "sharedjabund.h"
16 #include "sharedsorabund.h"
17 #include "sharedjclass.h"
18 #include "sharedsorclass.h"
19 #include "sharedjest.h"
20 #include "sharedsorest.h"
21 #include "sharedthetayc.h"
22 #include "sharedthetan.h"
23 #include "sharedkstest.h"
24 #include "whittaker.h"
25 #include "sharedochiai.h"
26 #include "sharedanderbergs.h"
27 #include "sharedkulczynski.h"
28 #include "sharedkulczynskicody.h"
29 #include "sharedlennon.h"
30 #include "sharedmorisitahorn.h"
31 #include "sharedbraycurtis.h"
32 #include "sharedjackknife.h"
33 #include "whittaker.h"
36 #include "structeuclidean.h"
37 #include "structchord.h"
38 #include "hellinger.h"
39 #include "manhattan.h"
40 #include "structpearson.h"
43 #include "structkulczynski.h"
44 #include "structchi2.h"
45 #include "speciesprofile.h"
50 #include "memeuclidean.h"
51 #include "mempearson.h"
53 //**********************************************************************************************************************
54 vector<string> SummarySharedCommand::getValidParameters(){
56 string Array[] = {"label","calc","groups","all","outputdir","distance","inputdir", "processors"};
57 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
61 m->errorOut(e, "SummarySharedCommand", "getValidParameters");
65 //**********************************************************************************************************************
66 SummarySharedCommand::SummarySharedCommand(){
69 //initialize outputTypes
70 vector<string> tempOutNames;
71 outputTypes["summary"] = tempOutNames;
74 m->errorOut(e, "SummarySharedCommand", "SummarySharedCommand");
78 //**********************************************************************************************************************
79 vector<string> SummarySharedCommand::getRequiredParameters(){
81 vector<string> myArray;
85 m->errorOut(e, "SummarySharedCommand", "getRequiredParameters");
89 //**********************************************************************************************************************
90 vector<string> SummarySharedCommand::getRequiredFiles(){
92 string Array[] = {"shared"};
93 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
97 m->errorOut(e, "SummarySharedCommand", "getRequiredFiles");
101 //**********************************************************************************************************************
103 SummarySharedCommand::SummarySharedCommand(string option) {
105 globaldata = GlobalData::getInstance();
111 //allow user to run help
112 if(option == "help") { validCalculator = new ValidCalculators(); help(); abort = true; }
115 //valid paramters for this command
116 string Array[] = {"label","calc","groups","all","outputdir","distance","inputdir", "processors"};
117 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
119 OptionParser parser(option);
120 map<string, string> parameters = parser.getParameters();
122 ValidParameters validParameter;
124 //check to make sure all parameters are valid for command
125 for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
126 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
129 //make sure the user has already run the read.otu command
130 if (globaldata->getSharedFile() == "") {
131 m->mothurOut("You must read a list and a group, or a shared before you can use the summary.shared command."); m->mothurOutEndLine(); abort = true;
134 //initialize outputTypes
135 vector<string> tempOutNames;
136 outputTypes["summary"] = tempOutNames;
138 //if the user changes the output directory command factory will send this info to us in the output parameter
139 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){
141 outputDir += m->hasPath(globaldata->getSharedFile()); //if user entered a file with a path then preserve it
144 //check for optional parameter and set defaults
145 // ...at some point should added some additional type checking...
146 label = validParameter.validFile(parameters, "label", false);
147 if (label == "not found") { label = ""; }
149 if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
150 else { allLines = 1; }
153 //if the user has not specified any labels use the ones from read.otu
155 allLines = globaldata->allLines;
156 labels = globaldata->labels;
159 calc = validParameter.validFile(parameters, "calc", false);
160 if (calc == "not found") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
162 if (calc == "default") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
164 m->splitAtDash(calc, Estimators);
166 groups = validParameter.validFile(parameters, "groups", false);
167 if (groups == "not found") { groups = ""; }
169 m->splitAtDash(groups, Groups);
170 globaldata->Groups = Groups;
173 string temp = validParameter.validFile(parameters, "all", false); if (temp == "not found") { temp = "false"; }
174 all = m->isTrue(temp);
176 temp = validParameter.validFile(parameters, "distance", false); if (temp == "not found") { temp = "false"; }
177 createPhylip = m->isTrue(temp);
179 temp = validParameter.validFile(parameters, "processors", false); if(temp == "not found"){ temp = "1"; }
180 convert(temp, processors);
182 if (abort == false) {
184 validCalculator = new ValidCalculators();
187 for (i=0; i<Estimators.size(); i++) {
188 if (validCalculator->isValidCalculator("sharedsummary", Estimators[i]) == true) {
189 if (Estimators[i] == "sharedsobs") {
190 sumCalculators.push_back(new SharedSobsCS());
191 }else if (Estimators[i] == "sharedchao") {
192 sumCalculators.push_back(new SharedChao1());
193 }else if (Estimators[i] == "sharedace") {
194 sumCalculators.push_back(new SharedAce());
195 }else if (Estimators[i] == "jabund") {
196 sumCalculators.push_back(new JAbund());
197 }else if (Estimators[i] == "sorabund") {
198 sumCalculators.push_back(new SorAbund());
199 }else if (Estimators[i] == "jclass") {
200 sumCalculators.push_back(new Jclass());
201 }else if (Estimators[i] == "sorclass") {
202 sumCalculators.push_back(new SorClass());
203 }else if (Estimators[i] == "jest") {
204 sumCalculators.push_back(new Jest());
205 }else if (Estimators[i] == "sorest") {
206 sumCalculators.push_back(new SorEst());
207 }else if (Estimators[i] == "thetayc") {
208 sumCalculators.push_back(new ThetaYC());
209 }else if (Estimators[i] == "thetan") {
210 sumCalculators.push_back(new ThetaN());
211 }else if (Estimators[i] == "kstest") {
212 sumCalculators.push_back(new KSTest());
213 }else if (Estimators[i] == "sharednseqs") {
214 sumCalculators.push_back(new SharedNSeqs());
215 }else if (Estimators[i] == "ochiai") {
216 sumCalculators.push_back(new Ochiai());
217 }else if (Estimators[i] == "anderberg") {
218 sumCalculators.push_back(new Anderberg());
219 }else if (Estimators[i] == "kulczynski") {
220 sumCalculators.push_back(new Kulczynski());
221 }else if (Estimators[i] == "kulczynskicody") {
222 sumCalculators.push_back(new KulczynskiCody());
223 }else if (Estimators[i] == "lennon") {
224 sumCalculators.push_back(new Lennon());
225 }else if (Estimators[i] == "morisitahorn") {
226 sumCalculators.push_back(new MorHorn());
227 }else if (Estimators[i] == "braycurtis") {
228 sumCalculators.push_back(new BrayCurtis());
229 }else if (Estimators[i] == "whittaker") {
230 sumCalculators.push_back(new Whittaker());
231 }else if (Estimators[i] == "odum") {
232 sumCalculators.push_back(new Odum());
233 }else if (Estimators[i] == "canberra") {
234 sumCalculators.push_back(new Canberra());
235 }else if (Estimators[i] == "structeuclidean") {
236 sumCalculators.push_back(new StructEuclidean());
237 }else if (Estimators[i] == "structchord") {
238 sumCalculators.push_back(new StructChord());
239 }else if (Estimators[i] == "hellinger") {
240 sumCalculators.push_back(new Hellinger());
241 }else if (Estimators[i] == "manhattan") {
242 sumCalculators.push_back(new Manhattan());
243 }else if (Estimators[i] == "structpearson") {
244 sumCalculators.push_back(new StructPearson());
245 }else if (Estimators[i] == "soergel") {
246 sumCalculators.push_back(new Soergel());
247 }else if (Estimators[i] == "spearman") {
248 sumCalculators.push_back(new Spearman());
249 }else if (Estimators[i] == "structkulczynski") {
250 sumCalculators.push_back(new StructKulczynski());
251 }else if (Estimators[i] == "speciesprofile") {
252 sumCalculators.push_back(new SpeciesProfile());
253 }else if (Estimators[i] == "hamming") {
254 sumCalculators.push_back(new Hamming());
255 }else if (Estimators[i] == "structchi2") {
256 sumCalculators.push_back(new StructChi2());
257 }else if (Estimators[i] == "gower") {
258 sumCalculators.push_back(new Gower());
259 }else if (Estimators[i] == "memchi2") {
260 sumCalculators.push_back(new MemChi2());
261 }else if (Estimators[i] == "memchord") {
262 sumCalculators.push_back(new MemChord());
263 }else if (Estimators[i] == "memeuclidean") {
264 sumCalculators.push_back(new MemEuclidean());
265 }else if (Estimators[i] == "mempearson") {
266 sumCalculators.push_back(new MemPearson());
275 catch(exception& e) {
276 m->errorOut(e, "SummarySharedCommand", "SummarySharedCommand");
281 //**********************************************************************************************************************
283 void SummarySharedCommand::help(){
285 m->mothurOut("The summary.shared command can only be executed after a successful read.otu command.\n");
286 m->mothurOut("The summary.shared command parameters are label, calc, distance and all. No parameters are required.\n");
287 m->mothurOut("The summary.shared command should be in the following format: \n");
288 m->mothurOut("summary.shared(label=yourLabel, calc=yourEstimators, groups=yourGroups).\n");
289 m->mothurOut("Example summary.shared(label=unique-.01-.03, groups=B-C, calc=sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan).\n");
290 validCalculator->printCalc("sharedsummary", cout);
291 m->mothurOut("The default value for calc is sharedsobs-sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan\n");
292 m->mothurOut("The default value for groups is all the groups in your groupfile.\n");
293 m->mothurOut("The distance parameter allows you to indicate you would like a distance file created for each calculator for each label, default=f.\n");
294 m->mothurOut("The label parameter is used to analyze specific labels in your input.\n");
295 m->mothurOut("The all parameter is used to specify if you want the estimate of all your groups together. This estimate can only be made for sharedsobs and sharedchao calculators. The default is false.\n");
296 m->mothurOut("If you use sharedchao and run into memory issues, set all to false. \n");
297 m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. You must enter at least 2 valid groups.\n");
298 m->mothurOut("Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabel).\n\n");
300 catch(exception& e) {
301 m->errorOut(e, "SummarySharedCommand", "help");
306 //**********************************************************************************************************************
308 SummarySharedCommand::~SummarySharedCommand(){
309 if (abort == false) {
311 delete validCalculator;
315 //**********************************************************************************************************************
317 int SummarySharedCommand::execute(){
320 if (abort == true) { return 0; }
322 ofstream outputFileHandle, outAll;
323 string outputFileName = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "shared.summary";
325 //if the users entered no valid calculators don't execute command
326 if (sumCalculators.size() == 0) { return 0; }
327 //check if any calcs can do multiples
330 for (int i = 0; i < sumCalculators.size(); i++) {
331 if (sumCalculators[i]->getMultiple() == true) { mult = true; }
337 read = new ReadOTUFile(globaldata->inputFileName);
338 read->read(&*globaldata);
340 input = globaldata->ginput;
341 lookup = input->getSharedRAbundVectors();
342 string lastLabel = lookup[0]->getLabel();
344 /******************************************************/
345 //output headings for files
346 /******************************************************/
347 //output estimator names as column headers
348 m->openOutputFile(outputFileName, outputFileHandle);
349 outputFileHandle << "label" <<'\t' << "comparison" << '\t';
350 for(int i=0;i<sumCalculators.size();i++){
351 outputFileHandle << '\t' << sumCalculators[i]->getName();
352 if (sumCalculators[i]->getCols() == 3) { outputFileHandle << "\t" << sumCalculators[i]->getName() << "_lci\t" << sumCalculators[i]->getName() << "_hci"; }
354 outputFileHandle << endl;
355 outputFileHandle.close();
357 //create file and put column headers for multiple groups file
358 string outAllFileName = ((m->getRootName(globaldata->inputFileName)) + "sharedmultiple.summary");
360 m->openOutputFile(outAllFileName, outAll);
361 outputNames.push_back(outAllFileName);
363 outAll << "label" <<'\t' << "comparison" << '\t';
364 for(int i=0;i<sumCalculators.size();i++){
365 if (sumCalculators[i]->getMultiple() == true) {
366 outAll << '\t' << sumCalculators[i]->getName();
373 if (lookup.size() < 2) {
374 m->mothurOut("I cannot run the command without at least 2 valid groups.");
375 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
377 //close files and clean up
378 remove(outputFileName.c_str());
379 if (mult == true) { remove(outAllFileName.c_str()); }
381 //if you only have 2 groups you don't need a .sharedmultiple file
382 }else if ((lookup.size() == 2) && (mult == true)) {
384 remove(outAllFileName.c_str());
385 outputNames.pop_back();
388 if (m->control_pressed) {
389 if (mult) { remove(outAllFileName.c_str()); }
390 remove(outputFileName.c_str());
391 delete input; globaldata->ginput = NULL;
392 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
393 for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; }
394 globaldata->Groups.clear();
397 /******************************************************/
400 /******************************************************/
401 //comparison breakup to be used by different processes later
402 numGroups = globaldata->Groups.size();
403 lines.resize(processors);
404 for (int i = 0; i < processors; i++) {
405 lines[i].start = int (sqrt(float(i)/float(processors)) * numGroups);
406 lines[i].end = int (sqrt(float(i+1)/float(processors)) * numGroups);
408 /******************************************************/
410 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
411 set<string> processedLabels;
412 set<string> userLabels = labels;
414 //as long as you are not at the end of the file or done wih the lines you want
415 while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
416 if (m->control_pressed) {
417 if (mult) { remove(outAllFileName.c_str()); }
418 remove(outputFileName.c_str());
419 delete input; globaldata->ginput = NULL;
420 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
421 for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; }
422 globaldata->Groups.clear();
427 if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){
428 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
429 process(lookup, outputFileName, outAllFileName);
431 processedLabels.insert(lookup[0]->getLabel());
432 userLabels.erase(lookup[0]->getLabel());
435 if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
436 string saveLabel = lookup[0]->getLabel();
438 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
439 lookup = input->getSharedRAbundVectors(lastLabel);
441 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
442 process(lookup, outputFileName, outAllFileName);
444 processedLabels.insert(lookup[0]->getLabel());
445 userLabels.erase(lookup[0]->getLabel());
447 //restore real lastlabel to save below
448 lookup[0]->setLabel(saveLabel);
451 lastLabel = lookup[0]->getLabel();
453 //get next line to process
454 //prevent memory leak
455 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
456 lookup = input->getSharedRAbundVectors();
459 if (m->control_pressed) {
460 if (mult) { remove(outAllFileName.c_str()); }
461 remove(outputFileName.c_str());
462 delete input; globaldata->ginput = NULL;
463 for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; }
464 globaldata->Groups.clear();
468 //output error messages about any remaining user labels
469 set<string>::iterator it;
470 bool needToRun = false;
471 for (it = userLabels.begin(); it != userLabels.end(); it++) {
472 m->mothurOut("Your file does not include the label " + *it);
473 if (processedLabels.count(lastLabel) != 1) {
474 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
477 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
481 //run last label if you need to
482 if (needToRun == true) {
483 for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } }
484 lookup = input->getSharedRAbundVectors(lastLabel);
486 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
487 process(lookup, outputFileName, outAllFileName);
488 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
492 //reset groups parameter
493 globaldata->Groups.clear();
495 for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; }
496 delete input; globaldata->ginput = NULL;
498 if (m->control_pressed) {
499 remove(outAllFileName.c_str());
500 remove(outputFileName.c_str());
504 m->mothurOutEndLine();
505 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
506 m->mothurOut(outputFileName); m->mothurOutEndLine();
507 if (mult) { m->mothurOut(outAllFileName); m->mothurOutEndLine(); outputTypes["summary"].push_back(outAllFileName); }
508 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } outputTypes["summary"].push_back(outputFileName);
509 m->mothurOutEndLine();
513 catch(exception& e) {
514 m->errorOut(e, "SummarySharedCommand", "execute");
519 /***********************************************************/
520 int SummarySharedCommand::process(vector<SharedRAbundVector*> thisLookup, string sumFileName, string sumAllFileName) {
522 vector< vector<seqDist> > calcDists; //vector containing vectors that contains the summary results for each group compare
523 calcDists.resize(sumCalculators.size()); //one for each calc, this will be used to make .dist files
525 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
527 driver(thisLookup, 0, numGroups, sumFileName+".temp", sumAllFileName+".temp", calcDists);
528 m->appendFiles((sumFileName + ".temp"), sumFileName);
529 remove((sumFileName + ".temp").c_str());
531 m->appendFiles((sumAllFileName + ".temp"), sumAllFileName);
532 remove((sumAllFileName + ".temp").c_str());
536 vector<int> processIDS;
538 //loop through and create all the processes you want
539 while (process != processors) {
543 processIDS.push_back(pid);
546 driver(thisLookup, lines[process].start, lines[process].end, sumFileName + toString(getpid()) + ".temp", sumAllFileName + toString(getpid()) + ".temp", calcDists);
548 //only do this if you want a distance file
550 string tempdistFileName = m->getRootName(m->getSimpleName(sumFileName)) + toString(getpid()) + ".dist";
552 m->openOutputFile(tempdistFileName, outtemp);
554 for (int i = 0; i < calcDists.size(); i++) {
555 outtemp << calcDists[i].size() << endl;
557 for (int j = 0; j < calcDists[i].size(); j++) {
558 outtemp << calcDists[i][j].seq1 << '\t' << calcDists[i][j].seq2 << '\t' << calcDists[i][j].dist << endl;
566 m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine();
567 for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); }
572 //parent do your part
573 driver(thisLookup, lines[0].start, lines[0].end, sumFileName + toString(getpid()) + ".temp", sumAllFileName + toString(getpid()) + ".temp", calcDists);
574 m->appendFiles((sumFileName + toString(getpid()) + ".temp"), sumFileName);
575 remove((sumFileName + toString(getpid()) + ".temp").c_str());
576 if (mult) { m->appendFiles((sumAllFileName + toString(getpid()) + ".temp"), sumAllFileName); }
578 //force parent to wait until all the processes are done
579 for (int i = 0; i < processIDS.size(); i++) {
580 int temp = processIDS[i];
584 for (int i = 0; i < processIDS.size(); i++) {
585 m->appendFiles((sumFileName + toString(processIDS[i]) + ".temp"), sumFileName);
586 remove((sumFileName + toString(processIDS[i]) + ".temp").c_str());
587 if (mult) { remove((sumAllFileName + toString(processIDS[i]) + ".temp").c_str()); }
590 string tempdistFileName = m->getRootName(m->getSimpleName(sumFileName)) + toString(processIDS[i]) + ".dist";
592 m->openInputFile(tempdistFileName, intemp);
594 for (int i = 0; i < calcDists.size(); i++) {
596 intemp >> size; m->gobble(intemp);
598 for (int j = 0; j < size; j++) {
603 intemp >> seq1 >> seq2 >> dist; m->gobble(intemp);
605 seqDist tempDist(seq1, seq2, dist);
606 calcDists[i].push_back(tempDist);
610 remove(tempdistFileName.c_str());
616 driver(thisLookup, 0, numGroups, (sumFileName + ".temp"), (sumAllFileName + ".temp"), calcDists);
617 m->appendFiles((sumFileName + ".temp"), sumFileName);
618 remove((sumFileName + ".temp").c_str());
620 m->appendFiles((sumAllFileName + ".temp"), sumAllFileName);
621 remove((sumAllFileName + ".temp").c_str());
626 for (int i = 0; i < calcDists.size(); i++) {
627 if (m->control_pressed) { break; }
629 string distFileName = outputDir + m->getRootName(m->getSimpleName(sumFileName)) + sumCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".dist";
630 outputNames.push_back(distFileName);
632 m->openOutputFile(distFileName, outDist);
633 outDist.setf(ios::fixed, ios::floatfield); outDist.setf(ios::showpoint);
636 vector< vector<float> > matrix; //square matrix to represent the distance
637 matrix.resize(thisLookup.size());
638 for (int k = 0; k < thisLookup.size(); k++) { matrix[k].resize(thisLookup.size(), 0.0); }
641 for (int j = 0; j < calcDists[i].size(); j++) {
642 int row = calcDists[i][j].seq1;
643 int column = calcDists[i][j].seq2;
644 float dist = calcDists[i][j].dist;
646 matrix[row][column] = dist;
647 matrix[column][row] = dist;
651 outDist << thisLookup.size() << endl;
652 for (int r=0; r<thisLookup.size(); r++) {
654 string name = thisLookup[r]->getGroup();
655 if (name.length() < 10) { //pad with spaces to make compatible
656 while (name.length() < 10) { name += " "; }
658 outDist << name << '\t';
661 for (int l = 0; l < r; l++) { outDist << matrix[r][l] << '\t'; }
670 catch(exception& e) {
671 m->errorOut(e, "SummarySharedCommand", "process");
675 /**************************************************************************************************/
676 int SummarySharedCommand::driver(vector<SharedRAbundVector*> thisLookup, int start, int end, string sumFile, string sumAllFile, vector< vector<seqDist> >& calcDists) {
679 //loop through calculators and add to file all for all calcs that can do mutiple groups
682 m->openOutputFile(sumAllFile, outAll);
685 outAll << thisLookup[0]->getLabel() << '\t';
687 //output groups names
688 string outNames = "";
689 for (int j = 0; j < thisLookup.size(); j++) {
690 outNames += thisLookup[j]->getGroup() + "-";
692 outNames = outNames.substr(0, outNames.length()-1); //rip off extra '-';
693 outAll << outNames << '\t';
695 for(int i=0;i<sumCalculators.size();i++){
696 if (sumCalculators[i]->getMultiple() == true) {
697 sumCalculators[i]->getValues(thisLookup);
699 if (m->control_pressed) { outAll.close(); return 1; }
702 sumCalculators[i]->print(outAll);
709 ofstream outputFileHandle;
710 m->openOutputFile(sumFile, outputFileHandle);
712 vector<SharedRAbundVector*> subset;
713 for (int k = start; k < end; k++) { // pass cdd each set of groups to compare
715 for (int l = 0; l < k; l++) {
717 outputFileHandle << thisLookup[0]->getLabel() << '\t';
719 subset.clear(); //clear out old pair of sharedrabunds
720 //add new pair of sharedrabunds
721 subset.push_back(thisLookup[k]); subset.push_back(thisLookup[l]);
723 //sort groups to be alphanumeric
724 if (thisLookup[k]->getGroup() > thisLookup[l]->getGroup()) {
725 outputFileHandle << (thisLookup[l]->getGroup() +'\t' + thisLookup[k]->getGroup()) << '\t'; //print out groups
727 outputFileHandle << (thisLookup[k]->getGroup() +'\t' + thisLookup[l]->getGroup()) << '\t'; //print out groups
730 for(int i=0;i<sumCalculators.size();i++) {
732 //if this calc needs all groups to calculate the pair load all groups
733 if (sumCalculators[i]->getNeedsAll()) {
734 //load subset with rest of lookup for those calcs that need everyone to calc for a pair
735 for (int w = 0; w < thisLookup.size(); w++) {
736 if ((w != k) && (w != l)) { subset.push_back(thisLookup[w]); }
740 vector<double> tempdata = sumCalculators[i]->getValues(subset); //saves the calculator outputs
742 if (m->control_pressed) { outputFileHandle.close(); return 1; }
744 outputFileHandle << '\t';
745 sumCalculators[i]->print(outputFileHandle);
747 seqDist temp(l, k, tempdata[0]);
748 calcDists[i].push_back(temp);
750 outputFileHandle << endl;
754 outputFileHandle.close();
758 catch(exception& e) {
759 m->errorOut(e, "SummarySharedCommand", "driver");
763 /**************************************************************************************************/