X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=parselistscommand.cpp;h=cfd1b6b9705ccb131e050ce132547192892d12ea;hp=5a568f3511d38f56601362d860a9643e702c9a1b;hb=b206f634aae1b4ce13978d203247fb64757d5482;hpb=af0a94ea8f02421b2b73e77e68753a2b4c37768e diff --git a/parselistscommand.cpp b/parselistscommand.cpp index 5a568f3..cfd1b6b 100644 --- a/parselistscommand.cpp +++ b/parselistscommand.cpp @@ -53,7 +53,7 @@ string ParseListCommand::getOutputPattern(string type) { try { string pattern = ""; - if (type == "list") { pattern = "[filename],[group],list"; } + if (type == "list") { pattern = "[filename],[group],[distance],list"; } else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } return pattern; @@ -169,7 +169,7 @@ ParseListCommand::ParseListCommand(string option) { else if (countfile == "not open") { abort = true; countfile = ""; } else { m->setCountTableFile(countfile); - ct.readTable(countfile, true); + ct.readTable(countfile, true, false); if (!ct.hasGroupInfo()) { abort = true; m->mothurOut("[ERROR]: The parse.list command requires group info to be present in your countfile, quitting."); m->mothurOutEndLine(); @@ -205,27 +205,6 @@ int ParseListCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - //set fileroot - map variables; - variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile)); - - //fill filehandles with neccessary ofstreams - int i; - ofstream* temp; - vector gGroups; - if (groupfile != "") { gGroups = groupMap->getNamesOfGroups(); } - else { gGroups = ct.getNamesOfGroups(); } - - for (i=0; iopenOutputFile(filename, *temp); - } - //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; set userLabels = labels; @@ -236,16 +215,13 @@ int ParseListCommand::execute(){ if (m->control_pressed) { delete list; if (groupfile != "") { delete groupMap; } - for (i=0; imothurRemove(outputNames[i]); } outputTypes.clear(); - return 0; + for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0; } while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if (m->control_pressed) { delete list; if (groupfile != "") { delete groupMap; } - for (i=0; imothurRemove(outputNames[i]); } outputTypes.clear(); return 0; } @@ -283,7 +259,6 @@ int ParseListCommand::execute(){ if (m->control_pressed) { if (groupfile != "") { delete groupMap; } - for (i=0; imothurRemove(outputNames[i]); } outputTypes.clear(); return 0; } @@ -304,7 +279,6 @@ int ParseListCommand::execute(){ if (m->control_pressed) { if (groupfile != "") { delete groupMap; } - for (i=0; imothurRemove(outputNames[i]); } outputTypes.clear(); return 0; } @@ -320,11 +294,6 @@ int ParseListCommand::execute(){ delete list; } - for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { - (*(filehandles[it3->first])).close(); - delete it3->second; - } - if (groupfile != "") { delete groupMap; } if (m->control_pressed) { @@ -354,8 +323,33 @@ int ParseListCommand::execute(){ /**********************************************************************************************************************/ int ParseListCommand::parse(ListVector* thisList) { try { + map filehandles; + map::iterator it3; + + //set fileroot + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile)); + variables["[distance]"] = thisList->getLabel(); + + //fill filehandles with neccessary ofstreams + ofstream* temp; + vector gGroups; + if (groupfile != "") { gGroups = groupMap->getNamesOfGroups(); } + else { gGroups = ct.getNamesOfGroups(); } + + for (int i=0; iopenOutputFile(filename, *temp); + outputNames.push_back(filename); outputTypes["list"].push_back(filename); + } + map groupVector; + map groupLabels; map::iterator itGroup; map groupNumBins; @@ -363,11 +357,12 @@ int ParseListCommand::parse(ListVector* thisList) { for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { groupNumBins[it3->first] = 0; groupVector[it3->first] = ""; + groupLabels[it3->first] = "label\tnumOtus\t"; } - + vector binLabels = thisList->getLabels(); for (int i = 0; i < thisList->getNumBins(); i++) { - if (m->control_pressed) { return 0; } + if (m->control_pressed) { break; } map groupBins; string bin = list->get(i); @@ -408,14 +403,26 @@ int ParseListCommand::parse(ListVector* thisList) { //print parsed bin info to files for (itGroup = groupBins.begin(); itGroup != groupBins.end(); itGroup++) { - groupVector[itGroup->first] += itGroup->second + '\t'; + groupVector[itGroup->first] += itGroup->second + '\t'; + groupLabels[itGroup->first] += binLabels[i] + '\t'; } } + if (m->control_pressed) { + for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { + (*(filehandles[it3->first])).close(); + delete it3->second; + } + return 0; + } + //end list vector for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { + (*(filehandles[it3->first])) << groupLabels[it3->first] << endl; (*(filehandles[it3->first])) << thisList->getLabel() << '\t' << groupNumBins[it3->first] << '\t' << groupVector[it3->first] << endl; // label numBins listvector for that group + (*(filehandles[it3->first])).close(); + delete it3->second; } return 0;