X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=metastats2.c;h=70edc3d63cda154b51bca2dcb8ee36b9413a97a9;hb=8dd3c225255d7084e3aff8740aa4f1f1cabb367a;hp=c4d1f46feaff17f90a6e6668126a0f0a1ecd96ac;hpb=2bf3df7736ef2a17286d99394e211f51751d6829;p=mothur.git diff --git a/metastats2.c b/metastats2.c index c4d1f46..70edc3d 100644 --- a/metastats2.c +++ b/metastats2.c @@ -1,672 +1,559 @@ -#include -#include -#include -#include -#include -#include "fisher2.h" -void testp(double *permuted_ttests,int *B,double *permuted,double - *Imatrix,int *nc,int *nr,int *g,double *Tinitial,double *ps); -void permute_matrix(double *Imatrix,int *nc,int *nr,double - *permuted,int *g,double *trial_ts,double *Tinitial,double - *counter); -void permute_array(int *array, int n); -void calc_twosample_ts(double *Pmatrix,int *g,int *nc,int *nr,double - *Ts,double *Tinitial,double *counter1); -void meanvar(double *pmatrix,int *g,int *nr,int *nc,double *storage); -void start(double *Imatrix,int *g,int *nr,int *nc,double *testing, - double storage[][9]); +#include "metastats.h" -int main (int argc, char *argv[]){ - - int col=-1, row=-1, size,g=0,c=0,i=0,j=0,k,counter=0,lines=0, B=10000; - double placeholder=0,min=0, thresh=0.05; +//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). - char arr[10000], str[51], a; - char location[41]="jobj.txt", output[41]="out.txt"; - - for(i=0;i<10000;i++){ - arr[i]='q'; - } - -int u,rflag=0,cflag=0, bflag=0; -char *filename; -int numbers; -double numb; -extern char *optarg; -extern int optind, optopt, opterr; - -while ((u = getopt(argc, argv, ":r:c:g:b:t:f:o:")) != -1) { - switch(u) { - case 'r': - numbers = atoi(optarg); - printf("The number of features/rows is %d.\n", numbers); - row = numbers; - rflag = 1; - break; - case 'c': - numbers = atoi(optarg); - printf("The number of samples/columns is %d.\n", numbers); - col = numbers; - cflag = 1; - break; - case 'g': - numbers = atoi(optarg); - printf("Your g-value is %d.\n", numbers); - g = numbers; - break; - case 'b': - numbers = atoi(optarg); - printf("The number of permutations is %d\n", numbers); - B = numbers; - break; - case 't': - numb = atof(optarg); - printf("Threshold is is %lf\n", numb); - thresh = numb; - break; - case 'f': - filename = optarg; - printf("filename input is %s\n", filename); - strcpy(location,filename); - break; - case 'o': - filename = optarg; - printf("filename output %s\n", filename); - strcpy(output,filename); - break; - case ':': - printf("-%c without filename\n", optopt); - break; - case '?': - printf("unknown arg %c\n", optopt); - break; - } -} - - FILE *jobj, *out; - jobj=fopen(location,"r"); - - if(jobj == NULL){ - printf("Please don't forget to save your matrix in the active"); - printf(" directory as \"%s\".\n",location); - return 0; - } - - // Gets the first line of samples names and checks for user error. - fgets(arr,10000,jobj); - - for(i=0;i<10000;i++){ - if(isspace(arr[i])){ - counter++; } - } - - if (cflag == 0) { - printf("You didn't tell us how many subjects there are!\n"); - printf("But we'll still do the analysis as if there are %d subjects.\n\n",col=counter-1); - } - if (cflag == 1) { - if (col != counter-1){ - printf("We would expect %d subjects, but you said %d.\n",counter-1,col); - } - } - - while((a = fgetc(jobj)) != EOF){ - if(a == '\n'){ - lines++; } - } - - if (rflag == 0) { - printf("You didn't specify the number of features!\n"); - printf("But we'll still do the analysis assuming %d features.\n\n", row=lines-1); - } - if (rflag == 1) { - if ( lines-1 != row ){ - printf("We would expect %d features, but you said %d.\n",lines-1,row); - } - } - - if (g>=col || g<=0){ - printf("Check your g value\n"); - } - - // Initialize the matrices - size = row*col; - double matrix[row][col]; - double pmatrix[size],pmatrix2[size],permuted[size]; - double storage[row][9]; - - 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;i=col || g<=0){ + printf("Check your g value\n"); } - - for(j=g-1;j.999999999){ - *pre=1; + // Creates the ratios by first finding the minimum of totals + min = total[0]; + if (col==2){ + if (total[0]2){ + for(i=1;i total[i]){ + min = total[i];} + } } + if (min<=0){ + printf("Error, the sum of one of the columns <= 0."); + return 0; + } + - if(sparse[i] < (double)(g-1)){ - c++; + // Ratio time... + for(i=0;i.999999999){ - *pre=1; + // Start the calculations. + + if ( (col==2) || ((g-1)<8) || ((col-g+1) < 8) ){ + + double fish[row], fish2[row]; + 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; + } } - storage[i][8] = *pre; - pvalues[i]=*pre; - } - } - // End of else statement - bflag = 1; - } - - // Calculates the mean of counts (not normalized) - double temp[row][2]; - - for(j=0;j.999999999){ + *pre=1; + } + storage[i][8] = *pre; + pvalues[i]=*pre; + } + } + // End of else statement + bflag = 1; } - } - - for (j=0;j(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