]> git.donarmstrong.com Git - mothur.git/blobdiff - libshuffcommand.cpp
fixed bug in read.tree updates help and validparameters strings, added ability for...
[mothur.git] / libshuffcommand.cpp
index 9ab9108f23ca4d63c3479bb8c6a27d27e08704ea..33a1a3ba0c4bf35e1ad005396a48b2a9c5c93add 100644 (file)
@@ -7,6 +7,12 @@
  *
  */
 
+/* This class is designed to implement an integral form of the Cramer-von Mises statistic.
+       you may refer to the "Integration of Microbial Ecology and Statistics: A Test To Compare Gene Libraries" 
+       paper in Applied and Environmental Microbiology, Sept. 2004, p. 5485-5492 0099-2240/04/$8.00+0  
+       DOI: 10.1128/AEM.70.9.5485-5492.2004 Copyright 2004 American Society for Microbiology for more information. */
+
+
 #include "libshuffcommand.h"
 
 //**********************************************************************************************************************
@@ -97,9 +103,11 @@ int LibShuffCommand::execute(){
                deltaValues.clear();
                deltaValues.resize(dist.size());                        
                
-               coverage->getValues(matrix, cValues, dist, "user");
+               coverage->getValues(matrix, cValues, dist);
+               
+               float distDiff = 0;
                
-               //loop through each distance and load rsumdelta
+               //loop through each distance and load sumdelta
                for (int p = 0; p < cValues.size(); p++) {      
                        //find delta values
                        int count = 0;
@@ -107,13 +115,16 @@ int LibShuffCommand::execute(){
                                for (int j = 0; j < numGroups; j++) {
                                        //don't save AA to AA
                                        if (i != j) {
-                                               //(Caa - Cab)^2
-                                               deltaValues[p].push_back( (abs(cValues[p][i][i]-cValues[p][i][j]) * abs(cValues[p][i][i]-cValues[p][i][j])) ); 
+                                               //(Caa - Cab)^2 * distDiff
+                                               deltaValues[p].push_back(((cValues[p][i][i]-cValues[p][i][j]) * (cValues[p][i][i]-cValues[p][i][j])) * distDiff); //* distDiff
                                                sumDelta[count] += deltaValues[p][count];
                                                count++;
                                        }
                                }
                        }
+                       if (p < cValues.size() - 1) {
+                               distDiff = dist[p+1] - dist[p]; 
+                       }
                }
                        
                printCoverageFile();
@@ -145,25 +156,18 @@ int LibShuffCommand::execute(){
                                        for (int j = 0; j < numGroups; j++) {
                                                //don't save AA to AA
                                                if (i != j) {
-                                                       //(Caa - Cab)^2
-                                                       rsumDelta[count][m] += ((abs(cValues[p][i][i]-cValues[p][i][j]) * abs(cValues[p][i][i]-cValues[p][i][j])));
+                                                       //rsumDelta[3][500] = the sum of the delta scores for BB-BC for random matrix # 500.
+                                                       rsumDelta[count][m] += cValues[p][i][j];  // where cValues[p][0][1] = delta value at distance p of AA-AB, cValues[p][1][2] = delta value at distance p of BB-BC. 
                                                        count++;
                                                }
                                        }
                                }
-                               
                        }
-//cout << "iter " << m << endl;
+
                        //clear out old Values
                        reading->update(m);
                        cValues.clear();
                        
-//cout << "random sum delta for iter " << m << endl;
-//for (int i = 0; i < rsumDelta.size(); i++) {
-//     cout << setprecision(6) << rsumDelta[i][m] << '\t';
-//}
-//cout << endl;
-
                }
                
                reading->finish();
@@ -320,6 +324,10 @@ void LibShuffCommand::setGroups() {
                //sort so labels match
                sort(globaldata->Groups.begin(), globaldata->Groups.end());
                
+               //sort
+               sort(globaldata->gGroupmap->namesOfGroups.begin(), globaldata->gGroupmap->namesOfGroups.end());
+
+               
                // number of comparisons i.e. with groups A,B,C = AA, AB, AC, BA, BB, BC...;
                for (int i=0; i<numGroups; i++) { 
                        for (int l = 0; l < numGroups; l++) {