]> git.donarmstrong.com Git - mothur.git/blob - qstat.cpp
changed random forest output filename
[mothur.git] / qstat.cpp
1 /*
2  *  qstat.cpp
3  *  Mothur
4  *
5  *  Created by Thomas Ryabin on 3/4/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. 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                 double sumSpec = 0;
35                 double iqSum = 0;
36                 for(int i = 1; i < rank->size(); i++) {
37                         if(r1 != -1 && r3 != -1)
38                                 i = rank->size();
39                                 
40                         sumSpec += rank->get(i);
41                         
42                         if(r1 == -1 && sumSpec >= numSpec*.25) {
43                                 r1 = rank->get(i);
44                                 r1Ind = i;
45                         }
46                         else if(r3 == -1 && sumSpec >= numSpec*.75) {
47                                 r3 = rank->get(i);
48                                 r3Ind = i;
49                         }
50                         else if(sumSpec >= numSpec*.25 && sumSpec < numSpec*.75)
51                                 iqSum += rank->get(i);
52                 }
53                 
54                 double qstat = (.5*r1 + iqSum + .5*r3)/log((double)r3Ind/r1Ind);
55                 
56                 data[0] = qstat;
57                 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
58                 
59                 return data;
60         }
61         catch(exception& e) {
62                 m->errorOut(e, "QStat", "getValues");
63                 exit(1);
64         }
65 }
66
67 /***********************************************************************/
68