]> git.donarmstrong.com Git - mothur.git/blob - coverage.cpp
libshuff and updated help to include libshuff and modifications to read.dist.
[mothur.git] / coverage.cpp
1 /*
2  *  coverage.cpp
3  *  Mothur
4  *
5  *  Created by Sarah Westcott on 3/9/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "coverage.h"
11
12 //**********************************************************************************************************************
13 Coverage::Coverage() {
14                 globaldata = GlobalData::getInstance();
15                 numUserGroups = globaldata->Groups.size();
16                 numGroups = globaldata->gGroupmap->getNumGroups();
17 }
18
19 //**********************************************************************************************************************
20 void Coverage::getValues(FullMatrix* matrix, vector< vector< vector<float> > >& data, vector<float> dist, string mode) {
21         try {
22                 vector<float> min;
23                 vector<string> groups;
24                 
25                 //initialize data
26                 data.resize(dist.size());
27                 for (int l = 0; l < data.size(); l++) {
28                         data[l].resize(numGroups);
29                         for (int k = 0; k < data[l].size(); k++) {
30                                 data[l][k].push_back(0.0);
31                         }
32                 }
33
34                 /**************************************/
35                 //get the minimums for each comparision
36                 /**************************************/
37                 int count = 0;
38                 int a = 0;
39                 int b = 0;
40                 for (int i = 0; i < numGroups; i++) {
41                         for (int j = 0; j < numGroups; j++) {
42                         
43                                 //is this "box" one hte user wants analyzed?
44                                 if ((inUsersGroups(globaldata->gGroupmap->namesOfGroups[i], globaldata->Groups) == true) && (inUsersGroups(globaldata->gGroupmap->namesOfGroups[j], globaldata->Groups) == true)) {
45                                         
46                                         if (mode == "random") {
47                                                 //create random matrix for this comparison
48                                                 matrix->shuffle(globaldata->gGroupmap->namesOfGroups[i], globaldata->gGroupmap->namesOfGroups[j]);
49                                         }
50                         
51                                         min = matrix->getMins(count);  //returns vector of mins for "box" requested ie. groups A, B, 0 = AA, 1 = AB, 2 = BA, 3 = BB;
52
53                                         //find the coverage at this distance
54                                         sort(min.begin(), min.end());
55                                         
56                                         //loop through each distance and fill data
57                                         for (int k = 0; k < data.size(); k++) {
58                                         
59                                                 int index = -1;
60                                                 //find index in min where value is higher than d
61                                                 for (int m = 0; m < min.size(); m++) {
62                                                         if (min[m] > dist[k])   { index = m; break;     }
63                                                 }
64                                         
65                                                 // if you don't find one than all the mins are less than d
66                                                 if (index == -1) { index = min.size();  }
67                                         
68                                                 //save value in data
69                                                 data[k][a][b] = 1.0 - ((min.size()-index)/(float)min.size());
70         
71                                         }
72                                         
73                                         //move to next box
74                                         if (b < numUserGroups-1) {  b++;  }
75                                         else{ //you are moving to a new row of "boxes"
76                                                 b = 0;
77                                                 a++;
78                                         }
79
80                                         count++;
81                                         
82                                         if (mode == "random") {
83                                                 //restore matrix to original form for next shuffle
84                                                 matrix->restore();
85                                         }
86                                 }
87                         }
88                 }
89                 
90         }
91         catch(exception& e) {
92                 cout << "Standard Error: " << e.what() << " has occurred in the Coverage class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
93                 exit(1);
94         }
95         catch(...) {
96                 cout << "An unknown error has occurred in the Coverage class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
97                 exit(1);
98         }       
99 }
100 //**********************************************************************************************************************
101
102