/* crops_total.c Compile with: gcc -g crops_total.c -lm -o crops_total Example run: crops_total beta_DEVIATION.X.l6 60 93 14 Example output: from: 61 to: 80 fp: 40 fn: 13 total: 53 (93) 60 l=6 Given an agree-DEVIATION file, it outputs the interval of p-values for which the best "total" (fn+fp) count is obtained, providing that only the runs with at least the specified percentage of true positives are included. In the example above, the best p-interval for agree runs on the HBB promoter region with l=6 (ct) which exceed 60% true positives (ie, < 40% fn) is [61,80]. The fp, fn and total counts are: 40, 13 and 53 respectively. 93 is the total length of the known functional regions (maxfn). The chars-to_len value is 14=strlen("agree.beta.X.l") (see the denomination for a run in the DEVIATION file). Produces an interval file as an intermediate (tmp) file. NOTE: Used in 'cut' experiments on individual regions. */ #include #include #include #include #include #include #define Usage "%s " void fatal(char *message); void fatalf(char *msg, char *val); FILE *ckopen(char *name, char *mode); int get_len(char *s); int main(int argc, char *argv[]) { char buffer[200], cmd[100]; int i, k, length, pct, best_k, best, thresh, chars_to_len; int from[1000], to[1000]; int fn[1000], fp[1000]; FILE *file; if (argc!=5) fatalf(Usage, argv[0]); pct = atoi(argv[2]); chars_to_len = atoi(argv[4]); length = atoi(argv[3]); thresh = ((100-pct)*length)/100; best = 100000; best_k = -1; sprintf(cmd,"interval %s %d > tmp", argv[1], chars_to_len); system(cmd); file = ckopen("tmp","r"); k = 0; while (fgets(buffer,200,file)!=NULL) { if (buffer[0]=='#') continue; sscanf(buffer,"%d %d %d %d", &from[k], &to[k], &fp[k], &fn[k]); if (fn[k]>thresh) continue; if (fp[k]+fn[k]= 0) printf("from: %d to: %d fp: %d fn: %d total: %d (%d) %d l=%d\n", from[best_k], to[best_k], fp[best_k], fn[best_k], fp[best_k]+fn[best_k], length, pct, get_len(argv[1])); /* i = k-1; while ((i>=1) && (fp[i]==fp[i-1])) i--; printf("Best_fpos %d: from: %d to: %d fp: %d fn: %d total: %d (%d)\n", pct, from[i], to[i], fp[i], fn[i], fp[i]+fn[i], length); */ return 0; } int get_len(char *s) { int len; char *p = s; while (*p && !isspace(*p) && (*p!='l')) p++; sscanf(p+1,"%d",&len); return len; } void fatal(char *msg) { (void)fprintf(stderr, "%s\n", msg); exit(1); } void fatalf(char *msg, char *val) { (void)fprintf(stderr, msg, val); (void)putc('\n', stderr); exit(1); } FILE *ckopen(char *name, char *mode) { FILE *fp; if ((fp = fopen(name, mode)) == NULL) fatalf("Cannot open %s.", name); return fp; }