]> git.donarmstrong.com Git - mothur.git/blobdiff - readdistcommand.cpp
changed defaults for filter.seqs()
[mothur.git] / readdistcommand.cpp
index 4feddfde47e51b6564e2da9b414009709fade4e8..8de0c34ee039e3c79d539fb7ed531fb2351f3400 100644 (file)
@@ -8,6 +8,9 @@
  */
 
 #include "readdistcommand.h"
+#include "readphylip.h"
+#include "readcolumn.h"
+#include "readmatrix.hpp"
 
 ReadDistCommand::ReadDistCommand(){
        try {
@@ -17,24 +20,32 @@ ReadDistCommand::ReadDistCommand(){
                format = globaldata->getFormat();       
                
                if (format == "column") { read = new ReadColumnMatrix(filename); }      
-               else if (format == "phylip") { read = new ReadPhylipMatrix(filename); } 
-                       
-               if(globaldata->getPrecision() != ""){
-                       convert(globaldata->getPrecision(), precision); 
+               else if (format == "phylip") { read = new ReadPhylipMatrix(filename); }
+               else if (format == "matrix") { 
+                               groupMap = new GroupMap(globaldata->getGroupFile());
+                               groupMap->readMap();
+                               //if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap;  }
+                               globaldata->gGroupmap = groupMap;
                }
                
-               if(globaldata->getCutOff() != ""){
-                       convert(globaldata->getCutOff(), cutoff);       
-                       cutoff += (5 / (precision * 10.0));
-               }
-               read->setCutoff(cutoff);
+               if (format != "matrix" ) {
+                       if(globaldata->getPrecision() != ""){
+                               convert(globaldata->getPrecision(), precision); 
+                       }
+               
+                       if(globaldata->getCutOff() != ""){
+                               convert(globaldata->getCutOff(), cutoff);       
+                               cutoff += (5 / (precision * 10.0));
+                       }
+                       read->setCutoff(cutoff);
        
-               if(globaldata->getNameFile() != ""){    
-                       nameMap = new NameAssignment(globaldata->getNameFile());
-                       nameMap->readMap(1,2);
-               }
-               else{
-                       nameMap = NULL;
+                       if(globaldata->getNameFile() != ""){    
+                               nameMap = new NameAssignment(globaldata->getNameFile());
+                               nameMap->readMap(1,2);
+                       }
+                       else{
+                               nameMap = NULL;
+                       }
                }
                        
        }
@@ -57,9 +68,22 @@ ReadDistCommand::~ReadDistCommand(){
 //**********************************************************************************************************************
 int ReadDistCommand::execute(){
        try {
-               read->read(nameMap);
-               globaldata->setListVector(read->getListVector());
-               globaldata->setSparseMatrix(read->getMatrix());
+               
+               if (format == "matrix") {
+                       ifstream in;
+                       openInputFile(filename, in);
+                       matrix = new FullMatrix(in); //reads the matrix file
+                       //memory leak prevention
+                       //if (globaldata->gMatrix != NULL) { delete globaldata->gMatrix;  }
+                       globaldata->gMatrix = matrix; //save matrix for coverage commands
+               }else {
+                       read->read(nameMap);
+                       //to prevent memory leak
+                       if (globaldata->gListVector != NULL) { delete globaldata->gListVector;  }
+                       globaldata->gListVector = read->getListVector();
+                       if (globaldata->gSparseMatrix != NULL) { delete globaldata->gSparseMatrix;  }
+                       globaldata->gSparseMatrix = read->getMatrix();
+               }
                return 0;
        }
        catch(exception& e) {
@@ -70,4 +94,4 @@ int ReadDistCommand::execute(){
                cout << "An unknown error has occurred in the ReadDistCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
                exit(1);
        }
-}
\ No newline at end of file
+}