- 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;i<row;i++){
- for (j =0;j<9;j++){
- storage[i][j]=0;
- }
- }
- // Reset file below and create a separate matrix.
- rewind(jobj);
- fgets(arr,10000,jobj);
-
- for(i=0; i<row; i++){
- fscanf(jobj,"%s",str);
- for(j=0; j<col;j++){
- fscanf(jobj,"%lf",&placeholder);
- matrix[i][j]=placeholder;
- if(isalnum(placeholder)!=0){ // check for ""
- printf("Your matrix isn't set up properly!\n");
- return 0;
- }
- pmatrix[c]=0; // initializing to zero
- permuted[c]=0;
- c++;
- }
- }
-
- fclose(jobj);
-
-
- // Produces the sum of each column
- double total[col],total1=0,total2=0;
- double ratio[col];
-
- for(i=0;i<col;i++){
- total[i]=0;
- ratio[i]=0; }
-
- for(i=0; i<col; i++){
- for(j=0;j<row;j++){
- total[i]=total[i]+matrix[j][i];
- }
- }
-
- for(i=0;i<g-1;i++){
- total1=total1+total[i];}
-
- for(i=g-1;i<col;i++){
- total2=total2+total[i];}
-
-
- // Creates the ratios by first finding the minimum of totals
- min = total[0];
- if (col==2){
- if (total[0]<total[1]){
- min = total[1];}
- }
- if (col >2){
- for(i=1;i<col;i++){
- if (min > 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;i++){
- ratio[i]=total[i]/min;
- }
-
- // Change matrix into an array as received by R for compatibility.
-
- c=0;
- for(i=0;i<col;i++){
- for(j=0;j<row;j++){
- pmatrix[c]=matrix[j][i];
- c++;
- }
- }
-
- if(row == 1){
- for (i =0; i<col;i++){
- pmatrix[i]=pmatrix[i]/ratio[i];
- }
- }
- else {
- counter = 0;
- j=-1;
- for (i=0; i<size; i++) {
- if (counter % row == 0) {
- j++;
- }
- pmatrix[i]=pmatrix[i]/ratio[j];
- counter++;
- }
- }
- // pass everything to the rest of the code using pointers. then
- // write to output file. below pointers for most of the values are
- // created to send everything by reference.
-
- int ptt_size, *permutes,*nc,*nr,*gvalue;
-
- nc = &col;
- nr = &row;
- gvalue = &g;
-
- permutes = &B;
- ptt_size = B*row;
-
- //changing ptt_size to row
- double permuted_ttests[row], pvalues[row], tinitial[row];
-
- for(i=0;i<row;i++){
- permuted_ttests[i]=0;}
-
- for(i=0;i<row;i++){
- pvalues[i]=0;
- tinitial[i]=0; }
-
- // Find the initial values for the matrix.
- start(pmatrix,gvalue,nr,nc,tinitial,storage);
-
- // Start the calculations.
-
- if ( (col==2) || ((g-1)<8) || ((col-g+1) < 8) ){
-
- double fish[row], fish2[row];
- for(i=0;i<row;i++){
- fish[i]=0;
- fish2[i]=0;}
-
- for(i=0;i<row;i++){
-
- for(j=0;j<g-1;j++){
- fish[i]=fish[i]+matrix[i][j];