X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=pcacommand.cpp;h=51e3c319f377b893224e1e2f2d7093b3665c0d8a;hb=7588ff51d365aad66f455694afb90b6fd3e6639a;hp=77b16e82d58a427634f6bcd5c58fafdd2fe9a1f5;hpb=315e38cf393c82be238da5b32574f225a020d25c;p=mothur.git diff --git a/pcacommand.cpp b/pcacommand.cpp index 77b16e8..51e3c31 100644 --- a/pcacommand.cpp +++ b/pcacommand.cpp @@ -12,7 +12,7 @@ //********************************************************************************************************************** -PCACommand::PCACommand(string option){ +PCACommand::PCACommand(string option) { try { abort = false; @@ -42,7 +42,7 @@ 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; } } @@ -57,16 +57,16 @@ PCACommand::PCACommand(string option){ //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 - if (phylipfile == "") { mothurOut("You must provide a distance file before running the pca command."); mothurOutEndLine(); abort = true; } + if (phylipfile == "") { m->mothurOut("You must provide a distance file before running the pca command."); m->mothurOutEndLine(); abort = true; } } } catch(exception& e) { - errorOut(e, "PCACommand", "PCACommand"); + m->errorOut(e, "PCACommand", "PCACommand"); exit(1); } } @@ -74,10 +74,10 @@ PCACommand::PCACommand(string option){ void PCACommand::help(){ try { - mothurOut("The pca command..."); mothurOutEndLine(); + m->mothurOut("The pca command..."); m->mothurOutEndLine(); } catch(exception& e) { - errorOut(e, "PCACommand", "help"); + m->errorOut(e, "PCACommand", "help"); exit(1); } } @@ -97,17 +97,11 @@ int PCACommand::execute(){ vector names; vector > 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 d; @@ -116,23 +110,31 @@ int PCACommand::execute(){ vector > 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(); } + m->mothurOutEndLine(); + return 0; } catch(exception& e) { - errorOut(e, "PCACommand", "execute"); + m->errorOut(e, "PCACommand", "execute"); exit(1); } } @@ -152,66 +154,14 @@ void PCACommand::get_comment(istream& f, char begin, char end){ d = f.peek(); } catch(exception& e) { - errorOut(e, "PCACommand", "get_comment"); + m->errorOut(e, "PCACommand", "get_comment"); exit(1); } } /*********************************************************************************************************************************/ -void PCACommand::read_mega(istream& f, vector& name_list, vector >& d){ - try { - get_comment(f, '#', '\n'); - - char test = f.peek(); - - while(test == '!'){ //get header comments - get_comment(f, '!', ';'); - while(isspace(test=f.get())) {;} - f.putback(test); - test = f.peek(); - } - while(test != '\n'){ //get sequence names - get_comment(f, '[', ']'); - char d = f.get(); - d = f.get(); - if(d == '#'){ - string name; - f >> name; - name_list.push_back(name); - while(isspace(test=f.get())) {;} - f.putback(test); - } - else{ - break; - } - } - int rank = name_list.size(); - d.resize(rank); - for(int i=0;i> d[i][j]; - if (d[i][j] == -0.0000) - d[i][j] = 0.0000; - d[j][i]=d[i][j]; - } - } - } - catch(exception& e) { - errorOut(e, "PCACommand", "read_mega"); - exit(1); - } -} - -/*********************************************************************************************************************************/ - -void PCACommand::read_phylip(istream& f, int square_m, vector& name_list, vector >& d){ +int PCACommand::read_phylip(istream& f, int square_m, vector& name_list, vector >& d){ try { // int count1=0; // int count2=0; @@ -228,6 +178,8 @@ void PCACommand::read_phylip(istream& f, int square_m, vector& name_list f >> name_list[i]; // cout << i << "\t" << name_list[i] << endl; for(int j=0;jcontrol_pressed) { return 0; } + f >> d[i][j]; if (d[i][j] == -0.0000) d[i][j] = 0.0000; @@ -244,6 +196,7 @@ void PCACommand::read_phylip(istream& f, int square_m, vector& name_list f >> name_list[i]; d[i][i]=0.0000; for(int j=0;jcontrol_pressed) { return 0; } f >> d[i][j]; if (d[i][j] == -0.0000) d[i][j] = 0.0000; @@ -251,9 +204,11 @@ void PCACommand::read_phylip(istream& f, int square_m, vector& name_list } } } + + return 0; } catch(exception& e) { - errorOut(e, "PCACommand", "read_phylip"); + m->errorOut(e, "PCACommand", "read_phylip"); exit(1); } @@ -264,55 +219,46 @@ void PCACommand::read_phylip(istream& f, int square_m, vector& name_list void PCACommand::read(string fname, vector& names, vector >& D){ try { ifstream f; - openInputFile(fname, f); + m->openInputFile(fname, f); + + //check whether matrix is square + char d; + int q = 1; + int numSeqs; + string name; - char test = f.peek(); + f >> numSeqs >> name; - if(test == '#'){ - read_mega(f, names, D); - } - else{ - //check whether matrix is square - char d; - int m = 1; - int numSeqs; - string name; - - f >> numSeqs >> name; + while((d=f.get()) != EOF){ - while((d=f.get()) != EOF){ - - //is d a number meaning its square - if(isalnum(d)){ - m = 1; - break; - } - - //is d a line return meaning its lower triangle - if(d == '\n'){ - m = 2; - break; - } + //is d a number meaning its square + if(isalnum(d)){ + q = 1; + break; } - f.close(); - //reopen to get back to beginning - openInputFile(fname, f); - read_phylip(f, m, names, D); + //is d a line return meaning its lower triangle + if(d == '\n'){ + q = 2; + break; + } } + f.close(); - //int rank = D.size(); + //reopen to get back to beginning + m->openInputFile(fname, f); + read_phylip(f, q, names, D); } - catch(exception& e) { - errorOut(e, "PCACommand", "read"); + catch(exception& e) { + m->errorOut(e, "PCACommand", "read"); exit(1); } } /*********************************************************************************************************************************/ -double PCACommand::pythag(double a, double b){ - return(pow(a*a+b*b,0.5)); -} + +double PCACommand::pythag(double a, double b) { return(pow(a*a+b*b,0.5)); } + /*********************************************************************************************************************************/ void PCACommand::matrix_mult(vector > first, vector > second, vector >& product){ @@ -336,7 +282,7 @@ void PCACommand::matrix_mult(vector > first, vectorerrorOut(e, "PCACommand", "matrix_mult"); exit(1); } @@ -370,7 +316,7 @@ void PCACommand::recenter(double offset, vector > D, vectorerrorOut(e, "PCACommand", "recenter"); exit(1); } @@ -463,7 +409,7 @@ void PCACommand::tred2(vector >& a, vector& d, vectorerrorOut(e, "PCACommand", "tred2"); exit(1); } @@ -547,7 +493,7 @@ void PCACommand::qtli(vector& d, vector& e, vectorerrorOut(e, "PCACommand", "qtli"); exit(1); } } @@ -566,20 +512,22 @@ void PCACommand::output(string fnameRoot, vector name_list, vector name_list, vectorerrorOut(e, "PCACommand", "output"); exit(1); } } /*********************************************************************************************************************************/ -void PCACommand::print_matrix(vector > A) { - try { - int rank = A.size(); - for(int i=0;i