X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sharedcommand.cpp;h=b322007bc5e8ef6cba50d4c6d2ff5fce0b87a0fa;hb=dbcb14c17c128987e59147f510950f32dbeb6698;hp=179424b3c9f395ce88774b00aa7f367581d8f775;hpb=ca9ac1d80c62f57270b0dcd49410ebe08a8aecd6;p=mothur.git diff --git a/sharedcommand.cpp b/sharedcommand.cpp index 179424b..b322007 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,12 +73,11 @@ 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 { - //valid paramters for this command - string Array[] = {"list","label","group","groups","ordergroup","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -126,7 +126,7 @@ SharedCommand::SharedCommand(string option) { //check for required parameters listfile = validParameter.validFile(parameters, "list", true); - if (listfile == "not open") { abort = true; } + if (listfile == "not open") { listfile = ""; abort = true; } else if (listfile == "not found") { listfile = m->getListFile(); if (listfile != "") { m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } @@ -138,7 +138,7 @@ SharedCommand::SharedCommand(string option) { 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 != "") { @@ -174,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; iGroups.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); @@ -315,6 +319,7 @@ int SharedCommand::execute(){ 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]; } @@ -344,6 +349,7 @@ int SharedCommand::execute(){ 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]; } @@ -389,6 +395,7 @@ int SharedCommand::execute(){ 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; @@ -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(); }