5 * Created by Sarah Westcott on 3/9/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 /* This class library coverage at the given distances of the Cramer-von Mises statistic.
11 you may refer to the "Integration of Microbial Ecology and Statistics: A Test To Compare Gene Libraries"
12 paper in Applied and Environmental Microbiology, Sept. 2004, p. 5485-5492 0099-2240/04/$8.00+0
13 DOI: 10.1128/AEM.70.9.5485-5492.2004 Copyright 2004 American Society for Microbiology for more information. */
18 //**********************************************************************************************************************
19 Coverage::Coverage() {
20 globaldata = GlobalData::getInstance();
21 numUserGroups = globaldata->Groups.size();
22 numGroups = globaldata->gGroupmap->getNumGroups();
25 //**********************************************************************************************************************
26 void Coverage::getValues(FullMatrix* matrix, vector< vector< vector<float> > >& data, vector<float> dist, string mode) {
29 vector<string> groups;
32 data.resize(dist.size());
33 for (int l = 0; l < data.size(); l++) {
34 data[l].resize(numGroups);
35 for (int k = 0; k < data[l].size(); k++) {
36 data[l][k].push_back(0.0);
40 /**************************************/
41 //get the minimums for each comparision
42 /**************************************/
46 for (int i = 0; i < numGroups; i++) {
47 for (int j = 0; j < numGroups; j++) {
49 //is this "box" one hte user wants analyzed?
50 if ((inUsersGroups(globaldata->gGroupmap->namesOfGroups[i], globaldata->Groups) == true) && (inUsersGroups(globaldata->gGroupmap->namesOfGroups[j], globaldata->Groups) == true)) {
52 if (mode == "random") {
53 //create random matrix for this comparison
54 matrix->shuffle(globaldata->gGroupmap->namesOfGroups[i], globaldata->gGroupmap->namesOfGroups[j]);
57 min = matrix->getMins(count); //returns vector of mins for "box" requested ie. groups A, B, 0 = AA, 1 = AB, 2 = BA, 3 = BB;
59 //find the coverage at this distance
60 sort(min.begin(), min.end());
62 //loop through each distance and fill data
63 for (int k = 0; k < data.size(); k++) {
66 //find index in min where value is higher than d
67 for (int m = 0; m < min.size(); m++) {
68 if (min[m] > dist[k]) { index = m; break; }
71 // if you don't find one than all the mins are less than d
72 if (index == -1) { index = min.size(); }
75 data[k][a][b] = 1.0 - ((min.size()-index)/(float)min.size());
80 if (b < numUserGroups-1) { b++; }
81 else{ //you are moving to a new row of "boxes"
88 if (mode == "random") {
89 //restore matrix to original form for next shuffle
98 cout << "Standard Error: " << e.what() << " has occurred in the Coverage class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
102 cout << "An unknown error has occurred in the Coverage class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
106 //**********************************************************************************************************************