X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=splitabundcommand.cpp;h=a8ca812e0e0cb6854fd3c806e8e26249eb9400a2;hb=5bb0453ee6ab8f7e700b5d0c61a84fdc73db4976;hp=17809631f9e9cc590e510a33ec5528e493a14d3c;hpb=a76d81690125ca57d7f602ac93abad75cf9796c2;p=mothur.git diff --git a/splitabundcommand.cpp b/splitabundcommand.cpp index 1780963..a8ca812 100644 --- a/splitabundcommand.cpp +++ b/splitabundcommand.cpp @@ -9,6 +9,58 @@ #include "splitabundcommand.h" +//********************************************************************************************************************** +vector SplitAbundCommand::getValidParameters(){ + try { + string Array[] = {"name","group","list","label","accnos","groups","fasta","cutoff","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SplitAbundCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +SplitAbundCommand::SplitAbundCommand(){ + try { + abort = true; + //initialize outputTypes + vector tempOutNames; + outputTypes["list"] = tempOutNames; + outputTypes["name"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + outputTypes["group"] = tempOutNames; + outputTypes["fasta"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "SplitAbundCommand", "SplitAbundCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector SplitAbundCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta","list","name","or"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SplitAbundCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector SplitAbundCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SplitAbundCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** SplitAbundCommand::SplitAbundCommand(string option) { try { @@ -33,7 +85,15 @@ SplitAbundCommand::SplitAbundCommand(string option) { for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } - + + //initialize outputTypes + vector tempOutNames; + outputTypes["list"] = tempOutNames; + outputTypes["name"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + outputTypes["group"] = tempOutNames; + outputTypes["fasta"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -177,24 +237,6 @@ int SplitAbundCommand::execute(){ if (listfile != "") { //you are using a listfile to determine abundance if (outputDir == "") { outputDir = m->hasPath(listfile); } - - //remove old files so you can append later.... - string fileroot = outputDir + m->getRootName(m->getSimpleName(listfile)); - if (Groups.size() == 0) { - remove((fileroot + "rare.list").c_str()); - remove((fileroot + "abund.list").c_str()); - - outputNames.push_back((fileroot + "rare.list")); - outputNames.push_back((fileroot + "abund.list")); - }else{ - for (int i=0; i processedLabels; @@ -290,7 +332,7 @@ int SplitAbundCommand::execute(){ if (accnos) { writeAccnos(tag); } if (fastafile != "") { parseFasta(tag); } } - + m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } @@ -326,9 +368,11 @@ int SplitAbundCommand::splitList(ListVector* thisList) { } }//end for - writeList(thisList); string tag = thisList->getLabel() + "."; + + writeList(thisList, tag); + if (groupfile != "") { parseGroup(tag); } if (accnos) { writeAccnos(tag); } if (fastafile != "") { parseFasta(tag); } @@ -342,7 +386,7 @@ int SplitAbundCommand::splitList(ListVector* thisList) { } } /**********************************************************************************************************************/ -int SplitAbundCommand::writeList(ListVector* thisList) { +int SplitAbundCommand::writeList(ListVector* thisList, string tag) { try { map filehandles; @@ -364,13 +408,13 @@ int SplitAbundCommand::writeList(ListVector* thisList) { ofstream aout; ofstream rout; - string rare = outputDir + m->getRootName(m->getSimpleName(listfile)) + "rare.list"; - m->openOutputFileAppend(rare, rout); - //outputNames.push_back(rare); + string rare = outputDir + m->getRootName(m->getSimpleName(listfile)) + tag + "rare.list"; + m->openOutputFile(rare, rout); + outputNames.push_back(rare); outputTypes["list"].push_back(rare); - string abund = outputDir + m->getRootName(m->getSimpleName(listfile)) + "abund.list"; - m->openOutputFileAppend(abund, aout); - //outputNames.push_back(abund); + string abund = outputDir + m->getRootName(m->getSimpleName(listfile)) + tag + "abund.list"; + m->openOutputFile(abund, aout); + outputNames.push_back(abund); outputTypes["list"].push_back(abund); if (rareNames.size() != 0) { rout << thisList->getLabel() << '\t' << numRareBins << '\t'; } if (abundNames.size() != 0) { aout << thisList->getLabel() << '\t' << numAbundBins << '\t'; } @@ -406,8 +450,10 @@ int SplitAbundCommand::writeList(ListVector* thisList) { temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - m->openOutputFileAppend(fileroot + Groups[i] + ".rare.list", *(filehandles[Groups[i]+".rare"])); - m->openOutputFileAppend(fileroot + Groups[i] + ".abund.list", *(filehandles[Groups[i]+".abund"])); + m->openOutputFile(fileroot + Groups[i] + tag + ".rare.list", *(filehandles[Groups[i]+".rare"])); + m->openOutputFile(fileroot + Groups[i] + tag + ".abund.list", *(filehandles[Groups[i]+".abund"])); + outputNames.push_back(fileroot + Groups[i] + tag + ".rare.list"); outputTypes["list"].push_back(fileroot + Groups[i] + tag + ".rare.list"); + outputNames.push_back(fileroot + Groups[i] + tag + ".abund.list"); outputTypes["list"].push_back(fileroot + Groups[i] + tag + ".abund.list"); } map groupVector; @@ -572,11 +618,11 @@ int SplitAbundCommand::writeNames() { //namefile string rare = outputDir + m->getRootName(m->getSimpleName(namefile)) + "rare.names"; m->openOutputFile(rare, rout); - outputNames.push_back(rare); + outputNames.push_back(rare); outputTypes["name"].push_back(rare); string abund = outputDir + m->getRootName(m->getSimpleName(namefile)) + "abund.names"; m->openOutputFile(abund, aout); - outputNames.push_back(abund); + outputNames.push_back(abund); outputTypes["name"].push_back(abund); if (rareNames.size() != 0) { for (set::iterator itRare = rareNames.begin(); itRare != rareNames.end(); itRare++) { @@ -642,7 +688,7 @@ int SplitAbundCommand::writeNames() { //namefile for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])).close(); - outputNames.push_back(fileroot + it3->first + ".names"); + outputNames.push_back(fileroot + it3->first + ".names"); outputTypes["name"].push_back(fileroot + it3->first + ".names"); delete it3->second; } } @@ -669,7 +715,7 @@ int SplitAbundCommand::writeAccnos(string tag) { string rare = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "rare.accnos"; m->openOutputFile(rare, rout); - outputNames.push_back(rare); + outputNames.push_back(rare); outputTypes["accnos"].push_back(rare); for (set::iterator itRare = rareNames.begin(); itRare != rareNames.end(); itRare++) { rout << (*itRare) << endl; @@ -678,7 +724,7 @@ int SplitAbundCommand::writeAccnos(string tag) { string abund = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "abund.accnos"; m->openOutputFile(abund, aout); - outputNames.push_back(abund); + outputNames.push_back(abund); outputTypes["accnos"].push_back(abund); for (set::iterator itAbund = abundNames.begin(); itAbund != abundNames.end(); itAbund++) { aout << (*itAbund) << endl; @@ -723,7 +769,7 @@ int SplitAbundCommand::writeAccnos(string tag) { //close files for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])).close(); - outputNames.push_back(fileroot + tag + it3->first + ".accnos"); + outputNames.push_back(fileroot + tag + it3->first + ".accnos"); outputTypes["accnos"].push_back(fileroot + tag + it3->first + ".accnos"); delete it3->second; } } @@ -748,11 +794,11 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile string rare = outputDir + m->getRootName(m->getSimpleName(groupfile)) + tag + "rare.groups"; m->openOutputFile(rare, rout); - outputNames.push_back(rare); + outputNames.push_back(rare); outputTypes["group"].push_back(rare); string abund = outputDir + m->getRootName(m->getSimpleName(groupfile)) + tag + "abund.groups"; m->openOutputFile(abund, aout); - outputNames.push_back(abund); + outputNames.push_back(abund); outputTypes["group"].push_back(abund); for (map::iterator itName = nameMap.begin(); itName != nameMap.end(); itName++) { vector names; @@ -817,7 +863,7 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])).close(); - outputNames.push_back(fileroot + tag + it3->first + ".groups"); + outputNames.push_back(fileroot + tag + it3->first + ".groups"); outputTypes["group"].push_back(fileroot + tag + it3->first + ".groups"); delete it3->second; } } @@ -842,11 +888,11 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile string rare = outputDir + m->getRootName(m->getSimpleName(fastafile)) + tag + "rare.fasta"; m->openOutputFile(rare, rout); - outputNames.push_back(rare); + outputNames.push_back(rare); outputTypes["fasta"].push_back(rare); string abund = outputDir + m->getRootName(m->getSimpleName(fastafile)) + tag + "abund.fasta"; m->openOutputFile(abund, aout); - outputNames.push_back(abund); + outputNames.push_back(abund); outputTypes["fasta"].push_back(abund); //open input file ifstream in; @@ -937,7 +983,7 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])).close(); - outputNames.push_back(fileroot + tag + it3->first + ".fasta"); + outputNames.push_back(fileroot + tag + it3->first + ".fasta"); outputTypes["fasta"].push_back(fileroot + tag + it3->first + ".fasta"); delete it3->second; } }