]> git.donarmstrong.com Git - mothur.git/blobdiff - trialSwap2.cpp
added count file to get.groups and remove.groups. added shortcut parameter to classif...
[mothur.git] / trialSwap2.cpp
index a0c3210c33dd49c97274b4ad555efe2a75f9fede..71c3027db2c8bbe97265cb40af839c6a81a17b33 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;
@@ -289,6 +291,34 @@ double TrialSwap2::t_test (double initialscore, int runs, double nullMean, vecto
     }
 }
 /**************************************************************************************************/
+double TrialSwap2::getSD (int runs, vector<double> scorevec, double nullMean)
+{
+    try{
+        double sum = 0;
+        for(int i=0;i<runs;i++)
+            {
+                if (m->control_pressed) { return 0; }
+                sum += pow((scorevec[i] - nullMean),2);
+            }
+        return sqrt( (1/double(runs)) * sum );
+    }
+    catch(exception& e) {
+        m->errorOut(e, "TrialSwap2", "getSD");
+        exit(1);
+    }
+}
+/**************************************************************************************************/
+double TrialSwap2::get_zscore (double sd, double nullMean, double initscore)
+{
+    try {
+        return (initscore - nullMean) / sd;
+    }
+    catch(exception& e) {
+        m->errorOut(e, "TrialSwap2", "get_zscore");
+        exit(1);
+    }
+}
+/**************************************************************************************************/
 int TrialSwap2::print_matrix(vector<vector<int> > &matrix, int nrows, int ncols)
 {
     try {