X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sharedcommand.cpp;h=731f981f7a7b9c14d7f0f9033671cc274b43595b;hb=d0954e27635712cdbd8b86e3c4510670803a2665;hp=195996e50d41ff81953f5715704964398b9715e9;hpb=5df1b242d9c2b604eb414da44b28de81d52567d7;p=mothur.git diff --git a/sharedcommand.cpp b/sharedcommand.cpp index 195996e..731f981 100644 --- a/sharedcommand.cpp +++ b/sharedcommand.cpp @@ -14,19 +14,72 @@ inline bool compareSharedRabunds(SharedRAbundVector* left, SharedRAbundVector* r return (left->getGroup() < right->getGroup()); } //********************************************************************************************************************** +vector SharedCommand::getValidParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SharedCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +SharedCommand::SharedCommand(){ + try { + + //initialize outputTypes + vector tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["shared"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "SharedCommand", "SharedCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector SharedCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SharedCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector SharedCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SharedCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** SharedCommand::SharedCommand(string o) : outputDir(o) { try { globaldata = GlobalData::getInstance(); + //initialize outputTypes + vector tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["shared"] = tempOutNames; + //getting output filename filename = globaldata->inputFileName; - if (outputDir == "") { outputDir += hasPath(filename); } + if (outputDir == "") { outputDir += m->hasPath(filename); } - filename = outputDir + getRootName(getSimpleName(filename)); + filename = outputDir + m->getRootName(m->getSimpleName(filename)); filename = filename + "shared"; + outputTypes["shared"].push_back(filename); - openOutputFile(filename, out); + m->openOutputFile(filename, out); pickedGroups = false; groupMap = globaldata->gGroupmap; @@ -48,12 +101,13 @@ SharedCommand::SharedCommand(string o) : outputDir(o) { } //set fileroot - fileroot = outputDir + getRootName(getSimpleName(globaldata->getListFile())); + fileroot = outputDir + m->getRootName(m->getSimpleName(globaldata->getListFile())); //clears file before we start to write to it below for (int i=0; iGroups[i] + "."; } - string newGroupFile = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + groups + "groups"; + string newGroupFile = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + groups + "groups"; ofstream outGroups; - openOutputFile(newGroupFile, outGroups); + m->openOutputFile(newGroupFile, outGroups); vector names = groupMap->getNamesSeqs(); string groupName; @@ -172,7 +226,7 @@ int SharedCommand::execute(){ userLabels.erase(SharedList->getLabel()); } - if ((anyLabelsToProcess(SharedList->getLabel(), userLabels, errorOff) == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(SharedList->getLabel(), userLabels, errorOff) == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = SharedList->getLabel(); delete SharedList; @@ -259,6 +313,7 @@ int SharedCommand::execute(){ globaldata->setGroupFile(""); globaldata->setSharedFile(filename); + if (m->control_pressed) { delete input; globaldata->ginput = NULL; remove(filename.c_str()); @@ -266,6 +321,18 @@ int SharedCommand::execute(){ return 1; } + //set rabund file as new current rabundfile + string current = ""; + itTypes = outputTypes.find("rabund"); + if (itTypes != outputTypes.end()) { + if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setRabundFile(current); } + } + + itTypes = outputTypes.find("shared"); + if (itTypes != outputTypes.end()) { + if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setSharedFile(current); } + } + m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } @@ -286,13 +353,17 @@ void SharedCommand::printSharedData(vector thislookup) { if (order.size() == 0) { //user has not specified an order so do aplabetically sort(thislookup.begin(), thislookup.end(), compareSharedRabunds); + globaldata->Groups.clear(); + //initialize bin values for (int i = 0; i < thislookup.size(); i++) { out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t'; thislookup[i]->print(out); + globaldata->Groups.push_back(thislookup[i]->getGroup()); + RAbundVector rav = thislookup[i]->getRAbundVector(); - openOutputFileAppend(fileroot + thislookup[i]->getGroup() + ".rabund", *(filehandles[thislookup[i]->getGroup()])); + m->openOutputFileAppend(fileroot + thislookup[i]->getGroup() + ".rabund", *(filehandles[thislookup[i]->getGroup()])); rav.print(*(filehandles[thislookup[i]->getGroup()])); (*(filehandles[thislookup[i]->getGroup()])).close(); } @@ -305,6 +376,7 @@ void SharedCommand::printSharedData(vector thislookup) { myMap[thislookup[i]->getGroup()] = thislookup[i]; } + globaldata->Groups.clear(); //loop through ordered list and print the rabund for (int i = 0; i < order.size(); i++) { @@ -313,9 +385,11 @@ void SharedCommand::printSharedData(vector thislookup) { if(myIt != myMap.end()) { //we found it out << (myIt->second)->getLabel() << '\t' << (myIt->second)->getGroup() << '\t'; (myIt->second)->print(out); + + globaldata->Groups.push_back((myIt->second)->getGroup()); RAbundVector rav = (myIt->second)->getRAbundVector(); - openOutputFileAppend(fileroot + (myIt->second)->getGroup() + ".rabund", *(filehandles[(myIt->second)->getGroup()])); + m->openOutputFileAppend(fileroot + (myIt->second)->getGroup() + ".rabund", *(filehandles[(myIt->second)->getGroup()])); rav.print(*(filehandles[(myIt->second)->getGroup()])); (*(filehandles[(myIt->second)->getGroup()])).close(); }else{ @@ -377,14 +451,14 @@ int SharedCommand::eliminateZeroOTUS(vector& thislookup) { int SharedCommand::createMisMatchFile() { try { ofstream outMisMatch; - string outputMisMatchName = outputDir + getRootName(getSimpleName(globaldata->inputFileName)); + string outputMisMatchName = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)); //you have sequences in your list file that are not in your group file if (SharedList->getNumSeqs() > groupMap->getNumSeqs()) { outputMisMatchName += "missing.group"; m->mothurOut("For a list of names that are in your list file and not in your group file, please refer to " + outputMisMatchName + "."); m->mothurOutEndLine(); - openOutputFile(outputMisMatchName, outMisMatch); + m->openOutputFile(outputMisMatchName, outMisMatch); map listNames; map::iterator itList; @@ -458,7 +532,7 @@ int SharedCommand::createMisMatchFile() { map::iterator itMatch; - openOutputFile(outputMisMatchName, outMisMatch); + m->openOutputFile(outputMisMatchName, outMisMatch); //loop through names in seqNames and if they aren't in namesIn list output them for (int i = 0; i < seqNames.size(); i++) { @@ -496,11 +570,11 @@ int SharedCommand::readOrderFile() { order.clear(); ifstream in; - openInputFile(globaldata->getOrderGroupFile(), in); + m->openInputFile(globaldata->getOrderGroupFile(), in); string thisGroup; while(!in.eof()){ - in >> thisGroup; gobble(in); + in >> thisGroup; m->gobble(in); order.push_back(thisGroup);