/* ctotal.c Compile with: gcc -g ctotal.c -lm -o ctotal Example run: ctotal hs23b_intvfile.l6 60 299 Example output: from: 0.601 to: 0.666 fp: 56 fn: 106 total: 162 (299) 60 l=6 Given an interval file, it outputs the interval of anchor 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. The intv_file denomination must contain the length specification. In the example above, the best a-interval for phylogen runs on the combined hs23b region with l=6 (ct) which exceed 60% true positives (ie, < 40% fn) is [0.601,0.666]. The fp, fn and total counts are: 56, 106 and 162 respectively. 299 is the total length of the known functional regions (maxfn). NOTE: Used in 'cut' experiments on combined regions, where the data files are in interval format. */ #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; double from[1000], to[1000]; int fn[1000], fp[1000]; FILE *file; if (argc!=4) fatalf(Usage, argv[0]); pct = atoi(argv[2]); length = atoi(argv[3]); thresh = ((100-pct)*length)/100; best = 100000; best_k = -1; file = ckopen(argv[1],"r"); k = 0; while (fgets(buffer,200,file)!=NULL) { if (buffer[0]=='#') continue; sscanf(buffer,"%lf %lf %d %d", &from[k], &to[k], &fp[k], &fn[k]); if (fn[k]>thresh) continue; if (fp[k]+fn[k]= 0) printf("from: %1.3lf to: %1.3lf 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: %1.3lf to: %1.3lf 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=='l') && (!isdigit(*(p+1)))))) 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; }