#include "pcacommand.h"
+//**********************************************************************************************************************
+vector<string> PCACommand::getValidParameters(){
+ try {
+ string Array[] = {"phylip", "outputdir","inputdir"};
+ vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "PCACommand", "getValidParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+PCACommand::PCACommand(){
+ try {
+ abort = true;
+ //initialize outputTypes
+ vector<string> tempOutNames;
+ outputTypes["pcoa"] = tempOutNames;
+ outputTypes["loadings"] = tempOutNames;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "PCACommand", "PCACommand");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+vector<string> PCACommand::getRequiredParameters(){
+ try {
+ string Array[] = {"phylip"};
+ vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "PCACommand", "getRequiredParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+vector<string> PCACommand::getRequiredFiles(){
+ try {
+ vector<string> myArray;
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "PCACommand", "getRequiredFiles");
+ exit(1);
+ }
+}
//**********************************************************************************************************************
PCACommand::PCACommand(string option) {
it = parameters.find("phylip");
//user has given a template file
if(it != parameters.end()){
- path = hasPath(it->second);
+ path = m->hasPath(it->second);
//if the user has not given a path then, add inputdir. else leave path alone.
if (path == "") { parameters["phylip"] = inputDir + it->second; }
}
}
-
+
+ //initialize outputTypes
+ vector<string> tempOutNames;
+ outputTypes["pcoa"] = tempOutNames;
+ outputTypes["loadings"] = tempOutNames;
+
//required parameters
phylipfile = validParameter.validFile(parameters, "phylip", true);
if (phylipfile == "not open") { abort = true; }
//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"){
outputDir = "";
- outputDir += hasPath(phylipfile); //if user entered a file with a path then preserve it
+ outputDir += m->hasPath(phylipfile); //if user entered a file with a path then preserve it
}
//error checking on files
vector<string> names;
vector<vector<double> > D;
- //fbase = filename;
- //if(fbase.find_last_of(".")!=string::npos){
- // fbase.erase(fbase.find_last_of(".")+1);
- //}
- //else{
- // fbase += ".";
- //}
-
- fbase = outputDir + getRootName(getSimpleName(filename));
+ fbase = outputDir + m->getRootName(m->getSimpleName(filename));
read(filename, names, D);
+
+ if (m->control_pressed) { return 0; }
double offset = 0.0000;
vector<double> d;
vector<vector<double> > copy_G;
//int rank = D.size();
- cout << "\nProcessing...\n";
+ m->mothurOut("\nProcessing...\n");
for(int count=0;count<2;count++){
- recenter(offset, D, G);
- tred2(G, d, e);
- qtli(d, e, G);
+ recenter(offset, D, G); if (m->control_pressed) { return 0; }
+ tred2(G, d, e); if (m->control_pressed) { return 0; }
+ qtli(d, e, G); if (m->control_pressed) { return 0; }
offset = d[d.size()-1];
if(offset > 0.0) break;
}
+ if (m->control_pressed) { return 0; }
output(fbase, names, G, d);
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
/*********************************************************************************************************************************/
-void PCACommand::read_phylip(istream& f, int square_m, vector<string>& name_list, vector<vector<double> >& d){
+int PCACommand::read_phylip(istream& f, int square_m, vector<string>& name_list, vector<vector<double> >& d){
try {
// int count1=0;
// int count2=0;
f >> name_list[i];
// cout << i << "\t" << name_list[i] << endl;
for(int j=0;j<rank;j++) {
+ if (m->control_pressed) { return 0; }
+
f >> d[i][j];
if (d[i][j] == -0.0000)
d[i][j] = 0.0000;
f >> name_list[i];
d[i][i]=0.0000;
for(int j=0;j<i;j++){
+ if (m->control_pressed) { return 0; }
f >> d[i][j];
if (d[i][j] == -0.0000)
d[i][j] = 0.0000;
}
}
}
+
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "PCACommand", "read_phylip");
void PCACommand::read(string fname, vector<string>& names, vector<vector<double> >& D){
try {
ifstream f;
- openInputFile(fname, f);
+ m->openInputFile(fname, f);
//check whether matrix is square
char d;
- int m = 1;
+ int q = 1;
int numSeqs;
string name;
//is d a number meaning its square
if(isalnum(d)){
- m = 1;
+ q = 1;
break;
}
//is d a line return meaning its lower triangle
if(d == '\n'){
- m = 2;
+ q = 2;
break;
}
}
f.close();
//reopen to get back to beginning
- openInputFile(fname, f);
- read_phylip(f, m, names, D);
+ m->openInputFile(fname, f);
+ read_phylip(f, q, names, D);
}
catch(exception& e) {
m->errorOut(e, "PCACommand", "read");
}
}
- ofstream pcaData((fnameRoot+"pca").c_str(), ios::trunc);
+ ofstream pcaData((fnameRoot+"pcoa").c_str(), ios::trunc);
pcaData.setf(ios::fixed, ios::floatfield);
pcaData.setf(ios::showpoint);
- outputNames.push_back(fnameRoot+"pca");
+ outputNames.push_back(fnameRoot+"pcoa");
+ outputTypes["pcoa"].push_back(fnameRoot+"pcoa");
- ofstream pcaLoadings((fnameRoot+"pca.loadings").c_str(), ios::trunc);
+ ofstream pcaLoadings((fnameRoot+"pcoa.loadings").c_str(), ios::trunc);
pcaLoadings.setf(ios::fixed, ios::floatfield);
pcaLoadings.setf(ios::showpoint);
- outputNames.push_back(fnameRoot+"pca.loadings");
+ outputNames.push_back(fnameRoot+"pcoa.loadings");
+ outputTypes["loadings"].push_back(fnameRoot+"pcoa.loadings");
pcaLoadings << "axis\tloading\n";
for(int i=0;i<rank;i++){