]> git.donarmstrong.com Git - mothur.git/blob - qstat.cpp
started shared utilities, updates to venn and heatmap added tree.groups command
[mothur.git] / qstat.cpp
1 /*
2  *  qstat.cpp
3  *  Mothur
4  *
5  *  Created by Thomas Ryabin on 3/4/09.
6  *  Copyright 2009 __MyCompanyName__. All rights reserved.
7  *
8  */
9
10 #include "qstat.h"
11
12
13 /***********************************************************************/
14
15 EstOutput QStat::getValues(SAbundVector* rank){
16         try {
17                 
18                 /*test data VVV
19                 int dstring[] = {0,0,1,4,2,0,2,1,1,1,1,1,0,1,1,2,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
20                 vector<int> dvec;
21                 for(int i = 0; i < 171; i++)
22                         dvec.push_back(dstring[i]);
23                 int mr = 170;
24                 int nb = 29;
25                 int ns = 884;
26                 SAbundVector rankw = SAbundVector(dvec, mr,nb,ns);
27                 SAbundVector *rank = &rankw;*/
28                 data.resize(1,0);
29                 int numSpec = rank->getNumBins();
30                 int r1 = -1;
31                 int r3 = -1;
32                 int r1Ind = 0;
33                 int r3Ind = 0;
34                 int sumSpec = 0;
35                 int iqSum = 0;
36                 for(int i = 1; i < rank->size(); i++)
37                 {
38                         if(r1 != -1 && r3 != -1)
39                                 i = rank->size();
40                                 
41                         sumSpec += rank->get(i);
42                         
43                         if(r1 == -1 && sumSpec >= numSpec*.25)
44                         {
45                                 r1 = rank->get(i);
46                                 r1Ind = i;
47                         }
48                         else if(r3 == -1 && sumSpec >= numSpec*.75)
49                         {
50                                 r3 = rank->get(i);
51                                 r3Ind = i;
52                         }
53                         else if(sumSpec >= numSpec*.25 && sumSpec < numSpec*.75)
54                                 iqSum += rank->get(i);
55                 }
56                 
57                 double qstat = (.5*r1 + iqSum + .5*r3)/log((double)r3Ind/r1Ind);
58                 //cout << "QStat:\nQStatistic = " << qstat << "\n\n";
59                 
60                 data[0] = qstat;
61                 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
62                 
63                 return data;
64         }
65         catch(exception& e) {
66                 cout << "Standard Error: " << e.what() << " has occurred in the NPShannon class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
67                 exit(1);
68         }
69         catch(...) {
70                 cout << "An unknown error has occurred in the NPShannon class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
71                 exit(1);
72         }       
73 }
74
75 /***********************************************************************/
76