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