X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sharedcommand.cpp;h=2928214c2e671e366553439504c4e78d572a1f1b;hb=1bf53bca7e26bf091588bc8ca6e68cbfae1df6fe;hp=2b4d56ec44591400f977e365f6501e89170c9f02;hpb=643cdf74ccd4fc2d565168716fb5645917dee834;p=mothur.git diff --git a/sharedcommand.cpp b/sharedcommand.cpp index 2b4d56e..2928214 100644 --- a/sharedcommand.cpp +++ b/sharedcommand.cpp @@ -58,6 +58,7 @@ SharedCommand::SharedCommand(){ vector tempOutNames; outputTypes["rabund"] = tempOutNames; outputTypes["shared"] = tempOutNames; + outputTypes["group"] = tempOutNames; } catch(exception& e) { m->errorOut(e, "SharedCommand", "SharedCommand"); @@ -72,6 +73,7 @@ SharedCommand::SharedCommand(string option) { //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } + else if(option == "citation") { citation(); abort = true; calledHelp = true;} else { @@ -129,14 +131,14 @@ SharedCommand::SharedCommand(string option) { listfile = m->getListFile(); if (listfile != "") { m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } else { m->mothurOut("You have no current list file and the list parameter is required."); m->mothurOutEndLine(); abort = true; } - } + }else { m->setListFile(listfile); } ordergroupfile = validParameter.validFile(parameters, "ordergroup", true); if (ordergroupfile == "not open") { abort = true; } else if (ordergroupfile == "not found") { ordergroupfile = ""; } groupfile = validParameter.validFile(parameters, "group", true); - if (groupfile == "not open") { abort = true; } + if (groupfile == "not open") { groupfile = ""; abort = true; } else if (groupfile == "not found") { groupfile = m->getGroupFile(); if (groupfile != "") { @@ -172,41 +174,6 @@ SharedCommand::SharedCommand(string option) { if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } - - //getting output filename - filename = listfile; - if (outputDir == "") { outputDir += m->hasPath(filename); } - - filename = outputDir + m->getRootName(m->getSimpleName(filename)); - filename = filename + "shared"; - outputTypes["shared"].push_back(filename); - - m->openOutputFile(filename, out); - pickedGroups = false; - - //if hte user has not specified any groups then use them all - if (Groups.size() == 0) { - Groups = groupMap->namesOfGroups; m->Groups = Groups; - } - - //fill filehandles with neccessary ofstreams - int i; - ofstream* temp; - for (i=0; igetRootName(m->getSimpleName(listfile)); - - //clears file before we start to write to it below - for (int i=0; ihasPath(filename); } + + filename = outputDir + m->getRootName(m->getSimpleName(filename)); + filename = filename + "shared"; + outputTypes["shared"].push_back(filename); + + m->openOutputFile(filename, out); + pickedGroups = false; + + //if hte user has not specified any groups then use them all + if (Groups.size() == 0) { + Groups = groupMap->namesOfGroups; m->Groups = Groups; + }else { pickedGroups = true; } + + //fill filehandles with neccessary ofstreams + int i; + ofstream* temp; + for (i=0; igetRootName(m->getSimpleName(listfile)); + + //clears file before we start to write to it below + for (int i=0; imothurRemove((fileroot + Groups[i] + ".rabund")); + outputNames.push_back((fileroot + Groups[i] + ".rabund")); + outputTypes["rabund"].push_back((fileroot + Groups[i] + ".rabund")); + } + //lookup.clear(); string errorOff = "no error"; //errorOff = ""; @@ -237,8 +239,8 @@ int SharedCommand::execute(){ if (m->control_pressed) { delete input; delete SharedList; delete groupMap; for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } - out.close(); remove(filename.c_str()); - for (int i=0; imothurRemove(filename); + for (int i=0; imothurRemove((fileroot + Groups[i] + ".rabund")); } return 0; } @@ -246,7 +248,7 @@ int SharedCommand::execute(){ m->mothurOut("Your group file contains " + toString(groupMap->getNumSeqs()) + " sequences and list file contains " + toString(SharedList->getNumSeqs()) + " sequences. Please correct."); m->mothurOutEndLine(); out.close(); - remove(filename.c_str()); //remove blank shared file you made + m->mothurRemove(filename); //remove blank shared file you made createMisMatchFile(); @@ -261,7 +263,7 @@ int SharedCommand::execute(){ } //if user has specified groups make new groupfile for them - if (m->Groups.size() != 0) { //make new group file + if (pickedGroups) { //make new group file string groups = ""; if (m->Groups.size() < 4) { for (int i = 0; i < m->Groups.size(); i++) { @@ -270,6 +272,8 @@ int SharedCommand::execute(){ }else { groups = "merge"; } string newGroupFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + groups + "groups"; + outputTypes["group"].push_back(newGroupFile); + outputNames.push_back(newGroupFile); ofstream outGroups; m->openOutputFile(newGroupFile, outGroups); @@ -292,8 +296,8 @@ int SharedCommand::execute(){ if (m->control_pressed) { delete input; delete SharedList; delete groupMap; for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } - out.close(); remove(filename.c_str()); - for (int i=0; imothurRemove(filename); + for (int i=0; imothurRemove((fileroot + Groups[i] + ".rabund")); } return 0; } @@ -310,11 +314,12 @@ int SharedCommand::execute(){ delete input; delete SharedList; delete groupMap; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } - out.close(); remove(filename.c_str()); - for (int i=0; imothurRemove(filename); + for (int i=0; imothurRemove((fileroot + Groups[i] + ".rabund")); } return 0; } + if (!m->printedHeaders) { lookup[0]->printHeaders(out); } printSharedData(lookup); //prints info to the .shared file for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } @@ -339,11 +344,12 @@ int SharedCommand::execute(){ delete input; delete SharedList; delete groupMap; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } - out.close(); remove(filename.c_str()); - for (int i=0; imothurRemove(filename); + for (int i=0; imothurRemove((fileroot + Groups[i] + ".rabund")); } return 0; } + if (!m->printedHeaders) { lookup[0]->printHeaders(out); } printSharedData(lookup); //prints info to the .shared file for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } @@ -384,11 +390,12 @@ int SharedCommand::execute(){ if (m->control_pressed) { delete input; delete groupMap; for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } - out.close(); remove(filename.c_str()); - for (int i=0; imothurRemove(filename); + for (int i=0; imothurRemove((fileroot + Groups[i] + ".rabund")); } return 0; } + if (!m->printedHeaders) { lookup[0]->printHeaders(out); } printSharedData(lookup); //prints info to the .shared file for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } delete SharedList; @@ -403,8 +410,8 @@ int SharedCommand::execute(){ delete input; delete groupMap; if (m->control_pressed) { - remove(filename.c_str()); - for (int i=0; imothurRemove(filename); + for (int i=0; imothurRemove((fileroot + Groups[i] + ".rabund")); } return 0; } @@ -420,6 +427,11 @@ int SharedCommand::execute(){ if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setSharedFile(current); } } + itTypes = outputTypes.find("group"); + if (itTypes != outputTypes.end()) { + if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setGroupFile(current); } + } + m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } @@ -519,6 +531,7 @@ int SharedCommand::eliminateZeroOTUS(vector& thislookup) { for (int j = 0; j < thislookup.size(); j++) { newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup()); } + //if there is a bin label use it otherwise make one } //else{ cout << "bin # " << i << " is all zeros" << endl; } } @@ -552,7 +565,7 @@ int SharedCommand::createMisMatchFile() { //go through list and if group returns "not found" output it for (int i = 0; i < SharedList->getNumBins(); i++) { - if (m->control_pressed) { outMisMatch.close(); remove(outputMisMatchName.c_str()); return 0; } + if (m->control_pressed) { outMisMatch.close(); m->mothurRemove(outputMisMatchName); return 0; } string names = SharedList->get(i); @@ -623,7 +636,7 @@ int SharedCommand::createMisMatchFile() { //loop through names in seqNames and if they aren't in namesIn list output them for (int i = 0; i < seqNames.size(); i++) { - if (m->control_pressed) { outMisMatch.close(); remove(outputMisMatchName.c_str()); return 0; } + if (m->control_pressed) { outMisMatch.close(); m->mothurRemove(outputMisMatchName); return 0; } itMatch = namesInList.find(seqNames[i]);