|
NCBI Home IEB Home C Toolkit docs C++ Toolkit source browser C Toolkit source browser (2) |
NCBI C Toolkit Cross ReferenceC/ddv/ddvcreate.c |
source navigation diff markup identifier search freetext search file search |
1 /* $Id: ddvcreate.c,v 1.66 2001/02/01 00:39:53 lewisg Exp $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information (NCBI)
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government do not place any restriction on its use or reproduction.
13 * We would, however, appreciate having the NCBI and the author cited in
14 * any work or product based on this material
15 *
16 * Although all reasonable efforts have been taken to ensure the accuracy
17 * and reliability of the software and data, the NLM and the U.S.
18 * Government do not and cannot warrant the performance or results that
19 * may be obtained by using this software or data. The NLM and the U.S.
20 * Government disclaim all warranties, express or implied, including
21 * warranties of performance, merchantability or fitness for any particular
22 * purpose.
23 *
24 * ===========================================================================
25 *
26 * File Name: ddvcreate.c
27 *
28 * Author: Sarah Wheelan
29 *
30 * Version Creation Date: 08/99
31 *
32 * $Revision: 1.66 $
33 *
34 * File Description:
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * $Log: ddvcreate.c,v $
39 * Revision 1.66 2001/02/01 00:39:53 lewisg
40 * fix leak
41 *
42 * Revision 1.65 2001/01/29 20:35:49 hurwitz
43 * make gap between aligned blocks optional
44 *
45 * Revision 1.64 2001/01/25 21:49:14 hurwitz
46 * added option for extra gap char (tilde) between aligned blocks
47 *
48 * Revision 1.63 2001/01/19 22:05:40 wheelan
49 * took out small spaces created by UABuildDescriptor
50 *
51 * Revision 1.62 2001/01/10 23:38:39 lewisg
52 * fix seqid and various memory leaks
53 *
54 * Revision 1.61 2000/09/08 21:50:38 hurwitz
55 * made DDV_ReadSeqBin public
56 *
57 * Revision 1.60 2000/09/06 17:41:26 shavirin
58 * Fixed bug with printing gaps with discontinuous alignment.
59 *
60 * Revision 1.59 2000/08/25 18:55:27 shavirin
61 * Changed layout - unaligned regions will be always in lower characters.
62 *
63 * Revision 1.58 2000/08/22 19:59:28 shavirin
64 * Changed layout no.1 - it will be used for standalone blast with
65 * decline-to-align parameter not = 0
66 *
67 * Revision 1.57 2000/07/19 18:46:19 bauer
68 * Fixed bug in DDV_CreateDisplayFromIndex_EX
69 *
70 * Revision 1.56 2000/06/29 23:15:13 hurwitz
71 * leave single space between aligned blocks with no unaligned sequence between them, no auto-merge of adjacent aligned blocks
72 *
73 * Revision 1.55 2000/06/22 20:56:52 hurwitz
74 * assorted bug fixes
75 *
76 * Revision 1.54 2000/06/13 18:23:55 hurwitz
77 * made ViewMgr_MakeMultiple routine, call this on each launch of DDE rather than launch of DDV
78 *
79 * Revision 1.53 2000/06/12 23:02:40 hurwitz
80 * enable launch of DDE from Cn3D, swith from DDV_ComputeRuler to DDE_ReMakeRuler, get rid of styles option for DDE
81 *
82 * Revision 1.52 2000/06/08 20:04:38 hurwitz
83 * made warning about converting to true multiple alignment into a Message window, and other small fixes
84 *
85 * Revision 1.51 2000/06/07 19:09:36 hurwitz
86 * made DDE_ReMakeRuler work with linked list of ParaGs
87 *
88 * Revision 1.50 2000/05/10 16:17:00 hurwitz
89 * can show tails for just 1 aligned block
90 *
91 * Revision 1.49 2000/05/08 13:16:00 wheelan
92 * replaced segment-based counting with block-based counting
93 *
94 * Revision 1.48 2000/05/04 22:43:38 hurwitz
95 * don't launch DDE on top of DDV, change some wording, redraw DDE after save to AlnMgr
96 *
97 * Revision 1.47 2000/05/03 19:34:38 wheelan
98 * added fix for NULL alignments
99 *
100 * Revision 1.46 2000/05/03 14:51:02 thiessen
101 * revert to ~ gap char for Cn3D
102 *
103 * Revision 1.45 2000/04/21 23:00:50 hurwitz
104 * can launch DDE from DDV
105 *
106 * Revision 1.44 2000/04/19 19:08:23 hurwitz
107 * problem with justification of flanking unaligned regions fixed
108 *
109 * Revision 1.43 2000/04/19 15:45:50 hurwitz
110 * can create display for a block
111 *
112 * Revision 1.42 2000/04/06 17:59:50 durand
113 * fixed a conflict between BLAST and DDV in the use of the function DDV_SetSTyle
114 *
115 * Revision 1.41 2000/04/04 19:08:00 durand
116 * add new BLAST color schemas; fixed a bug in DDV_PopulateDisplayForDisc
117 *
118 * Revision 1.40 2000/03/31 21:33:07 durand
119 * added new default color schemas for BLAST
120 *
121 * Revision 1.39 2000/03/28 21:20:07 shavirin
122 * Adjusted for correct structure of BLAST location mask.
123 *
124 * Revision 1.38 2000/03/28 17:08:17 durand
125 * removed debugging code lines
126 *
127 * Revision 1.37 2000/03/27 14:19:28 durand
128 * fixed bugs in BLAST outputs
129 *
130 * Revision 1.36 2000/03/21 19:26:45 durand
131 * adapt ddvcreate to be used by pgppop
132 *
133 * Revision 1.35 2000/03/20 13:46:23 durand
134 * fixed a bug in BLAST functions; added DDV_BLAST_COLOR0 to produce a BLAST output without any layout
135 *
136 * Revision 1.34 2000/02/28 16:52:47 durand
137 * wrote a new manager for unaligned regions
138 *
139 * Revision 1.33 2000/02/23 21:34:29 durand
140 * allow custom display of gap characters
141 *
142 * Revision 1.32 2000/02/23 19:49:33 durand
143 * use row number instead of SeqId for coloring
144 *
145 * Revision 1.31 2000/02/17 15:54:56 durand
146 * use ~ for an unaligned gap and - for an aligned gap
147 *
148 * Revision 1.30 2000/02/15 22:40:57 lewisg
149 * add ability to launch udv so that it colors by row, fixes to colormgr, track rows from viewmgr, fix visual c projects
150 *
151 * Revision 1.29 2000/02/14 16:49:33 durand
152 * add new options for BLAST output
153 *
154 * Revision 1.28 2000/02/11 13:58:21 wheelan
155 * bug fix for unaligned region of length 0 (Durand)
156 *
157 * Revision 1.27 2000/02/07 14:03:35 durand
158 * replace BioseqUnlockById by BioseqUnlock
159 *
160 * Revision 1.26 2000/02/05 01:32:22 lewisg
161 * add viewmgr, move place freeing is done in ddv, modify visual c++ projects
162 *
163 * Revision 1.25 2000/02/02 14:44:30 durand
164 * added function to create data structure for block editor, fixed some bugs
165 *
166 * Revision 1.24 2000/01/26 13:38:54 durand
167 * update the GUI for the editor. Add functions to create the data to be used by the editor
168 *
169 * Revision 1.23 1999/12/29 22:55:03 lewisg
170 * get rid of seqalign id
171 *
172 * Revision 1.22 1999/12/20 20:20:41 lewisg
173 * allow cn3d to do color and ddv to do case when both are running
174 *
175 * Revision 1.21 1999/12/20 14:45:37 durand
176 * add new functions for the new BLAST outputs
177 *
178 * Revision 1.20 1999/12/08 22:42:17 durand
179 * add the code to produce colored BLAST outputs
180 *
181 * Revision 1.19 1999/12/03 23:17:22 lewisg
182 * Patrick's new global update msg, argument passing when launching ddv, experimental editing
183 *
184 * Revision 1.18 1999/12/03 18:24:08 durand
185 * gapped regions are displayed using lower cases; BLAST outputs
186 *
187 * Revision 1.17 1999/12/03 13:23:08 durand
188 * replace AlnMgrGetNumSeqs by AlnMgrGetNumRows
189 *
190 * Revision 1.16 1999/12/02 14:46:42 durand
191 * fix a bug in UABuildDescriptor; problem with unaligned region of size 0
192 *
193 * Revision 1.15 1999/11/24 21:26:29 vakatov
194 * Fixed for the C++ and/or MSVC DLL compilation
195 *
196 * Revision 1.14 1999/11/17 22:44:02 durand
197 * speed up the selection manager for large SeqAlign
198 *
199 * Revision 1.13 1999/11/09 22:14:01 shavirin
200 * Added parameter follower to the Blast score printing function
201 *
202 * Revision 1.12 1999/11/09 17:08:59 durand
203 * transfer some functions from ddvgraph to ddvcreate, so that ddvcreate remains Vibrant free and can be compiled with BLAST
204 *
205 * Revision 1.11 1999/11/03 21:29:48 durand
206 * add CTRL and SHFT keys for mouse selection. redesign the loader functions of DDV to properly register the message callbacks
207 *
208 * Revision 1.10 1999/10/29 14:15:40 durand
209 * add simple mouse selection functions
210 *
211 * Revision 1.9 1999/10/22 20:12:47 durand
212 * add Export command (text, HTML and Phylip formats)
213 *
214 * Revision 1.8 1999/10/22 14:57:25 durand
215 * use AlnMgrIndexSingleChildSeqAlign to build BLAST output
216 *
217 * Revision 1.7 1999/10/22 13:17:19 durand
218 * remove unreferenced variables to avoid warnings with Visual C
219 *
220 * Revision 1.6 1999/10/20 13:17:19 durand
221 * add display for disc. SeqAlign tails
222 *
223 * Revision 1.5 1999/10/15 21:57:35 durand
224 * add a UI for display options
225 *
226 * Revision 1.4 1999/10/12 15:01:29 lewisg
227 * resolve confict with internal/ddv
228 *
229 * Revision 1.3 1999/10/07 13:36:08 wheelan
230 * bug fixes -- AlnLengths were 1 too long
231 *
232 * Revision 1.2 1999/10/05 14:04:21 wheelan
233 * made DDV_CreateDisplayFromIndex_2, which creates the display for discontinuous alignments; minor bug fixes
234 *
235 * Revision 1.1 1999/09/30 14:10:25 durand
236 * add ddv to toolkit
237 *
238 * Revision 1.11 1999/09/30 13:38:09 durand
239 * DDV_CreateDisplayFromIndex takes ParaG_Size as an argument
240 *
241 *
242 *
243 * ==========================================================================
244 */
245 #include <ddvcreate.h>
246 #include <pgppop.h>
247 #include <udvseq.h>
248 #include <tofasta.h>
249 #include <sqnutils.h>
250
251 typedef struct ddvdataforcolorfunc{
252 SeqIdPtr sip;
253 Int4 from;
254 Int4 to;
255 Int4 row;
256 Uint1 strand;
257 Boolean IsUnAligned;
258 Uint1 style;
259 Uint1 rgb[3];
260 Uint1 UAstyle;
261 Uint1 UArgb[3];
262 } DDVDataForColorFunc, PNTR DDVDataForColorFuncPtr;
263
264 #define MAX_NCBIstdaa 26
265 #define MAX_NCBI4na 17
266 #define DDVCOL_DEFAULT 0
267 #define DDVCOL_HOTPINK 1
268 #define DDVCOL_MAGENTA 2
269 #define DDVCOL_PURPLE 3
270 #define DDVCOL_BLUE 4
271 #define DDVCOL_SKY 5
272 #define DDVCOL_CYAN 6
273 #define DDVCOL_SEA 7
274 #define DDVCOL_GREEN 8
275 #define DDVCOL_YELLOW 9
276 #define DDVCOL_GOLD 10
277 #define DDVCOL_ORANGE 11
278 #define DDVCOL_RED 12
279 #define DDVCOL_PINK 13
280 #define DDVCOL_PINKTINT 14
281 #define DDVCOL_WHITE 15
282 #define DDVCOL_BLACK 16
283 #define DDVCOL_BLUETINT 17
284 #define DDVCOL_GREENTINT 18
285 #define DDVCOL_YELLOWTINT 19
286 #define DDVCOL_GRAY 20
287 #define DDVCOL_BROWN 21
288 #define DDV_COLOR_MAX 33
289 static Uint1 DDV_PaletteRGB[DDV_COLOR_MAX][3] =
290 {
291 /* Red Grn Blue Color ColorID Old Hex New Hex */
292 255, 255, 255, /* default 0 0xffffff - */
293 255, 0, 153, /* hotpink 1 0xff1493 0xff0099 */
294 255, 0, 255, /* magenta 2 0xff00ff - */
295 153, 51, 255, /* purple 3 0x9b30ff 0x9933ff */
296 0, 0, 255, /* blue 4 0x0000ff - */
297 00, 153, 255, /* sky 5 0x1e90ff 0x0099ff */
298 0, 255, 255, /* cyan 6 0x00ffff - */
299 0, 255, 153, /* sea 7 0x00ff8f 0x00ff99 */
300 0, 192, 0, /* green 8 0x00ff00 - */
301 255, 255, 0, /* yellow 9 0xffff00 - */
302 255, 204, 0, /* gold 10 0xffa500 0xffcc00 */
303 255, 102, 0, /* orange 11 0xff4500 0xff6600 */
304 255, 0, 0, /* red 12 0xff0000 - */
305 255, 153, 153, /* pink 13 0xff7256 0xff9999 */
306 255, 204, 204, /* pinktint 14 0xffaeb9 0xffcccc */
307 255, 255, 255, /* white 15 0xffffff -*/
308 0, 0, 0, /* black 16 0x000000 - */
309 204, 204, 255, /* bluetint 17 0xb0e2ff - 0xccccff*/
310 153, 255, 153, /* greentint 18 0x9aff9a - 0x99ff99 */
311 255, 255, 153, /* yellowtint 19 0xffec8b - 0xffff99 */
312 102, 102, 102, /* gray 20 0x7d7d7d 0x666666 */
313 153, 102, 51, /* brown 21 0x8b5742 01x996633 */
314 255, 0, 0, /* perm colors 22: red 0xff0000 - */
315 0, 255, 0, /* perm colors 23: green 0x00ff00 - */
316 255, 0, 255, /* perm colors 24: magenta 0xff00ff - */
317 00, 153, 255, /* perm colors 25: sky 0x1e90ff 0x0099ff */
318 153, 51, 255, /* perm colors 26: purple 0x9b30ff 0x9933ff */
319 0, 255, 0, /* SS colors 27: helix, green 0x00ff00 - */
320 255, 204, 0, /* SS colors 28: strand, gold 0xffa500 0xffcc00 */
321 255, 102, 0, /* SS colors 29: turn, orange 0xff4500 0xff6600 */
322 0, 255, 255, /* SS colors 30: coil, cyan ox00ffff - */
323 255, 255, 0, /* highlight colors 31: yellow 0xffff00 - */
324 0, 0, 0 /* background colors 32: black 0x000000 - */
325 };
326 Uint1 DDV_STD_AAColor[MAX_NCBIstdaa] =
327 {DDVCOL_BROWN, /*-*/
328 DDVCOL_GRAY, /*A*/
329 DDVCOL_ORANGE, /*B*/
330 DDVCOL_PINK, /*C*/
331 DDVCOL_RED, /*D*/
332 DDVCOL_RED, /*E*/
333 DDVCOL_PURPLE, /*F*/
334 DDVCOL_GRAY, /*G*/
335 DDVCOL_BLUE, /*H*/
336 DDVCOL_GRAY, /*I*/
337 DDVCOL_BLUE, /*K*/
338 DDVCOL_GRAY, /*L*/
339 DDVCOL_PINK, /*M*/
340 DDVCOL_CYAN, /*N*/
341 DDVCOL_MAGENTA,/*P*/
342 DDVCOL_CYAN, /*Q*/
343 DDVCOL_BLUE, /*R*/
344 DDVCOL_GREEN, /*S*/
345 DDVCOL_GREEN, /*T*/
346 DDVCOL_GRAY, /*V*/
347 DDVCOL_PURPLE, /*W*/
348 DDVCOL_GRAY, /*X*/
349 DDVCOL_PURPLE, /*Y*/
350 DDVCOL_ORANGE, /*Z*/
351 DDVCOL_GOLD, /*U*/
352 DDVCOL_HOTPINK /***/};
353
354 Uint1 DDV_STD_NAColor[MAX_NCBI4na] = {
355 DDVCOL_PINK, /* gap */
356 DDVCOL_GREEN, /* A */
357 DDVCOL_BLUE, /* C */
358 DDVCOL_CYAN, /* A or C */
359 DDVCOL_BLACK, /* G */
360 DDVCOL_CYAN, /* G or A */
361 DDVCOL_CYAN, /* G or C */
362 DDVCOL_PURPLE, /* G C or A */
363 DDVCOL_RED, /* T */
364 DDVCOL_CYAN, /* A or T */
365 DDVCOL_CYAN, /* T or C */
366 DDVCOL_PURPLE, /* A C ot T */
367 DDVCOL_CYAN, /* G ot T */
368 DDVCOL_PURPLE, /* G or A or T */
369 DDVCOL_PURPLE, /* G T or C */
370 DDVCOL_HOTPINK,/* G T A or C */
371 DDVCOL_GRAY /*?, but MAX_NCBI4na==17, see mmdbapi2.h*/
372 };
373
374 extern void display_ParaG_content(MsaParaGPopListPtr mpplp,Int2 LineSize)
375 {
376 BioseqPtr bsp_debug=NULL;
377 Char szBuf[15];
378 ParaGPtr pgp;
379 MsaTxtDispPtr mtdp;
380 ValNodePtr vnp,vnp2;
381 Uint4 j,k,size,sum;
382 FILE *fp;
383 Boolean bClose=TRUE;
384 Int4 i;
385 if (LineSize<=50)/*just for the integrity of the function...*/
386 LineSize=ParaG_Size;
387
388 fp=fopen("zpgplist.txt","w");
389 if (fp==NULL) {fp=stdout;bClose=FALSE;}
390 for(i=0;i<mpplp->nBsp;i++){
391 /*for each line (i.e. bioseq) */
392 vnp=mpplp->TableHead[i];
393 if (vnp) pgp=(ParaGPtr)(vnp->data.ptrvalue);
394 else pgp=NULL;
395 if(pgp){
396 if (pgp->sip) bsp_debug=BioseqLockById(pgp->sip);
397 else bsp_debug=NULL;
398 if (bsp_debug){
399 /*get the access code*/
400 SeqIdWrite(bsp_debug->id, szBuf, PRINTID_TEXTID_ACCESSION, 14);
401 fprintf(fp,"[%5u] %s , size: %d, IsAA :%d \n",
402 i,szBuf,BioseqGetLen(bsp_debug),
403 ISA_aa(bsp_debug->mol));
404 BioseqUnlock(bsp_debug);
405 }
406 else StringCpy(szBuf,"unknown");
407 }
408 k=1;size=1;
409 while(vnp){
410 pgp=(ParaGPtr)(vnp->data.ptrvalue);
411 if (pgp){/*create the name table*/
412 /*loop on the pgp*/
413 fprintf(fp," ->ParaG[%d] , range (%7d..%7d):\n",k++,size,size+LineSize-1);
414 size+=LineSize;
415 vnp2=pgp->ptxtList;
416 j=1;sum=0;
417 while(vnp2){
418 mtdp=(MsaTxtDispPtr)vnp2->data.ptrvalue;
419 if (mtdp){
420 fprintf(fp," (%4u): range(%7d..%7d) (%2d), Gap: %2d, Strand(%d)\n",
421 j++,mtdp->from,mtdp->to,mtdp->to-mtdp->from+1,mtdp->IsGap,
422 mtdp->strand);
423 }
424 sum+=(mtdp->to-mtdp->from+1);
425 vnp2=vnp2->next;
426 }
427 fprintf (fp," Total = %d.\n",sum);
428 }
429 vnp=vnp->next;
430 }
431 fprintf(fp,"\n");
432 }
433 if (bClose) fclose(fp);
434
435 }
436
437 static Boolean DDV_CreateDisplayFromIndex_1(SeqAlignPtr sap, MsaParaGPopListPtr mpplp, Int2 LineSize,
438 Int4 start,Int4 stop)
439 {
440 AlnMsgPtr amp;
441 Int4 i,from,to;
442 Boolean more;
443 MsaTxtDispPtr mtdp;
444 Int4 n;
445 ParaGPtr pgp;
446 SeqIdPtr sip;
447 ValNodePtr vnp;
448 ValNodePtr vnp_head;
449 ValNodePtr PNTR vnp_list;
450 ValNodePtr vnp_para;
451 ValNodePtr vnp_para_head;
452
453 if (LineSize<=50)/*just for the integrity of the function...*/
454 LineSize=ParaG_Size;
455
456 amp = AlnMsgNew();
457 vnp_list = (ValNodePtr PNTR)MemNew((mpplp->nBsp)*sizeof(ValNodePtr));
458 if (start!=(Int4)-1){
459 from=start;
460 }
461 else{
462 from=0;
463 }
464 if (stop!=(Int4)-1){
465 to=stop+1;
466 }
467 else{
468 to=mpplp->LengthAli;
469 }
470
471 for (n = 1; n<=(mpplp->nBsp); n++)
472 {
473 vnp_para = vnp_para_head = NULL;
474 sip = AlnMgrGetNthSeqIdPtr(mpplp->sap, n);
475 for (i = from; i<to; i+=LineSize)
476 {
477 amp = AlnMsgReNew(amp);
478 pgp = (ParaGPtr)MemNew(sizeof(ParaG));
479 pgp->StartLine = n - 1;
480 pgp->nLines = 1;
481 pgp->StartLetter = amp->from_m = i;
482 if (i + LineSize >= to)
483 pgp->StopLetter = amp->to_m = to - 1;
484 else
485 pgp->StopLetter = amp->to_m = i + LineSize -1;
486 if(i == from) pgp->sip = sip;
487 else pgp->sip = SeqIdDup(sip);
488 pgp->ScaleStyle = SCALE_POS_NONE;
489 amp->which_bsq = NULL;
490 amp->row_num = n;
491 vnp = vnp_head = NULL;
492 amp->place = 0;
493 while (more = AlnMgrGetNextAlnBit(mpplp->sap, amp))
494 {
495 vnp = ValNodeAdd(&vnp);
496 if (!vnp_head)
497 vnp_head = vnp;
498 mtdp = (MsaTxtDispPtr)MemNew(sizeof(MsaTxtDisp));
499 mtdp->from = amp->from_b;
500 mtdp->to = amp->to_b;
501 mtdp->IsGap = (Boolean)(amp->gap);
502 if (mtdp->IsGap)
503 mtdp->TextStyle = MSA_TXT_STYLE_GAP;
504 else
505 mtdp->TextStyle = MSA_TXT_STYLE_SEQ;
506 mtdp->strand = amp->strand;
507 mtdp->IsUnAligned=FALSE;
508 vnp->data.ptrvalue = mtdp;
509 }
510 pgp->ptxtList = vnp_head;
511 vnp_para = ValNodeAdd(&vnp_para);
512 vnp_para->data.ptrvalue = pgp;
513 if (!vnp_para_head)
514 vnp_para_head = vnp_para;
515 }
516 vnp_list[n-1]=vnp_para_head;
517 }
518 mpplp->TableHead = vnp_list;
519 /*display_ParaG_content(mpplp,LineSize);*/
520 DDV_LocateParaG(mpplp->TableHead,mpplp->nBsp);
521 return TRUE;
522 }
523
524
525 static Boolean DDV_CreateDisplayFromIndex_2(SeqAlignPtr sap, MsaParaGPopListPtr mpplp, Int2 LineSize)
526 {
527 AlnMsgPtr amp;
528 Int4 i;
529 Boolean more;
530 MsaTxtDispPtr mtdp;
531 Int4 n;
532 ParaGPtr pgp;
533
534
535 ValNodePtr vnp;
536 ValNodePtr vnp_head;
537 ValNodePtr PNTR vnp_list;
538 ValNodePtr vnp_para;
539 ValNodePtr vnp_para_head;
540 Int4 PopulateTo;
541 Int4 ReportSpacer;
542 Int4 PlaceSpacer;
543 Int4 RealAlnLength;
544 SeqIdPtr sip;
545 Boolean last;
546
547
548 amp = AlnMsgNew();
549 vnp_list = (ValNodePtr PNTR)MemNew((mpplp->nBsp)*sizeof(ValNodePtr));
550 RealAlnLength = AlnMgrGetAlnLength(mpplp->sap, FALSE);
551 for (n = 1; n<=(mpplp->nBsp); n++)
552 {
553 vnp_para = vnp_para_head = NULL;
554 sip = AlnMgrGetNthSeqIdPtr(mpplp->sap, n);
555 ReportSpacer=0;
556 amp->to_m=-1;
557 amp = AlnMsgReNew(amp);
558 last = FALSE;
559 for (i = 0; i<mpplp->LengthAli; i+=LineSize)
560 {
561 amp->place = 0;
562 pgp = (ParaGPtr)MemNew(sizeof(ParaG));
563 pgp->StartLine = n - 1;
564 pgp->nLines = 1;
565 pgp->StartLetter = i;
566 if (i + LineSize >= mpplp->LengthAli)
567 {
568 last = TRUE;
569 pgp->StopLetter = mpplp->LengthAli;
570 }
571 else
572 pgp->StopLetter = i + LineSize -1;
573 if(i == 0) pgp->sip = sip;
574 else pgp->sip = SeqIdDup(sip);
575 pgp->ScaleStyle = SCALE_POS_NONE;
576 amp->which_master = 0;
577 if (amp->to_m != 0)
578 amp->from_m = amp->to_m + 1 ;
579 else
580 amp->from_m = 0;
581 amp->to_m = amp->from_m + LineSize -1;
582 amp->row_num = n;
583 if (amp->to_m > RealAlnLength)
584 amp->to_m = RealAlnLength - 1;
585 more = TRUE;
586 vnp = vnp_head = NULL;
587 PopulateTo=0;
588 PlaceSpacer=0;
589 while (amp->place == 0)
590 {
591 vnp = ValNodeAdd(&vnp);
592 if (!vnp_head)
593 vnp_head = vnp;
594 if (amp->send_space)
595 {
596 if (!last)
597 amp->to_m=amp->to_m - PlaceSpacer;
598 }
599 if (ReportSpacer){
600 amp->to_m -=ReportSpacer;
601 mtdp = (MsaTxtDispPtr)MemNew(sizeof(MsaTxtDisp));
602 mtdp->from = pgp->StartLetter;
603 mtdp->to = mtdp->from+ReportSpacer-1;
604 PopulateTo+=(ReportSpacer+1);
605 ReportSpacer=0;
606 mtdp->IsGap = TRUE;
607 mtdp->TextStyle = MSA_TXT_STYLE_1;
608 vnp->data.ptrvalue = mtdp;
609 vnp = ValNodeAdd(&vnp);
610 }
611 amp->send_space = FALSE;
612 more = AlnMgrGetNextAlnBit(mpplp->sap, amp);
613 mtdp = (MsaTxtDispPtr)MemNew(sizeof(MsaTxtDisp));
614 mtdp->from = amp->from_b;
615 mtdp->to = amp->to_b;
616 PopulateTo+=(amp->to_b-amp->from_b+1);
617 mtdp->IsGap = (Boolean)(amp->gap);
618 if (mtdp->IsGap)
619 mtdp->TextStyle = MSA_TXT_STYLE_GAP;
620 else
621 mtdp->TextStyle = MSA_TXT_STYLE_SEQ;
622 mtdp->strand = amp->strand;
623 vnp->data.ptrvalue = mtdp;
624 if (amp->send_space)
625 {
626 vnp = ValNodeAdd(&vnp);
627 mtdp = (MsaTxtDispPtr)MemNew(sizeof(MsaTxtDisp));
628 mtdp->from = pgp->StartLetter+PopulateTo;
629 mtdp->to = mtdp->from+SPACER_TXT_BLANK-1;
630 if (mtdp->to>pgp->StopLetter){
631 ReportSpacer=mtdp->to-pgp->StopLetter;
632 mtdp->to=pgp->StopLetter;
633 }
634 else{
635 ReportSpacer=0;
636 }
637 PlaceSpacer=SPACER_TXT_BLANK-ReportSpacer;
638 PopulateTo+=(mtdp->to-mtdp->from+1);
639 mtdp->IsGap = TRUE;
640 mtdp->TextStyle = MSA_TXT_STYLE_1;
641 mtdp->IsUnAligned=FALSE;
642 vnp->data.ptrvalue = mtdp;
643 }
644 }
645 pgp->ptxtList = vnp_head;
646 vnp_para = ValNodeAdd(&vnp_para);
647 vnp_para->data.ptrvalue = pgp;
648 if (!vnp_para_head)
649 vnp_para_head = vnp_para;
650 }
651 vnp_list[n-1]=vnp_para_head;
652 }
653 mpplp->TableHead = vnp_list;
654 /*display_ParaG_content(mpplp,LineSize);*/
655 DDV_LocateParaG(mpplp->TableHead,mpplp->nBsp);
656 return TRUE;
657 }
658
659
660 NLM_EXTERN Boolean DDV_CreateDisplayFromIndex_EX(SeqAlignPtr sap, MsaParaGPopListPtr mpplp,
661 Int2 LineSize, DDV_Disp_OptPtr ddop,Int4 start, Int4 stop) {
662 /*******************************************************************************
663 * same as DDV_CreateDisplayFromIndex_EX2, but by default no extra gap char.
664 *******************************************************************************/
665 return(DDV_CreateDisplayFromIndex_EX2(sap, mpplp, LineSize, ddop, start, stop, FALSE));
666 }
667
668
669 NLM_EXTERN Boolean DDV_CreateDisplayFromIndex_EX2(SeqAlignPtr sap, MsaParaGPopListPtr mpplp,
670 Int2 LineSize, DDV_Disp_OptPtr ddop,Int4 start, Int4 stop, Boolean WantExtraGapChar)
671 {
672 AMAlignIndexPtr amaip;
673 AlnMsgPtr amp;
674 Int4 i,from,to;
675 Boolean more;
676 MsaTxtDispPtr mtdp;
677 Int4 n;
678 ParaGPtr pgp;
679
680
681 ValNodePtr vnp;
682 ValNodePtr vnp_head;
683 ValNodePtr PNTR vnp_list;
684 ValNodePtr vnp_para;
685 ValNodePtr vnp_para_head;
686 Int4 PopulateTo;
687
688
689 SeqIdPtr sip;
690 Boolean last;
691
692 if (LineSize<=50)/*just for the integrity of the function...*/
693 LineSize=ParaG_Size;
694
695 if (!sap)
696 return FALSE;
697 if (!AlnMgrIndexSeqAlign(sap))
698 return FALSE;
699 if (sap->saip->indextype == INDEX_PARENT)
700 {
701 amaip = (AMAlignIndexPtr)sap->saip;
702 if (sap->type == SAT_PARTIAL ||
703 (sap->type == SAT_MASTERSLAVE && (amaip->mstype == AM_SEGMENTED_MASTERSLAVE ||
704 amaip->mstype == AM_NULL ||
705 amaip->mstype == AM_MASTERSLAVE)))
706 {
707 return(DDV_CreateDisplay_DiscAlign2(sap,mpplp,LineSize,ddop,WantExtraGapChar));
708 }
709 else if (sap->type == SAT_MASTERSLAVE && amaip->mstype == AM_MASTERSLAVE)
710 {
711 mpplp->sap = sap;
712 if (start==(Int4)-1 && stop==(Int4)-1)
713 mpplp->LengthAli = AlnMgrGetAlnLength(mpplp->sap, FALSE);
714 else
715 mpplp->LengthAli=stop-start+1;
716 mpplp->nBsp = AlnMgrGetNumRows(mpplp->sap);
717 mpplp->DisplayType = DDV_DISP_HORZ;
718 if (!DDV_CreateDisplayFromIndex_1(sap, mpplp,LineSize,start,stop))
719 return FALSE;
720 else
721 return TRUE;
722 } else
723 mpplp->sap = (SeqAlignPtr)sap->segs;
724 } else
725 mpplp->sap = sap;
726 mpplp->LengthAli = AlnMgrGetAlnLength(mpplp->sap, FALSE);
727 mpplp->nBsp = AlnMgrGetNumRows(mpplp->sap);
728 mpplp->DisplayType = DDV_DISP_HORZ;
729 amp = AlnMsgNew();
730 vnp_list = (ValNodePtr PNTR)MemNew((mpplp->nBsp)*sizeof(ValNodePtr));
731 if (start!=(Int4)-1){
732 from=start;
733 }
734 else{
735 from=0;
736 }
737 if (stop!=(Int4)-1){
738 to=stop+1;
739 }
740 else{
741 to=mpplp->LengthAli;
742 }
743 for (n = 1; n<=(mpplp->nBsp); n++)
744 {
745 vnp_para = vnp_para_head = NULL;
746 sip = AlnMgrGetNthSeqIdPtr(mpplp->sap, n);
747 amp->to_m=-1;
748 amp = AlnMsgReNew(amp);
749 last = FALSE;
750 for (i = from; i<to; i+=LineSize)
751 {
752 amp->place = 0;
753 pgp = (ParaGPtr)MemNew(sizeof(ParaG));
754 pgp->StartLine = n - 1;
755 pgp->nLines = 1;
756 pgp->StartLetter = i;
757 if (i + LineSize >= to)
758 {
759 last = TRUE;
760 pgp->StopLetter = to;
761 }
762 else
763 pgp->StopLetter = i + LineSize -1;
764 if(i == from) pgp->sip = sip;
765 else pgp->sip = SeqIdDup(sip);
766 pgp->ScaleStyle = SCALE_POS_NONE;
767 amp->which_master = 0;
768 if (amp->to_m != 0)
769 amp->from_m = amp->to_m + 1 ;
770 else
771 amp->from_m = 0;
772 amp->to_m = amp->from_m + LineSize -1;
773 amp->row_num = n;
774 if (amp->to_m >= to)
775 amp->to_m = to - 1;
776 more = TRUE;
777 vnp = vnp_head = NULL;
778 PopulateTo=0;
779 while (more = AlnMgrGetNextAlnBit(mpplp->sap, amp))
780 {
781 vnp = ValNodeAdd(&vnp);
782 if (!vnp_head)
783 vnp_head = vnp;
784 mtdp = (MsaTxtDispPtr)MemNew(sizeof(MsaTxtDisp));
785 mtdp->from = amp->from_b;
786 mtdp->to = amp->to_b;
787 mtdp->IsGap = (Boolean)(amp->gap);
788 if (mtdp->IsGap)
789 mtdp->TextStyle = MSA_TXT_STYLE_GAP;
790 else
791 mtdp->TextStyle = MSA_TXT_STYLE_SEQ;
792 mtdp->strand = amp->strand;
793 mtdp->IsUnAligned=FALSE;
794 vnp->data.ptrvalue = mtdp;
795 }
796 pgp->ptxtList = vnp_head;
797 vnp_para = ValNodeAdd(&vnp_para);
798 vnp_para->data.ptrvalue = pgp;
799 if (!vnp_para_head)
800 vnp_para_head = vnp_para;
801 }
802 vnp_list[n-1]=vnp_para_head;
803 }
804 mpplp->TableHead = vnp_list;
805 /*display_ParaG_content(mpplp,LineSize);*/
806 DDV_LocateParaG(mpplp->TableHead,mpplp->nBsp);
807 return TRUE;
808 }
809
810
811 NLM_EXTERN Boolean DDV_CreateDisplayFromIndex(SeqAlignPtr sap, MsaParaGPopListPtr mpplp,
812 Int2 LineSize, DDV_Disp_OptPtr ddop) {
813 /*******************************************************************************
814 * same as DDV_CreateDisplayFromIndex2, but by default no extra gap char.
815 *******************************************************************************/
816 return(DDV_CreateDisplayFromIndex2(sap, mpplp, LineSize, ddop, FALSE));
817 }
818
819
820 NLM_EXTERN Boolean DDV_CreateDisplayFromIndex2(SeqAlignPtr sap, MsaParaGPopListPtr mpplp,
821 Int2 LineSize, DDV_Disp_OptPtr ddop, Boolean WantExtraGapChar)
822 {
823 return(DDV_CreateDisplayFromIndex_EX2(sap, mpplp,
824 LineSize, ddop, (Int4) -1, (Int4) -1, WantExtraGapChar));
825 }
826
827
828 static Boolean DDV_PopulateDisplayForDisc(SeqAlignPtr sap,MsaParaGPopListPtr mpplp,
829 Int4 nBsp,Int4 LineSize,DDV_Disp_OptPtr ddop,Int4 TotLength,ValNodePtr vnp_head,
830 Boolean OverrideDiscJustification, Boolean ForceLeft)
831 {
832 /*-------------------------------------------------------------
833 Added OverrideDiscJustification:
834 Set this true for single block alignment. In that case,
835 the first unaligned region will be right-justified and
836 the second unaligned region will be left-justified.
837
838 Added ForceLeft:
839 Set this true for single unaligned region alignment.
840 In that case, the unaligned region will be left-aligned.
841 -------------------------------------------------------------*/
842 Int4 cumulpop,StartLetter,n,nPgp,from_bsp,to_bsp,MaxLength,
843 BspLength=0,BspStart,BspStop,AbsPos;
844 Boolean more,bFirstMtdp,bFirstPgp,IsGap;
845 ValNodePtr vnp,vnp2,vnp3,vnp_para,vnp_mtdp=NULL;
846 ValNodePtr PNTR vnp_list;
847 ParaGPtr pgp;
848 SeqIdPtr sip;
849 DescriDispPtr ddp;
850 MsaTxtDispPtr mtdp_pgp;
851 AlnMsgPtr amp;
852 UAMsgPtr uamp;
853 Uint1 strand = Seq_strand_unknown;
854 Uint1 strand_tmp, Justification;
855 Int4 PassCount;
856
857 /*now, use the previous descriptor to build the ParaG List*/
858 mpplp->sap=sap;
859 mpplp->nBsp = nBsp;
860 mpplp->LengthAli = TotLength;
861 mpplp->DisplayType = DDV_DISP_HORZ;
862 amp = AlnMsgNew();
863 vnp_list = (ValNodePtr PNTR)MemNew((mpplp->nBsp)*sizeof(ValNodePtr));
864 if (!vnp_list || !amp){
865 /*delete the descriptor*/
866 ValNodeFreeData(vnp_head);
867 return(FALSE);
868 }
869
870 cumulpop=0;
871
872 /*loop on each sequence*/
873 for (n = 1; n<=(mpplp->nBsp); n++){
874 sip = AlnMgrGetNthSeqIdPtr(mpplp->sap, n);
875 /*for each sequence, use the descriptors to build the ParaG list*/
876 bFirstPgp=TRUE;
877 bFirstMtdp=TRUE;
878 StartLetter=0;AbsPos=0;/*disp coord*/
879 nPgp=0;
880 vnp=vnp_head;
881 PassCount = 0;
882 while(vnp){
883 ddp=(DescriDispPtr)vnp->data.ptrvalue;
884 if (ddp->TextStyle==MSA_TXT_STYLE_REG_ALIGN){/*aligned*/
885 /*initialize the amp struct for the current aligned region*/
886 amp = AlnMsgReNew(amp);
887 amp->place = 0;
888 amp->from_m = ddp->from;
889 amp->to_m=ddp->to;
890 amp->which_master=0;
891 amp->row_num=n;
892 amp->send_space = FALSE;
893 more=TRUE;
894 AlnMgrGetNextAlnBit(mpplp->sap, amp);
895 while (more){
896 /*list of TxT descriptors*/
897 mtdp_pgp = (MsaTxtDispPtr)MemNew(sizeof(MsaTxtDisp));
898 mtdp_pgp->IsGap = (Boolean)(amp->gap);
899 if (mtdp_pgp->IsGap){/*disp coord*/
900 mtdp_pgp->from=AbsPos;
901 mtdp_pgp->to=mtdp_pgp->from+(amp->to_b-amp->from_b);
902 mtdp_pgp->TextStyle = ddop->AGapStyle;
903 }
904 else{/*BSP coord*/
905 mtdp_pgp->from = amp->from_b;
906 mtdp_pgp->to = amp->to_b;
907 mtdp_pgp->TextStyle = MSA_TXT_STYLE_SEQ;
908 }
909 mtdp_pgp->strand = amp->strand;
910 mtdp_pgp->IsUnAligned=FALSE;
911 strand=amp->strand;
912 /*add the new node*/
913 if (bFirstMtdp){
914 vnp2=ValNodeAddPointer(NULL,0,(Pointer)mtdp_pgp);
915 vnp_mtdp=vnp2;
916 bFirstMtdp=FALSE;
917 }
918 else{
919 vnp2=ValNodeAddPointer(&vnp2,0,(Pointer)mtdp_pgp);
920 }
921 more=AlnMgrGetNextAlnBit(mpplp->sap, amp);
922 AbsPos+=(mtdp_pgp->to-mtdp_pgp->from+1);
923 }
924 }
925 else{/*unaligned*/
926 switch(ddop->DispDiscStyle){/*user's display choice*/
927 case MSA_TXT_STYLE_1:/*just put a little spacer*/
928 mtdp_pgp = (MsaTxtDispPtr)MemNew(sizeof(MsaTxtDisp));
929 mtdp_pgp->from = StartLetter;/*put DISP coord*/
930 mtdp_pgp->to = mtdp_pgp->from+(ddp->to-ddp->from);
931 mtdp_pgp->IsGap = TRUE;
932 mtdp_pgp->TextStyle = MSA_TXT_STYLE_1;
933 mtdp_pgp->strand = strand;
934 mtdp_pgp->IsUnAligned=TRUE;
935 /*add the new node*/
936 if (bFirstMtdp){
937 vnp2=ValNodeAddPointer(NULL,0,(Pointer)mtdp_pgp);
938 vnp_mtdp=vnp2;
939 bFirstMtdp=FALSE;
940 }
941 else{
942 vnp2=ValNodeAddPointer(&vnp2,0,(Pointer)mtdp_pgp);
943 }
944 break;
945 case MSA_TXT_STYLE_2:/*display the unaligned sequence*/
946 MaxLength=ddp->UAMaxlength;
947
948 if (ddp->UAnum>0){/*within SAP*/
949 AlnMgrGetNthUnalignedForNthRow(sap, ddp->UAnum, n, &BspStart,
950 &BspStop);
951 }
952 else{/*Tails of the SAP*/
953 if (AlnMgrGetNthRowTail(sap,n,
954 (Uint1)(ddp->UAnum==(Int4)-1 ? LEFT_TAIL : RIGHT_TAIL),
955 &BspStart,&BspStop,&strand_tmp)==FALSE){
956 BspStart=(Int4)-1;
957 BspStop=(Int4)-1;
958 BspLength=0;
959 }
960
961 }
962
963 if (BspStart!=(Int4)-1 && BspStop!=(Int4)-1){
964 BspLength=BspStop-BspStart+1;
965 }
966 /*init the analysis process of an UA region*/
967 switch(ddp->UAnum){
968 case (Int4)-1:/*left tail*/
969 Justification = ForceLeft ? DISP_JUST_LEFT : DISP_JUST_RIGHT;
970 uamp=UAMgrIntUAMsg(MaxLength,BspLength,BspStart,BspStop,
971 ddp->from,ddp->to, Justification, strand);
972 break;
973 case (Int4)-2:/*right tail*/
974 uamp=UAMgrIntUAMsg(MaxLength,BspLength,BspStart,BspStop,
975 ddp->from,ddp->to,DISP_JUST_LEFT, strand);
976 break;
977 default:/*within SAP*/
978 Justification = ddop->DiscJustification;
979 if (OverrideDiscJustification) {
980 if (PassCount==0) {Justification = DISP_JUST_RIGHT;}
981 if (PassCount==2) {Justification = DISP_JUST_LEFT;}
982 }
983 uamp=UAMgrIntUAMsg(MaxLength,BspLength,BspStart,BspStop,
984 ddp->from,ddp->to, Justification, strand);
985 break;
986 }
987 /*analyse the content of the UA region*/
988 while(UAMgrGetNextUAbit(uamp, BspStart, BspStop)){
989 /*get data*/
990 UAMgrUAMsgGetInfo(uamp,&from_bsp,&to_bsp,&IsGap);
991 /*list of TxT descriptors*/
992 mtdp_pgp = (MsaTxtDispPtr)MemNew(sizeof(MsaTxtDisp));
993 mtdp_pgp->IsGap = IsGap;
994 if (mtdp_pgp->IsGap){/*disp coord*/
995 mtdp_pgp->TextStyle = ddop->UAGapStyle;
996 mtdp_pgp->from=AbsPos;
997 mtdp_pgp->to=mtdp_pgp->from+(to_bsp-from_bsp);
998 }
999 else{/*BSP coord*/
1000 mtdp_pgp->from = from_bsp;
1001 mtdp_pgp->to = to_bsp;
1002 mtdp_pgp->TextStyle = MSA_TXT_STYLE_SEQ;
1003 }
1004 mtdp_pgp->strand = strand;
1005 mtdp_pgp->IsUnAligned=TRUE;
1006 /*add the new node*/
1007 if (bFirstMtdp){
1008 vnp2=ValNodeAddPointer(NULL,0,(Pointer)mtdp_pgp);
1009 vnp_mtdp=vnp2;
1010 bFirstMtdp=FALSE;
1011 }
1012 else{
1013 vnp2=ValNodeAddPointer(&vnp2,0,(Pointer)mtdp_pgp);
1014 }
1015 AbsPos+=(mtdp_pgp->to-mtdp_pgp->from+1);
1016 }
1017 uamp=UAMgrDelUAMsg(&uamp);
1018 break;
1019 }
1020 }
1021 cumulpop+=(ddp->to-ddp->from+1);
1022 StartLetter+=(ddp->to-ddp->from+1);
1023 if (cumulpop==LineSize || vnp->next==NULL){
1024 /*new ParaG*/
1025 pgp=(ParaGPtr)MemNew(sizeof(ParaG));
1026 pgp->StartLine=n-1;
1027 pgp->nLines=1;
1028 pgp->StartLetter=nPgp*LineSize;
1029 pgp->StopLetter=_min_(pgp->StartLetter+LineSize-1,mpplp->LengthAli-1);
1030 pgp->sip=SeqIdDup(sip);
1031 pgp->ScaleStyle=SCALE_POS_NONE;
1032 pgp->ptxtList=vnp_mtdp;
1033 if (bFirstPgp){
1034 vnp3=ValNodeAddPointer(NULL,0,(Pointer)pgp);
1035 vnp_para=vnp3;
1036 bFirstPgp=FALSE;
1037 }
1038 else{
1039 vnp3=ValNodeAddPointer(&vnp3,0,(Pointer)pgp);
1040 }
1041 bFirstMtdp=TRUE;
1042 cumulpop=0;
1043 nPgp++;
1044 }
1045 vnp=vnp->next;
1046 PassCount++;
1047 }/*while() on the descriptor list*/
1048 vnp_list[n-1]=vnp_para;
1049 SeqIdFree(sip);
1050 }/*for() on the bsp */
1051
1052 /*delete the descriptor*/
1053 ValNodeFreeData(vnp_head);
1054
1055 mpplp->TableHead = vnp_list;
1056 /*just for debugging purpose*/
1057 /*display_ParaG_content(mpplp,LineSize);*/
1058 DDV_LocateParaG(mpplp->TableHead,mpplp->nBsp);
1059 MemFree(amp);
1060
1061 return(TRUE);
1062 }
1063
1064 NLM_EXTERN Boolean DDV_CreateDisplay_DiscAlign(SeqAlignPtr sap,
1065 MsaParaGPopListPtr mpplp, Int2 LineSize,DDV_Disp_OptPtr ddop) {
1066 /*******************************************************************************
1067 * same as DDV_CreateDisplay_DiscAlign2, but by default no extra gap char.
1068 *******************************************************************************/
1069 return(DDV_CreateDisplay_DiscAlign2(sap, mpplp, LineSize, ddop, FALSE));
1070 }
1071
1072
1073 /*******************************************************************************
1074
1075 Function : DDV_CreateDisplay_DiscAlign2()
1076
1077 Purpose : create a display for a Disc. SeqAlign
1078
1079 Return value : FALSE if failure
1080
1081 *******************************************************************************/
1082 NLM_EXTERN Boolean DDV_CreateDisplay_DiscAlign2(SeqAlignPtr sap,
1083 MsaParaGPopListPtr mpplp, Int2 LineSize,DDV_Disp_OptPtr ddop, Boolean WantExtraGapChar)
1084 {
1085 Int4 nBsp,TotLength;
1086 ValNodePtr vnp_head;
1087
1088 /*descriptor*/
1089 nBsp = AlnMgrGetNumRows(sap);
1090 vnp_head=UABuildDescriptor2(sap,nBsp,LineSize,ddop,&TotLength,
1091 ddop->ShowLeftTail,ddop->ShowRightTail, WantExtraGapChar);
1092 if (vnp_head==NULL)
1093 return(FALSE);
1094
1095 /*build the display*/
1096 return(DDV_PopulateDisplayForDisc(sap,mpplp,nBsp,LineSize,ddop,
1097 TotLength,vnp_head, FALSE, FALSE));
1098 }
1099
1100 /*******************************************************************************
1101
1102 Function : DDV_BuildDisp_BlockEditor()
1103
1104 Purpose : create a display for a Disc. SeqAlign
1105
1106 Return value : FALSE if failure
1107
1108 *******************************************************************************/
1109 NLM_EXTERN Boolean DDV_BuildDisp_BlockEditor(SeqAlignPtr sap,
1110 MsaParaGPopListPtr mpplp, Int4 block_num)
1111 {
1112 Int4 nBsp,TotLength;
1113 ValNodePtr vnp_head;
1114 DDV_Disp_Opt ddo;
1115
1116 /*descriptor*/
1117 nBsp = AlnMgrGetNumRows(sap);
1118 vnp_head=UABuildDescriptorForBlockEditor(sap,nBsp,
1119 block_num,LIMIT_EDITOR_SIZE,&TotLength);
1120
1121 if (vnp_head==NULL)
1122 return(FALSE);
1123
1124 DDV_InitDDESAPdispStyles(&ddo);
1125 /*build the display*/
1126 return(DDV_PopulateDisplayForDisc(sap,mpplp,nBsp,LIMIT_EDITOR_SIZE,&ddo,
1127 TotLength,vnp_head, FALSE, FALSE));
1128 }
1129
1130 /*******************************************************************************
1131
1132 Function : UABitDescrInit()
1133
1134 Purpose : init a UABitDescr data block
1135
1136 Return value : -
1137
1138 *******************************************************************************/
1139 static void UABitDescrInit(UABitDescrPtr ubd,Int4 Start,Int4 Stop,Boolean IsGap)
1140 {
1141 ubd->from=Start;
1142 ubd->to=Stop;
1143 ubd->IsGap=IsGap;
1144 }
1145
1146 /*******************************************************************************
1147
1148 Function : UAMgrInitBitList()
1149
1150 Purpose : init the descriptor of an UA region
1151
1152 Return value : -
1153
1154 *******************************************************************************/
1155 static void UAMgrInitBitList(UAMsgPtr uamp, Int4 MaxLength, Int4 BspLength,
1156 Int4 BspStart,Int4 BspStop)
1157 {
1158 Int4 halfBspLengthSeqL,halfBspLengthSeqR,halfBspLengthDesc,start_middle,stop_middle;
1159
1160 /*just a gap*/
1161 if (BspStart==(Int4)-1 && BspStop==(Int4)-1){
1162 UABitDescrInit(&uamp->ubd[0],0,MaxLength-1,TRUE);
1163 UABitDescrInit(&uamp->ubd[1],(Int4)-1,(Int4)-1,FALSE);
1164 UABitDescrInit(&uamp->ubd[2],(Int4)-1,(Int4)-1,FALSE);
1165 return;
1166 }
1167 /*only sequence*/
1168 if (BspLength==MaxLength){
1169 UABitDescrInit(&uamp->ubd[0],BspStart,BspStop,FALSE);
1170 UABitDescrInit(&uamp->ubd[1],(Int4)-1,(Int4)-1,FALSE);
1171 UABitDescrInit(&uamp->ubd[2],(Int4)-1,(Int4)-1,FALSE);
1172 return;
1173 }
1174 /*additional data for DISP_JUST_CENTER and DISP_JUST_SPLIT*/
1175 if (uamp->DispType==DISP_JUST_CENTER || uamp->DispType==DISP_JUST_SPLIT){
1176 halfBspLengthSeqL=BspLength/2;
1177 halfBspLengthSeqR=BspLength-halfBspLengthSeqL;
1178 halfBspLengthDesc=MaxLength/2;
1179 start_middle=halfBspLengthDesc-halfBspLengthSeqL;
1180 stop_middle=start_middle+BspLength;
1181 }
1182
1183 /*only one sequence letter and DISP_JUST_SPLIT : use DISP_JUST_LEFT*/
1184 if (BspStart==BspStop && uamp->DispType==DISP_JUST_SPLIT){
1185 uamp->DispType=DISP_JUST_LEFT;
1186 }
1187
1188 switch(uamp->DispType){
1189 case DISP_JUST_RIGHT:
1190 UABitDescrInit(&uamp->ubd[0],0,MaxLength-BspLength-1,TRUE);
1191 UABitDescrInit(&uamp->ubd[1],BspStart,BspStop,FALSE);
1192 UABitDescrInit(&uamp->ubd[2],(Int4)-1,(Int4)-1,FALSE);
1193 break;
1194 case DISP_JUST_CENTER:
1195 UABitDescrInit(&uamp->ubd[0],0,start_middle-1,TRUE);
1196 UABitDescrInit(&uamp->ubd[1],BspStart,BspStop,FALSE);
1197 UABitDescrInit(&uamp->ubd[2],stop_middle,MaxLength-1,TRUE);
1198 break;
1199 case DISP_JUST_SPLIT:
1200 UABitDescrInit(&uamp->ubd[0],BspStart,BspStart+halfBspLengthSeqL-1,FALSE);
1201 UABitDescrInit(&uamp->ubd[1],halfBspLengthSeqL,MaxLength-halfBspLengthSeqR-1,TRUE);
1202 UABitDescrInit(&uamp->ubd[2],BspStart+halfBspLengthSeqL,BspStop,FALSE);
1203 break;
1204 case DISP_JUST_LEFT:
1205 UABitDescrInit(&uamp->ubd[0],BspStart,BspStop,FALSE);
1206 UABitDescrInit(&uamp->ubd[1],BspLength,MaxLength-1,TRUE);
1207 UABitDescrInit(&uamp->ubd[2],(Int4)-1,(Int4)-1,FALSE);
1208 default:
1209 break;
1210 }
1211 }
1212
1213
1214 /*******************************************************************************
1215
1216 Function : UAMgrIntUAMsg()
1217
1218 Purpose : constructor for a struct UAMsg
1219
1220 Note : from and to are in UnAligned region coord. system. Such a coord system
1221 always starts at 0. Length = max length of the UA region
1222
1223 Return value : -
1224
1225 *******************************************************************************/
1226 NLM_EXTERN UAMsgPtr UAMgrIntUAMsg( Int4 MaxLength, Int4 BspLength,
1227 Int4 BspStart,Int4 BspStop,Int4 ddpFrom ,Int4 ddpTo , Uint1 DispType, Uint1 strand)
1228 {
1229 UAMsgPtr uamp=NULL;
1230
1231 uamp=(UAMsgPtr)MemNew(sizeof(UAMsg));
1232 if (uamp){
1233 uamp->DispType=DispType;
1234 uamp->strand=strand;
1235 uamp->from_a=uamp->currentPos=ddpFrom;
1236 uamp->to_a=ddpTo;
1237 UAMgrInitBitList(uamp,MaxLength,BspLength,BspStart,BspStop);
1238 }
1239 return(uamp);
1240 }
1241
1242 /*******************************************************************************
1243
1244 Function : UAMgrDelUAMsg()
1245
1246 Purpose : destructor for UAMsg structure
1247
1248 Return value : -
1249
1250 *******************************************************************************/
1251 NLM_EXTERN UAMsgPtr UAMgrDelUAMsg(UAMsgPtr PNTR uamp)
1252 {
1253 if (*uamp)
1254 MemFree(*uamp);
1255 return(NULL);
1256 }
1257
1258 /*******************************************************************************
1259
1260 Function : UAMgrUAMsgGetInfo()
1261
1262 Purpose : query function for a UAMsg structure
1263
1264 Note : from_bsp and to_bsp are in BSP coord system.
1265
1266 Return value : -
1267
1268 *******************************************************************************/
1269 NLM_EXTERN void UAMgrUAMsgGetInfo(UAMsgPtr uamp,Int4Ptr from_bsp, Int4Ptr to_bsp,
1270 BoolPtr IsGap)
1271 {
1272 *from_bsp=uamp->from_r;
1273 *to_bsp=uamp->to_r;
1274 *IsGap=uamp->IsGap;
1275 }
1276
1277 /*******************************************************************************
1278
1279 Function : UAMgrGetNextUAbit()
1280
1281 Purpose : analytical function to retrieve information about an unaligned
1282 region. uamp must be init. before entering this function.
1283
1284 *******************************************************************************/
1285 NLM_EXTERN Boolean UAMgrGetNextUAbit(UAMsgPtr uamp,Int4 BspStart,Int4 BspStop)
1286 {
1287 Uint1 i;
1288 Int4 from_a,to_a,cumul=0,diff,tmp;
1289
1290 if (uamp->currentPos>uamp->to_a) return(FALSE);
1291 for (i=0;i<3;i++){
1292 if (uamp->ubd[i].from!=(Int4)-1 && uamp->ubd[i].to!=(Int4)-1){
1293 if (uamp->ubd[i].IsGap){/*disp coord*/
1294 from_a=uamp->ubd[i].from;
1295 to_a=uamp->ubd[i].to;
1296 }
1297 else{/*switch bsp coord to disp coord*/
1298 from_a=cumul;
1299 to_a=uamp->ubd[i].to-uamp->ubd[i].from+cumul;
1300 }
1301 if (uamp->currentPos>=from_a && uamp->currentPos<=to_a){
1302 if (uamp->ubd[i].IsGap)
1303 uamp->from_r=uamp->currentPos;
1304 else
1305 uamp->from_r=uamp->ubd[i].from+uamp->currentPos-cumul;
1306 }
1307 else{
1308 cumul+=(to_a-from_a+1);
1309 continue;
1310 }
1311 if (uamp->to_a>=from_a && uamp->to_a<=to_a){
1312 uamp->to_r=_min_(uamp->to_a,to_a);
1313 if (!uamp->ubd[i].IsGap)
1314 uamp->to_r+=uamp->ubd[i].from-cumul;
1315 }
1316 else{
1317 uamp->to_r=uamp->ubd[i].to;
1318 }
1319 uamp->currentPos+=(uamp->to_r-uamp->from_r+1);
1320 uamp->IsGap=uamp->ubd[i].IsGap;
1321 break;
1322 }
1323 }
1324
1325 /*if minus strand (nuc. only); reverse the values*/
1326 if (uamp->strand==Seq_strand_minus && !uamp->IsGap){
1327 diff=uamp->to_r-uamp->from_r;
1328 uamp->from_r=uamp->from_r+(BspStop-uamp->from_r)-(uamp->from_r-BspStart);
1329 uamp->to_r=uamp->from_r-diff;
1330 tmp=uamp->to_r;
1331 uamp->to_r=uamp->from_r;
1332 uamp->from_r=tmp;
1333 }
1334
1335 return(TRUE);
1336 }
1337
1338 /*******************************************************************************
1339
1340 Function : DDV_BuildBspEntitiesTbl()
1341
1342 Purpose : build a table of eID, iID of each Bioseq of a SeqAlign.
1343
1344 Return value : a table of entities
1345
1346 *******************************************************************************/
1347 NLM_EXTERN Uint4Ptr DDV_BuildBspEntitiesTbl(ValNodePtr PNTR TableHead,Int4 nBsp)
1348 {
1349 ValNodePtr vnp;
1350 ParaGPtr pgp;
1351 BioseqPtr bsp;
1352 Uint4Ptr entitiesTbl;
1353 Uint2 bsp_eID,bsp_iID;
1354 Int4 i;
1355
1356 entitiesTbl=(Uint4Ptr)MemNew(nBsp*sizeof(Uint4));
1357 if (!entitiesTbl) return(NULL);
1358
1359 for (i=0;i<nBsp;i++){
1360 vnp=TableHead[i];
1361 if (vnp){
1362 pgp=(ParaGPtr)vnp->data.ptrvalue;
1363
1364 bsp=BioseqLockById(pgp->sip);
1365 if (bsp){
1366 bsp_eID=ObjMgrGetEntityIDForPointer((Pointer)bsp);
1367 bsp_iID = GetItemIDGivenPointer (bsp_eID,
1368 OBJ_BIOSEQ, (Pointer) bsp);
1369 entitiesTbl[i]=UDV_EncodeIdxFeat(bsp_eID,bsp_iID);
1370 BioseqUnlock(bsp);
1371 }
1372 }
1373 }
1374 return(entitiesTbl);
1375 }
1376
1377 /*******************************************************************************
1378
1379 Function : DDV_BuildTailDescriptor()
1380
1381 Purpose : build a descriptor for the unaligned left/right tails of a SeqAlign
1382
1383 Return value : the descriptor (see also TotLength; total size of the tail)
1384
1385 *******************************************************************************/
1386 NLM_EXTERN ValNodePtr DDV_BuildTailDescriptor(SeqAlignPtr sap, Int4 nBsp,
1387 Int2 LineSize,Uint1 which_tail,Int4Ptr TotLength,Int4Ptr cumulpop)
1388 {
1389 Int4 startcopy,stopcopy,pop,i,MaxLength,start,stop;
1390 Boolean bError;
1391 ValNodePtr vnp,vnp_head;
1392 DescriDispPtr ddp;
1393 Uint1 strand;
1394
1395 vnp_head=NULL;
1396 bError=FALSE;
1397 MaxLength=0;
1398 /*get the size of the left UA region*/
1399 for(i=0;i<nBsp;i++){
1400 if (AlnMgrGetNthRowTail(sap,i+1,which_tail,&start,&stop,&strand)){
1401 if (start!=(Int4)-1 && stop!=(Int4)-1){
1402 MaxLength=MAX(MaxLength,ABS(stop-start)+1);
1403 }
1404 }
1405 }
1406 /*build a descriptor node for that region, if needed*/
1407 if (MaxLength>0){
1408 startcopy=0;
1409 stopcopy=MaxLength;
1410 *TotLength+=(stopcopy-startcopy);/*to be used for the display coord. system*/
1411
1412 while(startcopy<stopcopy){
1413 /*store data*/
1414 pop=_min_(stopcopy-startcopy,LineSize-(*cumulpop));
1415 ddp=(DescriDispPtr)MemNew(sizeof(DescriDisp));
1416 if (ddp==NULL) {
1417 bError=TRUE;break;
1418 }
1419 ddp->from=startcopy;/*use relative coord, i.e. UA coord system*/
1420 ddp->to=ddp->from+pop-1;
1421 ddp->TextStyle=MSA_TXT_STYLE_REG_UNALIGN;
1422 if (which_tail==LEFT_TAIL)
1423 ddp->UAnum=(Int4)-1;/*UA region number; -1 means LEFT TAIL*/
1424 else
1425 ddp->UAnum=(Int4)-2;/*UA region number; -2 means RIGHT TAIL*/
1426 ddp->UAMaxlength=stopcopy;
1427 /*create a new node*/
1428 if (vnp_head==NULL) {
1429 vnp_head=ValNodeAddPointer(NULL,0,(Pointer)ddp);
1430 vnp=vnp_head;
1431 }
1432 else vnp=ValNodeAddPointer(&vnp,0,(Pointer)ddp);
1433
1434 if (!vnp){
1435 bError=TRUE;
1436 break;
1437 }
1438 (*cumulpop)+=pop;
1439 if ((*cumulpop)==LineSize) (*cumulpop)=0;
1440 startcopy+=pop;
1441 }
1442 }
1443
1444 if (bError){
1445 vnp_head=ValNodeFreeData(vnp_head);
1446 }
1447
1448 return(vnp_head);
1449 }
1450
1451 NLM_EXTERN ValNodePtr UABuildDescriptor(SeqAlignPtr sap, Int4 nBsp, Int2 LineSize,
1452 DDV_Disp_OptPtr ddop, Int4Ptr TotLength,Boolean AddLeftUAPart,
1453 Boolean AddRightUAPart) {
1454 /*******************************************************************************
1455 * same as UABuildDescriptor2, but by default no extra gap char.
1456 *******************************************************************************/
1457 return(UABuildDescriptor2(sap, nBsp, LineSize, ddop, TotLength,
1458 AddLeftUAPart, AddRightUAPart, FALSE));
1459 }
1460
1461
1462 /*******************************************************************************
1463
1464 Function : UABuildDescriptor2()
1465
1466 Purpose : build the descriptor of a SeqAlign. This function is ONLY designed
1467 for discontinuous SeqAlign. The descriptor is a valnodelist. For
1468 each node, the field data.ptrvalue is of type MsaTxtDispPtr. It
1469 contains inportant info : start-stop of either an aligned or unaligned
1470 region. In the first case, SeqAlign coord system is used, otherwise
1471 UA coord system is used (UA=UnAligned). The descriptor should then
1472 be used as a guide to populate ParaG for the display. Note that this
1473 descriptor is a "pre"-layout of the ParaG structure : some descriptor's
1474 nodes put together = a ParaG in size.
1475
1476 Return value : the descriptor (see also TotLength; total size of the SeqAlign,
1477 display coordinates)
1478
1479 *******************************************************************************/
1480 NLM_EXTERN ValNodePtr UABuildDescriptor2(SeqAlignPtr sap, Int4 nBsp, Int2 LineSize,
1481 DDV_Disp_OptPtr ddop, Int4Ptr TotLength,Boolean AddLeftUAPart,
1482 Boolean AddRightUAPart, Boolean WantExtraGapChar)
1483 {
1484 Int4 length,r,cumulpop,StartLetter,startcopy,stopcopy,pop,UAnum;
1485 Boolean bUnAligned,bError;
1486 ValNodePtr vnp,vnp_head,vnp2;
1487 DescriDispPtr ddp;
1488
1489
1490 r=0;
1491 cumulpop=0;
1492 StartLetter=0;/*align coord*/
1493 bError=FALSE;
1494 vnp_head=NULL;
1495 *TotLength=0;
1496
1497 /*build UnAligned left part, if needed*/
1498 if (AddLeftUAPart && ddop->DispDiscStyle!=MSA_TXT_STYLE_1){
1499 vnp_head=DDV_BuildTailDescriptor(sap,nBsp,LineSize,LEFT_TAIL,TotLength,
1500 &cumulpop);
1501 /*get the last node; will be used in the SAP loop (see below)*/
1502 if (vnp_head){
1503 vnp=vnp_head;
1504 while(vnp->next){
1505 vnp=vnp->next;
1506 }
1507 }
1508 }
1509
1510 /*loop through each aligned and unaligned regions to build
1511 a ValNode list of descriptors. These descriptors will be used to
1512 generate the ParaG list*/
1513 UAnum=0;
1514 while(AlnMgrGetNextLengthBit(sap,&length,&r)){
1515
1516 startcopy=0;
1517
1518 if (length<=0){
1519 bUnAligned=TRUE;
1520 switch(ddop->DispDiscStyle){/*user's display choice*/
1521 case MSA_TXT_STYLE_1:/*put a spacer between 2 align blocks*/
1522 stopcopy=ddop->SpacerSize;
1523 break;
1524 case MSA_TXT_STYLE_2:/*put sequence between 2 align blocks*/
1525 stopcopy=ABS(length);
1526 /* give a small space no matter what */
1527 /* took out small spaces SW 1/19/01 */
1528 /* put it back in optionally, DIH, 1/25/01 */
1529 if (WantExtraGapChar) {
1530 if (stopcopy==0) stopcopy=1;
1531 }
1532 break;
1533 }
1534 UAnum++;
1535 }
1536 else if (length>0) {
1537 bUnAligned=FALSE;
1538 stopcopy=length;
1539 }
1540
1541 *TotLength+=(stopcopy-startcopy);/*to be used for the display coord. system*/
1542
1543 while(startcopy<stopcopy){
1544 /*store data*/
1545 pop=_min_(stopcopy-startcopy,LineSize-cumulpop);
1546 ddp=(DescriDispPtr)MemNew(sizeof(DescriDisp));
1547 if (ddp==NULL) {
1548 bError=TRUE;break;
1549 }
1550 if (bUnAligned==FALSE){
1551 ddp->from=StartLetter;/*use align coord*/
1552 ddp->to=ddp->from+pop-1;
1553 ddp->TextStyle=MSA_TXT_STYLE_REG_ALIGN;
1554 StartLetter+=pop;
1555 }
1556 else{
1557 ddp->from=startcopy;/*use relative coord, i.e. UA coord system*/
1558 ddp->to=ddp->from+pop-1;
1559 ddp->TextStyle=MSA_TXT_STYLE_REG_UNALIGN;
1560 ddp->UAnum=UAnum;/*UA region number*/
1561 ddp->UAMaxlength=stopcopy;
1562 }
1563 /*create a new node*/
1564 if (vnp_head==NULL) {
1565 vnp_head=ValNodeAddPointer(NULL,0,(Pointer)ddp);
1566 vnp=vnp_head;
1567 }
1568 else vnp=ValNodeAddPointer(&vnp,0,(Pointer)ddp);
1569
1570 if (!vnp){
1571 bError=TRUE;
1572 break;
1573 }
1574 cumulpop+=pop;
1575 if (cumulpop==LineSize) cumulpop=0;
1576 startcopy+=pop;
1577 }
1578 if (bError) break;
1579 }
1580
1581 if (bError){
1582 vnp_head=ValNodeFreeData(vnp_head);
1583 goto erreur;
1584 }
1585
1586 /*build UnAligned right part, if needed*/
1587 if (AddRightUAPart && ddop->DispDiscStyle!=MSA_TXT_STYLE_1){
1588 vnp2=DDV_BuildTailDescriptor(sap,nBsp,LineSize,RIGHT_TAIL,TotLength,
1589 &cumulpop);
1590 /*add vnp2 at the end of vnp_head*/
1591 if (vnp2) {
1592 vnp=vnp_head;
1593 while(vnp->next){
1594 vnp=vnp->next;
1595 }
1596 vnp->next=vnp2;
1597 }
1598 }
1599
1600 /*debug only : print the content of the descriptor
1601
1602 vnp=vnp_head;
1603 while(vnp){
1604 ddp=(DescriDispPtr)vnp->data.ptrvalue;
1605 printf("[%4i..%4i],%2i (%4i) ; ",ddp->from,ddp->to,ddp->TextStyle,
1606 ddp->to-ddp->from+1);
1607 if (ddp->TextStyle==MSA_TXT_STYLE_REG_UNALIGN){
1608 printf("MaxLength = %i ; UAnum = %i\n",ddp->UAMaxlength,ddp->UAnum);
1609 }
1610 else{
1611 printf("\n");
1612 }
1613 vnp=vnp->next;
1614 }
1615
1616 debug only - end*/
1617
1618 erreur :
1619 return(vnp_head);
1620 }
1621
1622 /*******************************************************************************
1623
1624 Function : UABuildDescriptorForBlockEditor()
1625
1626 Purpose : build the descriptor of a SeqAlign for the block editor; i.e. the
1627 descriptor contains the information about one aligned block along with
1628 its two adjacent unaligned regions. See also the 'purpose' fo the function
1629 UABuildDescriptor() above.
1630
1631 Return value : the descriptor (see also TotLength; total size of the SeqAlign,
1632 display coordinates)
1633
1634 *******************************************************************************/
1635 NLM_EXTERN ValNodePtr UABuildDescriptorForBlockEditor(SeqAlignPtr sap, Int4 nBsp,
1636 Int4 block_num,Int4 LineSize,Int4Ptr TotLength)
1637 {
1638 Int4 length,r,cumulpop,StartLetter,startcopy,stopcopy,pop,UAnum,nBlock,
1639 blockNum;
1640 Boolean bUnAligned,bError,bPopNow;
1641 ValNodePtr vnp,vnp_head,vnp2;
1642 DescriDispPtr ddp;
1643
1644
1645 /*test if we have a Discontinuous SeqAlign*/
1646 if (!AlnMgrIsSAPDiscAli(sap)) return(NULL);
1647
1648 /*get the number of block(s)*/
1649 nBlock=AlnMgrGetNumAlnBlocks(sap);
1650 if (block_num<0 || block_num>nBlock-1){
1651 return(NULL);
1652 }
1653 r=cumulpop=UAnum=blockNum=0;
1654 StartLetter=0;/*align coord*/
1655 bError=FALSE;
1656 vnp_head=NULL;
1657 *TotLength=0;
1658 /*if the user wants to edit the first block (block_num==0), I have
1659 to use a special function to create the left-side part of the
1660 descriptor*/
1661 if (block_num==0){
1662 vnp_head=DDV_BuildTailDescriptor(sap,nBsp,LIMIT_EDITOR_SIZE,
1663 LEFT_TAIL,TotLength,&cumulpop);
1664 if (vnp_head){
1665 vnp=vnp_head;
1666 while(vnp->next){
1667 vnp=vnp->next;
1668 }
1669 }
1670 }
1671
1672 while(AlnMgrGetNextLengthBit(sap,&length,&r)){
1673
1674 bPopNow=FALSE;
1675 startcopy=0;
1676
1677 /*unaligned region ?*/
1678 if (length<=0){
1679 /*region adjacent to the block of interest ?*/
1680 if (UAnum==block_num-1 || UAnum==block_num){
1681 bUnAligned=TRUE;
1682 stopcopy=ABS(length);
1683 bPopNow=TRUE;
1684 }
1685 UAnum++;
1686 }
1687 else{/*aligned region*/
1688 if (blockNum==block_num){
1689 bUnAligned=FALSE;
1690 stopcopy=length;
1691 bPopNow=TRUE;
1692 }
1693 else{
1694 StartLetter+=length;
1695 }
1696 blockNum++;
1697 }
1698
1699 if (!bPopNow) continue;
1700
1701 *TotLength+=(stopcopy-startcopy);/*to be used for the display coord. system*/
1702
1703 while(startcopy<stopcopy){
1704 /*store data*/
1705 pop=_min_(stopcopy-startcopy,LineSize-cumulpop);
1706 ddp=(DescriDispPtr)MemNew(sizeof(DescriDisp));
1707 if (ddp==NULL) {
1708 bError=TRUE;break;
1709 }
1710 if (bUnAligned==FALSE){
1711 ddp->from=StartLetter;/*use align coord*/
1712 ddp->to=ddp->from+pop-1;
1713 ddp->TextStyle=MSA_TXT_STYLE_REG_ALIGN;
1714 StartLetter+=pop;
1715 }
1716 else{
1717 ddp->from=startcopy;/*use relative coord, i.e. UA coord system*/
1718 ddp->to=ddp->from+pop-1;
1719 ddp->TextStyle=MSA_TXT_STYLE_REG_UNALIGN;
1720 ddp->UAnum=UAnum;/*UA region number*/
1721 ddp->UAMaxlength=stopcopy;
1722 }
1723 /*create a new node*/
1724 if (vnp_head==NULL) {
1725 vnp_head=ValNodeAddPointer(NULL,0,(Pointer)ddp);
1726 vnp=vnp_head;
1727 }
1728 else vnp=ValNodeAddPointer(&vnp,0,(Pointer)ddp);
1729
1730 if (!vnp){
1731 bError=TRUE;
1732 break;
1733 }
1734 cumulpop+=pop;
1735 if (cumulpop==LineSize) cumulpop=0;
1736 startcopy+=pop;
1737 }
1738 if (bError) break;
1739 }
1740
1741 /*oups...*/
1742 if (bError){
1743 vnp_head=ValNodeFreeData(vnp_head);
1744 goto erreur;
1745 }
1746
1747
1748 /*if the user wants to edit the last block (block_num==nBlock-1), I have
1749 to use a special function to create the right-side part of the
1750 descriptor*/
1751 if (block_num==nBlock-1){
1752 vnp2=DDV_BuildTailDescriptor(sap,nBsp,LIMIT_EDITOR_SIZE,
1753 RIGHT_TAIL,TotLength,&cumulpop);
1754 if (vnp2) {
1755 vnp=vnp_head;
1756 while(vnp->next){
1757 vnp=vnp->next;
1758 }
1759 vnp->next=vnp2;
1760 }
1761 }
1762
1763 erreur :
1764 return(vnp_head);
1765 }
1766
1767 /*******************************************************************************
1768
1769 Function : DDV_DumpSAPInAFile()
1770
1771 Purpose : write an Indexed SeqALign in a file (use the code of the Population
1772 Viewer).
1773
1774 Return value : -
1775
1776 *******************************************************************************/
1777 NLM_EXTERN void DDV_DumpSAPInAFile(MsaParaGPopListPtr mpplp,DDVOptionsBlockPtr dobp,
1778 FILE *hFile,Uint4 option,DDV_ColorGlobal * gclr)
1779 {
1780 ByteStorePtr PNTR byteSpp;
1781 Int4Ptr PNTR matrix ;
1782 Int2 LineSize;
1783
1784 if (!mpplp || !hFile) return;
1785
1786 /*get the optional data*/
1787 if (dobp){
1788 LineSize=dobp->LineSize;
1789 byteSpp=dobp->byteSpp;
1790 matrix=dobp->matrix;
1791 }
1792 else{
1793 LineSize=ParaG_Size;
1794 byteSpp=NULL;
1795 }
1796
1797 /*do the display */
1798 DDV_AffichageParaG(mpplp,0,0,mpplp->LengthAli-1,mpplp->LengthAli,0,option,
1799 LineSize,hFile,byteSpp,matrix,gclr,NULL);
1800
1801 }
1802
1803 /*******************************************************************************
1804
1805 Function : DDV_DumpSAPInFastaFile()
1806
1807 Purpose : write an Indexed SeqALign in a file (use FASTA format only).
1808
1809 Return value : -
1810
1811 *******************************************************************************/
1812 NLM_EXTERN void DDV_DumpSAPInFastaFile(MsaParaGPopListPtr mpplp,DDVOptionsBlockPtr dobp,
1813 FILE *fp,Boolean bPrintGap)
1814 {
1815 CharPtr szBuf,szSeq;
1816 ParaGPtr pgp;
1817 SeqIdPtr sip;
1818 ValNodePtr vnp;
1819 BioseqPtr bsp;
1820 Int4 i,j,n,LineSize,bspLength;
1821 Boolean bFirst,IsAA;
1822 Char letter;
1823 Char DefLine[255];
1824
1825 if (!mpplp || !fp) return;
1826
1827 if (dobp){
1828 LineSize=dobp->LineSize;
1829 }
1830 else{
1831 LineSize=ParaG_Size;
1832 }
1833
1834 szBuf=(CharPtr)MemNew((LineSize+1)*sizeof(Char));
1835 if (!szBuf) return;/*todo : error msg for the user*/
1836
1837 for(i=0;i<mpplp->nBsp;i++){
1838 vnp=mpplp->TableHead[i];
1839 n=0;
1840 bFirst=TRUE;
1841 while(vnp){
1842 pgp=(ParaGPtr)vnp->data.ptrvalue;
1843 sip=SeqIdFindBest(pgp->sip,0);
1844 if (sip==NULL) sip=pgp->sip;
1845 bsp=BioseqLockById(sip);
1846 if (!bsp) return;/*todo : error msg for the user*/
1847 bspLength=BioseqGetLen(bsp);
1848 IsAA=ISA_aa(bsp->mol);
1849 if (bFirst){
1850 FastaId(bsp,DefLine,254);
1851 fprintf(fp,">%s ",DefLine);
1852 CreateDefLine(NULL, bsp, DefLine, 254, 0,NULL, NULL);
1853 fprintf(fp,"%s\n",DefLine);
1854 bFirst=FALSE;
1855 }
1856 BioseqUnlock(bsp);
1857 szSeq=(CharPtr)MemNew((pgp->StopLetter-pgp->StartLetter+2)*sizeof(Char));
1858 if (!szSeq) return;/*todo : error msg for the user*/
1859 DDV_GetSequenceFromParaG(pgp,&szSeq,bspLength,IsAA,NULL,NULL,NULL);
1860 j=0;
1861 while(szSeq[j]){
1862 letter=szSeq[j++];
1863 if (isalpha(letter)){
1864 szBuf[n++]=letter;
1865 }
1866 else{
1867 if (bPrintGap)
1868 szBuf[n++]=letter;
1869 }
1870 if (n==LineSize){
1871 szBuf[n]='\0';
1872 fprintf(fp,"%s\n",szBuf);
1873 n=0;
1874 }
1875 }
1876 MemFree(szSeq);
1877 vnp=vnp->next;
1878 if (vnp==NULL && n!=0){
1879 szBuf[n]='\0';
1880 fprintf(fp,"%s\n",szBuf);
1881 }
1882 }
1883 }
1884 MemFree(szBuf);
1885 }
1886
1887 /*******************************************************************************
1888
1889 Function : DDV_InitDefSAPdispStyles_BLAST()
1890
1891 Purpose : set the default styles for SeqAligns.
1892
1893 Return value : -
1894
1895 *******************************************************************************/
1896 static void DDV_InitDefSAPdispStyles_BLAST(DDV_Disp_OptPtr ddop)
1897 {
1898 /*use colors*/
1899 ddop->bUseColors=FALSE;
1900 /*disc SAP styles*/
1901 ddop->ShowLeftTail=FALSE;
1902 ddop->ShowRightTail=FALSE;
1903 ddop->DispDiscStyle=MSA_TXT_STYLE_2;
1904 ddop->SpacerSize=SPACER_TXT_BLANK;
1905 ddop->DiscJustification=DISP_JUST_LEFT;
1906
1907 ddop->UAGapStyle=MSA_TXT_STYLE_UAGAP;
1908 ddop->AGapStyle=MSA_TXT_STYLE_GAP;
1909
1910 /*ruler style*/
1911 ddop->RulerStyle=RulerStyle_Continue_Start;
1912
1913 }
1914
1915
1916 /*******************************************************************************
1917
1918 Function : DDV_DisplayNewBLAST()
1919
1920 Purpose : build a default SeqAlign display for BLAST.
1921
1922 Parameters : sap; SeqAlign
1923 disp_format; display formats (see pgppop.h)
1924 disp_data; for future implementation
1925 fp; to send the output
1926
1927 NOTE : this function uses the alignmgr.[ch] instead of blocks.[ch]
1928
1929 Return value : FALSE if failed
1930
1931 *******************************************************************************/
1932 static Boolean DDV_DisplayNewBLAST(SeqAlignPtr sap, ValNodePtr mask,
1933 Int4Ptr PNTR matrix,Uint4 disp_format,Pointer disp_data,FILE *fp)
1934 {
1935 MsaParaGPopList mppl;/*contains the data for the display*/
1936 Int2 LineSize;
1937 DDVOptionsBlockPtr dobp;
1938 ByteStorePtr PNTR byteSpp;
1939 DDV_ColorGlobal *layout;
1940 DDV_Disp_Opt ddo;
1941 Boolean bUseLayout;
1942 Uint1 what;
1943
1944 MemSet(&mppl,0,sizeof(MsaParaGPopList));
1945 MemSet(&ddo,0,sizeof(DDV_Disp_Opt));
1946 layout=NULL;
1947
1948 /*get the optional data*/
1949 if (disp_data){
1950 dobp=(DDVOptionsBlockPtr)disp_data;
1951 LineSize=dobp->LineSize;
1952 byteSpp=dobp->byteSpp;
1953 bUseLayout=dobp->bUseLayout;
1954 what=dobp->LayoutType;
1955 }
1956 else{
1957 LineSize=ParaG_Size;
1958 byteSpp=NULL;
1959 bUseLayout=FALSE;
1960 }
1961
1962 DDV_InitDefSAPdispStyles_BLAST(&ddo);
1963
1964 /*build the indexed SeqAlign and the ParaG structure*/
1965 DDV_CreateDisplayFromIndex(sap, &mppl, LineSize,&ddo);
1966
1967 /*create the layout*/
1968 if (bUseLayout){
1969 layout = DDV_CreateColorGlobal(TRUE, (void *)sap);
1970 if (layout){
1971 if (dobp->LayoutType&DDV_USE_STDCLR){
1972 DDV_InitColour_When_Start(sap,&mppl,&layout, FALSE);
1973 }
1974 if (dobp->LayoutType&DDV_USE_UALAYOUT || dobp->LayoutType&DDV_USE_NOMLAYOUT){
1975 DDV_LayoutUAregion(sap,&mppl,&layout,
1976 dobp->normlayout.rgb,dobp->normlayout.style,
1977 dobp->UAlayout.rgb,dobp->UAlayout.style);
1978 }
1979 if (dobp->LayoutType&DDV_USE_ISOLAYOUT){
1980 DDV_LayoutISOColors(layout,mppl.TableHead,mppl.nBsp,
1981 0,TRUE,matrix,dobp->ISOlayout.clr_ident,
1982 dobp->ISOlayout.clr_simil,dobp->ISOlayout.clr_other,
1983 dobp->ISOlayout.sty_ident,
1984 dobp->ISOlayout.sty_simil,dobp->ISOlayout.sty_other);
1985 }
1986 if (dobp->LayoutType&DDV_USE_GAPLAYOUT){
1987 DDV_LayoutGap(layout,mppl.TableHead[0],mppl.TableHead[1],1,
1988 dobp->GAPlayout.style,dobp->GAPlayout.rgb);
1989 DDV_LayoutGap(layout,mppl.TableHead[1],mppl.TableHead[0],0,
1990 dobp->GAPlayout.style,dobp->GAPlayout.rgb);
1991 }
1992 if (dobp->LayoutType&DDV_USE_MASKLAYOUT){
1993 DDV_LayoutMaskRegions(layout,mppl.TableHead[0],mask,0,
1994 dobp->MASKlayout.style,dobp->MASKlayout.rgb);
1995 }
1996 }
1997 }
1998
1999 /*do the display */
2000 DDV_AffichageParaG(&mppl,0,0,mppl.LengthAli-1,mppl.LengthAli,0,disp_format,
2001 LineSize,fp,byteSpp,matrix,layout,mask);
2002
2003 /*done... delete data*/
2004 DDV_DeleteDisplayList(&mppl);
2005 if (layout) DDV_DeleteColorGlobal(layout);
2006
2007
2008 return(TRUE);
2009 }
2010
2011 /*******************************************************************************
2012
2013 Function : DDV_BlastGetColorSchemaZero()
2014
2015 Purpose : BLAST color sheme 0 : standard b&w BLAST output
2016
2017 *******************************************************************************/
2018 static void DDV_BlastGetColorSchemaZero(DDVOptionsBlockPtr dobp)
2019 {
2020 memset(dobp,0,sizeof(DDVOptionsBlock));
2021
2022 dobp->bUseLayout=FALSE;
2023 }
2024
2025 /*******************************************************************************
2026
2027 Function : DDV_BlastGetColorSchemaOne()
2028
2029 Purpose : BLAST color sheme 1 :
2030 - masked regions in lowe case,
2031 - everything else in upper case.
2032
2033 *******************************************************************************/
2034 static void DDV_BlastGetColorSchemaOne(DDVOptionsBlockPtr dobp)
2035 {
2036 memset(dobp,0,sizeof(DDVOptionsBlock));
2037
2038 dobp->bUseLayout=TRUE;
2039
2040 /* dobp->LayoutType=DDV_USE_MASKLAYOUT|DDV_USE_NOMLAYOUT; */
2041
2042 dobp->LayoutType=DDV_USE_UALAYOUT|DDV_USE_GAPLAYOUT;
2043
2044 dobp->UAlayout.style=DDV_TXTSTYLE_LOWERCASE;
2045 dobp->GAPlayout.style=DDV_TXTSTYLE_LOWERCASE;
2046
2047 /* dobp->MASKlayout.style=DDV_TXTSTYLE_LOWERCASE; */
2048 }
2049
2050 /*******************************************************************************
2051
2052 Function : DDV_BlastGetColorSchemaTwo()
2053
2054 Purpose : BLAST color sheme 2 :
2055 - masked regions in lower case, gray letters,
2056 - UnAligned regions in italic,
2057 - everything else in upper case.
2058
2059 *******************************************************************************/
2060 static void DDV_BlastGetColorSchemaTwo(DDVOptionsBlockPtr dobp)
2061 {
2062 memset(dobp,0,sizeof(DDVOptionsBlock));
2063
2064 dobp->bUseLayout=TRUE;
2065
2066 dobp->LayoutType=DDV_USE_MASKLAYOUT|DDV_USE_NOMLAYOUT;
2067 dobp->LayoutType|=DDV_USE_UALAYOUT;
2068
2069 dobp->UAlayout.style=DDV_TXTSTYLE_ITALIC|DDV_TXTSTYLE_LOWERCASE;
2070 dobp->normlayout.style=DDV_TXTSTYLE_BOLD;
2071
2072 dobp->MASKlayout.style=DDV_TXTSTYLE_LOWERCASE|DDV_TXTSTYLE_COLOR;
2073 dobp->MASKlayout.rgb[0]=102;
2074 dobp->MASKlayout.rgb[1]=102;
2075 dobp->MASKlayout.rgb[2]=102;
2076 }
2077
2078 /*******************************************************************************
2079
2080 Function : DDV_BlastGetColorSchemaThree()
2081
2082 Purpose : BLAST color sheme 3 :
2083 - masked regions in lower case, gray letters,
2084 - UnAligned regions in italic,
2085 - Identity/Similarity colors
2086 - everything else in upper case.
2087
2088 *******************************************************************************/
2089 static void DDV_BlastGetColorSchemaThree(DDVOptionsBlockPtr dobp)
2090 {
2091 memset(dobp,0,sizeof(DDVOptionsBlock));
2092
2093 dobp->bUseLayout=TRUE;
2094
2095 dobp->LayoutType=DDV_USE_MASKLAYOUT;
2096 dobp->LayoutType|=DDV_USE_UALAYOUT;
2097 dobp->LayoutType|=DDV_USE_ISOLAYOUT;
2098
2099 dobp->UAlayout.style=DDV_TXTSTYLE_ITALIC|DDV_TXTSTYLE_LOWERCASE;
2100
2101 dobp->MASKlayout.style=DDV_TXTSTYLE_LOWERCASE;/*|DDV_TXTSTYLE_COLOR;
2102 dobp->MASKlayout.rgb[0]=102;
2103 dobp->MASKlayout.rgb[1]=102;
2104 dobp->MASKlayout.rgb[2]=102;
2105 */
2106 dobp->ISOlayout.clr_ident=DDVCOL_ORANGE;
2107 dobp->ISOlayout.clr_simil=DDVCOL_BLUE;
2108 dobp->ISOlayout.clr_other=DDVCOL_BLACK;
2109 }
2110
2111 /*******************************************************************************
2112
2113 Function : DDV_BlastGetColorSchemaFour()
2114
2115 Purpose : BLAST color sheme 4 = BLAST color schema 3 but with different colors
2116
2117 *******************************************************************************/
2118 static void DDV_BlastGetColorSchemaFour(DDVOptionsBlockPtr dobp)
2119 {
2120 memset(dobp,0,sizeof(DDVOptionsBlock));
2121
2122 dobp->bUseLayout=TRUE;
2123
2124 dobp->LayoutType=DDV_USE_MASKLAYOUT;
2125 dobp->LayoutType|=DDV_USE_UALAYOUT;
2126 dobp->LayoutType|=DDV_USE_ISOLAYOUT;
2127
2128 dobp->UAlayout.style=DDV_TXTSTYLE_ITALIC|DDV_TXTSTYLE_LOWERCASE;
2129
2130 dobp->MASKlayout.style=DDV_TXTSTYLE_LOWERCASE|DDV_TXTSTYLE_COLOR;
2131 dobp->MASKlayout.rgb[0]=102;
2132 dobp->MASKlayout.rgb[1]=102;
2133 dobp->MASKlayout.rgb[2]=102;
2134
2135 dobp->ISOlayout.clr_ident=DDVCOL_BLUE;
2136 dobp->ISOlayout.clr_simil=DDVCOL_BROWN;
2137 dobp->ISOlayout.clr_other=DDVCOL_RED;
2138 }
2139
2140 /*******************************************************************************
2141
2142 Function : DDV_BlastGetColorSchemaFive()
2143
2144 Purpose : BLAST color sheme 5 = BLAST color schema 3 but with different colors
2145
2146 *******************************************************************************/
2147 static void DDV_BlastGetColorSchemaFive(DDVOptionsBlockPtr dobp)
2148 {
2149 memset(dobp,0,sizeof(DDVOptionsBlock));
2150
2151 dobp->bUseLayout=TRUE;
2152
2153 dobp->LayoutType=DDV_USE_MASKLAYOUT;
2154 dobp->LayoutType|=DDV_USE_UALAYOUT;
2155 dobp->LayoutType|=DDV_USE_ISOLAYOUT;
2156
2157 dobp->UAlayout.style=DDV_TXTSTYLE_ITALIC|DDV_TXTSTYLE_LOWERCASE;
2158
2159 dobp->MASKlayout.style=DDV_TXTSTYLE_LOWERCASE|DDV_TXTSTYLE_COLOR;
2160 dobp->MASKlayout.rgb[0]=102;
2161 dobp->MASKlayout.rgb[1]=102;
2162 dobp->MASKlayout.rgb[2]=102;
2163
2164 dobp->ISOlayout.clr_ident=DDVCOL_RED;
2165 dobp->ISOlayout.clr_simil=DDVCOL_BLUE;
2166 dobp->ISOlayout.clr_other=DDVCOL_BLACK;
2167 }
2168
2169 /*******************************************************************************
2170
2171 Function : DDV_BlastGetColorSchemaSix()
2172
2173 Purpose : BLAST color sheme 6 = BLAST color schema 3 but with different colors
2174
2175 *******************************************************************************/
2176 static void DDV_BlastGetColorSchemaSix(DDVOptionsBlockPtr dobp)
2177 {
2178 memset(dobp,0,sizeof(DDVOptionsBlock));
2179
2180 dobp->bUseLayout=TRUE;
2181
2182 dobp->LayoutType=DDV_USE_MASKLAYOUT;
2183 dobp->LayoutType|=DDV_USE_UALAYOUT;
2184 dobp->LayoutType|=DDV_USE_ISOLAYOUT;
2185
2186 dobp->UAlayout.style=DDV_TXTSTYLE_ITALIC|DDV_TXTSTYLE_LOWERCASE;
2187
2188 dobp->MASKlayout.style=DDV_TXTSTYLE_LOWERCASE;/*|DDV_TXTSTYLE_COLOR;
2189 dobp->MASKlayout.rgb[0]=102;
2190 dobp->MASKlayout.rgb[1]=102;
2191 dobp->MASKlayout.rgb[2]=102;
2192 */
2193 dobp->ISOlayout.clr_ident=DDVCOL_ORANGE;
2194 dobp->ISOlayout.clr_simil=DDVCOL_BLUE;
2195 dobp->ISOlayout.clr_other=DDVCOL_BLACK;
2196
2197 dobp->ISOlayout.sty_ident=DDV_TXTSTYLE_BOLD;
2198 }
2199
2200 /*******************************************************************************
2201
2202 Function : DDV_DisplayBlastPairList()
2203
2204 Purpose : function to display a BLAST output.
2205
2206 Parameters : sap; seqalign
2207 mask; list of masked regions in the query
2208 fp; output file;
2209 is_na; TRUE means nuc sequence
2210 tx_option; some display options
2211 ColorSchema; one of the available color schemes
2212
2213 Return value : FALSE if failure
2214
2215 *******************************************************************************/
2216 NLM_EXTERN Boolean DDV_DisplayBlastPairList(SeqAlignPtr sap, ValNodePtr mask,
2217 FILE *fp, Boolean is_na, Uint4 tx_option,Uint1 ColorSchema)
2218 {
2219 DDVOptionsBlock dob;
2220 SeqAlignPtr sap4;
2221 SeqIdPtr new_id = NULL, old_id = NULL;
2222 Int4Ptr PNTR matrix;
2223 Uint4 option,i;
2224 Boolean bRet, follower= FALSE;
2225
2226 if (!sap || !fp)
2227 return(FALSE);
2228
2229 /*get the matrix*/
2230 if (is_na == FALSE){
2231 matrix=load_default_matrix();
2232 if (!matrix)
2233 return(FALSE);
2234 } else {
2235 matrix=NULL;
2236 }
2237
2238 memset(&dob, '\0', sizeof(DDVOptionsBlock));
2239
2240 /*init display format*/
2241 option =VIEW_FULLSEQ;
2242
2243 if (ColorSchema==DDV_BLAST_COLOR0 || ColorSchema==DDV_BLAST_COLOR1)
2244 option|=DISP_FULL_TXT;
2245 else
2246 option|=DISP_FULL_HTML;
2247
2248 option|=DISP_BSP_COORD;
2249 option|=SEQNAME_BLAST_STD;
2250 option|=DISP_NOLINKONNAME;
2251 option|=DISP_BLAST_STD;
2252 option|=DISPE_COLOR;
2253
2254 /*get the color scheme layout*/
2255 /*note that the following functions will set to 0 the entire dob structure, before
2256 filling in its content with the layout information. All subsequent init. of dob
2257 should be done after the following switch()*/
2258 switch(ColorSchema){
2259 case DDV_BLAST_COLOR0:
2260 option|=DISP_BLAST_MIDLINE;
2261 DDV_BlastGetColorSchemaZero(&dob);
2262 break;
2263 case DDV_BLAST_COLOR1:
2264 option|=DISP_BLAST_MIDLINE;
2265 DDV_BlastGetColorSchemaOne(&dob);
2266 break;
2267 case DDV_BLAST_COLOR2:
2268 option|=DISP_BLAST_MIDLINE;
2269 DDV_BlastGetColorSchemaTwo(&dob);
2270 break;
2271 case DDV_BLAST_COLOR3:
2272 DDV_BlastGetColorSchemaThree(&dob);
2273 break;
2274 case DDV_BLAST_COLOR4:
2275 DDV_BlastGetColorSchemaFour(&dob);
2276 break;
2277 case DDV_BLAST_COLOR5:
2278 DDV_BlastGetColorSchemaFive(&dob);
2279 break;
2280 case DDV_BLAST_COLOR6:
2281 DDV_BlastGetColorSchemaSix(&dob);
2282 break;
2283 }
2284
2285 dob.LineSize=(Int2)60;
2286 dob.matrix=matrix;
2287 bRet=TRUE;
2288 sap4=sap;
2289
2290 while(sap4) {
2291 /*build the Index*/
2292 if (sap4->segtype == SAS_DISC){
2293 if (!sap4 || !AlnMgrIndexSingleSeqAlign(sap4)){
2294 bRet=FALSE;
2295 break;
2296 }
2297 }
2298 else{
2299 if (!sap4 || !AlnMgrIndexSingleChildSeqAlign(sap4)){
2300 bRet=FALSE;
2301 break;
2302 }
2303 }
2304
2305 if (option&DISP_FULL_HTML){
2306 fprintf(fp,"<pre>\n");
2307 }
2308 /* Attempt to print score for the alignment */
2309 new_id = TxGetSubjectIdFromSeqAlign(sap4);
2310 if(old_id != NULL) {
2311 if(SeqIdMatch(new_id, old_id))
2312 follower = TRUE;
2313 }
2314
2315 /*separator*/
2316 if (option&DISP_FULL_HTML)
2317 fprintf(fp,"<HR WIDTH=\"400\">");
2318
2319 old_id = new_id;
2320 if(!FormatScoreFromSeqAlign(sap4, tx_option, fp, matrix, follower)){
2321 bRet=FALSE;
2322 break;
2323 }
2324 follower = FALSE;
2325 if (option&DISP_FULL_HTML){
2326 fprintf(fp,"</pre>\n");
2327 }
2328
2329 /*display a SeqAlign*/
2330 if (!DDV_DisplayNewBLAST(sap4, mask, matrix, option, (Pointer) &dob, fp)){
2331 bRet=FALSE;
2332 break;
2333 }
2334 sap4 = sap4->next;
2335 }
2336
2337 if (matrix){
2338 for(i = 0; i<TX_MATRIX_SIZE; ++i)
2339 MemFree(matrix[i]);
2340 MemFree(matrix);
2341 }
2342
2343 return(bRet);
2344
2345 }
2346
2347 /*******************************************************************************
2348
2349 Function : DDV_DisplayBlastSAP()
2350
2351 Purpose : test function to display a BLAST output.
2352
2353 Parameters : sap; seqalign
2354 mask; list of masked regions in the query
2355 fo; output file;
2356 is_na; TRUE means nuc sequence
2357 tx_option; some display options
2358
2359 Return value : -
2360
2361 *******************************************************************************/
2362 static Boolean DDV_DisplayBlastSAP(SeqAlignPtr sap, ValNodePtr mask,
2363 FILE *fp, Boolean is_na, Uint4 tx_option)
2364 {
2365 DDVOptionsBlock dob;
2366 SeqAlignPtr sap4;
2367 SeqIdPtr new_id = NULL, old_id = NULL;
2368 Int4Ptr PNTR matrix;
2369 Uint4 option,i;
2370 Boolean bRet, follower= FALSE;
2371
2372 if (!sap || !fp)
2373 return(FALSE);
2374
2375 /*get the matrix*/
2376 if (is_na == FALSE){
2377 matrix=load_default_matrix();
2378 if (!matrix)
2379 return(FALSE);
2380 } else {
2381 matrix=NULL;
2382 }
2383
2384 /*init display format*/
2385 option =VIEW_FULLSEQ;
2386 option|=DISP_FULL_HTML;
2387 option|=DISP_BSP_COORD;
2388 option|=SEQNAME_BLAST_STD;
2389 option|=DISP_BLAST_STD;
2390 option|=DISP_BLAST_MIDLINE;
2391 option|=DISPE_COLOR;
2392 dob.LineSize=(Int2)60;
2393 dob.matrix=matrix;
2394
2395 bRet=TRUE;
2396 sap4=sap;
2397 while(sap4) {
2398 /*build the Index*/
2399 if (sap4->segtype == SAS_DISC){
2400 if (!sap4 || !AlnMgrIndexSingleSeqAlign(sap4)){
2401 bRet=FALSE;
2402 break;
2403 }
2404 dob.bUseLayout=TRUE;
2405 }
2406 else{
2407 if (!sap4 || !AlnMgrIndexSingleChildSeqAlign(sap4)){
2408 bRet=FALSE;
2409 break;
2410 }
2411 dob.bUseLayout=TRUE;
2412 }
2413
2414 /*set the layout type, if needed*/
2415 if (dob.bUseLayout){
2416 /*basic layout*/
2417 dob.LayoutType=DDV_USE_UALAYOUT;
2418 dob.LayoutType|=DDV_USE_GAPLAYOUT;
2419 dob.LayoutType|=DDV_USE_MASKLAYOUT;
2420 /*dob.LayoutType|=DDV_USE_ISOLAYOUT;*/
2421 /*ext. layout*/
2422 dob.UAlayout.style=DDV_TXTSTYLE_LOWERCASE;
2423 dob.UAlayout.style|=DDV_TXTSTYLE_ITALIC;
2424 dob.UAlayout.style|=DDV_TXTSTYLE_COLOR;
2425 dob.UAlayout.rgb[0]=255;
2426 dob.UAlayout.rgb[1]=0;
2427 dob.UAlayout.rgb[2]=0;
2428 dob.GAPlayout.style=DDV_TXTSTYLE_LOWERCASE;
2429 dob.GAPlayout.style|=DDV_TXTSTYLE_ITALIC;
2430 dob.GAPlayout.style|=DDV_TXTSTYLE_COLOR;
2431 dob.GAPlayout.rgb[0]=255;
2432 dob.GAPlayout.rgb[1]=0;
2433 dob.GAPlayout.rgb[2]=0;
2434 dob.MASKlayout.style=DDV_TXTSTYLE_BOLD;
2435 dob.MASKlayout.style|=DDV_TXTSTYLE_UNDERLINE;
2436 dob.ISOlayout.clr_ident=DDVCOL_ORANGE;
2437 dob.ISOlayout.clr_simil=DDVCOL_SKY;
2438 dob.ISOlayout.clr_other=DDVCOL_BLACK;
2439 }
2440
2441 if (option&DISP_FULL_HTML){
2442 fprintf(fp,"<pre>\n");
2443 }
2444 /* Attempt to print score for the alignment */
2445 new_id = TxGetSubjectIdFromSeqAlign(sap4);
2446 if(old_id != NULL) {
2447 if(SeqIdMatch(new_id, old_id))
2448 follower = TRUE;
2449 }
2450
2451 /*separator*/
2452 fprintf(fp,"<HR WIDTH=\"400\">");
2453 old_id = new_id;
2454 if(!FormatScoreFromSeqAlign(sap4, tx_option, fp, matrix, follower)){
2455 bRet=FALSE;
2456 break;
2457 }
2458 follower = FALSE;
2459 if (option&DISP_FULL_HTML){
2460 fprintf(fp,"</pre>\n");
2461 }
2462
2463 /*display a SeqAlign*/
2464 if (!DDV_DisplayNewBLAST(sap4, mask, matrix, option, (Pointer) &dob, fp)){
2465 bRet=FALSE;
2466 break;
2467 }
2468 sap4 = sap4->next;
2469 }
2470
2471 if (matrix){
2472 for(i = 0; i<TX_MATRIX_SIZE; ++i)
2473 MemFree(matrix[i]);
2474 MemFree(matrix);
2475 }
2476
2477 return(bRet);
2478 }
2479 /*******************************************************************************
2480
2481 Function : DDV_InitDefSAPdispStyles()
2482
2483 Purpose : set the default styles for SeqAligns.
2484
2485 Return value : -
2486
2487 *******************************************************************************/
2488 NLM_EXTERN void DDV_InitDefSAPdispStyles(DDV_Disp_OptPtr ddop)
2489 {
2490 /*use colors*/
2491 ddop->bUseColors=TRUE;
2492 /*disc SAP styles*/
2493 ddop->ShowLeftTail=FALSE;
2494 ddop->ShowRightTail=FALSE;
2495 ddop->DispDiscStyle=MSA_TXT_STYLE_1;
2496 ddop->SpacerSize=SPACER_TXT_BLANK;
2497 ddop->DiscJustification=DISP_JUST_CENTER;
2498 ddop->UAGapStyle=MSA_TXT_STYLE_UAGAP;
2499 ddop->AGapStyle=MSA_TXT_STYLE_GAP;
2500
2501 /*ruler style*/
2502 ddop->RulerStyle=RulerStyle_Continue_Start;
2503 }
2504
2505 /*******************************************************************************
2506
2507 Function : DDV_InitCn3DSAPdispStyles()
2508
2509 Purpose : set the styles for Cn3D SeqAligns.
2510
2511 Return value : -
2512
2513 *******************************************************************************/
2514 NLM_EXTERN void DDV_InitCn3DSAPdispStyles(DDV_Disp_OptPtr ddop)
2515 {
2516 /*use colors*/
2517 ddop->bUseColors=TRUE;
2518 /*disc SAP styles*/
2519 ddop->ShowLeftTail=TRUE;
2520 ddop->ShowRightTail=TRUE;
2521 ddop->DispDiscStyle=MSA_TXT_STYLE_2;
2522 ddop->SpacerSize=0;
2523 ddop->DiscJustification=DISP_JUST_SPLIT;
2524 ddop->UAGapStyle=MSA_TXT_STYLE_UAGAP; /* use different unaligned gap chars ('~') */
2525 ddop->AGapStyle=MSA_TXT_STYLE_GAP;
2526
2527 /*ruler style*/
2528 ddop->RulerStyle=RulerStyle_Continue_Start;
2529 }
2530
2531 /*******************************************************************************
2532
2533 Function : DDV_InitDDESAPdispStyles()
2534
2535 Purpose : set the styles for DDE (i.e. DDV used as an editor).
2536
2537 Return value : -
2538
2539 *******************************************************************************/
2540 NLM_EXTERN void DDV_InitDDESAPdispStyles(DDV_Disp_OptPtr ddop)
2541 {
2542 /*use colors*/
2543 ddop->bUseColors=TRUE;
2544 /*disc SAP styles*/
2545 ddop->ShowLeftTail=TRUE;
2546 ddop->ShowRightTail=TRUE;
2547 ddop->DispDiscStyle=MSA_TXT_STYLE_2;
2548 ddop->SpacerSize=0;
2549 ddop->DiscJustification=DISP_JUST_LEFT;
2550 ddop->UAGapStyle=MSA_TXT_STYLE_UAGAP;
2551 ddop->AGapStyle=MSA_TXT_STYLE_GAP;
2552
2553 /*ruler style*/
2554 ddop->RulerStyle=RulerStyle_Continue_Start;
2555 }
2556
2557 /*******************************************************************************
2558
2559 Function : DDV_ReadSeqBin()
2560
2561 Purpose : read a sequence using Seq_code_ncbistdaa or Seq_code_ncbi4na
2562
2563 Return value : the sequence
2564
2565 *******************************************************************************/
2566 NLM_EXTERN Uint1Ptr DDV_ReadSeqBin (SeqIdPtr sip, Int4 from, Int4 to,
2567 Boolean IsProt,Int2 len,Uint1 strand)
2568 {
2569 SeqLocPtr slp;
2570 SeqPortPtr spp;
2571 Uint1Ptr btr;
2572 Uint1 residue;
2573 Uint2 i=0;
2574
2575 /*from always < than to*/
2576 slp = SeqLocIntNew (from, to, strand, sip);
2577 if (!slp) return(NULL);
2578 spp = SeqPortNewByLoc (slp, (Uint1)(IsProt==TRUE ? Seq_code_ncbistdaa
2579 : Seq_code_ncbi4na));
2580 if (spp != NULL) {
2581 btr = (Uint1Ptr) MemNew (len * sizeof(Uint1));
2582 if (!btr) return(NULL);
2583 while ((residue = SeqPortGetResidue(spp)) != SEQPORT_EOF) {
2584 if (IS_residue(residue)) {
2585 btr[i] = residue;
2586 i++;
2587 }
2588 }
2589 /*SeqPortRead(spp, btr, len);*/
2590 SeqPortFree (spp);
2591 }
2592 SeqLocFree (slp);
2593 return btr;
2594 }
2595
2596 /*******************************************************************************
2597
2598 Function : DDV_SetStyle()
2599
2600 Purpose : set the layout of a single letter
2601
2602 Return value : -.
2603
2604 *******************************************************************************/
2605 static void DDV_SetStyle(DDV_ColorCell * dccp,Uint1 style, Uint1 *rgb,
2606 Boolean bAllowReset)
2607 {
2608 if (style&DDV_TXTSTYLE_ITALIC){
2609 dccp->UseItalic=TRUE;
2610 }
2611 else if (bAllowReset){
2612 dccp->UseItalic=FALSE;
2613 }
2614
2615 if (style&DDV_TXTSTYLE_BOLD){
2616 dccp->UseBold=TRUE;
2617 }
2618 else if (bAllowReset){
2619 dccp->UseBold=FALSE;
2620 }
2621
2622 if (style&DDV_TXTSTYLE_UNDERLINE){
2623 dccp->UseUnderline=TRUE;
2624 }
2625 else if (bAllowReset){
2626 dccp->UseUnderline=FALSE;
2627 }
2628
2629 if (style&DDV_TXTSTYLE_LOWERCASE){
2630 dccp->LowerCase=TRUE;
2631 }
2632 else if(bAllowReset) {
2633 dccp->LowerCase=FALSE;
2634 }
2635
2636 if (style&DDV_TXTSTYLE_COLOR && rgb){
2637 dccp->rgb[0]=rgb[0];
2638 dccp->rgb[1]=rgb[1];
2639 dccp->rgb[2]=rgb[2];
2640 }
2641 }
2642
2643 /*******************************************************************************
2644
2645 Function : DDV_SetStd_AA_UA_ClrEx()
2646
2647 Purpose : set the standard colours for a nuc or prot sequence;
2648 or the same function can be used to layout UnAligned regions
2649
2650 Note: For performance issue this function set up the layout of
2651 both aligned and unaligned regions at the same time
2652
2653 Return value : -
2654
2655 *******************************************************************************/
2656 #define read_buf_size 3000
2657 static void DDV_SetStd_AA_UA_ClrEx(DDV_ColorGlobal *pColorGlobal, void *pData,
2658 DDV_Range *pRange,Uint1 what)
2659 {
2660 DDVDataForColorFuncPtr ddfcfp;
2661 BioseqPtr bsp;
2662 Int4 bsp_length,i,from,to,limit;
2663 Boolean IsAA;
2664 Int4 dp;
2665 Uint1Ptr SeqBuf;
2666 Int2 len;
2667 Uint1 idx;
2668 DDV_ColorCell * dccp;
2669
2670 ddfcfp=(DDVDataForColorFuncPtr)pData;
2671
2672 if (!ddfcfp) return;
2673
2674 /*get bioseq size and type */
2675 bsp=BioseqLockById(ddfcfp->sip);
2676 if (bsp){
2677 bsp_length=bsp->length;
2678 IsAA=ISA_aa(bsp->mol);
2679 BioseqUnlock(bsp);
2680 }
2681 else return;
2682
2683
2684 /*compute the ends of the bioseq's region we want to analyse*/
2685 if (ddfcfp->from!=(Int4)-1)
2686 from=ddfcfp->from;
2687 else
2688 from=0;
2689
2690 if (ddfcfp->to!=(Int4)-1)
2691 limit=ddfcfp->to;
2692 else
2693 limit=bsp_length-1;
2694
2695 to=from+read_buf_size-1;
2696 if (to>limit) to=limit;
2697
2698 /*read the sequence by chunk of 'read_buf_size' letters*/
2699 while(TRUE){
2700 len=(Int2)(to-from+1);
2701 /*get a sequence chunck ; from is always < than to*/
2702 SeqBuf=DDV_ReadSeqBin (ddfcfp->sip, from, to, IsAA,len,ddfcfp->strand);
2703 if (SeqBuf){/*scan each letter and get the appropriate colour*/
2704 for(i=0;i<len;i++){
2705 /*compute the correct position; depend on the strand*/
2706 if (ddfcfp->strand==Seq_strand_minus)
2707 dp=to-i;
2708 else
2709 dp=from+i;
2710 /*first, query Color Manager*/
2711 dccp=DDV_GetColor(pColorGlobal,NULL,ddfcfp->row+1,dp);
2712 if (!dccp) return;
2713 if(what & DDV_USE_STDCLR) {
2714 if (IsAA)
2715 idx=DDV_STD_AAColor[*(SeqBuf+i)];/*AA*/
2716 else
2717 idx=DDV_STD_NAColor[*(SeqBuf+i)];/*NA*/
2718
2719 if (ddfcfp->IsUnAligned)
2720 DDV_SetStyle(dccp,ddfcfp->UAstyle,DDV_PaletteRGB[idx],TRUE);
2721 else
2722 DDV_SetStyle(dccp,ddfcfp->style,DDV_PaletteRGB[idx],TRUE);
2723 }
2724 else if(what & DDV_USE_UALAYOUT) {
2725 if (ddfcfp->IsUnAligned)
2726 DDV_SetStyle(dccp,ddfcfp->UAstyle,ddfcfp->UArgb,TRUE);
2727 else
2728 DDV_SetStyle(dccp,ddfcfp->style,DDV_PaletteRGB[DDVCOL_BLACK],TRUE);
2729 }
2730 /*set the colour*/
2731 DDV_SetColor(pColorGlobal, NULL, ddfcfp->row+1, dp, dccp);
2732 }
2733 MemFree(SeqBuf);
2734 }
2735
2736 /*compute the next chunk*/
2737 from+=read_buf_size;
2738 to+=read_buf_size;
2739 if (to>limit) to=limit;
2740 /*end ?*/
2741 if (from>limit) break;
2742 }
2743
2744 }
2745
2746
2747 /*******************************************************************************
2748
2749 Function : DDV_InitColourSAP()
2750
2751 Purpose : init the colours for each Bsp of a SeqAlign
2752
2753 Parameters : sap; a (indexed) SeqAlign
2754 global colour data struct (see ddvcolor.[ch] in api)
2755 NoColor; don't color the bsp's, but do change the case.
2756
2757 Note : usually, this function is called when DDV loads a SeqAlign
2758 For performance issue this function set up the layout of
2759 both aligned and unaligned regions at the same time
2760
2761 Return value : FALSE is failure.
2762
2763 *******************************************************************************/
2764 static Boolean DDV_InitColourSAP(SeqAlignPtr sap,MsaParaGPopListPtr mpplp,
2765 DDV_ColorGlobal * * gclr,Uint1 what,Uint1 * pRGB,Uint1 style,
2766 Uint1 * pUARGB,Uint1 UAstyle)
2767 {
2768 DDVDataForColorFunc ddfcf;
2769 SeqIdPtr sip;
2770 ValNodePtr vnp,vnp2;
2771 ParaGPtr pgp;
2772 MsaTxtDispPtr mtdp;
2773 Int4 n;
2774
2775 if (!sap)
2776 return (FALSE);
2777
2778 if (!(*gclr)){
2779 *gclr = DDV_CreateColorGlobal(FALSE, (void *) sap);
2780 if (!(*gclr))
2781 return(FALSE);
2782 }
2783
2784 for(n=0;n<mpplp->nBsp;n++){
2785 vnp=mpplp->TableHead[n];
2786 while(vnp){
2787 pgp=(ParaGPtr)vnp->data.ptrvalue;
2788 if (pgp){
2789 vnp2=pgp->ptxtList;
2790 sip=pgp->sip;
2791 while(vnp2){
2792 mtdp = (MsaTxtDispPtr)vnp2->data.ptrvalue;
2793 if(mtdp && mtdp->TextStyle==MSA_TXT_STYLE_SEQ){
2794 ddfcf.sip=sip;
2795 ddfcf.from=mtdp->from;
2796 ddfcf.to=mtdp->to;
2797 ddfcf.row=n;
2798 ddfcf.strand=mtdp->strand;
2799 ddfcf.IsUnAligned=mtdp->IsUnAligned;
2800 ddfcf.style=style;
2801 ddfcf.UAstyle=UAstyle;
2802 if (pRGB){
2803 ddfcf.rgb[0]=pRGB[0];
2804 ddfcf.rgb[1]=pRGB[1];
2805 ddfcf.rgb[2]=pRGB[2];
2806 }
2807 else{
2808 ddfcf.rgb[0]=0;
2809 ddfcf.rgb[1]=0;
2810 ddfcf.rgb[2]=0;
2811 }
2812 if (pUARGB){
2813 ddfcf.UArgb[0]=pUARGB[0];
2814 ddfcf.UArgb[1]=pUARGB[1];
2815 ddfcf.UArgb[2]=pUARGB[2];
2816 }
2817 else{
2818 ddfcf.UArgb[0]=0;
2819 ddfcf.UArgb[1]=0;
2820 ddfcf.UArgb[2]=0;
2821 }
2822 DDV_SetStd_AA_UA_ClrEx(*gclr, (Pointer)&ddfcf, NULL, what);
2823 }
2824 vnp2=vnp2->next;
2825 }
2826 }
2827 vnp=vnp->next;
2828 }
2829 }
2830 return(TRUE);
2831 }
2832
2833 /*******************************************************************************
2834
2835 Function : DDV_InitColour_When_Start()
2836
2837 Purpose : standard init function for Vibrant DDV ; see DDV_InitColourSAP()
2838
2839 *******************************************************************************/
2840 NLM_EXTERN Boolean DDV_InitColour_When_Start(SeqAlignPtr sap,MsaParaGPopListPtr mpplp,
2841 DDV_ColorGlobal * * gclr, Boolean NoColor)
2842 {
2843 if(NoColor)
2844 return(DDV_InitColourSAP(sap,mpplp,gclr,DDV_USE_STDCLR,NULL,0,NULL,0));
2845 else
2846 return(DDV_InitColourSAP(sap,mpplp,gclr,DDV_USE_STDCLR,NULL,
2847 DDV_TXTSTYLE_COLOR,NULL,DDV_TXTSTYLE_COLOR|DDV_TXTSTYLE_LOWERCASE));
2848 }
2849
2850 /*******************************************************************************
2851
2852 Function : DDV_LayoutUAregion()
2853
2854 Purpose : set a layout for UnAligned regions; see DDV_InitColourSAP()
2855
2856 *******************************************************************************/
2857 NLM_EXTERN Boolean DDV_LayoutUAregion(SeqAlignPtr sap,MsaParaGPopListPtr mpplp,
2858 DDV_ColorGlobal * * gclr,Uint1 * pRGB,Uint1 style,Uint1 * pUARGB,Uint1 UAstyle)
2859 {
2860 return(DDV_InitColourSAP(sap,mpplp,gclr,DDV_USE_UALAYOUT,pRGB,style,pUARGB,UAstyle));
2861 }
2862
2863
2864 /*******************************************************************************
2865
2866 Function : UDV_BigEncodeIdxFeat4()
2867
2868 Purpose : encode two Uint4 into one Uint8
2869
2870 *******************************************************************************/
2871 static Uint8 UDV_BigEncodeIdxFeat4 (Uint4 val1,Uint4 val2)
2872 {
2873 Uint4 index_g[2];
2874
2875 index_g[0]=val1;
2876 index_g[1]=val2;
2877
2878 return *((Uint8Ptr) index_g);
2879
2880 }
2881
2882 /*******************************************************************************
2883
2884 Function : UDV_BigEncodeIdxFeat4()
2885
2886 Purpose : decode one Uint8 into two Uint4
2887
2888 *******************************************************************************/
2889 static void UDV_BigDecodeIdxFeat4 (Uint8 index_g, Uint4Ptr val1, Uint4Ptr val2)
2890 {
2891 Uint4Ptr index_g2;
2892
2893 index_g2 = (Uint4Ptr) (&index_g);
2894 if (val1) *val1 = (Uint4) index_g2 [0];
2895 if (val2) *val2 = (Uint4) index_g2 [1];
2896 }
2897
2898 /*******************************************************************************
2899
2900 Function : DDV_GetGapCoord()
2901
2902 Purpose : get the list of gaps given a ParaG.
2903
2904 Return value : -.
2905
2906 *******************************************************************************/
2907 static void DDV_GetGapCoord(ParaGPtr pgp,ValNodePtr PNTR gap_list)
2908 {
2909 ValNodePtr vnp;
2910 MsaTxtDispPtr mtdp;
2911
2912 if (!pgp) return;
2913 vnp=pgp->ptxtList;
2914 while(vnp){
2915 mtdp=(MsaTxtDispPtr)vnp->data.ptrvalue;
2916 if (mtdp){
2917 if(mtdp->IsGap && (mtdp->TextStyle==MSA_TXT_STYLE_GAP ||
2918 mtdp->TextStyle==MSA_TXT_STYLE_2)){
2919 ValNodeAddBigInt(gap_list,0,
2920 UDV_BigEncodeIdxFeat4 ((Uint4)mtdp->from,(Uint4)mtdp->to));
2921 }
2922 }
2923 vnp=vnp->next;
2924 }
2925 }
2926
2927 /*******************************************************************************
2928
2929 Function : DDV_AllGapInLowerCase()
2930
2931 Purpose : analyse sequences by pair and switch to lower case all residues
2932 "aligned" with a gap.
2933
2934 Return value : -.
2935
2936 *******************************************************************************/
2937 NLM_EXTERN void DDV_LayoutGap(DDV_ColorGlobal *pcg,ValNodePtr vnp_seq1,
2938 ValNodePtr vnp_seq2,Int4 row2,Uint1 style,Uint1 *rgb)
2939 {
2940 DDV_ColorCell * dccp;
2941 ValNodePtr vnp1,vnp2,vnp3,vnp4;
2942 ParaGPtr pgp1,pgp2;
2943 Uint4 i,from,to;/*display coord.*/
2944 Int4 bsp_coord;
2945 DDV_ColorCell dcc;
2946
2947 if (pcg==NULL || vnp_seq1==NULL || vnp_seq2==NULL) return;
2948 /*scan the first sequence to modify the second*/
2949 vnp1=vnp_seq1;
2950 vnp2=vnp_seq2;
2951 vnp3=NULL;
2952 while(vnp1){
2953 /*is there a gap in the vnp1 ParaG*/
2954 pgp1=(ParaGPtr)vnp1->data.ptrvalue;
2955 pgp2=(ParaGPtr)vnp2->data.ptrvalue;
2956 DDV_GetGapCoord(pgp1,&vnp3);
2957 if (vnp3){
2958 vnp4=vnp3;
2959 while(vnp4){
2960 UDV_BigDecodeIdxFeat4((Uint8)vnp4->data.bigintvalue,
2961 &from, &to);
2962 to++;
2963 for (i=from;i<to;i++){
2964 bsp_coord=(Int4)DDV_GetBspCoordGivenDispCoord(pgp2,(Int4)i);
2965 if (bsp_coord>=0){
2966 dccp=DDV_GetColor(pcg,NULL,row2+1,bsp_coord);
2967 if (dccp){/*if there is already a color, just
2968 update the required parameter*/
2969 DDV_SetStyle(dccp,style,rgb,FALSE);
2970 DDV_SetColor(pcg,NULL,row2+1,bsp_coord,dccp);
2971 }
2972 else{/*otherwise, set up a new layout for that letter*/
2973 memset(&dcc,0,sizeof(DDV_ColorCell));
2974 DDV_SetStyle(&dcc,style,rgb,FALSE);
2975 DDV_SetColor(pcg, NULL, row2+1, bsp_coord, &dcc);
2976 }
2977 }
2978 }
2979 vnp4=vnp4->next;
2980 }
2981 }
2982 vnp1=vnp1->next;
2983 vnp2=vnp2->next;
2984 if (vnp3)
2985 vnp3=ValNodeFree(vnp3);
2986 }
2987 }
2988
2989 /*******************************************************************************
2990
2991 Function : DDV_LayoutMaskRegions()
2992
2993 Purpose : layout the masked regions of a sequence (usually the query sequence
2994 of BLAST).
2995
2996 Return value : -.
2997
2998 *******************************************************************************/
2999 NLM_EXTERN void DDV_LayoutMaskRegions(DDV_ColorGlobal *pcg,
3000 ValNodePtr vnp_query,ValNodePtr mask,Int4 row,Uint1 style,Uint1 *rgb)
3001 {
3002 DDV_ColorCell * dccp;
3003 ValNodePtr vnp;
3004 SeqLocPtr slp;
3005 Int4 i,bsp_start,bsp_stop,mask_start,mask_stop,scan_from,
3006 scan_to;
3007 DDV_ColorCell dcc;
3008
3009 if (pcg==NULL || vnp_query==NULL || mask==NULL) return;
3010
3011 /*get sequence range*/
3012 UDV_GetBspRangeinPGPList(vnp_query,&bsp_start,&bsp_stop);
3013
3014 /*scan the mask list*/
3015 vnp=mask;
3016 while(vnp) {
3017 slp=(SeqLocPtr)vnp->data.ptrvalue;
3018
3019 if(slp == NULL)
3020 return;
3021
3022 if(slp->choice == SEQLOC_PACKED_INT)
3023 slp = slp->data.ptrvalue;
3024 else if (slp->choice != SEQLOC_INT)
3025 return;
3026
3027 while(slp) {
3028
3029 if(slp->choice != SEQLOC_INT) {
3030 slp = slp->next;
3031 continue;
3032 }
3033
3034 mask_start=SeqLocStart(slp);
3035 mask_stop=SeqLocStop(slp);
3036
3037 /*check if the masked region is in the bsp range*/
3038 if (mask_stop>=bsp_start && mask_start<=bsp_stop){
3039 scan_from=_max_(mask_start,bsp_start);
3040 scan_to=_min_(mask_stop,bsp_stop)+1;
3041 for(i=scan_from;i<scan_to;i++) {
3042 dccp=DDV_GetColor(pcg,NULL,row+1,i);
3043 if (dccp){/*if there is already a color, just
3044 update the LowerCase parameter*/
3045 DDV_SetStyle(dccp,style,rgb,FALSE);
3046 DDV_SetColor(pcg,NULL,row+1,i,dccp);
3047 } else{/*otherwies, set a new layout for that letter*/
3048 memset(&dcc,0,sizeof(DDV_ColorCell));
3049 DDV_SetStyle(&dcc,style,rgb,FALSE);
3050 DDV_SetColor(pcg, NULL, row+1, i, &dcc);
3051 }
3052 }
3053 }
3054 slp = slp->next;
3055 }
3056 vnp=vnp->next;
3057 }
3058 }
3059
3060 /*******************************************************************************
3061
3062 Function : DDV_SetISOClr()
3063
3064 Purpose : layout the colors for ident/simil/other (I/S/O).
3065
3066 *******************************************************************************/
3067 static void DDV_SetISOClr(DDV_ColorGlobal * pcg, ParaGPtr pgp,Int4 disp_coord,
3068 Int4 row, Uint1 idx,Uint1 sty)
3069 {
3070 DDV_ColorCell * dccp;
3071 DDV_ColorCell dcc;
3072 Int4 bsp_coord;
3073
3074 bsp_coord=DDV_GetBspCoordGivenDispCoord(pgp,disp_coord);
3075 if (bsp_coord>=0){
3076 dccp=DDV_GetColor(pcg,NULL,row+1,bsp_coord);
3077 if (dccp){/*if there is already a color, just
3078 update the required parameter*/
3079 dccp->rgb[0]=DDV_PaletteRGB[idx][0];
3080 dccp->rgb[1]=DDV_PaletteRGB[idx][1];
3081 dccp->rgb[2]=DDV_PaletteRGB[idx][2];
3082 DDV_SetStyle(dccp,sty,NULL,FALSE);
3083 DDV_SetColor(pcg,NULL,row+1,bsp_coord,dccp);
3084 }
3085 else{/*otherwise, set up a new layout for that letter*/
3086 memset(&dcc,0,sizeof(DDV_ColorCell));
3087 dcc.rgb[0]=DDV_PaletteRGB[idx][0];
3088 dcc.rgb[1]=DDV_PaletteRGB[idx][1];
3089 dcc.rgb[2]=DDV_PaletteRGB[idx][2];
3090 DDV_SetStyle(&dcc,sty,NULL,FALSE);
3091 DDV_SetColor(pcg, NULL, row+1, bsp_coord, &dcc);
3092 }
3093 }
3094 }
3095
3096 /*******************************************************************************
3097
3098 Function : DDV_LayoutIdentColors()
3099
3100 Purpose : layout the colors for ident/simil/other (I/S/O).
3101
3102 Return value : -.
3103
3104 *******************************************************************************/
3105 NLM_EXTERN void DDV_LayoutISOColors(DDV_ColorGlobal *pcg,ValNodePtr * row_list,Int4 nRow,
3106 Int4 Master,Boolean bSetMaster,Int4Ptr * matrix,Uint1 IdentClr,Uint1 SimilClr,
3107 Uint1 OtherClr,Uint1 IdentSty,Uint1 SimilSty,Uint1 OtherSty)
3108 {
3109 ValNodePtr * row;
3110 ValNodePtr vnp;
3111 ParaGPtr pgpQuery,pgpSubject;
3112 CharPtr szQuery,szComp;
3113 BioseqPtr bsp;
3114 Boolean IsAA;
3115 Int4 i,j,len,bspLength;
3116 Uint1 idx,sty;
3117
3118 row=(ValNodePtr *)MemNew(nRow*sizeof(ValNodePtr));
3119 if (!row) return;
3120 for (i=0;i<nRow;i++){
3121 row[i]=row_list[i];
3122 }
3123
3124 vnp=row_list[Master];
3125 while(vnp){
3126 /*get the master sequence*/
3127 pgpQuery=(ParaGPtr)vnp->data.ptrvalue;
3128 szQuery=(CharPtr)MemNew((pgpQuery->StopLetter-pgpQuery->StartLetter+3)*sizeof(Char));
3129 if (!szQuery) goto error;
3130 bsp=BioseqLockById(pgpQuery->sip);
3131 if (!bsp) goto error;
3132 bspLength=BioseqGetLen(bsp);
3133 IsAA=ISA_aa(bsp->mol);
3134 BioseqUnlock(bsp);
3135 if (!DDV_GetSequenceFromParaG(pgpQuery,&szQuery,bspLength,IsAA,NULL,
3136 NULL,NULL)) goto error;
3137 /*lopp on each row, get the sequence, set the colors*/
3138 for (i=0;i<nRow;i++){
3139 if (i==Master) continue;
3140 pgpSubject=(ParaGPtr)row[i]->data.ptrvalue;
3141 szComp=DDV_GetBLASTCompLine_3(szQuery,pgpSubject,matrix);
3142 if (szComp){
3143 len=StringLen(szComp)+1;
3144 for (j=0;j<len;j++){
3145 if (isalpha(szComp[j]) || szComp[j]=='|'){
3146 idx=IdentClr;
3147 sty=IdentSty;
3148 }
3149 else if (szComp[j]=='+'){
3150 idx=SimilClr;
3151 sty=SimilSty;
3152 }
3153 else{
3154 idx=OtherClr;
3155 sty=OtherSty;
3156 }
3157 DDV_SetISOClr(pcg,pgpSubject,pgpSubject->StartLetter+j,i,idx,sty);
3158 if (bSetMaster)
3159 DDV_SetISOClr(pcg,pgpQuery,pgpQuery->StartLetter+j,0,idx,sty);
3160 }
3161 MemFree(szComp);
3162 }
3163 row[i]=row[i]->next;
3164 }
3165 szQuery=MemFree(szQuery);
3166 vnp=vnp->next;
3167 }
3168 error:
3169
3170 MemFree(row);
3171 if (szQuery) MemFree(szQuery);
3172 }
3173
3174
3175 NLM_EXTERN MsaParaGPopListPtr DDE_CreateDisplayForBlock(SeqAlignPtr sap, Int4 BlockIndex) {
3176 /*----------------------------------------------------------------------------
3177 * allocate and fill the paragraphs for displaying 1 block of a
3178 * sequence alignment, plus the flanking unaligned regions.
3179 * BlockIndex is a 0-based block count.
3180 *
3181 * This function works by making a linked-list of 3 DescriDisp's:
3182 * head --> node1 --> node2 --> node3
3183 * || || ||
3184 * \/ \/ \/
3185 * unaligned aligned unaligned
3186 *
3187 * This is a descriptor for the display. This descriptor is passed
3188 * to DDV_PopulateDisplayForDisc to create the paragraphs.
3189 * Each node is easy to construct:
3190 *
3191 *
3192 * Aligned (A) UnAligned (UA)
3193 * ----------- --------------
3194 * from: SeqAlign coords 0
3195 * to: " " length-1
3196 * TextStyle: MSA_TXT_STYLE_REG_ALIGN MSA_TXT_STYLE_REG_UNALIGN
3197 * UAnum: 0 (explained below)
3198 * UAMaxLength: 0 length
3199 *
3200 *
3201 * UAnum, for unaligned regions, is determined as shown here:
3202 *
3203 * BlockIndex: 0 1 2
3204 * |<--UA-->|<--A-->|<--UA-->|<--A-->|<--UA-->|<--A-->|<--UA-->|
3205 * UAnum: -1 1 2 -2
3206 * where -1 and -2 are for the LEFT_TAIL and RIGHT_TAIL, respectively.
3207 *
3208 *
3209 * return a pointer to the paragraph list.
3210 * return NULL for unsuccessful completion.
3211 *---------------------------------------------------------------------------*/
3212 ValNodePtr head = NULL;
3213 DescriDispPtr ddp1, ddp2, ddp3;
3214 Int4 i, NumRows, NumBlocks, Size, SaveSize, start, stop;
3215 Int4 TotalLength=0;
3216 Uint1 strand=Seq_strand_unknown;
3217 DDV_Disp_Opt DisplayOptions;
3218 MsaParaGPopListPtr pPopList;
3219
3220 /* index the seq align */
3221 /* if (!AlnMgrIndexSeqAlign(sap)) {
3222 return(NULL);
3223 } */
3224
3225 NumRows = AlnMgrGetNumRows(sap);
3226 NumBlocks = AlnMgrGetNumAlnBlocks(sap);
3227 if ((BlockIndex < 0) || (BlockIndex >= NumBlocks)) {
3228 return(NULL);
3229 }
3230
3231 /* figure out the length of the unaligned region preceeding the block */
3232 SaveSize = 0;
3233 for (i=0; i<NumRows; i++) {
3234 if (BlockIndex == 0) {
3235 AlnMgrGetNthRowTail(sap, i+1, LEFT_TAIL, &start, &stop, &strand);
3236 }
3237 else {
3238 AlnMgrGetNthUnalignedForNthRow(sap, BlockIndex, i+1, &start, &stop);
3239 }
3240 if ((start == -1) && (stop == -1)) {Size = 0;}
3241 else {Size = (stop-start)+1;}
3242 if (Size > SaveSize) {SaveSize = Size;}
3243 }
3244 TotalLength += SaveSize;
3245
3246 /* make a node for this region */
3247 ddp1 = MemNew(sizeof(DescriDisp));
3248 ddp1->from = 0;
3249 ddp1->to = SaveSize - 1;
3250 ddp1->TextStyle = MSA_TXT_STYLE_REG_UNALIGN;
3251 /* set UAnum to -1 for LEFT_TAIL */
3252 ddp1->UAnum = (BlockIndex == 0) ? -1 : BlockIndex;
3253 ddp1->UAMaxlength = SaveSize;
3254 ddp1->strand = strand;
3255 ddp1->IsGap = FALSE;
3256
3257 /* add it to the linked list */
3258 ValNodeAddPointer(&head, 0, ddp1);
3259
3260 /* make node for aligned block and add it to linked list */
3261 AlnMgrGetNthBlockRange(sap, BlockIndex+1, &start, &stop);
3262 ddp2 = MemNew(sizeof(DescriDisp));
3263 ddp2->from = start;
3264 ddp2->to = stop;
3265 ddp2->TextStyle = MSA_TXT_STYLE_REG_ALIGN;
3266 ddp2->UAnum = 0;
3267 ddp2->UAMaxlength = 0;
3268 ddp2->strand = strand;
3269 ddp2->IsGap = FALSE;
3270 ValNodeAddPointer(&head, 0, ddp2);
3271 TotalLength += (stop - start) + 1;
3272
3273 /* figure out the length of the unaligned region following the block */
3274 SaveSize = 0;
3275 for (i=0; i<NumRows; i++) {
3276 if (BlockIndex == (NumBlocks-1)) {
3277 AlnMgrGetNthRowTail(sap, i+1, RIGHT_TAIL, &start, &stop, &strand);
3278 }
3279 else {
3280 AlnMgrGetNthUnalignedForNthRow(sap, BlockIndex+1, i+1, &start, &stop);
3281 }
3282 if ((start == -1) && (stop == -1)) {Size = 0;}
3283 else {Size = (stop-start)+1;}
3284 if (Size > SaveSize) {SaveSize = Size;}
3285 }
3286 TotalLength += SaveSize;
3287
3288 /* make a node for this region */
3289 ddp3 = MemNew(sizeof(DescriDisp));
3290 ddp3->from = 0;
3291 ddp3->to = SaveSize - 1;
3292 ddp3->TextStyle = MSA_TXT_STYLE_REG_UNALIGN;
3293 /* set UAnum to -2 for RIGHT_TAIL */
3294 ddp3->UAnum = (BlockIndex == (NumBlocks-1)) ? -2 : BlockIndex + 1;
3295 ddp3->UAMaxlength = SaveSize;
3296 ddp3->strand = strand;
3297 ddp3->IsGap = FALSE;
3298
3299 /* add it to the linked list */
3300 ValNodeAddPointer(&head, 0, ddp3);
3301
3302 /* create the paragraphs from the descriptor */
3303 pPopList = MemNew(sizeof(MsaParaGPopList));
3304 DDV_InitDDESAPdispStyles(&DisplayOptions);
3305 if (DDV_PopulateDisplayForDisc(sap, pPopList, NumRows, TotalLength+10,
3306 &DisplayOptions, TotalLength, head, TRUE, FALSE)) {
3307 return(pPopList);
3308 }
3309 else {
3310 return(NULL);
3311 }
3312 }
3313
3314
3315 NLM_EXTERN MsaParaGPopListPtr DDE_CreateDisplayForUnAligned(SeqAlignPtr sap, Int4 UAIndex) {
3316 /*----------------------------------------------------------------------------
3317 * allocate and fill the paragraphs for displaying 1 unaligned
3318 * region of a sequence alignment. UAIndex is a 0-based count.
3319 * (UA = unaligned)
3320 *
3321 * This function works by making a linked-list of just 1 DescriDisp.
3322 * This is a descriptor for the display. This descriptor is passed
3323 * to DDV_PopulateDisplayForDisc to create the paragraphs.
3324 *
3325 * Each node is easy to construct:
3326 *
3327 * UnAligned (UA)
3328 * ---------------------------
3329 * from: 0
3330 * to: length-1
3331 * TextStyle: MSA_TXT_STYLE_REG_UNALIGN
3332 * UAnum: (explained below)
3333 * UAMaxLength: length
3334 *
3335 * UAnum is determined as shown here:
3336 *
3337 * UAIndex: 0 1 2 3
3338 * |<--UA-->|<--A-->|<--UA-->|<--A-->|<--UA-->|<--A-->|<--UA-->|
3339 * UAnum: -1 1 2 -2
3340 * where -1 and -2 are for the LEFT_TAIL and RIGHT_TAIL, respectively.
3341 *
3342 * return a pointer to the paragraph list.
3343 * return NULL for unsuccessful completion.
3344 *---------------------------------------------------------------------------*/
3345 ValNodePtr head = NULL;
3346 DescriDispPtr ddp1;
3347 Int4 NumRows, NumBlocks;
3348 Int4 i, Size, SaveSize, start, stop;
3349 Int4 TotalLength=0;
3350 Uint1 strand=Seq_strand_unknown;
3351 DDV_Disp_Opt DisplayOptions;
3352 MsaParaGPopListPtr pPopList;
3353
3354 /* index the seq align */
3355 /* if (!AlnMgrIndexSeqAlign(sap)) {
3356 return(NULL);
3357 } */
3358
3359 NumRows = AlnMgrGetNumRows(sap);
3360 NumBlocks = AlnMgrGetNumAlnBlocks(sap);
3361 if ((UAIndex < 0) || (UAIndex > NumBlocks)) {
3362 return(NULL);
3363 }
3364
3365 /* figure out the length of the unaligned region preceeding the block */
3366 SaveSize = 0;
3367 for (i=0; i<NumRows; i++) {
3368 if (UAIndex == 0) {
3369 AlnMgrGetNthRowTail(sap, i+1, LEFT_TAIL, &start, &stop, &strand);
3370 }
3371 else if (UAIndex == NumBlocks) {
3372 AlnMgrGetNthRowTail(sap, i+1, RIGHT_TAIL, &start, &stop, &strand);
3373 }
3374 else {
3375 AlnMgrGetNthUnalignedForNthRow(sap, UAIndex, i+1, &start, &stop);
3376 }
3377 if ((start == -1) && (stop == -1)) {Size = 0;}
3378 else {Size = (stop-start)+1;}
3379 if (Size > SaveSize) {SaveSize = Size;}
3380 }
3381 TotalLength += SaveSize;
3382
3383 /* make a node for this region */
3384 ddp1 = MemNew(sizeof(DescriDisp));
3385 ddp1->from = 0;
3386 ddp1->to = SaveSize - 1;
3387 ddp1->TextStyle = MSA_TXT_STYLE_REG_UNALIGN;
3388 /* set UAnum to -1 for LEFT_TAIL, -2 for RIGHT_TAIL, or UAIndex */
3389 if (UAIndex == 0) {ddp1->UAnum = -1;}
3390 else if (UAIndex == NumBlocks) {ddp1->UAnum = -2;}
3391 else {ddp1->UAnum = UAIndex;}
3392 ddp1->UAMaxlength = SaveSize;
3393 ddp1->strand = strand;
3394 ddp1->IsGap = FALSE;
3395
3396 /* add it to the linked list */
3397 ValNodeAddPointer(&head, 0, ddp1);
3398
3399 /* create the paragraphs from the descriptor */
3400 pPopList = MemNew(sizeof(MsaParaGPopList));
3401 DDV_InitDDESAPdispStyles(&DisplayOptions);
3402 if (DDV_PopulateDisplayForDisc(sap, pPopList, NumRows, TotalLength+10,
3403 &DisplayOptions, TotalLength, head, FALSE, TRUE)) {
3404 return(pPopList);
3405 }
3406 else {
3407 return(NULL);
3408 }
3409 }
3410
3411
3412 NLM_EXTERN MsaParaGPopListPtr DDE_CreateDisplay(SeqAlignPtr sap, Int4 BlockIndex,
3413 Boolean IsUnAligned, Int4* pNumBlocks) {
3414 /*----------------------------------------------------------------------------
3415 * build display, ruler, entitiesTbl for either an
3416 * unaligned region or an aligned block
3417 *---------------------------------------------------------------------------*/
3418 MsaParaGPopListPtr mpplp;
3419 Int4 from=-1, to;
3420
3421 if (IsUnAligned) {
3422 mpplp = DDE_CreateDisplayForUnAligned(sap, BlockIndex);
3423 *pNumBlocks = 0;
3424 }
3425 else {
3426 mpplp = DDE_CreateDisplayForBlock(sap, BlockIndex);
3427 *pNumBlocks = 1;
3428 /* get the first align index of block */
3429 AlnMgrGetNthBlockRange(sap, BlockIndex+1, &from, &to);
3430 }
3431 ASSERT(mpplp != NULL);
3432
3433 mpplp->entitiesTbl = DDV_BuildBspEntitiesTbl(mpplp->TableHead, mpplp->nBsp);
3434 ASSERT(mpplp->entitiesTbl != NULL);
3435
3436 mpplp->RulerDescr = DDE_ReMakeRuler(mpplp, FALSE, from);
3437 return(mpplp);
3438 }
3439
3440 |
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more information. |