source: tags/initial/NTREE/AP_cprofile.cxx

Last change on this file was 2, checked in by oldcode, 23 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 57.7 KB
Line 
1 /* -----------------------------------------------------------------
2 * Project:                       ARB
3 *
4 * Module:                        conservation profile [abbrev.: CPRO]
5 *
6 * Exported Classes:              x
7 *
8 * Global Functions:              x
9 *
10 * Global Variables:       
11 *                                  AWARS
12 *               AW_STRING, "cpro/alignment" : name of alignment
13 *               AW_STRING, "cpro/which_species" : all/marked
14 *               AW_STRING, "cpro/countgaps" : if off, drop gaps
15 *               AW_FLOAT, "cpro/rateofgroup" : how to rate, when two
16 *                 characters belong to the same group [ 0.0 means don't rate ]
17 *               AW_INT, AWAR_CURSOR_POSITION:
18 *                           column shown in func. CPRO_drawstatistic_cb
19 *
20 * Global Structures:             CPRO
21 *
22 * Private Classes:               .
23 *
24 * Private Functions:             .
25 *
26 * Private Variables:             .
27 *
28 * Dependencies:             Needs cprofile.fig, CPROdraw.fig, CPROdens.fig
29 *                                 CPROxpert.fig CPROcalc.fig
30 *
31 * Description:                   x
32 *
33 * Integration Notes: The main function using this module must have a
34 *                    callback to the function
35 *                    AW_window *AP_open_cprofile_window( AW_root *aw_root)
36 *                    and the function void create_consensus_var
37 *                    (AW_root *aw_root, AW_default aw_def) has to be called.
38 *
39 * -----------------------------------------------------------------
40 */
41#include <stdlib.h>
42#include <stdio.h>
43#include <iostream.h>
44#include <string.h>
45#include <memory.h>
46#include <malloc.h>
47#include <math.h>
48#include <arbdb.h>
49#include <arbdbt.h>
50#include <aw_root.hxx>
51#include <aw_device.hxx>
52#include <aw_window.hxx>
53#include <aw_awars.hxx>
54#include <awt.hxx>
55typedef GB_UINT4 STATTYPE;
56void CPRO_memrequirement_cb(AW_root *aw_root,AW_CL cd1,AW_CL cd2);
57extern GBDATA *gb_main;
58enum {
59        GAP = 1,
60        BAS_A = 2,
61        BAS_C = 3,
62        BAS_G = 4,
63        BAS_T = 5  ,
64        MAX_BASES = 6,
65        MAX_AMINOS =27+GAP
66         };
67#define GC_black 7
68#define GC_blue 6
69#define GC_green 5
70#define GC_grid 4
71
72
73struct CPRO_result_struct {
74        STATTYPE **statistic;
75        long maxalignlen;          // length of longest sequence
76        long resolution;           // resolution of statistic table
77        float ratio;               // ratio between transitions and transversion
78        long maxaccu;              // highest number of compares per distance
79        long memneeded;            // memory required for this statistic
80        char which_species[20];    // "marked vs all" , ...
81        char drawmode;             // smoothing
82        char alignname[80];        // name of alignment
83        char statisticexists;      // was there yet a statistic calculated/loaded ?
84        long leastcompares;        // if less overlap between two sequences
85                                   // comparison doesn't contribute to statistic
86        long countgaps;            // if 0, comparisons with gaps are not counted
87};
88
89struct CPRO_struct {
90        long numspecies;           // number of species
91        long maxresneeded;         // not yet used (max distance of calculation)
92        long partition;            // size of partition in matrix of compares
93        long leastaccu;            // if less compares per distance don't show
94        char *agonist;             // list of species that contribute to statistic
95        char *antagonist;          // -^-
96        char convtable[256];         // converts character to a token
97        char grouptable[MAX_AMINOS]; // gives number of group, in which token is
98                                     // member
99        float grouprate;           // ratio between transitions and transversions
100        float distancecorrection;  // results out of grouprate
101        long column;               // column of alignment that is shown
102        float maxdistance;         // statistic shows up to this point of distance
103        long gridhorizontal;       // grid over statistic
104        long gridvertical;         // -^-
105        float Z_it_group;          // last value , needed for smoothing
106        float Z_it_equal;          // -^-
107        struct CPRO_result_struct result[2]; // info needed for each statistic
108        } CPRO;
109
110
111/* -----------------------------------------------------------------
112 * Function:                     CPRO_readandallocate
113 *
114 * Arguments:                    char versus,char *align (name of alignment)
115 *
116 * Returns:                      modifies:   
117 *                               char **&speciesdata,GBDATA **&speciesdatabase
118 *
119 * Description:     Memory for 'statistic', 'speciesdata', 'speciesdatabase',
120 *                  'agonist' and 'antagonist' is allocated.
121 *                  Pointers to the sequences in the database are
122 *                  read into array 'speciesdatabase'.
123 *                 
124 *
125 * NOTE:                         .
126 *
127 * Global Variables referenced:  .
128 *
129 * Global Variables modified:    CPRO.agonist,CPRO.antagonist,CPRO.numspecies
130 *
131 * AWARs referenced:             .
132 *
133 * AWARs modified:               x
134 *
135 * Dependencies:                 . 
136 * -----------------------------------------------------------------
137 */
138void CPRO_readandallocate(char **&speciesdata,GBDATA **&speciesdatabase,
139                char versus,char *align)
140{
141        GBDATA *gb_species_data = GB_search(gb_main,"species_data",GB_FIND);
142        GBDATA *gb_species;
143
144        aw_status("reading database");
145
146        long nrofspecies=0;
147        gb_species = GBT_first_species_rel_species_data(gb_species_data);
148        while(gb_species)
149        {               
150                if(GBT_read_sequence(gb_species,align)){
151                        nrofspecies++;    }
152                gb_species = GBT_next_species(gb_species);     
153        }
154        CPRO.numspecies=nrofspecies;
155
156        speciesdata=(char **)calloc((size_t)CPRO.numspecies,sizeof(char *));
157        CPRO.agonist=(char *)calloc((size_t)CPRO.numspecies,sizeof(char));
158        CPRO.antagonist=(char *)calloc((size_t)CPRO.numspecies,sizeof(char));
159        speciesdatabase=(GBDATA **)calloc(
160                 (size_t)CPRO.numspecies+1,sizeof(GBDATA *)); // Null termintated
161        GBDATA *alidata;
162
163        long countspecies=0;
164        gb_species = GBT_first_species_rel_species_data(gb_species_data);
165        while(gb_species)
166        {               
167                if( (alidata=GBT_read_sequence(gb_species,align)) ) 
168                        {
169                        speciesdatabase[countspecies++]=alidata;         
170                        }
171                gb_species = GBT_next_species(gb_species);     
172        }
173
174        for(long i=0;i<CPRO.numspecies;i++)
175        {
176                CPRO.agonist[i]=1;
177                CPRO.antagonist[i]=1;
178        }
179
180        if(versus!=0)
181        {
182                for(long j=0;j<CPRO.numspecies;j++)
183                {
184                        CPRO.antagonist[j]=0;
185                        if(GB_read_flag(GB_get_father(GB_get_father(speciesdatabase[j])))) 
186                                        CPRO.antagonist[j]=(char)1;
187                }
188        }
189        if(versus==1)
190        {
191            long j;
192            for(j=0;j<CPRO.numspecies;j++) CPRO.agonist[j]=CPRO.antagonist[j];
193        }
194}
195
196// frees memory allocated by function CPRO_readandallocate
197void CPRO_deallocate(char **&speciesdata,GBDATA **&speciesdatabase)
198{
199        for(long i=0;i<CPRO.numspecies;i++)
200        {
201                if(speciesdata[i]) {  delete(speciesdata[i]); speciesdata[i]=0; }
202        }
203        delete(speciesdata); speciesdata=0;
204
205        delete(speciesdatabase);
206        delete CPRO.agonist; delete CPRO.antagonist;
207        // 'CPRO.statistic' must not be freed, because it is needed in
208        // function CPRO_drawstatistic
209}
210
211void CPRO_allocstatistic(char which_statistic)
212{
213                CPRO.result[which_statistic].statistic=(STATTYPE **)calloc(
214                    (size_t)CPRO.result[which_statistic].resolution*3+3,
215                                sizeof(STATTYPE *));
216                for(long i=0;i<CPRO.result[which_statistic].resolution*3;i++) 
217                {
218                        CPRO.result[which_statistic].statistic[i]=(STATTYPE *)calloc(
219                        (size_t)CPRO.result[which_statistic].maxalignlen,
220                                sizeof(STATTYPE)); 
221                }
222}
223
224void CPRO_freestatistic(char which_statistic)
225{
226        for(long j=0;j<CPRO.result[which_statistic].resolution*3;j++)
227        {
228                if(CPRO.result[which_statistic].statistic[j])
229                {
230                        delete(CPRO.result[which_statistic].statistic[j]);
231                        CPRO.result[which_statistic].statistic[j]=0;
232                }
233        }
234        delete(CPRO.result[which_statistic].statistic);
235        CPRO.result[which_statistic].statistic=0;
236}
237
238// memory not used is given back to system
239void CPRO_workupstatistic(char which_statistic)
240{
241        long base;
242        long column,colmax,memneeded=0;
243        long sum,hits,different,group;
244        long hitsc,diffc,groupc;
245        CPRO.maxresneeded=0;
246        CPRO.result[which_statistic].maxaccu=0;
247        for(long res=0;res<CPRO.result[which_statistic].resolution;res++)
248        {
249                base=res*3;
250                hits=0;different=0;group=0;
251                for(column=0;column<CPRO.result[which_statistic].maxalignlen;column++)
252                {
253                        hitsc=(long)CPRO.result[which_statistic].statistic[base+0][column];
254                        groupc=(long)CPRO.result[which_statistic].statistic
255                                                                    [base+1][column];
256                        diffc=(long)CPRO.result[which_statistic].statistic[base+2][column];
257                        sum=hitsc+groupc+diffc;
258                        hits+=hitsc; group+=groupc; different+=diffc;
259
260                        if(sum) CPRO.maxresneeded=res+1;
261                        if(sum>CPRO.result[which_statistic].maxaccu)
262                        {
263                                CPRO.result[which_statistic].maxaccu=sum;
264                                colmax=column;
265                        } 
266                }
267                if(hits) memneeded+=CPRO.result[which_statistic].maxalignlen;
268                else {  delete(CPRO.result[which_statistic].statistic[base+0]);
269                        CPRO.result[which_statistic].statistic[base+0]=0; }
270                if(group) memneeded+=CPRO.result[which_statistic].maxalignlen;
271                else { delete(CPRO.result[which_statistic].statistic[base+1]);
272                           CPRO.result[which_statistic].statistic[base+1]=0; }
273                if(different) memneeded+=
274                              CPRO.result[which_statistic].maxalignlen;
275                else { delete(CPRO.result[which_statistic].statistic[base+2]);
276                           CPRO.result[which_statistic].statistic[base+2]=0; }
277        }
278        if(!CPRO.result[which_statistic].maxaccu)
279                CPRO.result[which_statistic].maxaccu=1;
280        CPRO.result[which_statistic].memneeded=memneeded;
281}
282
283
284/* -----------------------------------------------------------------
285 * Function:          CPRO_maketables           
286 *
287 * Arguments:         char isamino
288 *
289 * Returns:           modifies: char *CPRO.convtable,
290 *                              char *CPRO.grouptable
291 *
292 * Description:       Fills tables CPRO.convtable and CPRO.grouptable, that are
293 *                    used later, when making the statistic. Meaning of tables:
294 *                    E.g. CPRO.convtable['a']=BAS_A means that char. 'a' is
295 *                    converted into number BAS_A. Then CPRO.grouptable[BAS_A]=1
296 *                    and CPRO.grouptable[BAS_G]=1 means, that characters 'a'
297  *                   and 'g' are both members of group 1.
298 *
299 * NOTE:                         .
300 *
301 * Global Variables referenced:  .
302 *
303 * Global Variables modified:    char *CPRO.convtable, char *CPRO.grouptable
304 *
305 * AWARs referenced:             .
306 *
307 * AWARs modified:               x
308 *
309 * Dependencies:                 . 
310 * -----------------------------------------------------------------
311 */
312void CPRO_maketables(char isamino,char countgaps)
313{
314        long i;
315        for(i=0;i<256;i++)  { 
316                CPRO.convtable[i]=0; }
317        if(!isamino)
318        {
319                if(countgaps) CPRO.convtable['-']=GAP;
320                CPRO.convtable['a']=BAS_A;      CPRO.convtable['A']=BAS_A;
321                CPRO.convtable['c']=BAS_C;      CPRO.convtable['C']=BAS_C;
322                CPRO.convtable['g']=BAS_G;      CPRO.convtable['G']=BAS_G;
323                CPRO.convtable['t']=BAS_T;      CPRO.convtable['T']=BAS_T;
324                CPRO.convtable['u']=BAS_T;      CPRO.convtable['U']=BAS_T;
325
326                for(i=0;i<MAX_AMINOS;i++) { 
327                        CPRO.grouptable[i]=0; }
328                CPRO.grouptable[BAS_A]=1;       CPRO.grouptable[BAS_G]=1;
329                CPRO.grouptable[BAS_C]=2;       CPRO.grouptable[BAS_T]=2;               
330        }
331        else
332        {
333                if(countgaps) CPRO.convtable['-']=GAP;
334                for(i=0;i<MAX_AMINOS;i++)
335                {
336                        CPRO.convtable['a'+i]=i+1+GAP;
337                        CPRO.convtable['A'+i]=i+1+GAP;
338                }
339                CPRO.convtable['*']=10+GAP   ; /* 'J' */
340
341                for(i=0;i<MAX_AMINOS;i++) { CPRO.grouptable[i]=0; }
342#define SC(x,P) CPRO.grouptable[P-'A'+1+GAP] = x
343                SC(1,'P');SC(1,'A');SC(1,'G');SC(1,'S');SC(1,'T');
344                                   /* PAGST */
345                SC(2,'Q');SC(2,'N');SC(2,'E');SC(2,'D');SC(2,'B');
346                SC(2,'Z');         /* QNEDBZ */
347                SC(3,'H');SC(3,'K');SC(3,'R');
348                                   /* HKR */
349                SC(4,'L');SC(4,'I');SC(4,'V');SC(4,'M');
350                                           /* LIVM */
351                SC(5,'F');SC(5,'Y');SC(5,'W');
352                                       /* FYW */
353#undef SC               
354        }
355}
356
357
358void CPRO_entryinstatistic(char **speciesdata,
359                           long elemx,long elemy,char which_statistic)
360{
361        register char value1, value2 =0;
362        register char *firstseq=speciesdata[elemx];
363        register char *secondseq=speciesdata[elemy];
364        register float rate=0.0;
365        register long numofcolumns=0;
366        float distance=0.0;
367
368       
369        if(elemx==elemy) return;
370        if(!(CPRO.agonist[elemx])) return;
371        if(!(CPRO.antagonist[elemy])) return;
372        if((CPRO.agonist[elemy])&&(CPRO.antagonist[elemx])&&(elemy<elemx)) return;     
373
374        //add similarities (added 1.0 means equal, 0.0 means different)
375        register long counter;
376        for(counter=0;counter<CPRO.result[which_statistic].maxalignlen;counter++)
377        {
378                if((value1=*firstseq)&&(value2=*secondseq))
379                {
380                        numofcolumns++;
381                        if(value1==value2) { 
382                                rate=rate+1.0; }
383                        else if(CPRO.grouptable[value1]==CPRO.grouptable[value2]) {
384                                        rate=rate+CPRO.grouprate; } // add transition weighted
385                                                                                                // between 1.0 and 0.0
386                }
387                firstseq++;
388                secondseq++;
389        }
390
391        if(numofcolumns<CPRO.result[which_statistic].leastcompares) return;
392        distance=((float)numofcolumns-rate)/(float)numofcolumns;
393        distance=distance*CPRO.distancecorrection;
394
395        long column=(long)(distance*CPRO.result[which_statistic].resolution);
396
397        if (column < 0 || column>= CPRO.result[which_statistic].resolution) return;
398       
399        register STATTYPE *equalentry=
400                                CPRO.result[which_statistic].statistic[3*column];
401        register STATTYPE *samegroupentry=
402                                CPRO.result[which_statistic].statistic[3*column+1];
403        register STATTYPE *differententry=
404                                CPRO.result[which_statistic].statistic[3*column+2];
405        firstseq=speciesdata[elemx];
406        secondseq=speciesdata[elemy];
407
408        for(counter=0;counter<CPRO.result[which_statistic].maxalignlen;counter++)
409        {
410                if((value1=*firstseq)&&(value2=*secondseq)) 
411                // when gap or unaligned base goto next position
412                {
413                        if(value1==value2) { (*equalentry)++; }
414                        else if(CPRO.grouptable[value1]==CPRO.grouptable[value2]) {
415                                (*samegroupentry)++; }
416                        else { (*differententry)++; }
417                }
418                firstseq++;
419                secondseq++;
420                equalentry++;
421                samegroupentry++;
422                differententry++;
423        }       
424       
425
426
427}
428
429// is used by function CPRO_makestatistic
430// reads sequences of a segment into memory, converts them
431// and frees older sequences
432void CPRO_readneededdata(char **speciesdata,GBDATA **speciesdatabase,
433         long elemx1,long elemx2,long elemy1,long elemy2,char which_statistic)
434{
435        long i=0,j=0;
436        char *tempdata;
437        for(i=0;i<CPRO.numspecies;i++)
438        {
439                if((speciesdata[i])&&(i<elemy1)&&(i>elemy2)&&(i<elemx1)&&(i>elemx2)) 
440                { 
441                         delete(speciesdata[i]); speciesdata[i]=0; 
442                }
443        }       
444
445        if(elemx1<CPRO.numspecies)
446        {
447                for(i=elemx1;(i<=elemx2 && i<CPRO.numspecies);i++) 
448                {
449                        if( (CPRO.agonist[i])&&(!(speciesdata[i])) )
450                        {
451                                tempdata=GB_read_char_pntr(speciesdatabase[i]);
452                                speciesdata[i]=(char*)calloc((unsigned int)
453                                                CPRO.result[which_statistic].maxalignlen,1);
454                                for(j=0;j<CPRO.result[which_statistic].maxalignlen;j++)  {
455                                        speciesdata[i][j]=CPRO.convtable[tempdata[j]];  }
456                        }
457                }
458        }
459        if(elemy1<CPRO.numspecies)             
460        {
461                for(i=elemy1;(i<=elemy2 && i<CPRO.numspecies);i++) 
462                {
463                        if( (CPRO.antagonist[i])&&(!(speciesdata[i])) )
464                        {
465                                tempdata=GB_read_char_pntr(speciesdatabase[i]);
466                                speciesdata[i]=(char*)calloc((unsigned int)
467                                                CPRO.result[which_statistic].maxalignlen,1); 
468                                for(j=0;j<CPRO.result[which_statistic].maxalignlen;j++)  {
469                                        speciesdata[i][j]=CPRO.convtable[tempdata[j]];  }
470                        }
471                }
472        }
473}
474
475
476/* -----------------------------------------------------------------
477 * Function:                     CPRO_makestatistic
478 *
479 * Arguments:                    char **speciesdata,
480 *                               GBDATA **speciesdatabase
481 *
482 * Returns:                      1 if successful, 0 if user abort
483 *                                   (without consequences)
484 *
485 * Description:    This function compares every sequence with every sequence.
486 *                 It devides the matrix into segments and goes through each
487 *                 segment. Width of a segment depends on CPRO.partition.
488 *                 MAX_MEMORY/2 is available.
489 *                 When a new segment is entered, the corresponding
490 *                 sequences are loaded into array 'speciesdata' by the function
491 *                 CPRO_readneededdata. 'speciesdatabase' contains pointers of
492 *                 sequences to the database. Comparison and evaluation of two
493 *                 sequences is done by function CPRO_entryinstatistic.
494 *
495 * NOTE:                         .
496 *
497 * Global Variables referenced:
498 *      CPRO.numspecies,CPRO.result[which_statistic].maxalignlen
499 *                               
500 * Global Variables modified:    x
501 *
502 * AWARs referenced:             .
503 *
504 * AWARs modified:          CPRO.result[which_statistic].statistic  is modified
505 *
506 * Dependencies:                 CPRO_entryinstatistic , CPRO_readneededdata 
507 * -----------------------------------------------------------------
508 */
509char CPRO_makestatistic(char **speciesdata,GBDATA **speciesdatabase,
510                            char which_statistic) 
511{
512        long widthmatrix=CPRO.partition;
513        long n=CPRO.numspecies;
514        long comparesneeded=n*n;    // (n*n-n)/2;
515        long compares=0;
516        long numofsegments=CPRO.numspecies/widthmatrix +1;
517        long segmentx=0,segmenty=0,elemx=0,elemy=0;
518        long elemx1=0,elemx2=0,elemy1=0,elemy2=0;
519
520        if(CPRO.result[which_statistic].statisticexists)
521        {
522                CPRO_freestatistic(which_statistic);
523        }
524        else CPRO.result[which_statistic].statisticexists=1;
525
526        CPRO_allocstatistic(which_statistic);
527
528        aw_status("calculating");
529
530        for(segmentx=0;segmentx<numofsegments;segmentx++)
531        {
532                elemx1=widthmatrix*segmentx;
533                elemx2=widthmatrix*(segmentx+1)-1;
534                for(segmenty=0;segmenty<numofsegments;segmenty++)
535                {
536                        elemy1=widthmatrix*segmenty;
537                        elemy2=widthmatrix*(segmenty+1)-1;
538                        //printf("Partition by %ld , %ld\n",elemx1,elemy1);
539                        CPRO_readneededdata(speciesdata,speciesdatabase,
540                                            elemx1,elemx2,elemy1,elemy2,which_statistic);
541                        for(elemx=elemx1;elemx<=elemx2;elemx++)
542                        {
543                                for(elemy=elemy1;elemy<=elemy2;elemy++)
544                                {
545                                        if((elemy<CPRO.numspecies)&&(elemx<CPRO.numspecies))
546                                        {
547                                                CPRO_entryinstatistic(speciesdata,
548                                                                      elemx,elemy,which_statistic);
549                                                compares++;
550                                                if(((compares/30)*30)==compares) 
551                                                {
552                                                        if(aw_status((double)compares
553                                                           /(double)comparesneeded))  return(0);
554                                                }
555                                        }
556                                }
557                        }
558                }
559        }
560        return(1);
561}
562
563
564
565/* -----------------------------------------------------------------
566 * Function:                     CPRO_calculate_cb
567 *
568 * Arguments:                    .
569 *
570 * Returns:                      .
571 *
572 * Description:          main callback
573 *                       This function calculates the conservative profile.
574 *                       Function CPRO_readandallocate allocates memory and
575 *                       reads necessary data. Calculation of the statistic
576 *                       is done in function CPRO_makestatistic.
577 *                       Allocated memory is freed in function CPRO_deallocate.
578 *
579 * NOTE:                         .
580 *
581 * Global Variables referenced:  .
582 *
583 * Global Variables modified:    x
584 *
585 * AWARs referenced:             cpro/alignment , cpro/which_species
586 *                               cpro/countgaps , cpro/rateofgroups
587 *
588 * AWARs modified:               x
589 *
590 * Dependencies:   CPRO_readandallocate , CPRO_makestatistic , CPRO_deallocate
591 * -----------------------------------------------------------------
592 */
593void CPRO_calculate_cb(AW_window *aw,AW_CL which_statistic)
594{
595        AW_root *awr=aw->get_root();
596        char *align=awr->awar("cpro/alignment")->read_string();
597        char *marked=awr->awar("cpro/which_species")->read_string();
598        char versus=0; /* all vs all */
599        if(!(strcmp("marked",marked))) versus=1; /*marked vs marked*/
600        if(!(strcmp("markedall",marked))) versus=2; /* marked vs all*/
601        GB_ERROR faultmessage;
602        delete marked;
603
604        if(CPRO.result[which_statistic].statisticexists)
605        {
606                CPRO_freestatistic((char)which_statistic);
607                CPRO.result[which_statistic].statisticexists=0;
608        }
609
610        strcpy(CPRO.result[which_statistic].alignname,align);
611        CPRO.result[which_statistic].resolution=awr->awar("cpro/resolution")->read_int();
612        if (CPRO.result[which_statistic].resolution<=0)
613                 CPRO.result[which_statistic].resolution=1;
614        CPRO.result[which_statistic].leastcompares=
615                awr->awar("cpro/leastcompares")->read_int();
616        if (CPRO.result[which_statistic].leastcompares<=0) CPRO.result[which_statistic].leastcompares=1;
617
618        if(versus==1) strcpy(CPRO.result[which_statistic].which_species,"m vs m\0");
619        else if(versus==2) strcpy(CPRO.result[which_statistic].which_species,
620                                  "m vs all\0");
621        else strcpy(CPRO.result[which_statistic].which_species,"all vs all\0");
622
623        if( (faultmessage=GB_push_transaction(gb_main)) ) 
624        {
625                aw_message(faultmessage,"OK,EXIT");
626                delete   align;
627                return;
628        }
629
630        CPRO.result[which_statistic].maxalignlen=
631                GBT_get_alignment_len(gb_main,align);
632        if(CPRO.result[which_statistic].maxalignlen<=0) {
633                GB_pop_transaction(gb_main);
634                aw_message("Error: Select an alignment !");
635                delete   align;
636                return;
637        }
638
639        char isamino= GBT_is_alignment_protein(gb_main,align);
640        aw_openstatus("calculating");aw_status((double)0);
641
642        GBDATA **speciesdatabase; // array of GBDATA-pointers to the species
643        char **speciesdata;//array of pointers to strings that hold data of species
644
645// allocate memory for 'CPRO.statistic','speciesdata' and fill
646//                'speciesdatabase','agonist' and 'antagonist'
647        CPRO_readandallocate(speciesdata,speciesdatabase,versus,align);
648
649        char *countgapsstring=awr->awar("cpro/countgaps")->read_string();
650        char countgaps=1;
651        if(strcmp("on",countgapsstring)) countgaps=0;
652        delete countgapsstring;
653        CPRO.result[which_statistic].countgaps=(long)countgaps;
654
655/* create convtable and grouptable */
656        CPRO_maketables(isamino,countgaps);
657        CPRO.result[which_statistic].ratio=awr->awar("cpro/transratio")->read_float();
658        CPRO.grouprate=1-(0.5/CPRO.result[which_statistic].ratio);
659        CPRO.distancecorrection=(CPRO.result[which_statistic].ratio+1)*2.0/3.0;
660
661/* fill the CPRO.statistic table */
662        char success=CPRO_makestatistic(speciesdata,speciesdatabase,(char)which_statistic);
663        GBUSE(success);
664        CPRO_workupstatistic((char)which_statistic);
665
666        aw_closestatus();
667
668        CPRO_deallocate(speciesdata,speciesdatabase);
669        delete   align;
670        if( (faultmessage=GB_pop_transaction(gb_main)) ) 
671        {
672                aw_message(faultmessage,"OK,EXIT");
673                return;
674        }       
675
676        CPRO_memrequirement_cb(awr,0,0);
677
678}
679
680void CPRO_memrequirement_cb(AW_root *aw_root,AW_CL cd1,AW_CL cd2)
681{
682        AWUSE(cd1),AWUSE(cd2);
683        char *align=aw_root->awar("cpro/alignment")->read_string();
684        char *marked=aw_root->awar("cpro/which_species")->read_string();
685        char versus=0; /* all vs all */
686        if(!(strcmp("marked",marked))) versus=1;
687        if(!(strcmp("markedall",marked))) versus=2;
688        delete marked;
689        CPRO.partition=aw_root->awar("cpro/partition")->read_int();
690        if (CPRO.partition<=0) CPRO.partition=1;
691        long resolution=aw_root->awar("cpro/resolution")->read_int();
692        if (resolution<=0) resolution=1;
693        char buf[80];
694        GB_ERROR faultmessage;
695
696        aw_root->awar("tmp/cpro/which1")->write_string(CPRO.result[0].which_species);
697        aw_root->awar("tmp/cpro/which2")->write_string(CPRO.result[1].which_species);
698       
699        sprintf(buf,"%5ld",CPRO.result[0].resolution);
700        aw_root->awar("tmp/cpro/nowres1")->write_string(buf);
701        sprintf(buf,"%5ld",CPRO.result[1].resolution);
702        aw_root->awar("tmp/cpro/nowres2")->write_string(buf);
703
704        if(!(CPRO.result[0].statisticexists))
705                        aw_root->awar("tmp/cpro/memfor1")->write_string("0KB\0");
706        else 
707        {
708                sprintf(buf,"%ldKB",CPRO.result[0].memneeded/1024);
709                aw_root->awar("tmp/cpro/memfor1")->write_string(buf);
710        }
711
712        if(!(CPRO.result[1].statisticexists))
713                        aw_root->awar("tmp/cpro/memfor2")->write_string("0KB\0");
714        else 
715        {
716                sprintf(buf,"%ldKB",CPRO.result[1].memneeded/1024);
717                aw_root->awar("tmp/cpro/memfor2")->write_string(buf);
718        }
719
720        if( (faultmessage=GB_push_transaction(gb_main)) ) 
721        {
722                aw_message(faultmessage,"OK,EXIT");
723                delete   align;
724                return;
725        }
726
727        long len=GBT_get_alignment_len(gb_main,align);
728
729        if(len<=0) {
730                GB_pop_transaction(gb_main);
731                aw_root->awar("tmp/cpro/mempartition")->write_string("???\0");
732                aw_root->awar("tmp/cpro/memstatistic")->write_string("???\0");
733                delete align;
734                return;
735        }
736
737
738/*      GBDATA *gb_species;
739        versus==1 -> marked vs marked
740                if (versus==1) {
741                gb_species = GBT_first_marked_species(gb_species_data);
742        } else {
743                gb_species = GBT_first_species(gb_species_data);
744        }
745        while(gb_species)
746        {               
747                if(GBT_read_sequence(gb_species,align)){
748                        nrofspecies++;   
749                }
750                if (versus==1) {
751                        gb_species = GBT_next_marked_species(gb_species);
752                }else{
753                        gb_species = GBT_next_species(gb_species);
754                }       
755        }
756        CPRO.numspecies=nrofspecies; */
757        long mem;
758
759        /*if(CPRO.numspecies<=2*CPRO.partition) mem=CPRO.numspecies*len;
760        else mem=CPRO.partition*2*len; */
761        mem=CPRO.partition*len*2;    // *2, because of row and column in matrix
762        sprintf(buf,"%ldKB",mem/1024);
763        aw_root->awar("tmp/cpro/mempartition")->write_string(buf);
764       
765        mem+=resolution*3*sizeof(STATTYPE)*len;
766        sprintf(buf,"%ldKB",mem/1024);
767        aw_root->awar("tmp/cpro/memstatistic")->write_string(buf);
768       
769        delete align;
770        if( (faultmessage=GB_pop_transaction(gb_main)) )
771        {
772                aw_message(faultmessage,"OK,EXIT");
773                return;
774        }
775}
776
777void create_cprofile_var(AW_root *aw_root, AW_default aw_def)
778{
779        aw_root->awar_string( "cpro/alignment", "" ,aw_def);
780        aw_root->awar_string( "cpro/which_species","marked",aw_def);
781        aw_root->awar_string( "cpro/which_result","transversion",aw_def);
782        aw_root->awar_string( "cpro/countgaps", "",aw_def);
783        aw_root->awar_string( "cpro/condensename", "PVD",aw_def);
784        aw_root->awar_float( "cpro/transratio",0.5,aw_def);
785        aw_root->awar_int( AWAR_CURSOR_POSITION,1,gb_main);
786        aw_root->awar_int( "cpro/maxdistance",100,aw_def);
787        aw_root->awar_int( "cpro/resolution",100,aw_def);
788        aw_root->awar_int( "cpro/partition",100,aw_def);
789        aw_root->awar_int( "cpro/drawmode0",0,aw_def);
790        aw_root->awar_int( "cpro/drawmode1",0,aw_def);
791        aw_root->awar_int( "cpro/leastaccu",3,aw_def);
792        aw_root->awar_int( "cpro/leastmax",50,aw_def);
793        aw_root->awar_int( "cpro/firsttoreach",50,aw_def);
794        aw_root->awar_int( "cpro/firstreachedstep",4,aw_def);
795        aw_root->awar_int( "cpro/leastcompares",300,aw_def);
796        aw_root->awar_string("tmp/cpro/mempartition","",aw_def);       
797        aw_root->awar_int( "cpro/gridhorizontal",20,aw_def);
798        aw_root->awar_int( "cpro/gridvertical",20,aw_def);
799        aw_root->awar_string( "tmp/cpro/which1","",aw_def);
800        aw_root->awar_string( "tmp/cpro/which2","",aw_def);
801        aw_root->awar_string( "tmp/cpro/nowres1","",aw_def);
802        aw_root->awar_string( "tmp/cpro/nowres2","",aw_def);
803        aw_root->awar_string( "tmp/cpro/memstatistic","",aw_def);
804        aw_root->awar_string( "tmp/cpro/memfor1","",aw_def);
805        aw_root->awar_string( "tmp/cpro/memfor2","",aw_def);
806        aw_root->awar_string("cpro/save/file_name", "" ,aw_def);
807        aw_root->awar_string( "cpro/save/directory", "." ,aw_def);
808        aw_root->awar_string( "cpro/save/filter", "cpr" ,aw_def);
809        aw_root->awar_string("cpro/load/file_name", "" ,aw_def);
810        aw_root->awar_string( "cpro/load/directory", "." ,aw_def);
811        aw_root->awar_string( "cpro/load/filter", "cpr" ,aw_def);
812        memset((char *)&CPRO,0,sizeof(struct CPRO_struct));
813
814}
815
816float CPRO_statisticaccumulation(long res,long column,char which_statistic)
817{
818        STATTYPE hits=0, sum=0, group=0, different=0;
819        long base=3*res;
820
821        if(!(CPRO.result[which_statistic].statistic[base+0])) hits=0;
822        else hits=CPRO.result[which_statistic].statistic[base+0][column];
823
824        if(!(CPRO.result[which_statistic].statistic[base+1])) group=0;
825        else group=CPRO.result[which_statistic].statistic[base+1][column];
826
827        if(!(CPRO.result[which_statistic].statistic[base+2])) different=0;
828        else different=CPRO.result[which_statistic].statistic[base+2][column];
829
830        sum=hits+group+different;
831
832        return ((float)sum);
833}
834
835
836// reports how many equal,group and differ entries are at a certain distance
837// at a certain column; mode=1 means smoothing is on.
838void CPRO_getfromstatistic(float &equal,float &ingroup,long res,long column,
839                               char which_statistic,char mode)
840{
841        STATTYPE hits=0, sum=0, group=0, different=0;
842        long base=3*res;
843
844        if(!(CPRO.result[which_statistic].statistic[base+0])) hits=0;
845        else hits=CPRO.result[which_statistic].statistic[base+0][column];
846
847        if(!(CPRO.result[which_statistic].statistic[base+1])) group=0;
848        else group=CPRO.result[which_statistic].statistic[base+1][column];
849
850        if(!(CPRO.result[which_statistic].statistic[base+2])) different=0;
851        else different=CPRO.result[which_statistic].statistic[base+2][column];
852
853        sum=hits+group+different;
854       
855        if(!(mode))
856        {
857                if(sum) 
858                {
859                        equal=(float)hits/(float)sum;
860                        ingroup=((float)hits+(float)group)/(float)sum; 
861                }
862                else 
863                {
864                        equal=1.0;
865                        ingroup=1.0; 
866                }
867        return;
868        }
869        else
870        {
871                float accu=pow(sum/(float)CPRO.result[which_statistic].maxaccu,0.0675);
872                float distance=(float)CPRO.result[which_statistic].drawmode*.01*
873                               CPRO.result[which_statistic].resolution; 
874                float alpha=0.0;   // alpha=0.0 no smoothing; alpha=0.99 high smoothing
875                if(distance>0.0000001) 
876                {
877                        alpha=1.0-accu/distance;
878                        if(alpha<0) alpha=0;
879                }
880
881                if(res==0) 
882                {
883                        CPRO.Z_it_group=1.0;
884                        CPRO.Z_it_equal=1.0;
885                }
886                if(sum)
887                {
888                        equal=(float)hits/(float)sum;
889                        ingroup=((float)hits+(float)group)/(float)sum;
890                        equal=(1-alpha)*equal+alpha*CPRO.Z_it_equal;
891                        ingroup=(1-alpha)*ingroup+alpha*CPRO.Z_it_group;
892                }
893                else
894                {
895                        equal=CPRO.Z_it_equal;
896                        ingroup=CPRO.Z_it_group;
897                }
898                CPRO.Z_it_equal=equal;
899                CPRO.Z_it_group=ingroup;
900        }
901
902}
903
904void CPRO_box(AW_device *device,int gc,float l,float t,float width,float high)
905{
906        device->line(gc,l,t,l+width,t,1,(AW_CL)0,(AW_CL)0);     
907        device->line(gc,l+width,t,l+width,t+high,1,(AW_CL)0,(AW_CL)0); 
908        device->line(gc,l,t+high,l+width,t+high,1,(AW_CL)0,(AW_CL)0);   
909        device->line(gc,l,t,l,t+high,1,(AW_CL)0,(AW_CL)0);     
910}
911
912float CPRO_confidinterval(long res,long column,char which_statistic,char mode)
913{
914        STATTYPE hits=0, sum=0, group=0, different=0;
915        long base=3*res;
916
917        if(!(CPRO.result[which_statistic].statistic[base+0])) hits=0;
918        else hits=CPRO.result[which_statistic].statistic[base+0][column];
919
920        if(!(CPRO.result[which_statistic].statistic[base+1])) group=0;
921        else group=CPRO.result[which_statistic].statistic[base+1][column];
922
923        if(!(CPRO.result[which_statistic].statistic[base+2])) different=0;
924        else different=CPRO.result[which_statistic].statistic[base+2][column];
925
926        sum=hits+group+different;
927        if(!(mode)) return(1/sqrt((float)sum)/2.0);
928        else return(0.0);
929}
930
931void CPRO_drawstatistic (AW_device *device,char which_statistic)
932{
933        float topdistance=70.0,leftdistance=40.0;
934        float rightdistance=20.0,bottomdistance=10.0;
935        float betweendistance=30.0;
936        float firstavailable=.65;
937        float secondavailable=.35; 
938        /* points are in the areas and without the frame */
939        float topfirst, leftfirst, widthfirst, highfirst;
940        float topsecond, leftsecond, widthsecond, highsecond;
941        float highboth;
942        float equal,ingroup;
943        char mode=CPRO.result[which_statistic].drawmode;
944
945        AW_rectangle rect;
946        device->get_area_size(&rect);
947        device->reset();
948        device->clear();
949
950        topfirst=39.0;
951        leftfirst=20.0;
952        widthfirst=(rect.r-rect.l)-leftdistance-1-rightdistance;
953        widthsecond=(rect.r-rect.l)-leftdistance-1-rightdistance;
954        highboth=(rect.b-rect.t)-topdistance-bottomdistance-betweendistance-4; 
955        if((highboth<12.0)||(widthfirst<10.0)) return;
956
957        highfirst=(float)(long)(highboth*firstavailable);
958        highsecond=(float)(long)(highboth*secondavailable)+1;
959
960        topfirst=topdistance+1;
961        leftfirst=leftdistance;
962        topsecond=rect.b-bottomdistance-highsecond;
963        leftsecond=leftdistance+1;
964
965    CPRO_box(device,GC_black,leftfirst-1,topfirst-1,
966                    widthfirst+2,highfirst+2);
967        CPRO_box(device,GC_black,leftsecond-1,topsecond-1,
968                    widthsecond+2,highsecond+2);
969       
970        device->text(GC_black,"column",leftdistance+82,14,0,1,0,0);
971
972/* draw grid and inscribe axes*/
973        char buf[30];
974        long gridx,gridy;
975        float xpos=leftdistance,ypos;
976        sprintf(buf," character difference");
977        device->text(GC_black,buf,leftdistance-40,topdistance-7,0,1,0,0);
978        device->text(GC_black,"  0%\0",
979                        leftdistance-26,topdistance+4+highfirst,0,1,0,0);
980
981        for(gridy=CPRO.gridhorizontal;gridy<100;gridy+=CPRO.gridhorizontal)
982        {
983                ypos=topdistance+1+(1.0-(float)gridy*0.01)*(highfirst-1);
984                device->line(GC_grid,xpos,ypos,xpos+widthfirst,ypos,1,0,0);
985                sprintf(buf,"%3ld%%",gridy);
986                device->text(GC_black,buf,xpos-27,ypos+4,0,1,0,0);
987        }               
988        device->text(GC_black,"100%",leftdistance-26,topdistance+5,0,1,0,0);
989
990        device->text(GC_black,"sequence distance",
991                leftdistance+widthfirst-95,topdistance+highfirst+25,0,1,0,0);
992        device->text(GC_black,"  0%",
993                leftdistance-11,topdistance+14+highfirst,0,1,0,0);
994        ypos=topdistance+1;
995
996        for(gridx=CPRO.gridvertical;(float)gridx<=100.0*CPRO.maxdistance;
997                                                                                gridx+=CPRO.gridvertical)
998        {
999                xpos=leftdistance+1+(float)gridx*0.01/CPRO.maxdistance*widthfirst;
1000                if((float)gridx*0.01<1.0*CPRO.maxdistance) 
1001                                device->line(GC_grid,xpos,ypos,xpos,ypos+highfirst,1,0,0);
1002                sprintf(buf,"%3ld%%",gridx);
1003                device->text(GC_black,buf,xpos-12,ypos+13+highfirst,0,1,0,0);
1004        }
1005
1006        if(!CPRO.result[which_statistic].statisticexists) return;
1007        if((CPRO.column<1)||(CPRO.column>CPRO.result[which_statistic].maxalignlen))
1008                     return;
1009
1010/* fill first box */
1011        float accu,confidinterval;
1012        float step=widthfirst/CPRO.result[which_statistic].resolution;
1013        float linelength=step/CPRO.maxdistance;
1014        float ytop,ybottom;
1015
1016        long firstx;
1017        for(firstx=0;
1018        firstx<CPRO.result[which_statistic].resolution*CPRO.maxdistance;
1019        firstx++)
1020        {
1021                CPRO_getfromstatistic(equal,ingroup,(long)firstx,CPRO.column-1,
1022                                      which_statistic,mode);
1023                accu=CPRO_statisticaccumulation((long)firstx,
1024                                        CPRO.column-1,which_statistic);
1025                if(accu>=(float)CPRO.leastaccu)
1026                {
1027                        xpos=(float)firstx*step/CPRO.maxdistance+leftfirst;
1028                        ypos=topfirst+equal*highfirst;
1029
1030                        // do not draw outside canvas-box
1031                        if(xpos+linelength > leftfirst+widthfirst+1) continue;
1032                       
1033                        confidinterval=highfirst*
1034                                CPRO_confidinterval(firstx,CPRO.column-1,which_statistic,mode);
1035       
1036                        ytop=ypos-confidinterval;
1037                        if(ytop>=topfirst) { 
1038                                device->line(GC_blue,xpos,ytop,xpos+linelength,ytop,1,0,0); }
1039                        else { ytop=topfirst; }
1040                        device->line(GC_blue,xpos+linelength/2,ytop,xpos+linelength/2,ypos,1,0,0);
1041
1042                        ybottom=ypos+confidinterval;
1043                        if(ybottom<topfirst+highfirst) { 
1044                                device->line(GC_blue,xpos,ybottom,xpos+linelength,ybottom,1,0,0);}
1045                        else { ybottom=topfirst+highfirst-1; }
1046                        device->line(GC_blue,xpos+linelength/2,ybottom,xpos+linelength/2,ypos,1,0,0);
1047
1048                        ypos=topfirst+ingroup*highfirst;
1049                        ytop=ypos-confidinterval;
1050                        if(ytop>=topfirst) { 
1051                                device->line(GC_green,xpos,ytop,xpos+linelength,ytop,1,0,0); }
1052                        else { ytop=topfirst; }
1053                        device->line(GC_green,xpos+linelength/2,ytop,xpos+linelength/2,ypos,1,0,0);
1054               
1055                        ybottom=ypos+confidinterval;
1056                        if(ybottom<topfirst+highfirst){ 
1057                                device->line(GC_green,xpos,ybottom,xpos+linelength,ybottom,1,0,0);}
1058                        else { ybottom=topfirst+highfirst-1; }
1059                        device->line(GC_green,xpos+linelength/2,ybottom,xpos+linelength/2,ypos,1,0,0);
1060               
1061                }
1062        }
1063
1064        float resaccu;
1065        float rate;           
1066        sprintf(buf," %5ld",CPRO.result[which_statistic].maxaccu);
1067        device->text(GC_black,"   max",leftsecond-50,topsecond,0,1,0,0);
1068        device->text(GC_black,buf,leftsecond-43,topsecond+10*1,0,1,0,0);
1069        device->text(GC_black,"  pairs",leftsecond-50,topsecond+10*3,0,1,0,0);
1070
1071/*fill second box*/
1072        for(firstx=0;firstx<(long)widthsecond;firstx++)
1073        {
1074                resaccu=CPRO_statisticaccumulation(
1075                                (long)(firstx*CPRO.result[which_statistic].resolution
1076                                /widthsecond*CPRO.maxdistance),CPRO.column-1,which_statistic);
1077                rate=1.0-(sqrt(resaccu)/sqrt(CPRO.result[which_statistic].maxaccu));
1078                device->line(GC_black,firstx+leftsecond,topsecond+rate*highsecond,
1079                firstx+leftsecond,topsecond+highsecond,1,0,0);
1080        }
1081}
1082
1083void CPRO_resize_cb( AW_window *aws,AW_CL which_statistic, AW_CL cd2)
1084{
1085        AWUSE(cd2);
1086        AW_root *awr=aws->get_root();
1087        CPRO.column=awr->awar(AWAR_CURSOR_POSITION)->read_int();
1088        CPRO.gridvertical=(long)awr->awar("cpro/gridvertical")->read_int();
1089        CPRO.gridhorizontal=(long)awr->awar("cpro/gridhorizontal")->read_int();
1090        CPRO.leastaccu=awr->awar("cpro/leastaccu")->read_int();
1091        if (CPRO.leastaccu<=0) CPRO.leastaccu=1;
1092
1093        AW_device *device=aws->get_device(AW_INFO_AREA);
1094        device->reset();
1095        CPRO_drawstatistic(device,(char)which_statistic);       
1096}
1097       
1098void CPRO_expose_cb( AW_window *aws,AW_CL which_statistic, AW_CL cd2)
1099{
1100        AWUSE(cd2);
1101        AW_root *awr=aws->get_root();
1102        CPRO.column=awr->awar(AWAR_CURSOR_POSITION)->read_int();
1103        char buf[80];
1104        sprintf(buf,"cpro/drawmode%d",(int)which_statistic);
1105        CPRO.result[which_statistic].drawmode=(char)awr->awar(buf)->read_int();
1106        CPRO.gridvertical=(long)awr->awar("cpro/gridvertical")->read_int();
1107        CPRO.gridhorizontal=(long)awr->awar("cpro/gridhorizontal")->read_int();
1108        CPRO.leastaccu=awr->awar("cpro/leastaccu")->read_int();
1109        if (CPRO.leastaccu<=0) CPRO.leastaccu=1;
1110
1111        long maxd=awr->awar("cpro/maxdistance")->read_int();
1112        if((maxd>0)&&(maxd<101))CPRO.maxdistance=(float)maxd/100.0;
1113
1114        AW_device *device=aws->get_device (AW_INFO_AREA);
1115        CPRO_drawstatistic(device,(char)which_statistic);       
1116}       
1117
1118void CPRO_column_cb(AW_root *awr,AW_window *aws,AW_CL which_statistic)
1119{
1120        AWUSE(awr);
1121        char buf[80];
1122        sprintf(buf,"cpro/drawmode%d",(int)which_statistic);
1123        CPRO.result[which_statistic].drawmode=(char)awr->awar(buf)->read_int();
1124        CPRO_expose_cb(aws,which_statistic,0);
1125}
1126
1127void CPRO_columnminus_cb(AW_window *aws)
1128{
1129        AWUSE(aws);
1130        AW_root *awr=aws->get_root();
1131        if(CPRO.column>1) {
1132                awr->awar(AWAR_CURSOR_POSITION)->write_int(CPRO.column-1); }
1133}
1134
1135void CPRO_columnplus_cb(AW_window *aws,AW_CL which_statistic,AW_CL cd2)
1136{
1137        AWUSE(aws);AWUSE(cd2);AWUSE(which_statistic);
1138        AW_root *awr=aws->get_root();
1139        awr->awar(AWAR_CURSOR_POSITION)->write_int(CPRO.column+1);
1140        /*if(CPRO.column<CPRO.result[which_statistic].maxalignlen) {
1141                awr->awar(AWAR_CURSOR_POSITION)->write_int(CPRO.column+1); }*/
1142}
1143
1144void CPRO_savestatistic_cb(AW_window *aw,AW_CL which_statistic)
1145{
1146        AW_root *awr=aw->get_root();
1147        char *filename=awr->awar("cpro/save/file_name")->read_string();
1148        if(!filename) { aw_message("no filename\0"); return; }
1149        GB_ERROR error;
1150
1151        if(!(CPRO.result[which_statistic].statisticexists))
1152        {
1153                aw_message("calculate first !\0");
1154                return;
1155        }
1156
1157        GBDATA *newbase=GB_open(filename,"wc");
1158
1159        if( (error=GB_begin_transaction(newbase)) )
1160        {
1161                aw_message(error);
1162                delete filename;
1163                return;
1164        }
1165
1166        GBDATA *gb_param=GB_create(newbase,"cpro_resolution",GB_INT);
1167        GB_write_int(gb_param,CPRO.result[which_statistic].resolution);
1168        gb_param=GB_create(newbase,"cpro_maxalignlen",GB_INT);
1169        GB_write_int(gb_param,CPRO.result[which_statistic].maxalignlen);       
1170        gb_param=GB_create(newbase,"cpro_maxaccu",GB_INT);
1171        GB_write_int(gb_param,CPRO.result[which_statistic].maxaccu);
1172        gb_param=GB_create(newbase,"cpro_memneeded",GB_INT);
1173        GB_write_int(gb_param,CPRO.result[which_statistic].memneeded);
1174        gb_param=GB_create(newbase,"cpro_alignname",GB_STRING);
1175        GB_write_string(gb_param,CPRO.result[which_statistic].alignname);
1176        gb_param=GB_create(newbase,"cpro_which_species",GB_STRING);
1177        GB_write_string(gb_param,CPRO.result[which_statistic].which_species);   
1178        gb_param=GB_create(newbase,"cpro_ratio",GB_FLOAT);
1179        GB_write_float(gb_param,CPRO.result[which_statistic].ratio);
1180        gb_param=GB_create(newbase,"cpro_gaps",GB_INT);
1181        GB_write_int(gb_param,CPRO.result[which_statistic].countgaps);
1182
1183       
1184        long maxalignlen=CPRO.result[which_statistic].maxalignlen;     
1185
1186        GBDATA *gb_colrescontainer;
1187        GBDATA *gb_colentry;
1188        GB_UINT4 *pointer;
1189        for(long column=0;column<CPRO.result[which_statistic].resolution;column++)
1190        {
1191                gb_colrescontainer=GB_create_container(newbase,"column");
1192                if( (pointer=CPRO.result[which_statistic].statistic[column*3+0]) )
1193                {
1194                        gb_colentry=GB_create(gb_colrescontainer,"equal",GB_INTS);
1195                        GB_write_ints(gb_colentry,pointer,maxalignlen);
1196                }
1197                if( (pointer=CPRO.result[which_statistic].statistic[column*3+1]))
1198                {
1199                        gb_colentry=GB_create(gb_colrescontainer,"group",GB_INTS);
1200                        GB_write_ints(gb_colentry,pointer,maxalignlen);
1201                }
1202                if( (pointer=CPRO.result[which_statistic].statistic[column*3+2]))
1203                {
1204                        gb_colentry=GB_create(gb_colrescontainer,"different",GB_INTS);
1205                        GB_write_ints(gb_colentry,pointer,maxalignlen);
1206                }
1207        }
1208               
1209        if( (error=GB_commit_transaction(newbase)) )
1210        {
1211                aw_message(error);
1212                delete filename;
1213                GB_close(newbase);
1214                return;
1215        }
1216        if( (error=GB_save(newbase,(char*)0,"b")) )
1217        {
1218                aw_message(error);
1219                delete filename;
1220                GB_close(newbase);
1221                return;
1222        }
1223        GB_close(newbase);
1224        delete filename;
1225        aw->hide();
1226}
1227
1228void CPRO_loadstatistic_cb(AW_window *aw,AW_CL which_statistic)
1229{
1230        AW_root *awr=aw->get_root();
1231        char *filename=awr->awar("cpro/load/file_name")->read_string();
1232        if(!filename) { aw_message("no filename\0"); return; }
1233        GB_ERROR error;
1234
1235        GBDATA *oldbase=GB_open(filename,"r");
1236        delete filename;
1237        if(!oldbase)
1238        {
1239                aw_message("wrong filename");
1240                return;
1241        }
1242
1243        if( (error=GB_begin_transaction(oldbase)) )
1244        {
1245                aw_message(error);
1246                GB_close(oldbase);
1247                return;
1248        }
1249
1250
1251        if(CPRO.result[which_statistic].statisticexists)
1252        {
1253                CPRO_freestatistic((char)which_statistic);
1254        }
1255
1256        GBDATA *gb_param=GB_search(oldbase,"cpro_resolution",GB_FIND);
1257        if(!(gb_param))
1258        {
1259                aw_message("not a valid statistic\0");
1260                GB_close(oldbase);
1261                GB_abort_transaction(oldbase);
1262                return;
1263        }
1264        CPRO.result[which_statistic].resolution=GB_read_int(gb_param);
1265
1266        gb_param=GB_search(oldbase,"cpro_maxalignlen",GB_FIND);
1267        CPRO.result[which_statistic].maxalignlen=GB_read_int(gb_param);
1268
1269        gb_param=GB_search(oldbase,"cpro_maxaccu",GB_FIND);
1270        CPRO.result[which_statistic].maxaccu=GB_read_int(gb_param);
1271
1272        gb_param=GB_search(oldbase,"cpro_memneeded",GB_FIND);
1273        CPRO.result[which_statistic].memneeded=GB_read_int(gb_param);
1274
1275        gb_param=GB_search(oldbase,"cpro_alignname",GB_FIND);
1276        strcpy(CPRO.result[which_statistic].alignname,GB_read_char_pntr(gb_param));
1277
1278        gb_param=GB_search(oldbase,"cpro_which_species",GB_FIND);
1279        if(gb_param) strcpy(CPRO.result[which_statistic].which_species,
1280               GB_read_char_pntr(gb_param));   
1281
1282        CPRO.result[which_statistic].statistic=(STATTYPE **)calloc(
1283                    (size_t)CPRO.result[which_statistic].resolution*3+3,
1284                        sizeof(STATTYPE *));
1285
1286
1287        GBDATA *gb_colrescontainer=0;
1288        GBDATA *gb_colentry;
1289        for(long column=0;column<CPRO.result[which_statistic].resolution;column++)
1290        {
1291                if(column) gb_colrescontainer=
1292                        GB_find(gb_colrescontainer,"column",0,search_next+this_level);
1293                else gb_colrescontainer=GB_search(oldbase,"column",GB_FIND);
1294                if( (gb_colentry=GB_search(gb_colrescontainer,"equal",GB_FIND)) )
1295                {
1296                        CPRO.result[which_statistic].statistic[column*3+0]=
1297                                (STATTYPE*)GB_read_ints(gb_colentry);
1298                }
1299                if( (gb_colentry=GB_search(gb_colrescontainer,"group",GB_FIND)) )
1300                {
1301                        CPRO.result[which_statistic].statistic[column*3+1]=
1302                                (STATTYPE*)GB_read_ints(gb_colentry);
1303                }
1304                if( (gb_colentry=GB_search(gb_colrescontainer,"different",GB_FIND)) )
1305                {
1306                        CPRO.result[which_statistic].statistic[column*3+2]=
1307                                (STATTYPE*)GB_read_ints(gb_colentry);
1308                }
1309        }
1310
1311        if( (error=GB_commit_transaction(oldbase)) )
1312        {
1313                aw_message(error);
1314                GB_close(oldbase);
1315                return;
1316        }
1317        GB_close(oldbase);
1318        CPRO.result[which_statistic].statisticexists=1;
1319        CPRO_memrequirement_cb(awr,0,0);
1320        aw->hide();
1321}
1322
1323AW_window *CPRO_savestatisticwindow_cb(AW_root *aw_root,AW_CL which_statistic)
1324{
1325        AW_window_simple *aws = new AW_window_simple;
1326        aws->init( aw_root, "SAVE_CPRO_STATISTIC", "SAVE STATISTIC", 10, 10 );
1327        aws->load_xfig("sel_box.fig");
1328
1329        aws->at("close");aws->callback((AW_CB0)AW_POPDOWN);
1330        aws->create_button("CLOSE","CLOSE","C");                           
1331
1332        aws->at("save");aws->callback(CPRO_savestatistic_cb,which_statistic);
1333        aws->create_button("SAVE","SAVE","S");                     
1334
1335        aws->callback( (AW_CB0)AW_POPDOWN);
1336        aws->at("cancel");
1337        aws->create_button("CANCEL","CANCEL","C");                         
1338
1339        awt_create_selection_box((AW_window *)aws,"cpro/save");
1340
1341        return (AW_window *)aws;
1342}
1343
1344AW_window *CPRO_loadstatisticwindow_cb(AW_root *aw_root,AW_CL which_statistic)
1345{
1346        AW_window_simple *aws = new AW_window_simple;
1347        aws->init( aw_root, "LOAD_CPRO_STATISTIC", "LOAD STATISTIC", 10, 10 );
1348        aws->load_xfig("sel_box.fig");
1349
1350        aws->at("close");aws->callback((AW_CB0)AW_POPDOWN);
1351        aws->create_button("CLOSE","CLOSE","C");                           
1352
1353        aws->at("save");aws->callback(CPRO_loadstatistic_cb,which_statistic);
1354        aws->create_button("LOAD","LOAD","S");                     
1355
1356        awt_create_selection_box((AW_window *)aws,"cpro/load");
1357
1358        return (AW_window *)aws;
1359}
1360
1361// search point of resolution when half maximum if reached (for condense)
1362float CPRO_gethalfmaximum(long column,float maximum,float firsttoreach,
1363                          char transversion,char which_statistic,char mode) 
1364{
1365        float equal,ingroup,interest;
1366        float interval,sum;
1367        float halfmax=0.0;
1368        long res;
1369        for(res=0;res<CPRO.result[which_statistic].resolution;res++)
1370        {
1371                sum=CPRO_statisticaccumulation(res,column,which_statistic);
1372                if((long)sum>=CPRO.leastaccu)
1373                {
1374                        CPRO_getfromstatistic(equal,ingroup,res,column,
1375                                              which_statistic,mode);
1376                        if(transversion) interest=1.0-ingroup;
1377                        else interest=1.0-equal;
1378                        interval=CPRO_confidinterval(res,column,which_statistic,mode);
1379                        if(interest-interval>=maximum*firsttoreach)
1380                        {
1381                                res++;
1382                                break;
1383                        }
1384                }
1385        }
1386        halfmax=(float)res/(float)CPRO.result[which_statistic].resolution;
1387        return(halfmax-(float)CPRO.result[which_statistic].drawmode*0.01); 
1388               // delay depending on drawmode
1389}
1390
1391// search maximum distance in character (for condense)
1392float CPRO_getmaximum(long column,char transversion,
1393                      char which_statistic,char mode)
1394{
1395        float maximum=-101.0,equal,ingroup,interest,sum,interval;
1396        for(long res=0;res<CPRO.result[which_statistic].resolution;res++)
1397        {
1398                sum=CPRO_statisticaccumulation(res,column,which_statistic);
1399                if((long)sum>=CPRO.leastaccu)
1400                {
1401                        CPRO_getfromstatistic(equal,ingroup,res,column,
1402                                              which_statistic,mode);
1403                        if(transversion) interest=1.0-ingroup;
1404                        else interest=1.0-equal;
1405                        interval=CPRO_confidinterval(res,column,which_statistic,mode);
1406                        if(interest-interval>maximum) maximum=interest-interval;
1407                }
1408        }
1409        //printf("\n");
1410        return(maximum);
1411}
1412
1413void CPRO_condense_cb( AW_window *aw,AW_CL which_statistic )
1414{
1415        AW_root *aw_root = aw->get_root();
1416        char mode=CPRO.result[which_statistic].drawmode;
1417        if(!(CPRO.result[which_statistic].statisticexists)) 
1418        {
1419                aw_message("statistic doesn't exist !");
1420                return;
1421        }
1422        float leastmax=(float)(aw_root->awar("cpro/leastmax")->read_int())/100.0;
1423        CPRO.leastaccu= aw_root->awar("cpro/leastaccu")->read_int();
1424        float firsttoreach=(float)(aw_root->awar("cpro/firsttoreach")->read_int())/100.0;
1425        float firstreachedstep=(float)
1426                         (aw_root->awar("cpro/firstreachedstep")->read_int())/100.0;
1427        char *transversionstring=aw_root->awar("cpro/which_result")->read_string();
1428        char transversion=1;
1429        if(strcmp(transversionstring,"transversions")) transversion=0;
1430        delete transversionstring;
1431        long maxcol=CPRO.result[which_statistic].maxalignlen;
1432
1433        char *savename=aw_root->awar("cpro/condensename")->read_string();
1434        if(savename[0]==0) 
1435        {
1436                delete savename;
1437                return;
1438        }
1439
1440        aw_openstatus("condense statistic");aw_status((double)0);
1441
1442        char *result=(char *)calloc((unsigned int)maxcol+1,1);
1443
1444        float maximum;
1445        float reachedhalf;
1446        char steps; 
1447        for(long column=0;column<maxcol;column++)
1448        {
1449                if(((column/100)*100)==column) aw_status((double)column/(double)maxcol);
1450                maximum=CPRO_getmaximum(column,transversion,(char)which_statistic,mode);
1451                if(maximum<-100.0) result[column]='.';
1452                else if(maximum<=0.0) result[column]='-';
1453                else 
1454                {
1455                        if(maximum>=leastmax) result[column]='A';
1456                        else result[column]='a';
1457                        reachedhalf=CPRO_gethalfmaximum(column,maximum,firsttoreach,
1458                                                   transversion,(char)which_statistic,mode);
1459                        for(steps=0;(reachedhalf>firstreachedstep)&&(steps<'Y'-'A');steps++)
1460                                reachedhalf-=firstreachedstep; 
1461                        result[column]+=steps;
1462                }
1463        }
1464
1465        GB_ERROR error = 0;
1466        char *align=CPRO.result[which_statistic].alignname;
1467
1468        aw_status("exporting result");
1469
1470        GB_begin_transaction(gb_main);
1471
1472        GBDATA *gb_extended = GBT_create_SAI(gb_main,savename);
1473
1474        GBDATA *gb_param;
1475        const char *typestring = GBS_global_string("RATES BY DISTANCE:  [%s] [UPPER_CASE%% %li]"
1476                                                " [ INTERREST%% %li] [STEP/CHAR %li]",
1477                (transversion)? "transversion":"all differences",
1478                (long)(leastmax*100.0),
1479                (long)(firsttoreach*100.0),
1480                (long)(firstreachedstep*100.0) );
1481
1482        gb_param=GBT_add_data(gb_extended,align,"_TYPE",GB_STRING);
1483        error=GB_write_string(gb_param,typestring);
1484
1485        GBDATA *gb_data = GBT_add_data(gb_extended, align,"data", GB_STRING);
1486
1487        error = GB_write_string(gb_data,result);
1488        aw_closestatus();
1489        if (error){
1490                GB_abort_transaction(gb_main);
1491                aw_message(error);
1492        }else{
1493                GB_commit_transaction(gb_main);
1494        }
1495
1496        delete result;
1497        delete savename;
1498}
1499
1500AW_window *CPRO_condensewindow_cb( AW_root *aw_root,AW_CL which_statistic )
1501{
1502        char buf[30];
1503        sprintf(buf,"CONDENSE STATISTIC %ld",(long)which_statistic+1);
1504
1505        AW_window_simple *aws = new AW_window_simple;
1506        aws->init( aw_root,buf, buf,10,10);
1507        aws->load_xfig("cpro/condense.fig");
1508        aws->button_length( 8 );
1509
1510        aws->at("close");aws->callback((AW_CB0)AW_POPDOWN);
1511        aws->create_button("CLOSE","CLOSE","C");                           
1512
1513        aws->at( "which_result" );
1514        aws->create_toggle_field( "cpro/which_result", NULL ,"" );
1515                aws->insert_default_toggle( "      all\ndifferences",  "1", "diffs" );
1516                aws->insert_toggle( "     only\ntransversions", "1", "transversions" );
1517        aws->update_toggle_field();
1518
1519        aws->button_length(11);
1520        aws->at("begin");aws->callback(CPRO_condense_cb,which_statistic);
1521        aws->create_button("CONDENSE_AND_EXPORT", "CONDENSE\nAND EXPORT","E"); 
1522
1523        aws->at("name");aws->create_input_field("cpro/condensename",11);
1524
1525        aws->at("save_box");
1526        awt_create_selection_list_on_extendeds(gb_main,aws,"cpro/condensename");
1527
1528        return( AW_window *)aws;
1529}
1530
1531AW_window *CPRO_xpert_cb( AW_root *aw_root )
1532{
1533        static AW_window *expertwindow = 0;
1534        if(expertwindow) return(expertwindow);
1535
1536        AW_window_simple *aws = new AW_window_simple;
1537        aws->init( aw_root, "CPRO_EXPERT_PROPS","EXPERT PROPERTIES",500,10);
1538        aws->load_xfig("cpro/expert.fig");
1539        aws->button_length( 8 );
1540
1541        aws->at("close");aws->callback((AW_CB0)AW_POPDOWN);
1542        aws->create_button("CLOSE","CLOSE","C");                           
1543       
1544        aws->at("partition");
1545        aws->create_input_field("cpro/partition",6);
1546
1547        aws->at("leastaccu");
1548        aws->create_input_field("cpro/leastaccu",3);
1549
1550        aws->at("leastcompares");
1551        aws->create_input_field("cpro/leastcompares",6);
1552
1553        aws->at("gridvertical");
1554        aws->create_input_field("cpro/gridvertical",3);
1555
1556        aws->at("gridhorizontal");
1557        aws->create_input_field("cpro/gridhorizontal",3);
1558
1559        aws->at("leastmax");
1560        aws->create_input_field("cpro/leastmax",3);
1561
1562        aws->at("firsttoreach");
1563        aws->create_input_field("cpro/firsttoreach",3);
1564
1565        aws->at("firstreachedstep");
1566        aws->create_input_field("cpro/firstreachedstep",3);
1567
1568        aws->label_length(8);
1569        aws->button_length(8);
1570        aws->at("mempartition");aws->create_button(0,"tmp/cpro/mempartition");
1571
1572        return expertwindow=(AW_window *)aws;
1573}
1574
1575AW_window *CPRO_showstatistic_cb( AW_root *aw_root, AW_CL which_statistic)
1576{
1577        char buf[20];
1578        sprintf(buf,"SHOW STATISTIC %d\n",(int)which_statistic+1);
1579        AW_window_simple *aws=new AW_window_simple;
1580                aws->init( aw_root,buf,buf,400,(int)(10+which_statistic*300));
1581        aws->load_xfig("cpro/show.fig");
1582        aws->button_length(6);
1583
1584        aws->at("close");aws->callback((AW_CB0)AW_POPDOWN);
1585        aws->create_button("CLOSE","CLOSE","C");                           
1586
1587        //aws->at("xpert");aws->callback(AW_POPUP,(AW_CL)CPRO_xpert_cb,0);
1588
1589
1590        aws->at("column");
1591        aws->create_input_field(AWAR_CURSOR_POSITION,4);
1592       
1593        aws->button_length(3);
1594        aws->at("d");aws->callback((AW_CB0)CPRO_columnminus_cb);
1595        aws->create_button(0,"-","1");
1596        aws->at("u");aws->callback((AW_CB2)CPRO_columnplus_cb,which_statistic,0);
1597        aws->create_button(0,"+","2");
1598       
1599        sprintf(buf,"cpro/drawmode%d",(int)which_statistic);
1600        aws->at("drawmode");aws->create_option_menu(buf);
1601                aws->insert_option( "no smoothing", "n",0); 
1602                aws->insert_option( "smoothing 1", "1",1); 
1603                aws->insert_option( "smoothing 2", "2",2); 
1604                aws->insert_option( "smoothing 3", "3",3); 
1605                aws->insert_option( "smoothing 5", "5",5); 
1606                aws->insert_option( "smoothing 10", "6",10); 
1607                aws->insert_option( "smoothing 15", "7",15);
1608        aws->update_option_menu(); 
1609
1610        aw_root->awar(buf)->add_callback(
1611                (AW_RCB)CPRO_column_cb,(AW_CL)aws,which_statistic);     
1612        aw_root->awar("cpro/gridhorizontal")->add_callback(
1613                (AW_RCB)CPRO_column_cb,(AW_CL)aws,which_statistic);     
1614        aw_root->awar("cpro/gridvertical")->add_callback(
1615                (AW_RCB)CPRO_column_cb,(AW_CL)aws,which_statistic);     
1616
1617        aws->at("maxdistance");
1618        //aws->label("max distance");
1619        aws->create_input_field("cpro/maxdistance",3);
1620
1621        aws->set_resize_callback (AW_INFO_AREA,(AW_CB)CPRO_resize_cb,
1622                                               which_statistic,0);
1623        aws->set_expose_callback (AW_INFO_AREA, (AW_CB)CPRO_expose_cb,
1624                                           (AW_CL)which_statistic,0);
1625        aw_root->awar(AWAR_CURSOR_POSITION)->add_callback((AW_RCB)CPRO_column_cb,
1626                                (AW_CL)aws,which_statistic);
1627        aw_root->awar("cpro/maxdistance")->add_callback((AW_RCB)CPRO_column_cb,
1628                                (AW_CL)aws,which_statistic);
1629        aw_root->awar("cpro/maxdistance")->add_callback((AW_RCB)CPRO_column_cb,
1630                                (AW_CL)aws,which_statistic);   
1631        aws->button_length( 6);
1632
1633        AW_device *device=aws->get_device (AW_INFO_AREA);
1634        device->reset();
1635
1636        device->new_gc( GC_black );
1637        device->set_line_attributes(GC_black,0.3,AW_SOLID);
1638        device->set_foreground_color(GC_black,AW_WINDOW_FG);
1639        device->set_font(GC_black,0,10);
1640        device->new_gc( GC_blue );
1641        device->set_line_attributes(GC_blue,0.3,AW_SOLID);
1642        device->set_foreground_color(GC_blue,AW_WINDOW_C1);     
1643        device->new_gc( GC_green );
1644        device->set_line_attributes(GC_green,0.3,AW_SOLID);
1645        device->set_foreground_color(GC_green,AW_WINDOW_C2);
1646        device->new_gc( GC_grid );
1647        device->set_line_attributes(GC_grid,0.3,AW_DOTTED);
1648        device->set_foreground_color(GC_grid,AW_WINDOW_C3);
1649       
1650        return (AW_window *)aws;
1651}
1652
1653AW_window *CPRO_calculatewin_cb(AW_root *aw_root,AW_CL which_statistic)
1654{
1655        char buf[30];
1656        sprintf(buf,"CALCULATE STATISTIC %ld",(long)which_statistic+1);
1657        AW_window_simple *aws = new AW_window_simple;
1658        aws->init( aw_root,buf,buf,10,10);
1659        aws->load_xfig("cpro/calc.fig");
1660        aws->button_length( 10 );
1661
1662        aws->at("close");aws->callback((AW_CB0)AW_POPDOWN);
1663        aws->create_button("CLOSE","CLOSE","C");                           
1664
1665        aws->at("resolution");
1666        aws->create_input_field("cpro/resolution",8);
1667
1668        aws->at("transratio");
1669        aws->create_input_field("cpro/transratio",8);
1670
1671        aws->at("which_alignment");
1672        awt_create_selection_list_on_ad(gb_main,
1673                (AW_window *)aws,"cpro/alignment","*=");
1674
1675        aws->button_length(10);
1676        aws->at("xpert");aws->callback(AW_POPUP,(AW_CL)CPRO_xpert_cb,0);
1677        aws->create_button("EXPERT_OPTIONS", "expert...","x");
1678
1679        aws->at("calculate");
1680                aws->callback(CPRO_calculate_cb,(AW_CL)which_statistic);
1681        aws->create_button("CALCULATE","CALCULATE","A");                           
1682
1683        aws->at( "which_species" );
1684        aws->create_toggle_field( "cpro/which_species", NULL ,"" );
1685                aws->insert_toggle( "all vs all", "1", "all" );
1686                aws->insert_toggle( "marked vs marked",  "1", "marked" );
1687                aws->insert_default_toggle( "marked vs all",  "1", "markedall" );
1688        aws->update_toggle_field();
1689
1690        aws->at( "countgaps" );
1691        aws->create_toggle_field( "cpro/countgaps", NULL ,"" );
1692                aws->insert_toggle( "on", "1", "on" );
1693                aws->insert_default_toggle( "off",  "1", "off" );
1694        aws->update_toggle_field();
1695
1696        aws->label_length(8);
1697        aws->button_length(8);
1698        aws->at("memstatistic");aws->create_button(0,"tmp/cpro/memstatistic");
1699
1700        return (AW_window *)aws;
1701
1702}
1703/* -----------------------------------------------------------------
1704 * Function:                 AP_open_cprofile_window
1705 *
1706 * Arguments:                    .
1707 *
1708 * Returns:                      .
1709 *
1710 * Description:      Draws window, initializes callback for most important
1711 *                   function, CPRO_begin_cb
1712 *
1713 * NOTE:                         .
1714 *
1715 * Global Variables referenced:  .
1716 *
1717 * Global Variables modified:    x
1718 *
1719 * AWARs referenced:             .
1720 *
1721 * AWARs modified:               x
1722 *
1723 * Dependencies:      Needs xfig file cprofile.fig 
1724 * -----------------------------------------------------------------
1725 */
1726AW_window *
1727AP_open_cprofile_window( AW_root *aw_root)
1728{
1729        AW_window_simple *aws = new AW_window_simple;
1730        aws->init( aw_root, "CPR_MAIN", "Conservation Profile: Distance Matrix",10,10);
1731        aws->load_xfig("cpro/main.fig");
1732        aws->button_length( 10 );
1733
1734        GB_push_transaction(gb_main);
1735
1736        aws->at("close");aws->callback((AW_CB0)AW_POPDOWN);
1737        aws->create_button("CLOSE","CLOSE","C");                           
1738       
1739        aws->at("help");aws->callback(AW_POPUP_HELP,(AW_CL)"pos_variability.ps");
1740        aws->create_button("HELP","HELP","H");                     
1741       
1742        aws->button_length(10);
1743        aws->at("xpert");aws->callback(AW_POPUP,(AW_CL)CPRO_xpert_cb,0);
1744        aws->create_button("EXPERT_OPTIONS","expert...","x");
1745
1746/* start action by button */
1747        aws->button_length(17);
1748        aws->at("calculate1");aws->callback(AW_POPUP,(AW_CL)CPRO_calculatewin_cb,0);
1749        aws->create_button("GO_STAT_1", "calculate as\nstatistic 1 ...","c");
1750        aws->at("calculate2");aws->callback(AW_POPUP,(AW_CL)CPRO_calculatewin_cb,1);
1751        aws->create_button("GO_STAT_2", "calculate as\nstatistic 2 ...","a");   
1752
1753        aws->button_length(17);
1754        aws->at("save1");aws->callback(AW_POPUP,(AW_CL)CPRO_savestatisticwindow_cb,0);
1755        aws->create_button("SAVE_STAT_1", "save\nstatistic 1 ...","s");
1756        aws->at("save2");aws->callback(AW_POPUP,(AW_CL)CPRO_savestatisticwindow_cb,1);
1757        aws->create_button("SAVE_STAT_2", "save\nstatistic 2 ...","v");
1758
1759        aws->button_length( 17);
1760        aws->at("show1");aws->callback(AW_POPUP,(AW_CL)CPRO_showstatistic_cb,0);
1761                aws->create_button("SHOW_STAT_!", "show\ngraph 1 ...","h");
1762        aws->at("show2");aws->callback(AW_POPUP,(AW_CL)CPRO_showstatistic_cb,1);
1763                aws->create_button("SHOW_STAT_2", "show\ngraph 2 ...","w");
1764
1765        aws->button_length( 17);
1766        aws->at("load1");aws->callback(AW_POPUP,(AW_CL)CPRO_loadstatisticwindow_cb,0);
1767                aws->create_button("LOAD_STAT_1", "load\nstatistic 1 ... ","l");
1768        aws->at("load2");aws->callback(AW_POPUP,(AW_CL)CPRO_loadstatisticwindow_cb,1);
1769                aws->create_button("LOAD_STAT_2", "load\nstatistic 2 ...","d");
1770
1771        aws->at("condense1");aws->callback(AW_POPUP,    (AW_CL)CPRO_condensewindow_cb,0);
1772                aws->create_button("CONDENSE_STAT_1", "condense\nstatistic 1 ...","o");
1773        aws->at("condense2");aws->callback(AW_POPUP,    (AW_CL)CPRO_condensewindow_cb,1);
1774                aws->create_button("CONDENSE_STAT_2",   "condense\nstatistic 2 ...","n");
1775
1776        aws->at("memfor1");aws->create_button(0,"tmp/cpro/memfor1");
1777        aws->at("memfor2");aws->create_button(0,"tmp/cpro/memfor2");
1778        aws->at("which1");aws->create_button(0,"tmp/cpro/which1");
1779        aws->at("which2");aws->create_button(0,"tmp/cpro/which2");
1780        aws->at("resolution1");aws->create_button(0,"tmp/cpro/nowres1");
1781        aws->at("resolution2");aws->create_button(0,"tmp/cpro/nowres2");
1782
1783        aw_root->awar("cpro/alignment")->add_callback(
1784                (AW_RCB)CPRO_memrequirement_cb,0,0);
1785        aw_root->awar("cpro/partition")->add_callback(
1786                (AW_RCB)CPRO_memrequirement_cb,0,0);
1787        aw_root->awar("cpro/resolution")->add_callback(
1788                (AW_RCB)CPRO_memrequirement_cb,0,0);
1789        aw_root->awar("cpro/which_species")->add_callback(
1790                (AW_RCB)CPRO_memrequirement_cb,0,0);   
1791
1792        GB_pop_transaction(gb_main);
1793
1794        CPRO_memrequirement_cb(aw_root,0,0);
1795
1796        return (AW_window *)aws;
1797}
Note: See TracBrowser for help on using the repository browser.