]> git.donarmstrong.com Git - mothur.git/blobdiff - cooccurrencecommand.cpp
fixed rowtotal and columntotal
[mothur.git] / cooccurrencecommand.cpp
index f1f849af255004e901777f32fb72aa7bd5e7a129..465ddced27b92345392d2752657bc1e3b7453f58 100644 (file)
@@ -272,20 +272,17 @@ int CooccurrenceCommand::execute(){
 int CooccurrenceCommand::getCooccurrence(vector<SharedRAbundVector*>& thisLookUp, ofstream& out){
     try {
         int numOTUS = thisLookUp[0]->getNumBins();
-        vector< vector<int> > initmatrix; initmatrix.resize(thisLookUp.size());
         vector< vector<int> > co_matrix; co_matrix.resize(thisLookUp[0]->getNumBins());
         for (int i = 0; i < thisLookUp[0]->getNumBins(); i++) { co_matrix[i].resize((thisLookUp.size()), 0); }
-        for (int i = 0; i < thisLookUp.size(); i++) { initmatrix[i].resize((thisLookUp[i]->getNumBins()), 0); }
         vector<int> columntotal; columntotal.resize(thisLookUp.size(), 0);
         vector<int> rowtotal; rowtotal.resize(numOTUS, 0);
         
-        for (int i = 0; i < thisLookUp.size(); i++) {
-            for (int j = 0; j < thisLookUp[i]->getNumBins(); j++) {
+        for (int i = 0; i < thisLookUp.size(); i++) { //nrows in the shared file
+            for (int j = 0; j < thisLookUp[i]->getNumBins(); j++) { //cols of original shared file
                 if (m->control_pressed) { return 0; }
                 int abund = thisLookUp[i]->getAbundance(j);
                 
                 if(abund > 0) {
-                    initmatrix[i][j] = 1;
                     co_matrix[j][i] = 1;
                     rowtotal[j]++;
                     columntotal[i]++;
@@ -299,8 +296,6 @@ int CooccurrenceCommand::getCooccurrence(vector<SharedRAbundVector*>& thisLookUp
         int ncols = thisLookUp.size();//groups
         double initscore = 0.0;
         
-        vector<int> columntotal; columntotal.resize(ncols, 0);
-        vector<int> rowtotal; rowtotal.resize(nrows, 0);
         vector<double> stats;
         double probabilityMatrix[ncols * nrows];
         vector<vector<int> > nullmatrix(nrows, vector<int>(ncols, 0));
@@ -396,11 +391,11 @@ int CooccurrenceCommand::getCooccurrence(vector<SharedRAbundVector*>& thisLookUp
         }
         
         
-        
-        if (metric == "cscore") { initscore = trial.calc_c_score(initmatrix, rowtotal, ncols, nrows); }
-        else if (metric == "checker") { initscore = trial.calc_checker(initmatrix, rowtotal, ncols, nrows); }
+        //co_matrix is the transposed shared file, initmatrix is the original shared file
+        if (metric == "cscore") { initscore = trial.calc_c_score(co_matrix, rowtotal, ncols, nrows); }
+        else if (metric == "checker") { initscore = trial.calc_checker(co_matrix, rowtotal, ncols, nrows); }
         else if (metric == "vratio") { initscore = trial.calc_vratio(nrows, ncols, rowtotal, columntotal); }
-        else if (metric == "combo") { initscore = trial.calc_combo(nrows, ncols, initmatrix); }
+        else if (metric == "combo") { initscore = trial.calc_combo(nrows, ncols, co_matrix); }
         else { m->mothurOut("[ERROR]: No metric selected!\n"); m->control_pressed = true; return 1; }
         
         m->mothurOut("Initial c score: " + toString(initscore)); m->mothurOutEndLine();
@@ -550,7 +545,7 @@ int CooccurrenceCommand::getCooccurrence(vector<SharedRAbundVector*>& thisLookUp
             
             //swap_checkerboards takes the original matrix and swaps checkerboards
             else if(matrix == "sim9") {
-                trial.swap_checkerboards (initmatrix, rowtotal, columntotal, ncols, nrows);
+                trial.swap_checkerboards (co_matrix, rowtotal, columntotal, ncols, nrows);
             }
             else {
                 m->mothurOut("[ERROR]: No null model selected!\n\n"); m->control_pressed = true;