X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=pcoacommand.cpp;fp=pcoacommand.cpp;h=354826f8c0b27a359b1eb1530e6a0d7a9fbaf32f;hb=49d2b7459c5027557564b21e9487dadafbbbdc96;hp=02e165e978dc071ba19808139060866d7e41388c;hpb=ee8403d4eb5760187d62b42a9cf4272de8fc0ec4;p=mothur.git diff --git a/pcoacommand.cpp b/pcoacommand.cpp index 02e165e..354826f 100644 --- a/pcoacommand.cpp +++ b/pcoacommand.cpp @@ -46,6 +46,27 @@ string PCOACommand::getHelpString(){ } } +//********************************************************************************************************************** +string PCOACommand::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 == "pcoa") { outputFileName = "pcoa.axes"; } + else if (type == "loadings") { outputFileName = "pcoa.loadings"; } + 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, "PCOACommand", "getOutputFileNameTag"); + exit(1); + } +} //********************************************************************************************************************** PCOACommand::PCOACommand(){ @@ -229,17 +250,21 @@ void PCOACommand::output(string fnameRoot, vector name_list, vectoropenOutputFile(pcoaDataFile, pcaData); pcaData.setf(ios::fixed, ios::floatfield); pcaData.setf(ios::showpoint); - outputNames.push_back(fnameRoot+"pcoa.axes"); - outputTypes["pcoa"].push_back(fnameRoot+"pcoa.axes"); + outputNames.push_back(pcoaDataFile); + outputTypes["pcoa"].push_back(pcoaDataFile); - ofstream pcaLoadings((fnameRoot+"pcoa.loadings").c_str(), ios::trunc); + ofstream pcaLoadings; + string loadingsFile = fnameRoot+getOutputFileNameTag("loadings"); + m->openOutputFile(loadingsFile, pcaLoadings); pcaLoadings.setf(ios::fixed, ios::floatfield); pcaLoadings.setf(ios::showpoint); - outputNames.push_back(fnameRoot+"pcoa.loadings"); - outputTypes["loadings"].push_back(fnameRoot+"pcoa.loadings"); + outputNames.push_back(loadingsFile); + outputTypes["loadings"].push_back(loadingsFile); pcaLoadings << "axis\tloading\n"; for(int i=0;i