1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
//
// erarefaction.cpp
// Mothur
//
// Created by Sarah Westcott on 4/3/19.
// Copyright © 2019 Schloss Lab. All rights reserved.
//
#include "erarefaction.hpp"
/***********************************************************************/
ERarefaction::ERarefaction(int inc) : increment(inc), DiversityCalculator(true) {}
/***********************************************************************/
void ERarefaction::getValues(SAbundVector* rank, vector<double>& values){
try {
int maxRank = rank->getMaxRank();
int sampled = rank->getNumSeqs(); //nl
int numOTUs = rank->getNumBins(); //ns
for (int n = 1; n <= sampled; n++) {
if((n % increment) == 0){
double dSum = 0.0;
#ifdef USE_GSL
double dDenom = gsl_sf_lnchoose(sampled, n);
for(int i = 1; i <= maxRank; i++){
if (m->getControl_pressed()) { break; }
int abund = rank->get(i);
if (abund != 0) {
int thisRank = i; //nA
if(sampled - thisRank >= n){
double dNumer = gsl_sf_lnchoose(sampled - thisRank, n);
dSum += ((double) abund)*exp(dNumer - dDenom);
}
}
}
#endif
double result = ((double) numOTUs) - dSum;
if (isnan(result) || isinf(result)) { result = 0; }
values.push_back(result);
}
}
}
catch(exception& e) {
m->errorOut(e, "ERarefaction", "getValues");
exit(1);
}
}
/***********************************************************************/
|