]> git.donarmstrong.com Git - mothur.git/commitdiff
pat's differences before v.1.8
authorpschloss <pschloss>
Tue, 2 Feb 2010 15:00:23 +0000 (15:00 +0000)
committerpschloss <pschloss>
Tue, 2 Feb 2010 15:00:23 +0000 (15:00 +0000)
pcacommand.cpp
pcacommand.h

index 77b16e82d58a427634f6bcd5c58fafdd2fe9a1f5..c17053e29cb31812f681333078199c9abaea02fa 100644 (file)
@@ -159,58 +159,6 @@ void PCACommand::get_comment(istream& f, char begin, char end){
 
 /*********************************************************************************************************************************/
 
-void PCACommand::read_mega(istream& f, vector<string>& name_list, vector<vector<double> >& 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<rank;i++){                d[i].resize(rank);              }
-               
-               d[0][0] = 0.0000;
-               get_comment(f, '[', ']');
-               for(int i=1;i<rank;i++){
-                       get_comment(f, '[', ']');
-                       d[i][i]=0.0000;
-                       for(int j=0;j<i;j++){
-                               f >> 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<string>& name_list, vector<vector<double> >& d){
        try {
                //     int count1=0;
@@ -265,54 +213,45 @@ void PCACommand::read(string fname, vector<string>& names, vector<vector<double>
        try {
                ifstream f;
                openInputFile(fname, f);
+                       
+               //check whether matrix is square
+               char d;
+               int m = 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;
+               while((d=f.get()) != EOF){
                        
-                       f >> numSeqs >> name; 
-                       
-                       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)){ 
+                               m = 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'){
+                               m = 2;
+                               break;
+                       }
                }
+               f.close();
                
-               //int rank = D.size();
+               //reopen to get back to beginning
+               openInputFile(fname, f);                        
+               read_phylip(f, m, names, D);
        }
-       catch(exception& e) {
+               catch(exception& e) {
                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<vector<double> > first, vector<vector<double> > second, vector<vector<double> >& product){
@@ -579,7 +518,7 @@ void PCACommand::output(string fnameRoot, vector<string> name_list, vector<vecto
                        pcaLoadings << i+1 << '\t' << d[i] * 100.0 / dsum << endl;
                }
                
-               pcaData << "SeqName";
+               pcaData << "group";
                for(int i=0;i<rank;i++){
                        pcaData << '\t' << "axis" << i+1;
                }
@@ -601,20 +540,3 @@ void PCACommand::output(string fnameRoot, vector<string> name_list, vector<vecto
 
 /*********************************************************************************************************************************/
 
-void PCACommand::print_matrix(vector<vector<double> > A) {
-       try {
-               int rank = A.size();
-               for(int i=0;i<rank;i++){
-                       for(int j=0;j<rank;j++){
-                               cout << A[i][j] << "  ";
-                       }
-                       cout << endl;
-               }
-       }
-       catch(exception& e) {
-               errorOut(e, "PCACommand", "print_matrix");
-               exit(1);
-       }
-}
-/*********************************************************************************************************************************/
-
index a447ffced3040086a2c91a7f6014a79cf50b58b8..8a36323582b6ca42f153110c48f012148d59cd2b 100644 (file)
@@ -29,7 +29,6 @@ private:
        float cutoff, precision;
        
        void get_comment(istream&, char, char);
-       void read_mega(istream&, vector<string>&, vector<vector<double> >&);
        void read_phylip(istream&, int, vector<string>&, vector<vector<double> >&);
        void read(string, vector<string>&, vector<vector<double> >&);
        double pythag(double, double);
@@ -38,7 +37,6 @@ private:
        void tred2(vector<vector<double> >&, vector<double>&, vector<double>&);
        void qtli(vector<double>&, vector<double>&, vector<vector<double> >&);
        void output(string, vector<string>, vector<vector<double> >, vector<double>);
-       void print_matrix(vector<vector<double> >);
        
 };