X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=libshuffcommand.cpp;h=7f8cd9b721fe50e82f4fdf2553e51a6d53b86a22;hb=529ec122f7cac4af987e121d150b878d7c7a0d5d;hp=11430117dd1df9c9e2696010324eb3c51b4f2fe6;hpb=f06fdb807822f8e06db003ed809c87250905cfc8;p=mothur.git diff --git a/libshuffcommand.cpp b/libshuffcommand.cpp index 1143011..7f8cd9b 100644 --- a/libshuffcommand.cpp +++ b/libshuffcommand.cpp @@ -65,6 +65,27 @@ string LibShuffCommand::getHelpString(){ } } //********************************************************************************************************************** +string LibShuffCommand::getOutputFileNameTag(string type, string inputName=""){ + try { + string outputFileName = ""; + map >::iterator it; + + //is this a type this command creates + it = outputTypes.find(type); + if (it == outputTypes.end()) { m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); } + else { + if (type == "coverage") { outputFileName = "libshuff.coverage"; } + else if (type == "libshuffsummary") { outputFileName = "libshuff.summary"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; } + } + return outputFileName; + } + catch(exception& e) { + m->errorOut(e, "LibShuffCommand", "getOutputFileNameTag"); + exit(1); + } +} +//********************************************************************************************************************** LibShuffCommand::LibShuffCommand(){ try { abort = true; calledHelp = true; @@ -138,7 +159,7 @@ LibShuffCommand::LibShuffCommand(string option) { m->mothurOut("You must provide a phylip file."); m->mothurOutEndLine(); abort = true; } - } + }else { m->setPhylipFile(phylipfile); } //check for required parameters groupfile = validParameter.validFile(parameters, "group", true); @@ -150,7 +171,7 @@ LibShuffCommand::LibShuffCommand(string option) { m->mothurOut("You must provide a group file."); m->mothurOutEndLine(); abort = true; } - } + }else { m->setGroupFile(groupfile); } //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ @@ -165,18 +186,18 @@ LibShuffCommand::LibShuffCommand(string option) { else { savegroups = groups; m->splitAtDash(groups, Groups); - m->Groups = Groups; + m->setGroups(Groups); } string temp; temp = validParameter.validFile(parameters, "iters", false); if (temp == "not found") { temp = "10000"; } - convert(temp, iters); + m->mothurConvert(temp, iters); temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found") { temp = "1.0"; } - convert(temp, cutOff); + m->mothurConvert(temp, cutOff); temp = validParameter.validFile(parameters, "step", false); if (temp == "not found") { temp = "0.01"; } - convert(temp, step); + m->mothurConvert(temp, step); temp = validParameter.validFile(parameters, "sim", false); if (temp == "not found") { temp = "F"; } sim = m->isTrue(temp); @@ -222,7 +243,7 @@ int LibShuffCommand::execute(){ m->openOutputFile(newGroupFile, outGroups); for (int i = 0; i < matrix->getNumSeqs(); i++) { - if (m->control_pressed) { delete groupMap; delete matrix; outGroups.close(); remove(newGroupFile.c_str()); return 0; } + if (m->control_pressed) { delete groupMap; delete matrix; outGroups.close(); m->mothurRemove(newGroupFile); return 0; } Names temp = matrix->getRowInfo(i); outGroups << temp.seqName << '\t' << temp.groupName << endl; @@ -238,7 +259,7 @@ int LibShuffCommand::execute(){ groupMap = new GroupMap(groupfile); groupMap->readMap(); - if (m->control_pressed) { delete groupMap; delete matrix; remove(newGroupFile.c_str()); return 0; } + if (m->control_pressed) { delete groupMap; delete matrix; m->mothurRemove(newGroupFile); return 0; } } @@ -252,9 +273,9 @@ int LibShuffCommand::execute(){ //this is needed because when we read the matrix we sort it into groups in alphabetical order //the rest of the command and the classes used in this command assume specific order /********************************************************************************************/ - matrix->setGroups(groupMap->namesOfGroups); + matrix->setGroups(groupMap->getNamesOfGroups()); vector sizes; - for (int i = 0; i < groupMap->namesOfGroups.size(); i++) { sizes.push_back(groupMap->getNumSeqs(groupMap->namesOfGroups[i])); } + for (int i = 0; i < (groupMap->getNamesOfGroups()).size(); i++) { sizes.push_back(groupMap->getNumSeqs((groupMap->getNamesOfGroups())[i])); } matrix->setSizes(sizes); @@ -268,21 +289,21 @@ int LibShuffCommand::execute(){ savedDXYValues = form->evaluateAll(); savedMinValues = form->getSavedMins(); - if (m->control_pressed) { delete form; m->Groups.clear(); delete matrix; delete groupMap; return 0; } + if (m->control_pressed) { delete form; m->clearGroups(); delete matrix; delete groupMap; return 0; } pValueCounts.resize(numGroups); for(int i=0;icontrol_pressed) { outputTypes.clear(); delete form; m->Groups.clear(); delete matrix; delete groupMap; return 0; } + if (m->control_pressed) { outputTypes.clear(); delete form; m->clearGroups(); delete matrix; delete groupMap; return 0; } Progress* reading = new Progress(); for(int i=0;icontrol_pressed) { outputTypes.clear(); delete form; m->Groups.clear(); delete matrix; delete groupMap; delete reading; return 0; } + if (m->control_pressed) { outputTypes.clear(); delete form; m->clearGroups(); delete matrix; delete groupMap; delete reading; return 0; } reading->newLine(groupNames[i]+'-'+groupNames[j], iters); int spoti = groupMap->groupIndex[groupNames[i]]; //neccessary in case user selects groups so you know where they are in the matrix @@ -290,13 +311,13 @@ int LibShuffCommand::execute(){ for(int p=0;pcontrol_pressed) { outputTypes.clear(); delete form; m->Groups.clear(); delete matrix; delete groupMap; delete reading; return 0; } + if (m->control_pressed) { outputTypes.clear(); delete form; m->clearGroups(); delete matrix; delete groupMap; delete reading; return 0; } form->randomizeGroups(spoti,spotj); if(form->evaluatePair(spoti,spotj) >= savedDXYValues[spoti][spotj]) { pValueCounts[i][j]++; } if(form->evaluatePair(spotj,spoti) >= savedDXYValues[spotj][spoti]) { pValueCounts[j][i]++; } - if (m->control_pressed) { outputTypes.clear(); delete form; m->Groups.clear(); delete matrix; delete groupMap; delete reading; return 0; } + if (m->control_pressed) { outputTypes.clear(); delete form; m->clearGroups(); delete matrix; delete groupMap; delete reading; return 0; } reading->update(p); } @@ -305,7 +326,7 @@ int LibShuffCommand::execute(){ } } - if (m->control_pressed) { outputTypes.clear(); delete form; m->Groups.clear(); delete matrix; delete groupMap; delete reading; return 0; } + if (m->control_pressed) { outputTypes.clear(); delete form; m->clearGroups(); delete matrix; delete groupMap; delete reading; return 0; } reading->finish(); delete reading; @@ -315,12 +336,12 @@ int LibShuffCommand::execute(){ printCoverageFile(); //clear out users groups - m->Groups.clear(); + m->clearGroups(); delete form; delete matrix; delete groupMap; - if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); @@ -341,7 +362,7 @@ int LibShuffCommand::printCoverageFile() { try { ofstream outCov; - summaryFile = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + "libshuff.coverage"; + summaryFile = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + getOutputFileNameTag("coverage"); m->openOutputFile(summaryFile, outCov); outputNames.push_back(summaryFile); outputTypes["coverage"].push_back(summaryFile); outCov.setf(ios::fixed, ios::floatfield); outCov.setf(ios::showpoint); @@ -437,7 +458,7 @@ int LibShuffCommand::printSummaryFile() { try { ofstream outSum; - summaryFile = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + "libshuff.summary"; + summaryFile = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + getOutputFileNameTag("libshuffsummary"); m->openOutputFile(summaryFile, outSum); outputNames.push_back(summaryFile); outputTypes["libshuffsummary"].push_back(summaryFile); @@ -492,49 +513,51 @@ int LibShuffCommand::printSummaryFile() { void LibShuffCommand::setGroups() { try { + vector myGroups = m->getGroups(); //if the user has not entered specific groups to analyze then do them all - if (m->Groups.size() == 0) { + if (m->getNumGroups() == 0) { numGroups = groupMap->getNumGroups(); for (int i=0; i < numGroups; i++) { - m->Groups.push_back(groupMap->namesOfGroups[i]); + myGroups.push_back((groupMap->getNamesOfGroups())[i]); } } else { if (savegroups != "all") { //check that groups are valid - for (int i = 0; i < m->Groups.size(); i++) { - if (groupMap->isValidGroup(m->Groups[i]) != true) { - m->mothurOut(m->Groups[i] + " is not a valid group, and will be disregarded."); m->mothurOutEndLine(); + for (int i = 0; i < myGroups.size(); i++) { + if (groupMap->isValidGroup(myGroups[i]) != true) { + m->mothurOut(myGroups[i] + " is not a valid group, and will be disregarded."); m->mothurOutEndLine(); // erase the invalid group from globaldata->Groups - m->Groups.erase(m->Groups.begin()+i); + myGroups.erase(myGroups.begin()+i); } } //if the user only entered invalid groups - if ((m->Groups.size() == 0) || (m->Groups.size() == 1)) { + if ((myGroups.size() == 0) || (myGroups.size() == 1)) { numGroups = groupMap->getNumGroups(); for (int i=0; i < numGroups; i++) { - m->Groups.push_back(groupMap->namesOfGroups[i]); + myGroups.push_back((groupMap->getNamesOfGroups())[i]); } m->mothurOut("When using the groups parameter you must have at least 2 valid groups. I will run the command using all the groups in your groupfile."); m->mothurOutEndLine(); - } else { numGroups = m->Groups.size(); } + } else { numGroups = myGroups.size(); } } else { //users wants all groups numGroups = groupMap->getNumGroups(); - m->Groups.clear(); + myGroups.clear(); for (int i=0; i < numGroups; i++) { - m->Groups.push_back(groupMap->namesOfGroups[i]); + myGroups.push_back((groupMap->getNamesOfGroups())[i]); } } } //sort so labels match - sort(m->Groups.begin(), m->Groups.end()); + sort(myGroups.begin(), myGroups.end()); //sort - sort(groupMap->namesOfGroups.begin(), groupMap->namesOfGroups.end()); + //sort(groupMap->namesOfGroups.begin(), groupMap->namesOfGroups.end()); - for (int i = 0; i < groupMap->namesOfGroups.size(); i++) { groupMap->groupIndex[groupMap->namesOfGroups[i]] = i; } + for (int i = 0; i < (groupMap->getNamesOfGroups()).size(); i++) { groupMap->groupIndex[(groupMap->getNamesOfGroups())[i]] = i; } - groupNames = m->Groups; + groupNames = myGroups; + m->setGroups(myGroups); } catch(exception& e) {