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::setParameters(){
56 CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared);
57 CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel);
58 CommandParameter pdistance("distance", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pdistance);
59 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);
60 CommandParameter pall("all", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pall);
61 CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors);
62 CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups);
63 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
64 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
66 vector<string> myArray;
67 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
71 m->errorOut(e, "SummarySharedCommand", "setParameters");
75 //**********************************************************************************************************************
76 string SummarySharedCommand::getHelpString(){
78 string helpString = "";
79 ValidCalculators validCalculator;
80 helpString += "The summary.shared command parameters are shared, label, calc, distance, processors and all. shared is required if there is no current sharedfile.\n";
81 helpString += "The summary.shared command should be in the following format: \n";
82 helpString += "summary.shared(label=yourLabel, calc=yourEstimators, groups=yourGroups).\n";
83 helpString += "Example summary.shared(label=unique-.01-.03, groups=B-C, calc=sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan).\n";
84 helpString += validCalculator.printCalc("sharedsummary");
85 helpString += "The default value for calc is sharedsobs-sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan\n";
86 helpString += "The default value for groups is all the groups in your groupfile.\n";
87 helpString += "The distance parameter allows you to indicate you would like a distance file created for each calculator for each label, default=f.\n";
88 helpString += "The label parameter is used to analyze specific labels in your input.\n";
89 helpString += "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";
90 helpString += "If you use sharedchao and run into memory issues, set all to false. \n";
91 helpString += "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";
92 helpString += "Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabel).\n";
96 m->errorOut(e, "SummarySharedCommand", "getHelpString");
100 //**********************************************************************************************************************
101 SummarySharedCommand::SummarySharedCommand(){
103 abort = true; calledHelp = true;
105 vector<string> tempOutNames;
106 outputTypes["summary"] = tempOutNames;
108 catch(exception& e) {
109 m->errorOut(e, "SummarySharedCommand", "SummarySharedCommand");
113 //**********************************************************************************************************************
115 SummarySharedCommand::SummarySharedCommand(string option) {
117 abort = false; calledHelp = false;
120 //allow user to run help
121 if(option == "help") { help(); abort = true; calledHelp = true; }
122 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
125 vector<string> myArray = setParameters();
127 OptionParser parser(option);
128 map<string, string> parameters = parser.getParameters();
129 map<string, string>::iterator it;
131 ValidParameters validParameter;
133 //check to make sure all parameters are valid for command
134 for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
135 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
138 //initialize outputTypes
139 vector<string> tempOutNames;
140 outputTypes["summary"] = tempOutNames;
142 //if the user changes the input directory command factory will send this info to us in the output parameter
143 string inputDir = validParameter.validFile(parameters, "inputdir", false);
144 if (inputDir == "not found"){ inputDir = ""; }
147 it = parameters.find("shared");
148 //user has given a template file
149 if(it != parameters.end()){
150 path = m->hasPath(it->second);
151 //if the user has not given a path then, add inputdir. else leave path alone.
152 if (path == "") { parameters["shared"] = inputDir + it->second; }
157 sharedfile = validParameter.validFile(parameters, "shared", true);
158 if (sharedfile == "not open") { sharedfile = ""; abort = true; }
159 else if (sharedfile == "not found") {
160 //if there is a current shared file, use it
161 sharedfile = m->getSharedFile();
162 if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
163 else { m->mothurOut("You have no current sharedfile and the shared parameter is required."); m->mothurOutEndLine(); abort = true; }
164 }else { m->setSharedFile(sharedfile); }
167 //if the user changes the output directory command factory will send this info to us in the output parameter
168 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(sharedfile); }
171 //check for optional parameter and set defaults
172 // ...at some point should added some additional type checking...
173 label = validParameter.validFile(parameters, "label", false);
174 if (label == "not found") { label = ""; }
176 if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
177 else { allLines = 1; }
181 calc = validParameter.validFile(parameters, "calc", false);
182 if (calc == "not found") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
184 if (calc == "default") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
186 m->splitAtDash(calc, Estimators);
187 if (m->inUsersGroups("citation", Estimators)) {
188 ValidCalculators validCalc; validCalc.printCitations(Estimators);
189 //remove citation from list of calcs
190 for (int i = 0; i < Estimators.size(); i++) { if (Estimators[i] == "citation") { Estimators.erase(Estimators.begin()+i); break; } }
193 groups = validParameter.validFile(parameters, "groups", false);
194 if (groups == "not found") { groups = ""; }
196 m->splitAtDash(groups, Groups);
197 m->setGroups(Groups);
200 string temp = validParameter.validFile(parameters, "all", false); if (temp == "not found") { temp = "false"; }
201 all = m->isTrue(temp);
203 temp = validParameter.validFile(parameters, "distance", false); if (temp == "not found") { temp = "false"; }
204 createPhylip = m->isTrue(temp);
206 temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); }
207 m->setProcessors(temp);
208 m->mothurConvert(temp, processors);
210 if (abort == false) {
212 ValidCalculators validCalculator;
215 for (i=0; i<Estimators.size(); i++) {
216 if (validCalculator.isValidCalculator("sharedsummary", Estimators[i]) == true) {
217 if (Estimators[i] == "sharedsobs") {
218 sumCalculators.push_back(new SharedSobsCS());
219 }else if (Estimators[i] == "sharedchao") {
220 sumCalculators.push_back(new SharedChao1());
221 }else if (Estimators[i] == "sharedace") {
222 sumCalculators.push_back(new SharedAce());
223 }else if (Estimators[i] == "jabund") {
224 sumCalculators.push_back(new JAbund());
225 }else if (Estimators[i] == "sorabund") {
226 sumCalculators.push_back(new SorAbund());
227 }else if (Estimators[i] == "jclass") {
228 sumCalculators.push_back(new Jclass());
229 }else if (Estimators[i] == "sorclass") {
230 sumCalculators.push_back(new SorClass());
231 }else if (Estimators[i] == "jest") {
232 sumCalculators.push_back(new Jest());
233 }else if (Estimators[i] == "sorest") {
234 sumCalculators.push_back(new SorEst());
235 }else if (Estimators[i] == "thetayc") {
236 sumCalculators.push_back(new ThetaYC());
237 }else if (Estimators[i] == "thetan") {
238 sumCalculators.push_back(new ThetaN());
239 }else if (Estimators[i] == "kstest") {
240 sumCalculators.push_back(new KSTest());
241 }else if (Estimators[i] == "sharednseqs") {
242 sumCalculators.push_back(new SharedNSeqs());
243 }else if (Estimators[i] == "ochiai") {
244 sumCalculators.push_back(new Ochiai());
245 }else if (Estimators[i] == "anderberg") {
246 sumCalculators.push_back(new Anderberg());
247 }else if (Estimators[i] == "kulczynski") {
248 sumCalculators.push_back(new Kulczynski());
249 }else if (Estimators[i] == "kulczynskicody") {
250 sumCalculators.push_back(new KulczynskiCody());
251 }else if (Estimators[i] == "lennon") {
252 sumCalculators.push_back(new Lennon());
253 }else if (Estimators[i] == "morisitahorn") {
254 sumCalculators.push_back(new MorHorn());
255 }else if (Estimators[i] == "braycurtis") {
256 sumCalculators.push_back(new BrayCurtis());
257 }else if (Estimators[i] == "whittaker") {
258 sumCalculators.push_back(new Whittaker());
259 }else if (Estimators[i] == "odum") {
260 sumCalculators.push_back(new Odum());
261 }else if (Estimators[i] == "canberra") {
262 sumCalculators.push_back(new Canberra());
263 }else if (Estimators[i] == "structeuclidean") {
264 sumCalculators.push_back(new StructEuclidean());
265 }else if (Estimators[i] == "structchord") {
266 sumCalculators.push_back(new StructChord());
267 }else if (Estimators[i] == "hellinger") {
268 sumCalculators.push_back(new Hellinger());
269 }else if (Estimators[i] == "manhattan") {
270 sumCalculators.push_back(new Manhattan());
271 }else if (Estimators[i] == "structpearson") {
272 sumCalculators.push_back(new StructPearson());
273 }else if (Estimators[i] == "soergel") {
274 sumCalculators.push_back(new Soergel());
275 }else if (Estimators[i] == "spearman") {
276 sumCalculators.push_back(new Spearman());
277 }else if (Estimators[i] == "structkulczynski") {
278 sumCalculators.push_back(new StructKulczynski());
279 }else if (Estimators[i] == "speciesprofile") {
280 sumCalculators.push_back(new SpeciesProfile());
281 }else if (Estimators[i] == "hamming") {
282 sumCalculators.push_back(new Hamming());
283 }else if (Estimators[i] == "structchi2") {
284 sumCalculators.push_back(new StructChi2());
285 }else if (Estimators[i] == "gower") {
286 sumCalculators.push_back(new Gower());
287 }else if (Estimators[i] == "memchi2") {
288 sumCalculators.push_back(new MemChi2());
289 }else if (Estimators[i] == "memchord") {
290 sumCalculators.push_back(new MemChord());
291 }else if (Estimators[i] == "memeuclidean") {
292 sumCalculators.push_back(new MemEuclidean());
293 }else if (Estimators[i] == "mempearson") {
294 sumCalculators.push_back(new MemPearson());
303 catch(exception& e) {
304 m->errorOut(e, "SummarySharedCommand", "SummarySharedCommand");
308 //**********************************************************************************************************************
310 int SummarySharedCommand::execute(){
313 if (abort == true) { if (calledHelp) { return 0; } return 2; }
315 ofstream outputFileHandle, outAll;
316 string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "shared.summary";
318 //if the users entered no valid calculators don't execute command
319 if (sumCalculators.size() == 0) { return 0; }
320 //check if any calcs can do multiples
323 for (int i = 0; i < sumCalculators.size(); i++) {
324 if (sumCalculators[i]->getMultiple() == true) { mult = true; }
329 input = new InputData(sharedfile, "sharedfile");
330 lookup = input->getSharedRAbundVectors();
331 string lastLabel = lookup[0]->getLabel();
333 /******************************************************/
334 //output headings for files
335 /******************************************************/
336 //output estimator names as column headers
337 m->openOutputFile(outputFileName, outputFileHandle);
338 outputFileHandle << "label" <<'\t' << "comparison" << '\t';
339 for(int i=0;i<sumCalculators.size();i++){
340 outputFileHandle << '\t' << sumCalculators[i]->getName();
341 if (sumCalculators[i]->getCols() == 3) { outputFileHandle << "\t" << sumCalculators[i]->getName() << "_lci\t" << sumCalculators[i]->getName() << "_hci"; }
343 outputFileHandle << endl;
344 outputFileHandle.close();
346 //create file and put column headers for multiple groups file
347 string outAllFileName = ((m->getRootName(sharedfile)) + "sharedmultiple.summary");
349 m->openOutputFile(outAllFileName, outAll);
350 outputNames.push_back(outAllFileName);
352 outAll << "label" <<'\t' << "comparison" << '\t';
353 for(int i=0;i<sumCalculators.size();i++){
354 if (sumCalculators[i]->getMultiple() == true) {
355 outAll << '\t' << sumCalculators[i]->getName();
362 if (lookup.size() < 2) {
363 m->mothurOut("I cannot run the command without at least 2 valid groups.");
364 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
366 //close files and clean up
367 m->mothurRemove(outputFileName);
368 if (mult == true) { m->mothurRemove(outAllFileName); }
370 //if you only have 2 groups you don't need a .sharedmultiple file
371 }else if ((lookup.size() == 2) && (mult == true)) {
373 m->mothurRemove(outAllFileName);
374 outputNames.pop_back();
377 if (m->control_pressed) {
378 if (mult) { m->mothurRemove(outAllFileName); }
379 m->mothurRemove(outputFileName);
381 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
382 for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; }
386 /******************************************************/
389 /******************************************************/
390 //comparison breakup to be used by different processes later
391 numGroups = m->getNumGroups();
392 lines.resize(processors);
393 for (int i = 0; i < processors; i++) {
394 lines[i].start = int (sqrt(float(i)/float(processors)) * numGroups);
395 lines[i].end = int (sqrt(float(i+1)/float(processors)) * numGroups);
397 /******************************************************/
399 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
400 set<string> processedLabels;
401 set<string> userLabels = labels;
403 //as long as you are not at the end of the file or done wih the lines you want
404 while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
405 if (m->control_pressed) {
406 if (mult) { m->mothurRemove(outAllFileName); }
407 m->mothurRemove(outputFileName);
409 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
410 for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; }
416 if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){
417 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
418 process(lookup, outputFileName, outAllFileName);
420 processedLabels.insert(lookup[0]->getLabel());
421 userLabels.erase(lookup[0]->getLabel());
424 if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
425 string saveLabel = lookup[0]->getLabel();
427 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
428 lookup = input->getSharedRAbundVectors(lastLabel);
430 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
431 process(lookup, outputFileName, outAllFileName);
433 processedLabels.insert(lookup[0]->getLabel());
434 userLabels.erase(lookup[0]->getLabel());
436 //restore real lastlabel to save below
437 lookup[0]->setLabel(saveLabel);
440 lastLabel = lookup[0]->getLabel();
442 //get next line to process
443 //prevent memory leak
444 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
445 lookup = input->getSharedRAbundVectors();
448 if (m->control_pressed) {
449 if (mult) { m->mothurRemove(outAllFileName); }
450 m->mothurRemove(outputFileName);
452 for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; }
457 //output error messages about any remaining user labels
458 set<string>::iterator it;
459 bool needToRun = false;
460 for (it = userLabels.begin(); it != userLabels.end(); it++) {
461 m->mothurOut("Your file does not include the label " + *it);
462 if (processedLabels.count(lastLabel) != 1) {
463 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
466 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
470 //run last label if you need to
471 if (needToRun == true) {
472 for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } }
473 lookup = input->getSharedRAbundVectors(lastLabel);
475 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
476 process(lookup, outputFileName, outAllFileName);
477 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
481 //reset groups parameter
484 for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; }
487 if (m->control_pressed) {
488 m->mothurRemove(outAllFileName);
489 m->mothurRemove(outputFileName);
493 m->mothurOutEndLine();
494 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
495 m->mothurOut(outputFileName); m->mothurOutEndLine();
496 if (mult) { m->mothurOut(outAllFileName); m->mothurOutEndLine(); outputTypes["summary"].push_back(outAllFileName); }
497 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } outputTypes["summary"].push_back(outputFileName);
498 m->mothurOutEndLine();
502 catch(exception& e) {
503 m->errorOut(e, "SummarySharedCommand", "execute");
508 /***********************************************************/
509 int SummarySharedCommand::process(vector<SharedRAbundVector*> thisLookup, string sumFileName, string sumAllFileName) {
511 vector< vector<seqDist> > calcDists; //vector containing vectors that contains the summary results for each group compare
512 calcDists.resize(sumCalculators.size()); //one for each calc, this will be used to make .dist files
514 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
516 driver(thisLookup, 0, numGroups, sumFileName+".temp", sumAllFileName+".temp", calcDists);
517 m->appendFiles((sumFileName + ".temp"), sumFileName);
518 m->mothurRemove((sumFileName + ".temp"));
520 m->appendFiles((sumAllFileName + ".temp"), sumAllFileName);
521 m->mothurRemove((sumAllFileName + ".temp"));
525 vector<int> processIDS;
527 //loop through and create all the processes you want
528 while (process != processors) {
532 processIDS.push_back(pid);
535 driver(thisLookup, lines[process].start, lines[process].end, sumFileName + toString(getpid()) + ".temp", sumAllFileName + toString(getpid()) + ".temp", calcDists);
537 //only do this if you want a distance file
539 string tempdistFileName = m->getRootName(m->getSimpleName(sumFileName)) + toString(getpid()) + ".dist";
541 m->openOutputFile(tempdistFileName, outtemp);
543 for (int i = 0; i < calcDists.size(); i++) {
544 outtemp << calcDists[i].size() << endl;
546 for (int j = 0; j < calcDists[i].size(); j++) {
547 outtemp << calcDists[i][j].seq1 << '\t' << calcDists[i][j].seq2 << '\t' << calcDists[i][j].dist << endl;
555 m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine();
556 for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); }
561 //parent do your part
562 driver(thisLookup, lines[0].start, lines[0].end, sumFileName + toString(getpid()) + ".temp", sumAllFileName + toString(getpid()) + ".temp", calcDists);
563 m->appendFiles((sumFileName + toString(getpid()) + ".temp"), sumFileName);
564 m->mothurRemove((sumFileName + toString(getpid()) + ".temp"));
565 if (mult) { m->appendFiles((sumAllFileName + toString(getpid()) + ".temp"), sumAllFileName); }
567 //force parent to wait until all the processes are done
568 for (int i = 0; i < processIDS.size(); i++) {
569 int temp = processIDS[i];
573 for (int i = 0; i < processIDS.size(); i++) {
574 m->appendFiles((sumFileName + toString(processIDS[i]) + ".temp"), sumFileName);
575 m->mothurRemove((sumFileName + toString(processIDS[i]) + ".temp"));
576 if (mult) { m->mothurRemove((sumAllFileName + toString(processIDS[i]) + ".temp")); }
579 string tempdistFileName = m->getRootName(m->getSimpleName(sumFileName)) + toString(processIDS[i]) + ".dist";
581 m->openInputFile(tempdistFileName, intemp);
583 for (int k = 0; k < calcDists.size(); k++) {
585 intemp >> size; m->gobble(intemp);
587 for (int j = 0; j < size; j++) {
592 intemp >> seq1 >> seq2 >> dist; m->gobble(intemp);
594 seqDist tempDist(seq1, seq2, dist);
595 calcDists[k].push_back(tempDist);
599 m->mothurRemove(tempdistFileName);
605 driver(thisLookup, 0, numGroups, (sumFileName + ".temp"), (sumAllFileName + ".temp"), calcDists);
606 m->appendFiles((sumFileName + ".temp"), sumFileName);
607 m->mothurRemove((sumFileName + ".temp"));
609 m->appendFiles((sumAllFileName + ".temp"), sumAllFileName);
610 m->mothurRemove((sumAllFileName + ".temp"));
615 for (int i = 0; i < calcDists.size(); i++) {
616 if (m->control_pressed) { break; }
618 string distFileName = outputDir + m->getRootName(m->getSimpleName(sumFileName)) + sumCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".dist";
619 outputNames.push_back(distFileName);
621 m->openOutputFile(distFileName, outDist);
622 outDist.setf(ios::fixed, ios::floatfield); outDist.setf(ios::showpoint);
625 vector< vector<float> > matrix; //square matrix to represent the distance
626 matrix.resize(thisLookup.size());
627 for (int k = 0; k < thisLookup.size(); k++) { matrix[k].resize(thisLookup.size(), 0.0); }
630 for (int j = 0; j < calcDists[i].size(); j++) {
631 int row = calcDists[i][j].seq1;
632 int column = calcDists[i][j].seq2;
633 float dist = calcDists[i][j].dist;
635 matrix[row][column] = dist;
636 matrix[column][row] = dist;
640 outDist << thisLookup.size() << endl;
641 for (int r=0; r<thisLookup.size(); r++) {
643 string name = thisLookup[r]->getGroup();
644 if (name.length() < 10) { //pad with spaces to make compatible
645 while (name.length() < 10) { name += " "; }
647 outDist << name << '\t';
650 for (int l = 0; l < r; l++) { outDist << matrix[r][l] << '\t'; }
659 catch(exception& e) {
660 m->errorOut(e, "SummarySharedCommand", "process");
664 /**************************************************************************************************/
665 int SummarySharedCommand::driver(vector<SharedRAbundVector*> thisLookup, int start, int end, string sumFile, string sumAllFile, vector< vector<seqDist> >& calcDists) {
668 //loop through calculators and add to file all for all calcs that can do mutiple groups
671 m->openOutputFile(sumAllFile, outAll);
674 outAll << thisLookup[0]->getLabel() << '\t';
676 //output groups names
677 string outNames = "";
678 for (int j = 0; j < thisLookup.size(); j++) {
679 outNames += thisLookup[j]->getGroup() + "-";
681 outNames = outNames.substr(0, outNames.length()-1); //rip off extra '-';
682 outAll << outNames << '\t';
684 for(int i=0;i<sumCalculators.size();i++){
685 if (sumCalculators[i]->getMultiple() == true) {
686 sumCalculators[i]->getValues(thisLookup);
688 if (m->control_pressed) { outAll.close(); return 1; }
691 sumCalculators[i]->print(outAll);
698 ofstream outputFileHandle;
699 m->openOutputFile(sumFile, outputFileHandle);
701 vector<SharedRAbundVector*> subset;
702 for (int k = start; k < end; k++) { // pass cdd each set of groups to compare
704 for (int l = 0; l < k; l++) {
706 outputFileHandle << thisLookup[0]->getLabel() << '\t';
708 subset.clear(); //clear out old pair of sharedrabunds
709 //add new pair of sharedrabunds
710 subset.push_back(thisLookup[k]); subset.push_back(thisLookup[l]);
712 //sort groups to be alphanumeric
713 if (thisLookup[k]->getGroup() > thisLookup[l]->getGroup()) {
714 outputFileHandle << (thisLookup[l]->getGroup() +'\t' + thisLookup[k]->getGroup()) << '\t'; //print out groups
716 outputFileHandle << (thisLookup[k]->getGroup() +'\t' + thisLookup[l]->getGroup()) << '\t'; //print out groups
719 for(int i=0;i<sumCalculators.size();i++) {
721 //if this calc needs all groups to calculate the pair load all groups
722 if (sumCalculators[i]->getNeedsAll()) {
723 //load subset with rest of lookup for those calcs that need everyone to calc for a pair
724 for (int w = 0; w < thisLookup.size(); w++) {
725 if ((w != k) && (w != l)) { subset.push_back(thisLookup[w]); }
729 vector<double> tempdata = sumCalculators[i]->getValues(subset); //saves the calculator outputs
731 if (m->control_pressed) { outputFileHandle.close(); return 1; }
733 outputFileHandle << '\t';
734 sumCalculators[i]->print(outputFileHandle);
736 seqDist temp(l, k, tempdata[0]);
737 calcDists[i].push_back(temp);
739 outputFileHandle << endl;
743 outputFileHandle.close();
747 catch(exception& e) {
748 m->errorOut(e, "SummarySharedCommand", "driver");
752 /**************************************************************************************************/