X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=coverage.cpp;h=6b514fbc2e47a40c8312ecfa206bc4d9e04a1e50;hb=81ff02ef4064fe4dec986ea3110c1cb8e1285fe6;hp=e7baf001fefe4d5de552c1cd6362eaa2b1333d2c;hpb=42b802c0006d8b13bd5b27ea48d032a85d3f2102;p=mothur.git diff --git a/coverage.cpp b/coverage.cpp index e7baf00..6b514fb 100644 --- a/coverage.cpp +++ b/coverage.cpp @@ -7,24 +7,92 @@ * */ +/* This class library coverage at the given distances 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 "coverage.h" //********************************************************************************************************************** -vector< vector > Coverage::getValues(FullMatrix*, float) { - try { +Coverage::Coverage() { globaldata = GlobalData::getInstance(); - numGroups = globaldata->Groups.size(); + numUserGroups = globaldata->Groups.size(); + numGroups = globaldata->gGroupmap->getNumGroups(); +} + +//********************************************************************************************************************** +void Coverage::getValues(FullMatrix* matrix, vector< vector< vector > >& data, vector dist, string mode) { + try { + vector min; + vector groups; //initialize data - data.resize(numGroups); + data.resize(dist.size()); for (int l = 0; l < data.size(); l++) { - data[l].push_back(0.0); + data[l].resize(numGroups); + for (int k = 0; k < data[l].size(); k++) { + data[l][k].push_back(0.0); + } } /**************************************/ - //get the minumums for each comparision + //get the minimums for each comparision /**************************************/ - return data; + int count = 0; + int a = 0; + int b = 0; + for (int i = 0; i < numGroups; i++) { + for (int j = 0; j < numGroups; j++) { + + //is this "box" one hte user wants analyzed? + if ((inUsersGroups(globaldata->gGroupmap->namesOfGroups[i], globaldata->Groups) == true) && (inUsersGroups(globaldata->gGroupmap->namesOfGroups[j], globaldata->Groups) == true)) { + + if (mode == "random") { + //create random matrix for this comparison + matrix->shuffle(globaldata->gGroupmap->namesOfGroups[i], globaldata->gGroupmap->namesOfGroups[j]); + } + + min = matrix->getMins(count); //returns vector of mins for "box" requested ie. groups A, B, 0 = AA, 1 = AB, 2 = BA, 3 = BB; + + //find the coverage at this distance + sort(min.begin(), min.end()); + + //loop through each distance and fill data + for (int k = 0; k < data.size(); k++) { + + int index = -1; + //find index in min where value is higher than d + for (int m = 0; m < min.size(); m++) { + if (min[m] > dist[k]) { index = m; break; } + } + + // if you don't find one than all the mins are less than d + if (index == -1) { index = min.size(); } + + //save value in data + data[k][a][b] = 1.0 - ((min.size()-index)/(float)min.size()); + + } + + //move to next box + if (b < numUserGroups-1) { b++; } + else{ //you are moving to a new row of "boxes" + b = 0; + a++; + } + + count++; + + if (mode == "random") { + //restore matrix to original form for next shuffle + matrix->restore(); + } + } + } + } + } catch(exception& e) { cout << "Standard Error: " << e.what() << " has occurred in the Coverage class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";