X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=metastats2.c;h=70edc3d63cda154b51bca2dcb8ee36b9413a97a9;hb=8dd3c225255d7084e3aff8740aa4f1f1cabb367a;hp=a6424f5fa95086083d4c09658f7c9e2338d2381c;hpb=8173238f9f94af9baab8471de58bed7c8830948d;p=mothur.git diff --git a/metastats2.c b/metastats2.c index a6424f5..70edc3d 100644 --- a/metastats2.c +++ b/metastats2.c @@ -4,576 +4,554 @@ //The following code has been modified using the original Metastats program from White, J.R., Nagarajan, N. & Pop, M. Statistical methods for detecting differentially abundant features in clinical metagenomic samples. PLoS Comput Biol 5, e1000352 (2009). int metastat_main (char* outputFileName, int numRows, int numCols, double threshold, int numPermutations, double** data, int secondGroupingStart){ - - int size,c=0,i=0,j=0,k,counter=0, bflag=0; - int B=numPermutations; - int row = numRows; - int col = numCols; - int g = secondGroupingStart; - double thresh=threshold; - double placeholder=0,min=0; - - char output[1024]; - strcpy(output, outputFileName); - FILE *out; - - if (g>=col || g<=0){ - printf("Check your g value\n"); - } - - // Initialize the matrices + + int size,c=0,i=0,j=0,counter=0, bflag=0; + int B=numPermutations; + int row = numRows; + int col = numCols; + int g = secondGroupingStart; + double thresh=threshold; + double min=0; + + char output[1024]; + strcpy(output, outputFileName); + FILE *out; + + if (g>=col || g<=0){ + printf("Check your g value\n"); + } + + // Initialize the matrices size = row*col; + double matrix[row][col]; + double pmatrix[size],permuted[size]; + double storage[row][9]; - double ** matrix, * pmatrix, * permuted, ** storage; - matrix = malloc(row*sizeof(double *)); - storage = malloc(row*sizeof(double *)); - for (i = 0; i2){ - for(i=1;i total[i]){ - min = total[i];} - } - } - if (min<=0){ - printf("Error, the sum of one of the columns <= 0."); - return 0; - } - - - // Ratio time... - for(i=0;i2){ + for(i=1;i total[i]){ + min = total[i];} + } + } + if (min<=0){ + printf("Error, the sum of one of the columns <= 0."); + return 0; } - double f11,f12,f21,f22; - - f11=fish[i]; - f12=fish2[i]; - - f21=total1-f11; - f22=total2-f12; - - double data[] = {f11, f12, f21, f22}; - - // CONTINGENGCY TABLE: - // f11 f12 - // f21 f22 - - int *nr, *nc, *ldtabl, *work; - int nrow=2, ncol=2, ldtable=2; - int workspace = 6*(row*col*sizeof(double *)); - double *expect, *prc, *emin,*prt,*pre; - double e=0, prc1=0, emin1=0, prt1=0, pre1=0; - - prt = (double *) malloc(size*sizeof(double *)); - prc = (double *) malloc(size*sizeof(double *)); - - nr = &nrow; - nc = &ncol; - ldtabl=&ldtable; - work = &workspace; - - expect = &e; - prc = &prc1; - emin=&emin1; - prt=&prt1; - pre=&pre1; - - fexact(nr,nc,data, ldtabl,expect,prc,emin,prt,pre,work); - if (*pre>.999999999){ - *pre=1; + // Ratio time... + for(i=0;i.999999999){ + *pre=1; + } + + //printf("feaxt = %f\t%f\t%f\t%f\t%f\t%f\n", *expect, *pre, f11, f12, f21, f22); + storage[i][8] = *pre; + pvalues[i]=*pre; + } } + else{ + + testp(permuted_ttests, permutes, permuted,pmatrix, nc, nr, gvalue,tinitial,pvalues); + + // Checks to make sure the matrix isn't sparse. + double sparse[row], sparse2[row]; + for(i=0;i.999999999){ + *pre=1; + } + storage[i][8] = *pre; + pvalues[i]=*pre; + } + } + // End of else statement + bflag = 1; + } - double f11,f12,f21,f22; - - f11=sparse[i]; - sparse[i]=0; + // Calculates the mean of counts (not normalized) + double temp[row][2]; - f12=sparse2[i]; - sparse2[i]=0; + for(j=0;j.999999999){ - *pre=1; + for(i=0;i(fabs(Tinitial[i])+.0000000000001)){ //13th place - counter[i]++; - } + xbardiff = C1[i][0]-C2[i][0]; + denom = sqrt(C1[i][2]+C2[i][2]); + Ts[i]=fabs(xbardiff/denom); + if (fabs(Ts[i])>(fabs(Tinitial[i])+.0000000000001)){ //13th place + counter[i]++; + } } } void meanvar(double *pmatrix,int *g,int *nr,int *nc,double *store){ - double temp[*nr], temp2[*nr],var[*nr],var2[*nr],a,b; - - int i,m,k,l,n; - - a = (double) *g-1; - b = (double) (*nc-a); - - for (i = 0; i<*nr; i++){ - temp[i]=0; - temp2[i]=0; - var[i]=0; - var2[i]=0; - } - - k = *nr; // number of rows - l = *nc; - n = k*l; - + double temp[*nr], temp2[*nr],var[*nr],var2[*nr],a,b; + + int i,m,k,l,n; + + a = (double) *g-1; + b = (double) (*nc-a); + + for (i = 0; i<*nr; i++){ + temp[i]=0; + temp2[i]=0; + var[i]=0; + var2[i]=0; + } + + k = *nr; // number of rows + l = *nc; + n = k*l; + m=0; m=*g-1; k=*nr; m*=k; // m = g * nr now for (i=0;i