]> git.donarmstrong.com Git - mothur.git/commitdiff
Merge remote-tracking branch 'mothur/master'
authorPat Schloss <pschloss@umich.edu>
Tue, 1 May 2012 18:01:13 +0000 (14:01 -0400)
committerPat Schloss <pschloss@umich.edu>
Tue, 1 May 2012 18:01:13 +0000 (14:01 -0400)
cooccurrencecommand.cpp
matrixoutputcommand.cpp
treegroupscommand.cpp
trialSwap2.cpp

index 8c763e275e5d9cebf885794fafdc3c9f44f0cb6a..75b87fae4303f161a1f75fb632e831672a80e29d 100644 (file)
@@ -494,6 +494,7 @@ int CooccurrenceCommand::getCooccurrence(vector<SharedRAbundVector*>& thisLookUp
             //swap_checkerboards takes the original matrix and swaps checkerboards
             else if(matrix == "sim9") {
                 trial.swap_checkerboards (co_matrix, ncols, nrows);
+                nullmatrix = co_matrix;
             }
             else {
                 m->mothurOut("[ERROR]: No null model selected!\n\n"); m->control_pressed = true;
index 0bfb0098eba2de2600ab4939da8b3e3197b1b4fa..c879d1b621b871a5f7a9e3dbf48df70a7d928320 100644 (file)
@@ -298,13 +298,6 @@ int MatrixOutputCommand::execute(){
                set<string> userLabels = labels;
                                        
                if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups.  I cannot run the command."); m->mothurOutEndLine(); delete input; for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } return 0;}
-               
-               numGroups = lookup.size();
-               lines.resize(processors);
-               for (int i = 0; i < processors; i++) {
-                       lines[i].start = int (sqrt(float(i)/float(processors)) * numGroups);
-                       lines[i].end = int (sqrt(float(i+1)/float(processors)) * numGroups);
-               }       
         
         if (subsample) { 
             if (subsampleSize == -1) { //user has not set size, set size = smallest samples size
@@ -330,8 +323,17 @@ int MatrixOutputCommand::execute(){
                 lookup = temp;
                 m->setGroups(Groups);
             }
+            
+            if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups.  I cannot run the command."); m->mothurOutEndLine(); m->control_pressed = true; delete input; return 0; }
         }
-               
+        
+               numGroups = lookup.size();
+        lines.resize(processors);
+               for (int i = 0; i < processors; i++) {
+                       lines[i].start = int (sqrt(float(i)/float(processors)) * numGroups);
+                       lines[i].end = int (sqrt(float(i+1)/float(processors)) * numGroups);
+               }       
+        
                if (m->control_pressed) { delete input; for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } m->clearGroups(); return 0;  }
                                
                //as long as you are not at the end of the file or done wih the lines you want
index 2542431f111f85b5bc344d93388662364045a509..c26199d673088b5b64872b672ab8e64ca780e616 100644 (file)
@@ -570,13 +570,6 @@ vector< vector<double> > TreeGroupCommand::makeSimsDist() {
 int TreeGroupCommand::makeSimsShared() {
        try {
         
-        numGroups = lookup.size();
-               lines.resize(processors);
-               for (int i = 0; i < processors; i++) {
-                       lines[i].start = int (sqrt(float(i)/float(processors)) * numGroups);
-                       lines[i].end = int (sqrt(float(i+1)/float(processors)) * numGroups);
-               }       
-        
         if (subsample) { 
             if (subsampleSize == -1) { //user has not set size, set size = smallest samples size
                 subsampleSize = lookup[0]->getNumSeqs();
@@ -601,8 +594,17 @@ int TreeGroupCommand::makeSimsShared() {
                 lookup = temp;
                 m->setGroups(Groups);
             }
+            
+            if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups.  I cannot run the command."); m->mothurOutEndLine(); m->control_pressed = true; return 0; }
         }
         
+        numGroups = lookup.size();
+               lines.resize(processors);
+               for (int i = 0; i < processors; i++) {
+                       lines[i].start = int (sqrt(float(i)/float(processors)) * numGroups);
+                       lines[i].end = int (sqrt(float(i+1)/float(processors)) * numGroups);
+               }       
+        
                set<string> processedLabels;
                set<string> userLabels = labels;
                
index a0c3210c33dd49c97274b4ad555efe2a75f9fede..2d25e835cbd5608bc1c4f4c6cc67397155f2c834 100644 (file)
@@ -195,20 +195,22 @@ int TrialSwap2::calc_combo (int nrows, int ncols, vector<vector<int> > &nullmatr
 int TrialSwap2::swap_checkerboards (vector<vector<int> > &co_matrix, int ncols, int nrows)
 {
     try {
-        //int ncols = co_matrix[0].size(); int nrows = co_matrix.size();
-        int i, j, k, l;
-        i = m->getRandomIndex(nrows-1);
-        while((j = m->getRandomIndex(nrows-1) ) == i ) {;if (m->control_pressed) { return 0; }}
-        k = m->getRandomIndex(ncols-1);
-        while((l = m->getRandomIndex(ncols-1)) == k ) {;if (m->control_pressed) { return 0; }}
-        
-        if((co_matrix[i][k]*co_matrix[j][l]==1 && co_matrix[i][l]+co_matrix[j][k]==0)||(co_matrix[i][k]+co_matrix[j][l]==0 && co_matrix[i][l]*co_matrix[j][k]==1)) //checking for checkerboard value and swap
-        {
-            co_matrix[i][k]=1-co_matrix[i][k];
-            co_matrix[i][l]=1-co_matrix[i][l];
-            co_matrix[j][k]=1-co_matrix[j][k];
-            co_matrix[j][l]=1-co_matrix[j][l];
-            
+        //do 100 runs to make sure enough swaps are happening. This does NOT mean that there will be 1000 swaps, but that is the theoretical max.
+        for(int a=0;a<1000;a++){
+            int i, j, k, l;
+            i = m->getRandomIndex(nrows-1);
+            while((j = m->getRandomIndex(nrows-1) ) == i ) {;if (m->control_pressed) { return 0; }}
+            k = m->getRandomIndex(ncols-1);
+            while((l = m->getRandomIndex(ncols-1)) == k ) {;if (m->control_pressed) { return 0; }}
+
+            if((co_matrix[i][k]*co_matrix[j][l]==1 && co_matrix[i][l]+co_matrix[j][k]==0)||(co_matrix[i][k]+co_matrix[j][l]==0 && co_matrix[i][l]*co_matrix[j][k]==1)) //checking for checkerboard value and swap
+            {
+                co_matrix[i][k]=1-co_matrix[i][k];
+                co_matrix[i][l]=1-co_matrix[i][l];
+                co_matrix[j][k]=1-co_matrix[j][k];
+                co_matrix[j][l]=1-co_matrix[j][l];
+
+            }
         }
         
         return 0;