]> git.donarmstrong.com Git - mothur.git/blobdiff - calculator.cpp
test
[mothur.git] / calculator.cpp
index 71aa99cfb1c6f4f887389e530c1ceeed9dbfeef3..7f7296b7362912843d85448bd625454de709aeae 100644 (file)
@@ -9,7 +9,7 @@
 
 #include "calculator.h"
 
-/***********************************************************************/
+/***********************************************************************
 void VecCalc::printElements(vector<double> vec){
        try {
                for(int i = 0; i < vec.size(); i++)
@@ -26,7 +26,7 @@ void VecCalc::printElements(vector<double> vec){
        }       
 }
 
-/***********************************************************************/
+/***********************************************************************
 
 void VecCalc::printElements(vector<string> vec){
        try {
@@ -43,7 +43,7 @@ void VecCalc::printElements(vector<string> vec){
                exit(1);
        }       
 }
-/***********************************************************************/
+/***********************************************************************
 int VecCalc::findString(vector<string> vec, string str){
        try {
                for(int i = 0; i < vec.size(); i++)
@@ -60,11 +60,11 @@ int VecCalc::findString(vector<string> vec, string str){
                exit(1);
        }       
 }
-/***********************************************************************/
+/***********************************************************************
 double VecCalc::mean(vector<double> vec){
        return sumElements(vec)/vec.size();
 }
-/***********************************************************************/
+/***********************************************************************
 double VecCalc::stError(vector<double> vec){
        try {
                double sum = 0;
@@ -88,13 +88,9 @@ int VecCalc::sumElements(vector<int> vec){
                return sumElements(vec,0);
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function sumElements. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "VecCalc", "sumElements");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the VecCalc class function sumElements. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 /***********************************************************************/
 int VecCalc::sumElements(vector<int> vec, int index){
@@ -105,13 +101,9 @@ int VecCalc::sumElements(vector<int> vec, int index){
                return sum;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function sumElements. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "VecCalc", "sumElements");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the VecCalc class function sumElements. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
 /***********************************************************************/
@@ -123,13 +115,9 @@ double VecCalc::sumElements(vector<double> vec){
                return sum;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function sumElements. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "VecCalc", "sumElements");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the VecCalc class function sumElements. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 /***********************************************************************/
 double VecCalc::sumElements(vector<double> vec, int index){
@@ -140,15 +128,11 @@ double VecCalc::sumElements(vector<double> vec, int index){
                return sum;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function sumElements. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "VecCalc", "sumElements");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the VecCalc class function sumElements. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
-/***********************************************************************/
+/***********************************************************************
 double VecCalc::findMax(vector<double> vec){
        try {
                double max = -1000000.0;
@@ -176,13 +160,9 @@ int VecCalc::numNZ(vector<int> vec){
                return numNZ;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function numNZ. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "VecCalc", "numNZ");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the VecCalc class function numNZ. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 /***********************************************************************/
 double VecCalc::numNZ(vector<double> vec){
@@ -194,15 +174,11 @@ double VecCalc::numNZ(vector<double> vec){
                return numNZ;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function numNZ. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "VecCalc", "numNZ");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the VecCalc class function numNZ. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
-/***********************************************************************/
+/***********************************************************************
 double VecCalc::numPos(vector<double> vec){
        try {
                double numPos = 0;
@@ -220,7 +196,7 @@ double VecCalc::numPos(vector<double> vec){
                exit(1);
        }       
 }
-/***********************************************************************/
+/***********************************************************************
 double VecCalc::findMaxDiff(vector<double> vec1, vector<double> vec2){
        try {
                double maxDiff = -10000000000.0;
@@ -238,7 +214,7 @@ double VecCalc::findMaxDiff(vector<double> vec1, vector<double> vec2){
                exit(1);
        }       
 }
-/***********************************************************************/
+/***********************************************************************
 double VecCalc::findDStat(vector<double> vec1, vector<double> vec2, double num){
        try {
                double mDiff = findMaxDiff(vec1, vec2);
@@ -253,7 +229,7 @@ double VecCalc::findDStat(vector<double> vec1, vector<double> vec2, double num){
                exit(1);
        }       
 }
-/***********************************************************************/
+/***********************************************************************
 vector<int> VecCalc::findQuartiles(vector<double> vec){
        try {
                vector<int> quartiles;
@@ -286,7 +262,7 @@ vector<int> VecCalc::findQuartiles(vector<double> vec){
                exit(1);
        }       
 }
-/***********************************************************************/
+/***********************************************************************
 vector<double> VecCalc::add(vector<double> vec, double x){
        try {
                vector<double> newVec;
@@ -303,7 +279,7 @@ vector<double> VecCalc::add(vector<double> vec, double x){
                exit(1);
        }       
 }
-/***********************************************************************/
+/***********************************************************************
 vector<double> VecCalc::multiply(vector<double> vec, double x){
        try {
                vector<double> newVec;
@@ -320,7 +296,7 @@ vector<double> VecCalc::multiply(vector<double> vec, double x){
                exit(1);
        }       
 }
-/***********************************************************************/
+/***********************************************************************
 vector<double> VecCalc::power(vector<double> vec, double p){
        try {
                vector<double> newVec;
@@ -337,7 +313,7 @@ vector<double> VecCalc::power(vector<double> vec, double p){
                exit(1);
        }       
 }
-/***********************************************************************/
+/***********************************************************************
 vector<double> VecCalc::addVecs(vector<double> vec1, vector<double> vec2) //Vectors must be the same size.
 {      try {
                vector<double> newVec;
@@ -354,7 +330,7 @@ vector<double> VecCalc::addVecs(vector<double> vec1, vector<double> vec2) //Vect
                exit(1);
        }       
 }
-/***********************************************************************/
+/***********************************************************************
 vector<double> VecCalc::multVecs(vector<double> vec1, vector<double> vec2) //Vectors must be the same size.
 {      try {
                vector<double> newVec;
@@ -371,7 +347,7 @@ vector<double> VecCalc::multVecs(vector<double> vec1, vector<double> vec2) //Vec
                exit(1);
        }       
 }
-/***********************************************************************/
+/***********************************************************************
 vector<double> VecCalc::remDup(vector<double> vec){
        try {
                vector<double> newVec;
@@ -390,7 +366,7 @@ vector<double> VecCalc::remDup(vector<double> vec){
                exit(1);
        }       
 }      
-/***********************************************************************/      
+/***********************************************************************       
 vector<double> VecCalc::genCVec(vector<double> vec1){
        try {
                vector<double> vec2;
@@ -411,7 +387,7 @@ vector<double> VecCalc::genCVec(vector<double> vec1){
                exit(1);
        }       
 }
-/***********************************************************************/
+/***********************************************************************
 vector<double> VecCalc::genRelVec(vector<double> vec){ 
        try {
                vector<double> newVec;
@@ -429,7 +405,7 @@ vector<double> VecCalc::genRelVec(vector<double> vec){
                exit(1);
        }       
 }
-/***********************************************************************/
+/***********************************************************************
 vector<double> VecCalc::genDiffVec(vector<double> vec1, vector<double> vec2){
        try {
                vector<double> newVec;
@@ -446,7 +422,7 @@ vector<double> VecCalc::genDiffVec(vector<double> vec1, vector<double> vec2){
                exit(1);
        }       
 }
-/***********************************************************************/
+/***********************************************************************
 vector<double> VecCalc::genCSVec(vector<double> vec){
        try {
                vector<double> newVec;
@@ -478,7 +454,7 @@ vector<double> VecCalc::genCSVec(vector<double> vec){
                exit(1);
        }       
 }
-/***********************************************************************/      
+/***********************************************************************       
 vector<double> VecCalc::genTotVec(vector<vector<double> > vec){
        try {
                vector<double> newVec = vec.at(0);
@@ -495,7 +471,7 @@ vector<double> VecCalc::genTotVec(vector<vector<double> > vec){
                exit(1);
        }       
 }
-/***********************************************************************/
+/***********************************************************************
 vector<double> VecCalc::quicksort(vector<double> vec){
        try {
                sort(vec.rbegin(), vec.rend());
@@ -510,7 +486,7 @@ vector<double> VecCalc::quicksort(vector<double> vec){
                exit(1);
        }       
 }
-/***********************************************************************/
+/***********************************************************************
 vector<vector<double> > VecCalc::gen2DVec(vector<double> vec, int div, int type){
        try {
                vector<vector<double> > vec2D;
@@ -536,7 +512,7 @@ vector<vector<double> > VecCalc::gen2DVec(vector<double> vec, int div, int type)
                exit(1);
        }       
 }
-/***********************************************************************/
+/***********************************************************************
 vector<string> VecCalc::getSData(char name[]){
        try {
                vector<string> vec;
@@ -561,7 +537,7 @@ vector<string> VecCalc::getSData(char name[]){
 }
 /***********************************************************************/      
 
-/***********************************************************************/
+/***********************************************************************
 void BrokenStick::doBStick(vector<double> vec)//vec = The data vector.
 {      try {
                VecCalc vecCalc;
@@ -600,7 +576,7 @@ void BrokenStick::doBStick(vector<double> vec)//vec = The data vector.
        }       
 }
 
-/***********************************************************************/
+/***********************************************************************
 double kEq(double k, double spec)
 {
        return k/(1-k)*pow(1-k, spec)/(1-pow(1-k, spec));
@@ -652,7 +628,7 @@ double kEq(double k, double spec)
        }       
 }*/
 
-/***********************************************************************/
+/***********************************************************************
 void Jackknifing::doJK(vector<double> vec, double cols)//vec = the data vector if the data table was read left-to-right, top-to-bottom. cols = The number of columns in the data table.
 {      try {
                VecCalc vecCalc;
@@ -703,7 +679,7 @@ void Jackknifing::doJK(vector<double> vec, double cols)//vec = the data vector i
                exit(1);
        }       
 }
-/***********************************************************************/
+/***********************************************************************
 void KS2SampleTest::doKSTest(vector<double> abun1, vector<double> abun2)//abun1 = 1st vector of abundances, abun2 = 2nd vector of abundances
 {      try {
                VecCalc vecCalc;
@@ -745,7 +721,7 @@ void KS2SampleTest::doKSTest(vector<double> abun1, vector<double> abun2)//abun1
        }       
 }
 
-/***********************************************************************/
+/***********************************************************************
 
 void QStatistic::doQStat(vector<double> vec)//vec = The data vector.
 {      try {
@@ -772,7 +748,7 @@ void QStatistic::doQStat(vector<double> vec)//vec = The data vector.
                exit(1);
        }       
 }
-/***********************************************************************/
+/***********************************************************************
 double SSBPDiversityIndices::getShan(vector<double> vec)//vec = The data vector.
 {      try {
                VecCalc vecCalc;
@@ -793,7 +769,7 @@ double SSBPDiversityIndices::getShan(vector<double> vec)//vec = The data vector.
                exit(1);
        }       
 }
-/***********************************************************************/
+/***********************************************************************
 double SSBPDiversityIndices::getSimp(vector<double> vec)//vec = The data vector.
 {      try {
                VecCalc vecCalc;
@@ -812,7 +788,7 @@ double SSBPDiversityIndices::getSimp(vector<double> vec)//vec = The data vector.
                exit(1);
        }       
 }
-/***********************************************************************/
+/***********************************************************************
 double SSBPDiversityIndices::getBP(vector<double> vec)//vec = The data vector.
 {      try {
                VecCalc vecCalc;
@@ -828,7 +804,7 @@ double SSBPDiversityIndices::getBP(vector<double> vec)//vec = The data vector.
                exit(1);
        }       
 }
-/***********************************************************************/
+/***********************************************************************
 void SSBPDiversityIndices::doSSBP(vector<double> vec)//vec = The data vector.
 {      try {
                VecCalc vecCalc;
@@ -863,7 +839,7 @@ double TDTable::getConfLimit(int row, int col) //Rows are the degrees of freedom
                //Found on http://www.vgtu.lt/leidiniai/elektroniniai/Probability.pdf/Table%203.pdf
 
                //Confidence Level        .90    .95     .975     .99    .995     .999    .9995
-               double values[33][7] = {{3.078, 6.314,  12.706, 31.821, 63.656, 318.289, 636.578},
+               double values[30][7] = {{3.078, 6.314,  12.706, 31.821, 63.656, 318.289, 636.578},
                                                        {1.886, 2.920,  4.303,  6.965,  9.925,  22.328, 31.600},
                                                            {1.638,     2.353,  3.182,  4.541,  5.841,  10.214, 12.924},
                                                            {1.533,     2.132,  2.776,  3.747,  4.604,  7.173,  8.610},
@@ -892,23 +868,17 @@ double TDTable::getConfLimit(int row, int col) //Rows are the degrees of freedom
                                                                {1.314, 1.703,  2.052,  2.473,  2.771,  3.421,  3.689},
                                                                {1.313, 1.701,  2.048,  2.467,  2.763,  3.408,  3.674},
                                                                {1.311, 1.699,  2.045,  2.462,  2.756,  3.396,  3.660},
-                                                               {1.310, 1.697,  2.042,  2.457,  2.750,  3.385,  3.646},
-                                                               {1.296, 1.671,  2.000,  2.390,  2.660,  3.232,  3.460},
-                                                               {1.289, 1.658,  1.980,  2.358,  2.617,  3.160,  3.373},
-                                                               {1.282, 1.645,  1.960,  2.326,  2.576,  3.091,  3.291}};
+                                                               {1.310, 1.697,  2.042,  2.457,  2.750,  3.385,  3.646}};
+                                                               
                return values[row][col];
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the TDTable class Function getConfLimit. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "TDTable", "getConfLimit");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the TDTable class function getConfLimit. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
-/***********************************************************************/
+/***********************************************************************
 double KOSTable::getConfLimit(int index) //Table of Critical values for N = 4-20 for One-Sample Kolmogorov-Smirnov Test
 {    try {                       
                //Confidence Level = .05