home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / TIERRA40.ZIP / BEAGLE / BPROBE.C < prev    next >
C/C++ Source or Header  |  1992-09-11  |  10KB  |  346 lines

  1. /* probe.c  27-3-92  genome probe for the Beagle Explorer */
  2. /*** Beagle Explorer: Version 3.1  Copyright (c) 1990, 1991, 1992  Tom Ray ***/
  3.  
  4. #include "beagle.h"
  5. #include "externb.h"
  6.  
  7. HWND         whpr, wili, wima;
  8. TRANSACTION  *ptpr;
  9.  
  10. char  genomefile[13], genomepath[51], genome[4];
  11. char  probefile[13], probepath[51], proben[4];
  12. struct geneprobe  *p;
  13. int  asize, gsize, psize, num_match;
  14. Instruction  *pgene, *pprobe;
  15.  
  16. int probe(void)
  17. {   int  i;
  18.     static int  first = 1;
  19.     char  t;
  20.     HWND  whins;
  21.  
  22.     if(first)
  23.     {   first = 0;
  24.         sprintf(genomepath,"c:\\tierra\\gb");
  25.         sprintf(genomefile,"0080.gen");
  26.         sprintf(genome,"aaa");
  27.         sprintf(probepath,"c:\\tierra\\gb");
  28.         sprintf(probefile,"0045.gen");
  29.         sprintf(proben,"aaa");
  30.     }
  31.     while(1) {
  32.     whpr = vcreat(6,66,REVNORML,YES);
  33.     vwind(whpr,6,66,0,0);
  34.     vlocate(whpr,2,4);
  35.     vframe(whpr,REVNORML,FRDOUBLE);
  36.     vtitle(whpr,REVNORML,"probe");
  37.     ptpr = vpreload(6,0,NULLF,NULLF,NULLF,NULLF);
  38.     for(i = 0; i <= 5; i++) (*(ptpr->def))[i].use_ext = TRUE;
  39.     vdeffld(ptpr,0,STRING,0,1,"genome path =",-1,50,NULL,genomepath,NO);
  40.     vdeffld(ptpr,1,STRING,1,1,"genome file =",-1,12,NULL,genomefile,NO);
  41.     vdeffld(ptpr,2,STRING,2,1,"genome      =",-1,3,NULL,genome,NO);
  42.     vdeffld(ptpr,3,STRING,3,1,"probe path =", -1,50,NULL,probepath,NO);
  43.     vdeffld(ptpr,4,STRING,4,1,"probe file =", -1,12,NULL,probefile,NO);
  44.     vdeffld(ptpr,5,STRING,5,1,"probe      =", -1,3,NULL,proben,NO);
  45.     whins = wiinv(23,13,
  46.         "\x1e\x1f, or Enter to select; Esc to exit; Ctrl-Enter to run");
  47.     visible(whpr,YES,YES);
  48.     ptpr->fld_valfn = prob_info_chk;
  49.     if(DWSUCCESS == vread(ptpr,whpr,YES))
  50.     {   vdelete(whpr,NONE); vdelete(whins,NONE);
  51.         for (t = 0; t < PLOIDY; t++)
  52.             prob(t);
  53.     }
  54.     else
  55.     {   vdelete(whpr,NONE); vdelete(whins,NONE);
  56.         return 1;
  57.     }
  58.     }
  59.     vdelete(whins,NONE);
  60.     return 1;
  61. }
  62.  
  63. int prob_info_chk(TRANSACTION  *tp)
  64. {   int  success;
  65.     char  path[80];
  66.     head_t  head;
  67.     indx_t  *indx;
  68.     FILE  *inf;
  69.  
  70.     if(tp->cur_fld == 0)
  71.     {   getcwd(path,79);
  72.         success = chdir(genomepath);
  73.         chdir(path);
  74.         if(success)
  75.         {   wierror(2,45,"genomepath not found");
  76.             return FALSE;
  77.         }
  78.         sprintf(path,"%s/opcode.map", genomepath);
  79.         inf = fopen(path,"r");
  80.         if(inf == NULL)
  81.         {   wierror(2,45,"opcode.map not found");
  82.             return FALSE;
  83.         }
  84.         fclose(inf);
  85.         return TRUE;
  86.     }
  87.     if(tp->cur_fld == 1)
  88.     {   sprintf(path,"%s/%s", genomepath, genomefile);
  89.         inf = fopen(path,"r");
  90.         if(inf == NULL)
  91.         {   wierror(2,45,"genomefile not found");
  92.             return FALSE;
  93.         }
  94.         fclose(inf);
  95.         return TRUE;
  96.     }
  97.     if(tp->cur_fld == 2)
  98.     {   sprintf(path,"%s/%s", genomepath, genomefile);
  99.     if (!(inf = fopen(path, "rb")))
  100.         {   wierror(2,45,"file not found");
  101.             return FALSE;
  102.     }
  103.     head = read_head(inf);
  104.     indx = read_indx(inf, &head);
  105.         fclose(inf);
  106.         if (find_gen(indx, genome, head.n) == head.n)
  107.         {   wierror(2,35,"genotype not contained in genomefile");
  108.             farfree(indx);
  109.             return FALSE;
  110.         }
  111.         farfree(indx);
  112.         return TRUE;
  113.     }
  114.     if(tp->cur_fld == 3)
  115.     {   getcwd(path,79);
  116.         success = chdir(probepath);
  117.         chdir(path);
  118.         if(success)
  119.         {   wierror(2,45,"probepath not found");
  120.             return FALSE;
  121.         }
  122.         sprintf(path,"%s/opcode.map", probepath);
  123.         inf = fopen(path,"r");
  124.         if(inf == NULL)
  125.         {   wierror(2,45,"opcode.map not found");
  126.             return FALSE;
  127.         }
  128.         fclose(inf);
  129.         return TRUE;
  130.     }
  131.     if(tp->cur_fld == 4)
  132.     {   sprintf(path,"%s/%s", probepath, probefile);
  133.         inf = fopen(path,"r");
  134.         if(inf == NULL)
  135.         {   wierror(2,45,"probefile not found");
  136.             return FALSE;
  137.         }
  138.         fclose(inf);
  139.         return TRUE;
  140.     }
  141.     if(tp->cur_fld == 5)
  142.     {   sprintf(path,"%s/%s", probepath, probefile);
  143.     if (!(inf = fopen(path, "rb")))
  144.         {   wierror(2,45,"file not found");
  145.             return FALSE;
  146.     }
  147.     head = read_head(inf);
  148.     indx = read_indx(inf, &head);
  149.         fclose(inf);
  150.         if (find_gen(indx, proben, head.n) == head.n)
  151.         {   wierror(2,35,"genotype not contained in probefile");
  152.             farfree(indx);
  153.             return FALSE;
  154.         }
  155.         farfree(indx);
  156.     }
  157.     return TRUE;
  158. }
  159.  
  160. void prob(char  track)
  161. {   char  tname[13];
  162.     int  tsize, i;
  163.     Instruction  *tgene;
  164.     FILE  *info;
  165.     char  data[85], error[110];
  166.     ArgInstDef  *paid;
  167.  
  168.     paid = (ArgInstDef  *) calloc(INSTNUM, sizeof(ArgInstDef));
  169.     sprintf(data,"%s/opcode.map", probepath);
  170.     GetAMap(data);
  171.     for (i = 0; i < INSTNUM; i++)
  172.         paid[i] = aid[i];
  173. /*
  174.     info = fopen(data,"r");
  175.     if(info == NULL)
  176.         wierror(2,45,"opcode.map not found");
  177.     fgets(data, 84, info);
  178.     while (strlen(data) > 3)
  179.     {   if (!GetAMap(data))
  180.         {   sprintf(error, "bad IMapFile line: %s", data);
  181.             wierror(2,10,error);
  182.         }
  183.         if (fgets(data, 84, info) == NULL)
  184.             break ;
  185.     }
  186.     fclose(info);
  187.     for (i = 0; i < INSTNUM; i++)
  188.         paid[i] = aid[i];
  189.     qsort(paid,INSTNUM,sizeof(ArgInstDef),aid_compare);
  190. */
  191.  
  192.     sprintf(data,"%s/opcode.map", genomepath);
  193.     GetAMap(data);
  194. /*
  195.     info = fopen(data,"r");
  196.     if(info == NULL)
  197.         wierror(2,45,"opcode.map not found");
  198.     fgets(data, 84, info);
  199.     while (strlen(data) > 3)
  200.     {   if (!GetAMap(data))
  201.         {   sprintf(error, "bad IMapFile line: %s", data);
  202.             wierror(2,10,error);
  203.         }
  204.         if (fgets(data, 84, info) == NULL)
  205.             break ;
  206.     }
  207.     fclose(info);
  208.     qsort(aid,INSTNUM,sizeof(ArgInstDef),aid_compare);
  209. */
  210.  
  211.     for (i = 0; i < INSTNUM; i++)
  212.         if (paid[i].op != aid[i].op || strcmp(paid[i].mn,aid[i].mn))
  213.         {   wierror(2,45,"incompatible opcode.maps");
  214.             break;
  215.         }
  216.     free(paid);
  217.  
  218.     sscanf(genomefile, "%d", &gsize);
  219.     pgene = get_gentype(genomepath, genomefile, genome);
  220.     if(pgene == NULL)
  221.     {   wierror(2,45,"genome file not found");
  222.         return ;
  223.     }
  224.     sscanf(probefile, "%d", &psize);
  225.     pprobe = get_gentype(probepath, probefile, proben);
  226.     if(pprobe == NULL)
  227.     {   wierror(2,45,"probe file not found");
  228.         return ;
  229.     }
  230.     if(psize > gsize)
  231.     {   tgene = pgene;
  232.         pgene = pprobe;
  233.         pprobe = tgene;
  234.         sprintf(tname,"%s", genome);
  235.         sprintf(genome,"%s", proben);
  236.         sprintf(proben,"%s", tname);
  237.         tsize = gsize;
  238.         gsize = psize;
  239.         psize = tsize;
  240.     }
  241.     asize = 1 + ((2 * (gsize + psize)) / psize);
  242.     p = (struct geneprobe  *) calloc(asize, sizeof(struct geneprobe));
  243.     probeslide(pprobe,psize,pgene,gsize,track);
  244.     qsort(p, asize, sizeof(struct geneprobe), prcmp);
  245.     comp_ins_del();
  246.     plogical(asize);
  247.     instlist();
  248.     pmatch(track);
  249.     free(pgene);
  250.     free(pprobe);
  251.     free(p);
  252. }
  253.  
  254. void pmatch(char  track)
  255. {   HWND  whins;
  256.     int   i, r = -3, wr, page;
  257.     char  title[78];
  258.  
  259.     wr = gsize / 76;
  260.     if(gsize % 76) wr++; wr *= 3;  page = wr;
  261.     wima = vcreat(wr - 1,78,REVNORML,YES);
  262.     if(wr > 17) { vwind(wima,17,78,0,0); page = 16; }
  263.     else vwind(wima,wr - 1,78,0,0);
  264.     vlocate(wima,7,1);
  265.     vframe(wima,REVNORML,FRSINGLE);
  266.     sprintf(title,
  267.         "genome-to-probe match:  genome (top) - %04d%s    probe - %04d%s",
  268.         gsize, genome, psize, proben);
  269.     vtitle(wima,REVNORML,title);
  270.     visible(wima,YES,YES);
  271.     for(i = 0; i < gsize; i++)
  272.     {   if(!(i % 76)) { r += 3; lcurset(wima,r,1); }
  273. #if PLOIDY == 1
  274.         vrpc(NORML,inst_letter((int)(pgene + i)->inst));
  275. #else /* PLOIDY > 1 */
  276.         vrpc(NORML,inst_letter((int)(pgene + i)[track]->inst));
  277. #endif /* PLOIDY == 1 */
  278.     }
  279.     qsort(p, num_match, sizeof(struct geneprobe), orcmp);
  280.     unlap(track);
  281.     if(wr > 17)
  282.          whins = wint(24,18,
  283.              "Instructions: \x1e\x1f to scroll; Esc to continue");
  284.     else
  285.          whins = wint(6 + wr,25,"Instructions: Esc to continue");
  286.     lineup(track);
  287.     scroll(page,wima);
  288.     vdelete(wima,NONE);
  289.     vdelete(wili,NONE);
  290.     vdelete(whins,NONE);
  291. }
  292.  
  293. void plogical(int  size)
  294. {   HWND  winl, winu, whins;
  295.     int   i, page = size - 1;
  296.     TRANSACTION  *ptnu;
  297.  
  298.     num_match = gsize / 80;
  299.     if(gsize % 80 > 40) num_match++;
  300.     if(gsize <= 40) num_match = 1;
  301.     if(size > 400) size = 400;
  302.     winl = vcreat(size,55,NORML,YES);
  303.     if(size > 21) { vwind(winl,21,55,0,0); page = 20; }
  304.     else vwind(winl,size,55,0,0);
  305.     vlocate(winl,2,8);
  306.     vframe(winl,NORML,FRSINGLE);
  307.     for(i = 0; i < size; i++)
  308.         vatputf(winl,i,3,"position: %4d   fit: %3d   diff: %2d   idpos: %3d",
  309.             p[i].position, p[i].fit, p[i].diff, p[i].idpos);
  310.     if(size > 21)
  311.          whins = wiinv(23,25,"\x1e\x1f to scroll; Esc to continue");
  312.     else
  313.          whins = wiinv(23,32,"Esc to continue");
  314.     visible(winl,YES,YES);
  315.     scroll(page,winl);
  316.     vdelete(whins,NONE);
  317.     winu = wigen(2,46,1,30,FRDOUBLE,"number of matches to use");
  318.     ptnu = vpreload(5,0,NULLF,NULLF,NULLF,NULLF);
  319.     (*(ptnu->def))[0].use_ext = TRUE;
  320.     vdeffld(ptnu,0,INTEGER,0,1,"number of matches =",-1,4,NULL,&num_match,NO);
  321.     whins = wiinv(23,28,"Ctrl-Enter to continue");
  322.     visible(winu,YES,YES);
  323.     vread(ptnu,winu,YES);
  324.     vdelete(winu,NONE);
  325.     vdelete(winl,NONE); 
  326.     vdelete(whins,NONE);
  327. }
  328.  
  329. int orcmp(const void  *g1, const void  *g2)
  330. {   struct geneprobe  *ge1 = g1, *ge2 = g2;
  331.  
  332.     return ge1->position - ge2->position;
  333. }
  334.  
  335. int prcmp(const void  *g1, const void  *g2)
  336. {   struct geneprobe  *ge1 = g1, *ge2 = g2;
  337.  
  338.     return ge2->fit - ge1->fit;
  339. }
  340.  
  341. int rprcmp(const void  *g1, const void  *g2)
  342. {   struct geneprobe  *ge1 = g1, *ge2 = g2;
  343.  
  344.     return ge1->fit - ge2->fit;
  345. }
  346.