X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=pcoacommand.cpp;h=2043a128bd94bc755cb7ef10f5a8b8d9bdb5a6be;hb=bd27c2b0612942815b7417c79f7ee41f669a2a34;hp=20e8e1be712765513c1f581b4e94536207f4f773;hpb=7bf9a81bba76538ecaf351ae208de3da4bf1b6dd;p=mothur.git diff --git a/pcoacommand.cpp b/pcoacommand.cpp index 20e8e1b..2043a12 100644 --- a/pcoacommand.cpp +++ b/pcoacommand.cpp @@ -15,10 +15,10 @@ //********************************************************************************************************************** vector PCOACommand::setParameters(){ try { - CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip); - CommandParameter pmetric("metric", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pmetric); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none","pcoa-loadings",false,true,true); parameters.push_back(pphylip); + CommandParameter pmetric("metric", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pmetric); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); vector myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } @@ -45,6 +45,22 @@ string PCOACommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string PCOACommand::getOutputPattern(string type) { + try { + string pattern = ""; + + if (type == "pcoa") { pattern = "[filename],pcoa.axes"; } + else if (type == "loadings") { pattern = "[filename],pcoa.loadings"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "PCOACommand", "getOutputPattern"); + exit(1); + } +} //********************************************************************************************************************** @@ -172,7 +188,7 @@ int PCOACommand::execute(){ output(fbase, names, G, d); - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } if (metric) { @@ -180,13 +196,13 @@ int PCOACommand::execute(){ vector< vector > EuclidDists = linearCalc.calculateEuclidianDistance(G, i); //G is the pcoa file - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } double corr = linearCalc.calcPearson(EuclidDists, D); //G is the pcoa file, D is the users distance matrix m->mothurOut("Rsq " + toString(i) + " axis: " + toString(corr * corr)); m->mothurOutEndLine(); - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } } } @@ -229,17 +245,23 @@ void PCOACommand::output(string fnameRoot, vector name_list, vector variables; + variables["[filename]"] = fnameRoot; + string pcoaDataFile = getOutputFileName("pcoa",variables); + m->openOutputFile(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 = getOutputFileName("loadings",variables); + 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