]> git.donarmstrong.com Git - mothur.git/blobdiff - readdistcommand.cpp
a few modifications for 1.9
[mothur.git] / readdistcommand.cpp
index c83ed8a9a6031663869176a3dda21923229da03a..bcecb7844e8a0348180884fbdb54993c286c53ac 100644 (file)
@@ -22,7 +22,7 @@ ReadDistCommand::ReadDistCommand(string option) {
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"phylip", "column", "name", "cutoff", "precision", "group","outputdir","inputdir"};
+                       string Array[] =  {"phylip", "column", "name", "cutoff", "precision", "group","outputdir","inputdir","sim"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -119,9 +119,13 @@ ReadDistCommand::ReadDistCommand(string option) {
                        // ...at some point should added some additional type checking...
                        //get user cutoff and precision or use defaults
                        string temp;
-                       temp = validParameter.validFile(parameters, "precision", false);                        if (temp == "not found") { temp = "100"; }
+                       temp = validParameter.validFile(parameters, "precision", false);                if (temp == "not found") { temp = "100"; }
                        convert(temp, precision); 
                        
+                       temp = validParameter.validFile(parameters, "sim", false);                              if (temp == "not found") { temp = "F"; }
+                       sim = isTrue(temp); 
+                       globaldata->sim = sim;
+                       
                        temp = validParameter.validFile(parameters, "cutoff", false);                   if (temp == "not found") { temp = "10"; }
                        convert(temp, cutoff); 
                        cutoff += (5 / (precision * 10.0));
@@ -166,11 +170,12 @@ ReadDistCommand::ReadDistCommand(string option) {
 
 void ReadDistCommand::help(){
        try {
-               m->mothurOut("The read.dist command parameter options are phylip or column, group, name, cutoff and precision\n");
+               m->mothurOut("The read.dist command parameter options are phylip or column, group, name, sim, cutoff and precision\n");
                m->mothurOut("The read.dist command can be used in two ways.  The first is to read a phylip or column and run the cluster command\n");
                m->mothurOut("For this use the read.dist command should be in the following format: \n");
                m->mothurOut("read.dist(phylip=yourDistFile, name=yourNameFile, cutoff=yourCutoff, precision=yourPrecision) \n");
                m->mothurOut("The phylip or column parameter is required, but only one may be used.  If you use a column file the name filename is required. \n");
+               m->mothurOut("The sim parameter is used to indicate that your distance file contains similiarity values instead of distance values. The default is false, if sim=true then mothur will convert the similairity values to distances. \n");
                m->mothurOut("If you do not provide a cutoff value 10.00 is assumed. If you do not provide a precision value then 100 is assumed.\n");
                m->mothurOut("The second way to use the read.dist command is to read a phylip or column and a group, so you can use the libshuff command.\n");
                m->mothurOut("For this use the read.dist command should be in the following format: \n");
@@ -211,6 +216,8 @@ int ReadDistCommand::execute(){
                        matrix = new FullMatrix(in); //reads the matrix file
                        in.close();
                        
+                       if (m->control_pressed) { delete groupMap; delete matrix; return 0; }
+                       
                        //if files don't match...
                        if (matrix->getNumSeqs() < groupMap->getNumSeqs()) {  
                                m->mothurOut("Your distance file contains " + toString(matrix->getNumSeqs()) + " sequences, and your group file contains " + toString(groupMap->getNumSeqs()) + " sequences.");  m->mothurOutEndLine();                         
@@ -223,6 +230,8 @@ int ReadDistCommand::execute(){
                                openOutputFile(newGroupFile, outGroups);
                                
                                for (int i = 0; i < matrix->getNumSeqs(); i++) {
+                                       if (m->control_pressed) { delete groupMap; delete matrix; outGroups.close(); remove(newGroupFile.c_str()); return 0; }
+                                       
                                        Names temp = matrix->getRowInfo(i);
                                        outGroups << temp.seqName << '\t' << temp.groupName << endl;
                                }
@@ -238,6 +247,8 @@ int ReadDistCommand::execute(){
                                groupMap = new GroupMap(groupfile);
                                groupMap->readMap();
                                
+                               if (m->control_pressed) { delete groupMap; delete matrix; remove(newGroupFile.c_str()); return 0; }
+       
                                globaldata->gGroupmap = groupMap;
                        }
                        
@@ -248,41 +259,19 @@ int ReadDistCommand::execute(){
                } else {
                        read->read(nameMap);
                        //to prevent memory leak
-
+                       
+                       if (m->control_pressed) {  return 0; }
+               
                        if (globaldata->gListVector != NULL) {  delete globaldata->gListVector;  }
                        globaldata->gListVector = read->getListVector();
 
                        if (globaldata->gSparseMatrix != NULL) { delete globaldata->gSparseMatrix;  }
                        globaldata->gSparseMatrix = read->getMatrix();
                        numDists = globaldata->gSparseMatrix->getNNodes();
-       //cout << "matrix contains " << numDists << " distances." << endl;
-                       
-    /*  int lines = cutoff / (1.0/precision);
-      vector<float> dist_cutoff(lines+1,0);
-                       for (int i = 0; i <= lines;i++) {       
-       dist_cutoff[i] = (i + 0.5) / precision; 
-      } 
-      vector<int> dist_count(lines+1,0);
-      list<PCell>::iterator currentCell;
-      SparseMatrix* smatrix = globaldata->gSparseMatrix;
-               for (currentCell = smatrix->begin(); currentCell != smatrix->end(); currentCell++) {
-                               for (int i = 0; i <= lines;i++) {       
-                                       if (currentCell->dist < dist_cutoff[i]) {
-                                               dist_count[i]++;
-            break;
-          }
-        }
-                       }
-*/
-     // string dist_string = "Dist:";
-    //  string count_string = "Count: ";
-                       //for (int i = 0; i <= lines;i++) {     
-       //dist_string = dist_string.append("\t").append(toString(dist_cutoff[i]));
-      //       count_string = count_string.append("\t").append(toString(dist_count[i]));
-               //      }
-      //m->mothurOut(dist_string); m->mothurOutEndLine(); m->mothurOut(count_string); m->mothurOutEndLine();
                }
                
+               if (m->control_pressed) {  return 0; }
+
                if (outputNames.size() != 0) {
                        m->mothurOutEndLine();
                        m->mothurOut("Output File Name: "); m->mothurOutEndLine();