]> git.donarmstrong.com Git - mothur.git/blobdiff - readcolumn.cpp
added sparseDistanceMatrix class. Modified cluster commands to use the new sparse...
[mothur.git] / readcolumn.cpp
index f61a40c483b69f7418ca4d2702ca995f4180f3e2..665dcabd5db7fd17513d912bab974ae4087d449f 100644 (file)
 
 ReadColumnMatrix::ReadColumnMatrix(string df) : distFile(df){
        
-       successOpen = openInputFile(distFile, fileHandle);
+       successOpen = m->openInputFile(distFile, fileHandle);
+       sim = false;
        
 }
+/***********************************************************************/
+
+ReadColumnMatrix::ReadColumnMatrix(string df, bool s) : distFile(df){
+       
+       successOpen = m->openInputFile(distFile, fileHandle);
+       sim = s;
+}
 
 /***********************************************************************/
 
@@ -26,7 +34,7 @@ int ReadColumnMatrix::read(NameAssignment* nameMap){
                string firstName, secondName;
                float distance;
                int nseqs = nameMap->size();
-
+        DMatrix->resize(nseqs);
                list = new ListVector(nameMap->getListVector());
        
                Progress* reading = new Progress("Reading matrix:     ", nseqs * nseqs);
@@ -47,58 +55,55 @@ int ReadColumnMatrix::read(NameAssignment* nameMap){
                        map<string,int>::iterator itA = nameMap->find(firstName);
                        map<string,int>::iterator itB = nameMap->find(secondName);
                                
-                       if(itA == nameMap->end()){
-                               cerr << "AAError: Sequence '" << firstName << "' was not found in the names file, please correct\n"; exit(1);
-                       }
-                       if(itB == nameMap->end()){
-                               cerr << "ABError: Sequence '" << secondName << "' was not found in the names file, please correct\n"; exit(1);
-                       }
+                       if(itA == nameMap->end()){  m->mothurOut("AAError: Sequence '" + firstName + "' was not found in the names file, please correct\n"); exit(1);  }
+                       if(itB == nameMap->end()){  m->mothurOut("ABError: Sequence '" + secondName + "' was not found in the names file, please correct\n"); exit(1);  }
 
                        if (distance == -1) { distance = 1000000; }
-                       else if (globaldata->sim) { distance = 1.0 - distance;  }  //user has entered a sim matrix that we need to convert.
+                       else if (sim) { distance = 1.0 - distance;  }  //user has entered a sim matrix that we need to convert.
                        
                        if(distance < cutoff && itA != itB){
                                if(itA->second > itB->second){
-                                       PCell value(itA->second, itB->second, distance);
-                       
+                    PDistCell value(itA->second, distance);
+                    
+                    
                                        if(refRow == refCol){           // in other words, if we haven't loaded refRow and refCol...
                                                refRow = itA->second;
                                                refCol = itB->second;
-                                               D->addCell(value);
+                                               DMatrix->addCell(itB->second, value);
                                        }
                                        else if(refRow == itA->second && refCol == itB->second){
                                                lt = 0;
                                        }
                                        else{
-                                               D->addCell(value);
+                                               DMatrix->addCell(itB->second, value);
                                        }
                                }
                                else if(itA->second < itB->second){
-                                       PCell value(itB->second, itA->second, distance);
+                                       PDistCell value(itB->second, distance);
                        
                                        if(refRow == refCol){           // in other words, if we haven't loaded refRow and refCol...
                                                refRow = itA->second;
                                                refCol = itB->second;
-                                               D->addCell(value);
+                                               DMatrix->addCell(itA->second, value);
                                        }
                                        else if(refRow == itB->second && refCol == itA->second){
                                                lt = 0;
                                        }
                                        else{
-                                               D->addCell(value);
+                                               DMatrix->addCell(itA->second, value);
                                        }
                                }
                                reading->update(itA->second * nseqs);
                        }
-                       gobble(fileHandle);
+                       m->gobble(fileHandle);
                }
 
                if(lt == 0){  // oops, it was square
        
                        fileHandle.close();  //let's start over
-                       D->clear();  //let's start over
+                       DMatrix->clear();  //let's start over
                   
-                       openInputFile(distFile, fileHandle);  //let's start over
+                       m->openInputFile(distFile, fileHandle);  //let's start over
 
                        while(fileHandle){
                                fileHandle >> firstName >> secondName >> distance;
@@ -108,23 +113,19 @@ int ReadColumnMatrix::read(NameAssignment* nameMap){
                                map<string,int>::iterator itA = nameMap->find(firstName);
                                map<string,int>::iterator itB = nameMap->find(secondName);
                                
-                               if(itA == nameMap->end()){
-                                       cerr << "BError: Sequence '" << firstName << "' was not found in the names file, please correct\n";
-                               }
-                               if(itB == nameMap->end()){
-                                       cerr << "BError: Sequence '" << secondName << "' was not found in the names file, please correct\n";
-                               }
+                               if(itA == nameMap->end()){  m->mothurOut("AAError: Sequence '" + firstName + "' was not found in the names file, please correct\n"); exit(1);  }
+                               if(itB == nameMap->end()){  m->mothurOut("ABError: Sequence '" + secondName + "' was not found in the names file, please correct\n"); exit(1);  }
                                
                                if (distance == -1) { distance = 1000000; }
-                               else if (globaldata->sim) { distance = 1.0 - distance;  }  //user has entered a sim matrix that we need to convert.
+                               else if (sim) { distance = 1.0 - distance;  }  //user has entered a sim matrix that we need to convert.
                                
                                if(distance < cutoff && itA->second > itB->second){
-                                       PCell value(itA->second, itB->second, distance);
-                                       D->addCell(value);
+                    PDistCell value(itA->second, distance);
+                                       DMatrix->addCell(itB->second, value);
                                        reading->update(itA->second * nseqs);
                                }
                
-                               gobble(fileHandle);
+                               m->gobble(fileHandle);
                        }
                }
                
@@ -145,10 +146,6 @@ int ReadColumnMatrix::read(NameAssignment* nameMap){
 }
 
 /***********************************************************************/
-
-ReadColumnMatrix::~ReadColumnMatrix(){
-       //delete D;
-       //delete list;
-}
-
+ReadColumnMatrix::~ReadColumnMatrix(){}
+/***********************************************************************/