/* * fraxtr.c - from: * abercl.c Mon Aug 25 12:59:49 WET 1986 John Ireland * * display all type 1 objects in a file at a suitable scale * or at specified scale. Number unless contrary is specified. * interactivly allow the user to clasify type one objects. * * 22-02-87 jimp "btype" replaced by "Cotype" in restrict test * Aspect ratio set suitable for FIP by default. * Scale forced to 8 (may be unsuitable). * Mon Feb 23 1987 -ireland ACROCENTRIC class added * 26-02-87 jimp Object numbers in bit-plane zero, grey-values in * planes 1-7, for overlayed numbers. */ #define MAXCHARS 20 #include #include #include #include #include #include struct chromosome *objlist[200]; int scale, cellw, celll; /* For scaling transformations */ char filename[100], directory[100]; int number; /* Total number of type 1 objects */ int restrict; /* Do we restrict what we display? */ int file_saved; /* Has Data Been Saved? */ int nonum; main(argc,argv) int argc; char **argv; { int objnum; int cellkol1,cellline1,celllastkl,celllastln; struct chromosome *obj, *readobj(); struct propertylist *makechromplist(); FILE *fp, *fopen(); char line[100], name[100], *np; char arg[100]; /* Arg for interp loop */ int i; int no_file; /* Has a file been opened? */ int carg; /* Current arg to scan */ int slen, sarg; /* Length of switch argument & current switch arg */ no_file = TRUE; restrict = FALSE; file_saved = FALSE; strcpy(directory,"./"); for (carg = 1; carg < argc; ++carg) if (argv[carg][0] == '-'){ slen = strlen(argv[carg]); for (sarg = 1; sarg < slen; sarg++) switch(argv[carg][sarg]){ case 'N': case 'n': nonum = TRUE; break; case 'r': case 'R': restrict = TRUE; break; case 'd': case 'D': strcpy(directory,argv[++carg]); strcat(directory,"/"); break; default: break; } } else { if((fp = fopen(argv[carg],"r")) == NULL){ fprintf(stderr,"Can't open %s\n", argv[carg]); continue; } strcpy(filename, argv[carg]); no_file = FALSE; } if(no_file){ fprintf(stderr,"Usage: abercl file | sto...\n"); exit(1); } scale = -1; /* if (argc > 3) { scale = atoi(argv[4]); if (scale <= 0 || scale > 1024) { fprintf(stderr,"ridiculous scale\n"); exit(1); } } */ /* Read in chromosome and store in objectlist, add plist if non exists */ number = 0; while((obj = readobj(fp)) != NULL) { if (obj->type == 1) { objlist[number++] = obj; if(obj->plist == NULL) obj->plist = (struct chromplist *) makechromplist(); if (number == 1) { cellline1 = obj->idom->line1; cellkol1 = obj->idom->kol1; celllastln = obj->idom->lastln; celllastkl = obj->idom->lastkl; } else { cellline1 = min(cellline1,obj->idom->line1); cellkol1 = min(cellkol1,obj->idom->kol1); celllastln = max(celllastln,obj->idom->lastln); celllastkl = max(celllastkl,obj->idom->lastkl); } } } fclose(fp); /* Set scaling transformations */ if (scale < 0) { celll = celllastln - cellline1 + 1; cellw = celllastkl - cellkol1 + 1; /* aspect ratio for FIP */ celll = 3*celll/4; scale = 3840/max(celll,cellw); if (scale > 8) scale = 8; fprintf(stderr,"scale = %d\n",scale); } /* aspect ratio for FIP */ celll = 2112 - 3*scale*(cellline1+celllastln)/8; cellw = 2112 - scale*(cellkol1+celllastkl)/2; /* Draw type 1 objects */ dinit(); draw_all(); /* Command Handler */ for(;;){ fprintf(stderr,": "); fgets(line,MAXCHARS,stdin); if(isempty(line)) continue; i = 0; sscanf(line,"%s%s",name,arg); while(isspace(line[i])) i++; while(!isspace(line[i])) i++; if(strcmp(name,"step") == NULL) step(); else if(strcmp(name,"enter") == NULL) enter(); else if(strcmp(name,"save") == NULL) save(arg); else if(strcmp(name,"ind") == NULL) ind(); else if(strcmp(name,"q") == NULL) exit_abercl(); else if(strcmp(name,"?") == NULL) main_help(); else if(strcmp(name,"R") == NULL) redraw(); else fprintf(stderr,"unknown command %s\n",name); } } exit_abercl() { char c, line[MAXCHARS]; start: if (!file_saved){ fprintf(stderr,"No save! Exit? (Y/N) "); fgets(line,MAXCHARS,stdin); sscanf(line,"%c",&c); if (c == 'Y' || c == 'y') exit(1); else if ( c == 'N' || c == 'n') return; } else exit(1); goto start; } save(arg) char *arg; { FILE *fp, *fopen(); char name[100]; int i; strcpy(name,directory); if (strcmp(arg, "") == 0) strcat(name,filename); else strcat(name,arg); if ((fp = fopen(name,"w")) == NULL) { fprintf(stderr,"Can't open %s\n",name); return; } for(i = 0; i < number; i++) writeobj(fp,objlist[i]); file_saved = TRUE; } enter() { } max(i,j) { return ( i>j? i: j); } min(i,j) { return ( iplist->btype = obj->plist->Cbtype = obj->plist->otype = obj->plist->Cotype = 0; file_saved = FALSE; start: fprintf(stderr,"\t%d> ",j); fgets(line,MAXCHARS,stdin); argc = sscanf(line,"%s %c",objtype,&objstatus); if(argc == EOF){ set_btype_bit(obj,CHROMOSOME); return; } if(argc == 2) switch(objstatus){ case 'i': obj->plist->otype = PIECE; obj->plist->Cotype = PIECE; break; case 't': obj->plist->otype = COMPOSITE; obj->plist->Cotype = COMPOSITE; break; case 'o': obj->plist->otype = OVERLAP; obj->plist->Cotype = OVERLAP; break; case 's': obj->plist->otype = CHROMOSOME; obj->plist->Cotype = CHROMOSOME; break; case 'd': obj->plist->otype = CUT; obj->plist->Cotype = CUT; break; default: fprintf(stderr,"unknown chromosome status %c\n",objstatus); goto start; } i = 0; while(objtype[i] != '\0'){ switch(objtype[i++]){ case 'c': set_btype_bit(obj,CHROMOSOME); break; case 'd': set_btype_bit(obj,DICENTRIC); break; case 'r': set_btype_bit(obj,RING); break; case 'f': set_btype_bit(obj,FRAGMENT); break; case 'i': set_btype_bit(obj,INTERPHASE); break; case 'p': set_btype_bit(obj,PHYBROKEN); break; case 'x': set_btype_bit(obj,CROSSARMS); break; case 'u': set_btype_bit(obj,UNSHURE); break; case 'j': set_btype_bit(obj,JUNK); break; case 'a': set_btype_bit(obj,ACROCENTRIC); break; default: fprintf(stderr,"unknown chromosome type %c\n",objtype[--i]); goto start; } } } set_btype_bit(obj,type) struct chromosome *obj; int type; { obj->plist->btype = obj->plist->btype | type; obj->plist->Cbtype = obj->plist->Cbtype | type; } draw_single(obj) struct chromosome *obj; { int sscale, ccellw, ccelll; ccelll = obj->idom->lastln - obj->idom->line1 + 1; ccellw = obj->idom->lastkl - obj->idom->kol1 + 1; sscale = 1920 / max(ccelll,ccellw); ccelll = 2112 - sscale * (obj->idom->lastln + obj->idom->line1) / 2 ; ccellw = 2112 - sscale * (obj->idom->lastkl + obj->idom->kol1) / 2 ; picobj(obj,sscale,ccellw,ccelll); if(!nonum) dispobjnum(obj,sscale,ccellw,ccelll); } print_EXPAND0() { int i, j; for(i = 0; i < number; i++){ for(j = 0; j < 9; j++) fprintf(stderr,"%c ",objlist[i]->plist->EXPAND0[j]); fprintf(stderr,"\n"); } } pr_EXP(i) int i; { int j; for(j = 0; j < 9; j++) fprintf(stderr,"%c ",objlist[i]->plist->EXPAND0[j]); fprintf(stderr,"\n"); } redraw() { clear(); draw_all(); } ind() { char line[MAXCHARS], com[5]; int argc, arg; start: fprintf(stderr,"\t*> "); fgets(line,MAXCHARS,stdin); argc = sscanf(line,"%s %d",com,&arg); if(argc <= 0) goto start; switch(*com){ case 'z': clear(); zoom(arg); goto start; case '?': ind_help(); goto start; case 'q': return; } if(isdigit(*com)){ arg = atoi(com); if(arg < 1 || arg > number){ fprintf(stderr,"\t unknown chromosome number: %d\n",arg); goto start; } probjtype(objlist[arg - 1]); get_store_data(objlist[arg - 1],arg); probjtype(objlist[arg - 1]); fprintf(stderr,"\n"); goto start; } else{ fprintf(stderr,"\t unknown command: %s\n",line); goto start; } } zoom(arg) int arg; { char dummy; if(arg < 1 || arg > number){ fprintf("\t unknown chromosome number: %d\n",arg); return; } draw_single(objlist[arg - 1]); fprintf(stderr,"\t hit return to continue"); scanf("%c",&dummy); draw_all(); } draw_all() { register int objnum; struct pframe f; f.type = 60; /* FIP aspect ratio correction */ f.ix = scale; f.iy = (3*scale +2)/4; f.scale = 1; f.dx = cellw; f.dy = celll; f.ox = 0; f.oy = 0; if (number > 0) { colour(255); clear(); for (objnum=1; objnum<=number; objnum++){ if(restrict && objlist[objnum-1]->plist != NULL && objlist[objnum-1]->plist->Cotype > CHROMOSOME && objlist[objnum-1]->plist->Cotype < CUT) continue; picframe(objlist[objnum-1],&f); } for (objnum=1; objnum<=number; objnum++){ if(restrict && objlist[objnum-1]->plist != NULL && objlist[objnum-1]->plist->Cotype > CHROMOSOME && objlist[objnum-1]->plist->Cotype < CUT) continue; if (!nonum) frameobjnum(objnum,objlist[objnum-1],&f); } } } probjtype(obj) struct chromosome *obj; { if(obj->plist->Cbtype || obj->plist->Cotype){ fprintf(stderr,"\t type = "); if(obj->plist->Cbtype & CHROMOSOME) fprintf(stderr,"c"); if(obj->plist->Cbtype & DICENTRIC) fprintf(stderr,"d"); if(obj->plist->Cbtype & RING) fprintf(stderr,"r"); if(obj->plist->Cbtype & FRAGMENT) fprintf(stderr,"f"); if(obj->plist->Cbtype & INTERPHASE) fprintf(stderr,"i"); if(obj->plist->Cbtype & PHYBROKEN) fprintf(stderr,"p"); if(obj->plist->Cbtype & CROSSARMS) fprintf(stderr,"x"); if(obj->plist->Cbtype & UNSHURE) fprintf(stderr,"u"); if(obj->plist->Cbtype & JUNK) fprintf(stderr,"j"); if(obj->plist->Cbtype & ACROCENTRIC) fprintf(stderr,"a"); if(obj->plist->Cotype != 0) switch(obj->plist->Cotype){ case CHROMOSOME: fprintf(stderr," s"); /* Single object */ break; case COMPOSITE: fprintf(stderr," t"); /* Touching */ break; case OVERLAP: fprintf(stderr," o"); break; case PIECE: fprintf(stderr," i"); break; case CUT: fprintf(stderr," d"); /* Cut by digitisation area */ break; } fprintf(stderr,"\n"); } } ind_help() { fprintf(stderr,"\t q:\tQuit Ind\n"); fprintf(stderr,"\t z :\tZoom in on chromosome \n"); fprintf(stderr,"\t :\tPrint type & status of chromosome , allow user to clasify\n"); } main_help() { fprintf(stderr,"q:\tQuit\n"); fprintf(stderr,"step:\tStep through each chromosome allowing user to clasify\n"); fprintf(stderr,"ind:\tIndivudaly select objects to be classified\n"); fprintf(stderr,"save:\tWrite all objects to disk\n"); fprintf(stderr,"R:\tRedraw screen\n"); }