]> git.donarmstrong.com Git - mothur.git/blob - calculator.h
fixed bug with trim.seqs- when a file is blank for a grouping mothur removed it,...
[mothur.git] / calculator.h
1 #ifndef CALCULATOR_H
2 #define CALCULATOR_H
3
4
5 #include "mothur.h"
6 #include "sabundvector.hpp"
7 #include "sharedsabundvector.h"
8 #include "rabundvector.hpp"
9 #include "uvest.h"
10 #include "mothurout.h"
11
12 /* The calculator class is the parent class for all the different estimators implemented in mothur except the tree calculators.
13 It has 2 pure functions EstOutput getValues(SAbundVector*), which works on a single group, and 
14 EstOutput getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2), which compares 2 groups. */ 
15
16
17 typedef vector<double> EstOutput;
18
19 /***********************************************************************/
20
21 class Calculator {
22
23 public:
24         Calculator(){ m = MothurOut::getInstance(); needsAll = false; }
25         virtual ~Calculator(){};
26         Calculator(string n, int c, bool f) : name(n), cols(c), multiple(f) { m = MothurOut::getInstance(); needsAll = false; };
27         Calculator(string n, int c, bool f, bool a) : name(n), cols(c), multiple(f), needsAll(a) { m = MothurOut::getInstance(); };
28         virtual EstOutput getValues(SAbundVector*) = 0; 
29         virtual EstOutput getValues(vector<SharedRAbundVector*>) = 0;
30         virtual void print(ostream& f)  { f.setf(ios::fixed, ios::floatfield); f.setf(ios::showpoint);
31                                                                           f << data[0]; for(int i=1;i<data.size();i++){ f << '\t' << data[i];   }}
32         virtual string getName()                {       return name;    }
33         virtual int getCols()           {       return cols;    }
34         virtual bool getMultiple()  {   return multiple;   }
35         virtual bool getNeedsAll()  {   return needsAll;   }
36 protected:
37         MothurOut* m;
38         EstOutput data;
39         string name;
40         int cols;
41         bool multiple;
42         bool needsAll;
43
44 };
45
46 /**************************************************************************************************/
47 /*This Class holds all of the methods that manipulate vectors.
48 These methods are used in the other classes.
49 This class must be included if any of the other classes are to be used. */
50
51 class VecCalc
52 {
53         // The methods seen in the order here is how they are ordered throughout the class.
54         public:
55                 VecCalc(){};
56                 //void printElements(vector<double>); //This prints the values of the vector on one line with a space between each value.
57                 //void printElements(vector<string>); //This prints the values of the vector on one line with a space between each value.
58                 //int findString(vector<string>, string);//This returns the index of the given string in the given <string> vector, if the string does not exist in the vector it returns -1.
59                 //double mean(vector<double>); //This returns the mean value of the vector.
60                 //double stError(vector<double>); //This returns the standard error of the vector.
61                 int sumElements(vector<int>, int);
62                 int sumElements(vector<int>);
63                 double sumElements(vector<double>); //This returns the sum of all the values in the vector.
64                 double sumElements(vector<double>, int); //This returns the sum of all the values in the vector excluding those whose index is before the given index.  
65                 //double findMax(vector<double>); //This returns the maximum value in the vector.
66                 int numNZ(vector<int>); //This returns the number of non-zero values in the vector.
67                 double numNZ(vector<double>); //This returns the number of non-zero values in the vector.
68                 //double numPos(vector<double>); //This returns the number of positive values in the vector.
69                 //double findMaxDiff(vector<double>, vector<double>); //This returns the absolute value of the maximum difference between the two vectors.
70                 //double findDStat(vector<double>, vector<double>, double); //This returns the D-Statistic of the two vectors with the given total number of species.
71                 //vector<int> findQuartiles(vector<double>); //This returns a vector with the first element being the index of the lower quartile of the vector and the second element being the index of the upper quartile of the vector.
72                 //vector<double> add(vector<double>, double); //This adds the given number to every element in the given vector and returns the new vector.
73                 //vector<double> multiply(vector<double>, double); //This multiplies every element in the given vector by the given number and returns the new vector.
74                 //vector<double> power(vector<double>, double); //This raises every element in the given vector to the given number and returns the new vector.
75                 //vector<double> addVecs(vector<double>,vector<double>); //The given vectors must be the same size. This adds the ith element of the first given vector to the ith element of the second given vector and returns the new vector.
76                 //vector<double> multVecs(vector<double>,vector<double>); //The given vectors must be the same size. This multiplies the ith element of the first given vector to the ith element of the second given vector and returns the new vector.
77                 //vector<double> remDup(vector<double>); //This returns a vector that contains 1 of each unique element in the given vector. The order of the elements is not changed.
78                 //vector<double> genCVec(vector<double>); //This returns a cumilative vector of the given vector. The ith element of the returned vector is the sum of all the elements in the given vector up to i.
79                 //vector<double> genRelVec(vector<double>); //This finds the sum of all the elements in the given vector and then divides the ith element in the given vector by that sum and then puts the result into a new vector, which is returned after all of the elements in the given vector have been used.
80                 ///vector<double> genDiffVec(vector<double>, vector<double>);//This subtracts the ith element of the second given vector from the ith element of the first given vector and returns the new vector.
81                 //vector<double> genCSVec(vector<double>);//This calculates the number of species that have the same number of individuals as the ith element of the given vector and then returns a cumulative vector.
82                 //vector<double> genTotVec(vector<vector<double> >); //This adds up the ith element of all the columns and puts that value into a new vector. It those this for all the rows and then returns the new vector.
83                 //vector<double> quicksort(vector<double>); //This sorts the given vector from highest to lowest and returns the sorted vector.
84                 //vector<vector<double> > gen2DVec(vector<double>, int, int); //(vector, #rows/columns, 0 if the second parameter was rows, 1 if the second parameter was columns) Transforms a single vector that was formatted like a table into a 2D vector.
85                 //vector<string> getSData(char[]);//This takes a file name as a parameter and reads all of the data in the file into a <string> vector.
86 };
87
88 /**************************************************************************************************/
89
90 /*This Class is similar to the GeometricSeries.h class. It calculates
91 the broken stick distribution of the table and prints the D-Statistic 
92 and the confidence limits for the Kolmogorov-Smirnov 1-Sample test
93 with a 95% confidence level.
94
95 class BrokenStick
96 {
97         public:
98                 void doBStick(vector<double>);
99 };
100
101 /**************************************************************************************************/
102 /*This Class calculates the geometric series distribution for the data.
103 It prints the D-Statistic and the critical values for the Kolmogorov-Smirnov
104 1-sample test at the 95% confidence interval.*/
105
106 /*class GeometricSeries
107 {
108         public:
109                 void doGeomTest(vector<double>);
110 };*/
111
112 /**************************************************************************************************
113 //This Class calculates the jackknifed estimate of the data and
114 //prints it and the confidence limits at a chosen confidence level.
115
116 class Jackknifing
117 {
118         public:
119                 void doJK(vector<double>, double);
120 };
121 /**************************************************************************************************
122 /*This Class stores calculates the Kolmogorov-Smirnov 2-Sample test between two samples.
123 It prints the D-Statistic and the critical value for the test at 
124 the 90% and 95% confidence interval.
125
126 class KS2SampleTest
127 {
128         public:
129                 void doKSTest(vector<double>, vector<double>);
130 };
131
132 /**************************************************************************************************
133 //This Class calculates and prints the Q-Statistic for the data.
134 class QStatistic
135 {
136         public:
137                 void doQStat(vector<double>);
138 };
139 /**************************************************************************************************
140 class SSBPDiversityIndices
141 {
142         public:
143                 void doSSBP(vector<double>);
144                 double getShan(vector<double> vec);//The Shannon Index
145                 double getSimp(vector<double> vec);//The Simpson Index
146                 double getBP(vector<double> vec);//The Berger-Parker Index
147 };
148 /**************************************************************************************************/
149 //This Class stores the table of the confidence limits of the Student-T distribution.
150 class TDTable
151 {
152         public:
153                 double getConfLimit(int,int);
154 };
155
156 /**************************************************************************************************
157 //This Class stores the table of the confidence limits of the One-Sample Kolmogorov-Smirnov Test.
158 class KOSTable
159 {
160         public:
161                 double getConfLimit(int);
162 };
163
164 /**************************************************************************************************/
165 /*This Class calculates the truncated lognormal for the data.
166 It then prints the D-Statistic and the critical values for the
167 Kolmogorov-Smirnov 1-Sample test.*
168
169 class TrunLN
170 {
171         public:
172                 void doTrunLN(vector<double>, vector<double>);
173 };
174 /**************************************************************************************************/
175
176 #endif
177