]> git.donarmstrong.com Git - mothur.git/blobdiff - cooccurrencecommand.cpp
Merge remote-tracking branch 'mothur/master'
[mothur.git] / cooccurrencecommand.cpp
index fa9f7231228d92585edabe144d9434b04b5be058..85379d1a286f6a822a3a4a5fdb9525a9b7b5f2ca 100644 (file)
@@ -33,8 +33,16 @@ vector<string> CooccurrenceCommand::setParameters() {
 //**********************************************************************************************************************
 string CooccurrenceCommand::getHelpString(){   
        try {
-               string helpString = "help!";
-
+               string helpString = "The cooccurrence command calculates four metrics and tests their significance to assess whether presence-absence patterns are different than what one would expect by chance.";
+        helpString += "The cooccurrence command parameters are shared, metric, matrixmodel, iters, label and groups.";
+        helpString += "The matrixmodel parameter options are sim1, sim2, sim3, sim4, sim5, sim6, sim7, sim8 and sim9. Default=sim2";
+        helpString += "The metric parameter options are cscore, checker, combo and vratio. Default=cscore";
+        helpString += "The label parameter is used to analyze specific labels in your input.\n";
+               helpString += "The groups parameter allows you to specify which of the groups you would like analyzed.\n";
+        helpString += "The cooccurrence command should be in the following format: \n";
+               helpString += "cooccurrence(shared=yourSharedFile) \n";
+               helpString += "Example cooccurrence(shared=final.an.shared).\n";
+               helpString += "Note: No spaces between parameter labels (i.e. shared), '=' and parameters (i.e.yourShared).\n";
                return helpString;
        }
        catch(exception& e) {
@@ -128,7 +136,7 @@ CooccurrenceCommand::CooccurrenceCommand(string option) {
                                m->mothurOut("[ERROR]: " + metric + " is not a valid metric option for the cooccurrence command. Choices are cscore, checker, combo, vratio."); m->mothurOutEndLine(); abort = true; 
                        }
                        
-                       matrix = validParameter.validFile(parameters, "matrix", false);                         if (matrix == "not found") { matrix = "sim2"; }
+                       matrix = validParameter.validFile(parameters, "matrixmodel", false);                            if (matrix == "not found") { matrix = "sim2"; }
                        
                        if ((matrix != "sim1") && (matrix != "sim2") && (matrix != "sim3") && (matrix != "sim4") && (matrix != "sim5" ) && (matrix != "sim6" ) && (matrix != "sim7" ) && (matrix != "sim8" ) && (matrix != "sim9" )) {
                                m->mothurOut("[ERROR]: " + matrix + " is not a valid matrix option for the cooccurrence command. Choices are sim1, sim2, sim3, sim4, sim5, sim6, sim7, sim8, sim9."); m->mothurOutEndLine(); abort = true; 
@@ -245,6 +253,7 @@ int CooccurrenceCommand::execute(){
         
                //reset groups parameter 
                delete input; 
+        m->clearGroups(); 
 
         m->mothurOutEndLine();
                m->mothurOut("Output File Names: "); m->mothurOutEndLine();
@@ -263,14 +272,13 @@ int CooccurrenceCommand::execute(){
 int CooccurrenceCommand::getCooccurrence(vector<SharedRAbundVector*>& thisLookUp, ofstream& out){
        try {
         int numOTUS = thisLookUp[0]->getNumBins();
-        vector< vector<int> > initmatrix (thisLookUp.size());
-        vector< vector<int> > co_matrix (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(thisLookUp.size(), 0);
-        vector<int> rowtotal(numOTUS, 0);
+        vector<int> columntotal; columntotal.resize(thisLookUp.size(), 0);
+        vector<int> rowtotal; rowtotal.resize(numOTUS, 0);
         
-        int rowcount = 0;
         for (int i = 0; i < thisLookUp.size(); i++) {
                        for (int j = 0; j < thisLookUp[i]->getNumBins(); j++) {
                                if (m->control_pressed) { return 0; }                   
@@ -279,29 +287,20 @@ int CooccurrenceCommand::getCooccurrence(vector<SharedRAbundVector*>& thisLookUp
                                if(abund > 0) {
                                    initmatrix[i][j] = 1;
                     co_matrix[j][i] = 1;
-                    rowcount++;
-                    columntotal[j]++;
+                    rowtotal[j]++;
+                    columntotal[i]++;
                                }
                        }
-            rowtotal[i] = rowcount;
-            rowcount = 0;
         }
         
         //nrows is ncols of inital matrix. All the functions need this value. They assume the transposition has already taken place and nrows and ncols refer to that matrix.
         //comatrix and initmatrix are still vectors of vectors of ints as in the original script. The abundancevector is only what was read in ie not a co-occurrence matrix!
-        int ncols = numOTUS;//rows of inital matrix
-        int nrows = thisLookUp.size();//OTUs
+        int nrows = numOTUS;//rows of inital matrix
+        int ncols = thisLookUp.size();//groups
         double initscore = 0.0;
-        //transpose matrix
-        int newmatrows = ncols;
-        int newmatcols = nrows;
-      
-        //swap for transposed matrix
-        nrows = newmatrows;//ncols;
-        ncols = newmatcols;//nrows;
-        
-        vector<int> initcolumntotal(ncols, 0);
-        vector<int> initrowtotal(nrows, 0);
+                
+        vector<int> initcolumntotal; initcolumntotal.resize(ncols, 0);
+        vector<int> initrowtotal; initrowtotal.resize(nrows, 0);
         vector<double> stats;
                
         TrialSwap2 trial;
@@ -379,7 +378,7 @@ int CooccurrenceCommand::getCooccurrence(vector<SharedRAbundVector*>& thisLookUp
             }
             //
             //            
-            trial.update_row_col_totals(co_matrix, rowtotal, columntotal); 
+            //trial.update_row_col_totals(co_matrix, rowtotal, columntotal); 
             
             if (metric == "cscore") { 
                 stats.push_back(trial.calc_c_score(co_matrix, rowtotal));