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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
//
// igrarefaction.cpp
// Mothur
//
// Created by Sarah Westcott on 5/6/19.
// Copyright © 2019 Schloss Lab. All rights reserved.
//
#include "igrarefaction.hpp"
/***********************************************************************/
IGRarefaction::IGRarefaction(double c) : coverage(c), DiversityCalculator(true) {}
/***********************************************************************/
inline int compare_doubles1(const void* a, const void* b)
{
double* arg1 = (double *) a;
double* arg2 = (double *) b;
if( *arg1 < *arg2 ) return -1;
else if( *arg1 == *arg2 ) return 0;
else return 1;
}
/***********************************************************************/
vector<double> IGRarefaction::getValues(int numSeqs, vector<mcmcSample>& sampling){ //numSeqs = rank->getNumSeqs(); //nj
try {
#ifdef USE_GSL
DiversityUtils dutils("igrarefaction");
int nSamples = sampling.size();
double* adMu = nullptr;
double dLower = 0.0, dMedian = 0.0, dUpper = 0.0;
gsl_set_error_handler_off();
t_IGParams* atIGParams;
atIGParams = (t_IGParams *) malloc(nSamples*sizeof(t_IGParams)); //MAX_SAMPLES
//load sampling data
for (int i = 0; i < nSamples; i++) {
if (m->getControl_pressed()) { free(atIGParams); return results; }
atIGParams[i].dAlpha = sampling[i].alpha;
atIGParams[i].dBeta = sampling[i].beta;
atIGParams[i].nS = sampling[i].ns;
atIGParams[i].dC = coverage;
}
adMu = (double *) malloc(sizeof(double)*nSamples);
for(int i = 0; i < nSamples; i++){ adMu[i] = ((double) numSeqs)*dutils.calcMu(&atIGParams[i]); }
qsort(adMu, nSamples, sizeof(double), compare_doubles1);
dLower = gsl_stats_quantile_from_sorted_data(adMu, 1, nSamples, 0.025);
dMedian = gsl_stats_quantile_from_sorted_data(adMu, 1, nSamples, 0.5);
dUpper = gsl_stats_quantile_from_sorted_data(adMu, 1, nSamples, 0.975);
m->mothurOut("\nIGRarefaction - d_Lower = " + toString(dLower) + " d_Median = " + toString(dMedian) + " d_Upper = " + toString(dUpper) + "\n\n");
if (isnan(dLower) || isinf(dLower)) { dLower = 0; }
if (isnan(dMedian) || isinf(dMedian)) { dMedian = 0; }
if (isnan(dUpper) || isinf(dUpper)) { dUpper = 0; }
results.push_back(dLower); results.push_back(dMedian); results.push_back(dUpper);
free(adMu);
free(atIGParams);
#endif
return results;
}
catch(exception& e) {
m->errorOut(e, "IGRarefaction", "getValues");
exit(1);
}
}
/***********************************************************************/
|