5 * Created by Sarah Westcott on 1/2/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "rarefactcommand.h"
15 #include "bootstrap.h"
17 #include "simpsoneven.h"
19 #include "smithwilson.h"
20 #include "invsimpson.h"
21 #include "npshannon.h"
22 #include "shannoneven.h"
24 #include "jackknife.h"
28 //**********************************************************************************************************************
29 vector<string> RareFactCommand::setParameters(){
31 CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(plist);
32 CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prabund);
33 CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(psabund);
34 CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(pshared);
35 CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel);
36 CommandParameter pfreq("freq", "Number", "", "100", "", "", "",false,false); parameters.push_back(pfreq);
37 CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters);
38 CommandParameter pcalc("calc", "Multiple", "sobs-chao-nseqs-coverage-ace-jack-shannon-shannoneven-npshannon-heip-smithwilson-simpson-simpsoneven-invsimpson-bootstrap", "sobs", "", "", "",true,false); parameters.push_back(pcalc);
39 CommandParameter pabund("abund", "Number", "", "10", "", "", "",false,false); parameters.push_back(pabund);
40 CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors);
41 CommandParameter pgroupmode("groupmode", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pgroupmode);
42 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
43 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
45 vector<string> myArray;
46 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
50 m->errorOut(e, "RareFactCommand", "setParameters");
54 //**********************************************************************************************************************
55 string RareFactCommand::getHelpString(){
57 ValidCalculators validCalculator;
58 string helpString = "";
59 helpString += "The rarefaction.single command parameters are list, sabund, rabund, shared, label, iters, freq, calc, processors and abund. list, sabund, rabund or shared is required unless you have a valid current file. \n";
60 helpString += "The freq parameter is used indicate when to output your data, by default it is set to 100. But you can set it to a percentage of the number of sequence. For example freq=0.10, means 10%. \n";
61 helpString += "The processors parameter allows you to specify the number of processors to use. The default is 1.\n";
62 helpString += "The rarefaction.single command should be in the following format: \n";
63 helpString += "rarefaction.single(label=yourLabel, iters=yourIters, freq=yourFreq, calc=yourEstimators).\n";
64 helpString += "Example rarefaction.single(label=unique-.01-.03, iters=10000, freq=10, calc=sobs-rchao-race-rjack-rbootstrap-rshannon-rnpshannon-rsimpson).\n";
65 helpString += "The default values for iters is 1000, freq is 100, and calc is rarefaction which calculates the rarefaction curve for the observed richness.\n";
66 validCalculator.printCalc("rarefaction");
67 helpString += "If you are running rarefaction.single with a shared file and would like your results collated in one file, set groupmode=t. (Default=true).\n";
68 helpString += "The label parameter is used to analyze specific labels in your input.\n";
69 helpString += "Note: No spaces between parameter labels (i.e. freq), '=' and parameters (i.e.yourFreq).\n";
73 m->errorOut(e, "RareFactCommand", "getHelpString");
78 //**********************************************************************************************************************
79 RareFactCommand::RareFactCommand(){
81 abort = true; calledHelp = true;
83 vector<string> tempOutNames;
84 outputTypes["rarefaction"] = tempOutNames;
85 outputTypes["r_chao"] = tempOutNames;
86 outputTypes["r_ace"] = tempOutNames;
87 outputTypes["r_jack"] = tempOutNames;
88 outputTypes["r_shannon"] = tempOutNames;
89 outputTypes["r_shannoneven"] = tempOutNames;
90 outputTypes["r_heip"] = tempOutNames;
91 outputTypes["r_smithwilson"] = tempOutNames;
92 outputTypes["r_npshannon"] = tempOutNames;
93 outputTypes["r_simpson"] = tempOutNames;
94 outputTypes["r_simpsoneven"] = tempOutNames;
95 outputTypes["r_invsimpson"] = tempOutNames;
96 outputTypes["r_bootstrap"] = tempOutNames;
97 outputTypes["r_coverage"] = tempOutNames;
98 outputTypes["r_nseqs"] = tempOutNames;
100 catch(exception& e) {
101 m->errorOut(e, "RareFactCommand", "RareFactCommand");
105 //**********************************************************************************************************************
106 RareFactCommand::RareFactCommand(string option) {
108 abort = false; calledHelp = false;
111 //allow user to run help
112 if(option == "help") { help(); abort = true; calledHelp = true; }
113 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
116 vector<string> myArray = setParameters();
118 OptionParser parser(option);
119 map<string,string> parameters = parser.getParameters();
120 map<string,string>::iterator it;
122 ValidParameters validParameter;
124 //check to make sure all parameters are valid for command
125 for (it = parameters.begin(); it != parameters.end(); it++) {
126 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
129 //initialize outputTypes
130 vector<string> tempOutNames;
131 outputTypes["rarefaction"] = tempOutNames;
132 outputTypes["r_chao"] = tempOutNames;
133 outputTypes["r_ace"] = tempOutNames;
134 outputTypes["r_jack"] = tempOutNames;
135 outputTypes["r_shannon"] = tempOutNames;
136 outputTypes["r_shannoneven"] = tempOutNames;
137 outputTypes["r_heip"] = tempOutNames;
138 outputTypes["r_smithwilson"] = tempOutNames;
139 outputTypes["r_npshannon"] = tempOutNames;
140 outputTypes["r_simpson"] = tempOutNames;
141 outputTypes["r_simpsoneven"] = tempOutNames;
142 outputTypes["r_invsimpson"] = tempOutNames;
143 outputTypes["r_bootstrap"] = tempOutNames;
144 outputTypes["r_coverage"] = tempOutNames;
145 outputTypes["r_nseqs"] = tempOutNames;
147 //if the user changes the input directory command factory will send this info to us in the output parameter
148 string inputDir = validParameter.validFile(parameters, "inputdir", false);
149 if (inputDir == "not found"){ inputDir = ""; }
152 it = parameters.find("shared");
153 //user has given a template file
154 if(it != parameters.end()){
155 path = m->hasPath(it->second);
156 //if the user has not given a path then, add inputdir. else leave path alone.
157 if (path == "") { parameters["shared"] = inputDir + it->second; }
160 it = parameters.find("rabund");
161 //user has given a template file
162 if(it != parameters.end()){
163 path = m->hasPath(it->second);
164 //if the user has not given a path then, add inputdir. else leave path alone.
165 if (path == "") { parameters["rabund"] = inputDir + it->second; }
168 it = parameters.find("sabund");
169 //user has given a template file
170 if(it != parameters.end()){
171 path = m->hasPath(it->second);
172 //if the user has not given a path then, add inputdir. else leave path alone.
173 if (path == "") { parameters["sabund"] = inputDir + it->second; }
176 it = parameters.find("list");
177 //user has given a template file
178 if(it != parameters.end()){
179 path = m->hasPath(it->second);
180 //if the user has not given a path then, add inputdir. else leave path alone.
181 if (path == "") { parameters["list"] = inputDir + it->second; }
185 //check for required parameters
186 listfile = validParameter.validFile(parameters, "list", true);
187 if (listfile == "not open") { listfile = ""; abort = true; }
188 else if (listfile == "not found") { listfile = ""; }
189 else { format = "list"; inputfile = listfile; m->setListFile(listfile); }
191 sabundfile = validParameter.validFile(parameters, "sabund", true);
192 if (sabundfile == "not open") { sabundfile = ""; abort = true; }
193 else if (sabundfile == "not found") { sabundfile = ""; }
194 else { format = "sabund"; inputfile = sabundfile; m->setSabundFile(sabundfile); }
196 rabundfile = validParameter.validFile(parameters, "rabund", true);
197 if (rabundfile == "not open") { rabundfile = ""; abort = true; }
198 else if (rabundfile == "not found") { rabundfile = ""; }
199 else { format = "rabund"; inputfile = rabundfile; m->setRabundFile(rabundfile); }
201 sharedfile = validParameter.validFile(parameters, "shared", true);
202 if (sharedfile == "not open") { sharedfile = ""; abort = true; }
203 else if (sharedfile == "not found") { sharedfile = ""; }
204 else { format = "sharedfile"; inputfile = sharedfile; m->setSharedFile(sharedfile); }
206 if ((sharedfile == "") && (listfile == "") && (rabundfile == "") && (sabundfile == "")) {
207 //is there are current file available for any of these?
208 //give priority to shared, then list, then rabund, then sabund
209 //if there is a current shared file, use it
210 sharedfile = m->getSharedFile();
211 if (sharedfile != "") { inputfile = sharedfile; format = "sharedfile"; m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
213 listfile = m->getListFile();
214 if (listfile != "") { inputfile = listfile; format = "list"; m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); }
216 rabundfile = m->getRabundFile();
217 if (rabundfile != "") { inputfile = rabundfile; format = "rabund"; m->mothurOut("Using " + rabundfile + " as input file for the rabund parameter."); m->mothurOutEndLine(); }
219 sabundfile = m->getSabundFile();
220 if (sabundfile != "") { inputfile = sabundfile; format = "sabund"; m->mothurOut("Using " + sabundfile + " as input file for the sabund parameter."); m->mothurOutEndLine(); }
222 m->mothurOut("No valid current files. You must provide a list, sabund, rabund or shared file before you can use the collect.single command."); m->mothurOutEndLine();
230 //if the user changes the output directory command factory will send this info to us in the output parameter
231 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(inputfile); }
233 //check for optional parameter and set defaults
234 // ...at some point should added some additional type checking...
235 label = validParameter.validFile(parameters, "label", false);
236 if (label == "not found") { label = ""; }
238 if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
239 else { allLines = 1; }
242 calc = validParameter.validFile(parameters, "calc", false);
243 if (calc == "not found") { calc = "sobs"; }
245 if (calc == "default") { calc = "sobs"; }
247 m->splitAtDash(calc, Estimators);
248 if (m->inUsersGroups("citation", Estimators)) {
249 ValidCalculators validCalc; validCalc.printCitations(Estimators);
250 //remove citation from list of calcs
251 for (int i = 0; i < Estimators.size(); i++) { if (Estimators[i] == "citation") { Estimators.erase(Estimators.begin()+i); break; } }
255 temp = validParameter.validFile(parameters, "freq", false); if (temp == "not found") { temp = "100"; }
258 temp = validParameter.validFile(parameters, "abund", false); if (temp == "not found") { temp = "10"; }
259 convert(temp, abund);
261 temp = validParameter.validFile(parameters, "iters", false); if (temp == "not found") { temp = "1000"; }
262 convert(temp, nIters);
264 temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); }
265 m->setProcessors(temp);
266 convert(temp, processors);
268 temp = validParameter.validFile(parameters, "groupmode", false); if (temp == "not found") { temp = "T"; }
269 groupMode = m->isTrue(temp);
273 catch(exception& e) {
274 m->errorOut(e, "RareFactCommand", "RareFactCommand");
278 //**********************************************************************************************************************
280 int RareFactCommand::execute(){
283 if (abort == true) { if (calledHelp) { return 0; } return 2; }
285 if ((format != "sharedfile")) { inputFileNames.push_back(inputfile); }
286 else { inputFileNames = parseSharedFile(sharedfile); format = "rabund"; }
288 if (m->control_pressed) { return 0; }
290 for (int p = 0; p < inputFileNames.size(); p++) {
292 string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p]));
294 if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } m->clearGroups(); return 0; }
296 if (inputFileNames.size() > 1) {
297 m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine();
300 ValidCalculators validCalculator;
303 for (i=0; i<Estimators.size(); i++) {
304 if (validCalculator.isValidCalculator("rarefaction", Estimators[i]) == true) {
305 if (Estimators[i] == "sobs") {
306 rDisplays.push_back(new RareDisplay(new Sobs(), new ThreeColumnFile(fileNameRoot+"rarefaction")));
307 outputNames.push_back(fileNameRoot+"rarefaction"); outputTypes["rarefaction"].push_back(fileNameRoot+"rarefaction");
308 }else if (Estimators[i] == "chao") {
309 rDisplays.push_back(new RareDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"r_chao")));
310 outputNames.push_back(fileNameRoot+"r_chao"); outputTypes["r_chao"].push_back(fileNameRoot+"r_chao");
311 }else if (Estimators[i] == "ace") {
314 rDisplays.push_back(new RareDisplay(new Ace(abund), new ThreeColumnFile(fileNameRoot+"r_ace")));
315 outputNames.push_back(fileNameRoot+"r_ace"); outputTypes["r_ace"].push_back(fileNameRoot+"r_ace");
316 }else if (Estimators[i] == "jack") {
317 rDisplays.push_back(new RareDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"r_jack")));
318 outputNames.push_back(fileNameRoot+"r_jack"); outputTypes["r_jack"].push_back(fileNameRoot+"r_jack");
319 }else if (Estimators[i] == "shannon") {
320 rDisplays.push_back(new RareDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"r_shannon")));
321 outputNames.push_back(fileNameRoot+"r_shannon"); outputTypes["r_shannon"].push_back(fileNameRoot+"r_shannon");
322 }else if (Estimators[i] == "shannoneven") {
323 rDisplays.push_back(new RareDisplay(new ShannonEven(), new ThreeColumnFile(fileNameRoot+"r_shannoneven")));
324 outputNames.push_back(fileNameRoot+"r_shannoneven"); outputTypes["r_shannoneven"].push_back(fileNameRoot+"r_shannoneven");
325 }else if (Estimators[i] == "heip") {
326 rDisplays.push_back(new RareDisplay(new Heip(), new ThreeColumnFile(fileNameRoot+"r_heip")));
327 outputNames.push_back(fileNameRoot+"r_heip"); outputTypes["r_heip"].push_back(fileNameRoot+"r_heip");
328 }else if (Estimators[i] == "smithwilson") {
329 rDisplays.push_back(new RareDisplay(new SmithWilson(), new ThreeColumnFile(fileNameRoot+"r_smithwilson")));
330 outputNames.push_back(fileNameRoot+"r_smithwilson"); outputTypes["r_smithwilson"].push_back(fileNameRoot+"r_smithwilson");
331 }else if (Estimators[i] == "npshannon") {
332 rDisplays.push_back(new RareDisplay(new NPShannon(), new ThreeColumnFile(fileNameRoot+"r_npshannon")));
333 outputNames.push_back(fileNameRoot+"r_npshannon"); outputTypes["r_npshannon"].push_back(fileNameRoot+"r_npshannon");
334 }else if (Estimators[i] == "simpson") {
335 rDisplays.push_back(new RareDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"r_simpson")));
336 outputNames.push_back(fileNameRoot+"r_simpson"); outputTypes["r_simpson"].push_back(fileNameRoot+"r_simpson");
337 }else if (Estimators[i] == "simpsoneven") {
338 rDisplays.push_back(new RareDisplay(new SimpsonEven(), new ThreeColumnFile(fileNameRoot+"r_simpsoneven")));
339 outputNames.push_back(fileNameRoot+"r_simpsoneven"); outputTypes["r_simpsoneven"].push_back(fileNameRoot+"r_simpsoneven");
340 }else if (Estimators[i] == "invsimpson") {
341 rDisplays.push_back(new RareDisplay(new InvSimpson(), new ThreeColumnFile(fileNameRoot+"r_invsimpson")));
342 outputNames.push_back(fileNameRoot+"r_invsimpson"); outputTypes["r_invsimpson"].push_back(fileNameRoot+"r_invsimpson");
343 }else if (Estimators[i] == "bootstrap") {
344 rDisplays.push_back(new RareDisplay(new Bootstrap(), new ThreeColumnFile(fileNameRoot+"r_bootstrap")));
345 outputNames.push_back(fileNameRoot+"r_bootstrap"); outputTypes["r_bootstrap"].push_back(fileNameRoot+"r_bootstrap");
346 }else if (Estimators[i] == "coverage") {
347 rDisplays.push_back(new RareDisplay(new Coverage(), new ThreeColumnFile(fileNameRoot+"r_coverage")));
348 outputNames.push_back(fileNameRoot+"r_coverage"); outputTypes["r_coverage"].push_back(fileNameRoot+"r_coverage");
349 }else if (Estimators[i] == "nseqs") {
350 rDisplays.push_back(new RareDisplay(new NSeqs(), new ThreeColumnFile(fileNameRoot+"r_nseqs")));
351 outputNames.push_back(fileNameRoot+"r_nseqs"); outputTypes["r_nseqs"].push_back(fileNameRoot+"r_nseqs");
357 //if the users entered no valid calculators don't execute command
358 if (rDisplays.size() == 0) { for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; } return 0; }
360 input = new InputData(inputFileNames[p], format);
361 order = input->getOrderVector();
362 string lastLabel = order->getLabel();
364 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
365 set<string> processedLabels;
366 set<string> userLabels = labels;
368 if (m->control_pressed) { for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; } delete input; delete order; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
370 //as long as you are not at the end of the file or done wih the lines you want
371 while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
373 if (m->control_pressed) { for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; } delete input; delete order; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
376 if(allLines == 1 || labels.count(order->getLabel()) == 1){
378 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
379 rCurve = new Rarefact(order, rDisplays, processors);
380 rCurve->getCurve(freq, nIters);
383 processedLabels.insert(order->getLabel());
384 userLabels.erase(order->getLabel());
387 if ((m->anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
388 string saveLabel = order->getLabel();
391 order = (input->getOrderVector(lastLabel));
393 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
394 rCurve = new Rarefact(order, rDisplays, processors);
395 rCurve->getCurve(freq, nIters);
398 processedLabels.insert(order->getLabel());
399 userLabels.erase(order->getLabel());
401 //restore real lastlabel to save below
402 order->setLabel(saveLabel);
405 lastLabel = order->getLabel();
408 order = (input->getOrderVector());
411 if (m->control_pressed) { for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; } delete input; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
413 //output error messages about any remaining user labels
414 set<string>::iterator it;
415 bool needToRun = false;
416 for (it = userLabels.begin(); it != userLabels.end(); it++) {
417 m->mothurOut("Your file does not include the label " + *it);
418 if (processedLabels.count(lastLabel) != 1) {
419 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
422 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
426 if (m->control_pressed) { for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; } delete input; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
428 //run last label if you need to
429 if (needToRun == true) {
430 if (order != NULL) { delete order; }
431 order = (input->getOrderVector(lastLabel));
433 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
434 rCurve = new Rarefact(order, rDisplays, processors);
435 rCurve->getCurve(freq, nIters);
442 for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; }
448 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
450 //create summary file containing all the groups data for each label - this function just combines the info from the files already created.
451 if ((sharedfile != "") && (groupMode)) { outputNames = createGroupFile(outputNames); }
453 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
455 m->mothurOutEndLine();
456 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
457 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
458 m->mothurOutEndLine();
462 catch(exception& e) {
463 m->errorOut(e, "RareFactCommand", "execute");
467 //**********************************************************************************************************************
468 vector<string> RareFactCommand::createGroupFile(vector<string>& outputNames) {
471 vector<string> newFileNames;
473 //find different types of files
474 map<string, vector<string> > typesFiles;
475 for (int i = 0; i < outputNames.size(); i++) {
476 string extension = m->getExtension(outputNames[i]);
479 m->openInputFile(outputNames[i], in);
481 string labels = m->getline(in);
482 string newLine = labels.substr(0, labels.find_first_of('\t'));
484 newLine += "\tGroup" + labels.substr(labels.find_first_of('\t'));
486 typesFiles[extension].push_back(outputNames[i]);
488 string combineFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "groups" + extension;
492 m->openOutputFile(combineFileName, out);
493 out << newLine << endl;
498 //for each type create a combo file
499 for (map<string, vector<string> >::iterator it = typesFiles.begin(); it != typesFiles.end(); it++) {
502 string combineFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "groups" + it->first;
503 m->openOutputFileAppend(combineFileName, out);
504 newFileNames.push_back(combineFileName);
506 vector<string> thisTypesFiles = it->second;
508 //open each type summary file
509 map<string, vector<string> > files; //maps file name to lines in file
511 for (int i=0; i<thisTypesFiles.size(); i++) {
514 m->openInputFile(thisTypesFiles[i], temp);
516 //read through first line - labels
517 m->getline(temp); m->gobble(temp);
519 vector<string> thisFilesLines;
520 string group = m->getRootName(thisTypesFiles[i]);
521 group = group.substr(0, group.length()-1);
522 group = group.substr(group.find_last_of('.')+1);
524 thisFilesLines.push_back(group);
527 string thisLine = m->getline(temp);
529 thisFilesLines.push_back(thisLine);
534 files[thisTypesFiles[i]] = thisFilesLines;
536 //save longest file for below
537 if (maxLines < thisFilesLines.size()) { maxLines = thisFilesLines.size(); }
540 m->mothurRemove(thisTypesFiles[i]);
545 for (int k = 1; k < maxLines; k++) {
547 //grab data for each group
548 for (int i=0; i<thisTypesFiles.size(); i++) {
550 string output = "NA\t";
551 if (k < files[thisTypesFiles[i]].size()) {
552 string line = files[thisTypesFiles[i]][k];
553 output = line.substr(0, line.find_first_of('\t'));
554 output += '\t' + files[thisTypesFiles[i]][0] + '\t' + line.substr(line.find_first_of('\t'));
556 output += '\t' + files[thisTypesFiles[i]][0] + '\t';
558 out << output << endl;
566 //return combine file name
570 catch(exception& e) {
571 m->errorOut(e, "RareFactCommand", "createGroupFile");
575 //**********************************************************************************************************************
576 vector<string> RareFactCommand::parseSharedFile(string filename) {
578 vector<string> filenames;
580 map<string, ofstream*> filehandles;
581 map<string, ofstream*>::iterator it3;
583 input = new InputData(filename, "sharedfile");
584 vector<SharedRAbundVector*> lookup = input->getSharedRAbundVectors();
586 string sharedFileRoot = m->getRootName(filename);
588 //clears file before we start to write to it below
589 for (int i=0; i<lookup.size(); i++) {
590 m->mothurRemove((sharedFileRoot + lookup[i]->getGroup() + ".rabund"));
591 filenames.push_back((sharedFileRoot + lookup[i]->getGroup() + ".rabund"));
595 for (int i=0; i<lookup.size(); i++) {
597 filehandles[lookup[i]->getGroup()] = temp;
598 groups.push_back(lookup[i]->getGroup());
601 while(lookup[0] != NULL) {
603 for (int i = 0; i < lookup.size(); i++) {
604 RAbundVector rav = lookup[i]->getRAbundVector();
605 m->openOutputFileAppend(sharedFileRoot + lookup[i]->getGroup() + ".rabund", *(filehandles[lookup[i]->getGroup()]));
606 rav.print(*(filehandles[lookup[i]->getGroup()]));
607 (*(filehandles[lookup[i]->getGroup()])).close();
610 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
611 lookup = input->getSharedRAbundVectors();
615 for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
624 catch(exception& e) {
625 m->errorOut(e, "RareFactCommand", "parseSharedFile");
629 //**********************************************************************************************************************