2
* $Id: vastgraphDB.c,v 1.3 2003/01/14 20:49:20 chenj Exp $
5
* ===========================================================================
8
* National Center for Biotechnology Information (NCBI)
10
* This software/database is a "United States Government Work" under the
11
* terms of the United States Copyright Act. It was written as part of
12
* the author's official duties as a United States Government employee and
13
* thus cannot be copyrighted. This software/database is freely available
14
* to the public for use. The National Library of Medicine and the U.S.
15
* Government do not place any restriction on its use or reproduction.
16
* We would, however, appreciate having the NCBI and the author cited in
17
* any work or product based on this material
19
* Although all reasonable efforts have been taken to ensure the accuracy
20
* and reliability of the software and data, the NLM and the U.S.
21
* Government do not and cannot warrant the performance or results that
22
* may be obtained by using this software or data. The NLM and the U.S.
23
* Government disclaim all warranties, express or implied, including
24
* warranties of performance, merchantability or fitness for any particular
27
* ===========================================================================
32
* $Log: vastgraphDB.c,v $
33
* Revision 1.3 2003/01/14 20:49:20 chenj
37
* This is to show the "red-cloud" graph.
38
* The footprint alignment is broken at the position of insert.
40
* ===========================================================================
50
#include "vastgenDB.h"
54
static double pix_per_res;
55
static CharPtr QueryBit;
57
static Int2 white, black, red, blue, gray;
58
static Int4 iDartCol[13];
60
extern Dart_Connect *dartcon;
61
extern Char URLcgi[MAX_TBUFF],MMDBCGIname[MAX_TBUFF], CGIname[MAX_TBUFF];
62
extern Char MAILto[PATH_MAX], ENTREZurl[PATH_MAX];
63
extern Char VSPATH[PATH_MAX], CDDurl[PATH_MAX];
67
GetLeftAnglePoints(gdPoint *points, Int4 x1, Int4 x2, Int4 dx, Int4 y, Int4 dy)
73
points[0].x = MIN(midp, x1+dx); points[0].y = y;
74
points[1].x = x1; points[1].y = y+0.5*dy;
75
points[2].x = MIN(midp, x1+dx); points[2].y = y+dy;
77
} /* GetLeftAnglePoints */
83
GetRightAnglePoints(gdPoint *points, Int4 x1, Int4 x2, Int4 dx, Int4 y, Int4 dy)
89
points[0].x = MAX(midp, x2-dx); points[0].y = y;
90
points[1].x = x2; points[1].y = y+0.5*dy;
91
points[2].x = MAX(midp, x2-dx); points[2].y = y+dy;
93
} /* GetRightAnglePoints */
98
static void GetPoints(gdPoint *points, Int2 *n, CharPtr flag,
99
Int4 x1, Int4 x2, Int4 y, Int4 dy)
106
case 'L': /* Left zigzag */
107
GetRightAnglePoints(points, x1, x2, 7, y, dy);
108
points[3].x = x1; points[3].y = y+dy;
109
points[4].x = MIN(x1+3, midp); points[4].y = y+dy*0.75;
110
points[5].x = x1; points[5].y = y+dy*0.5;
111
points[6].x = MIN(x1+3, midp); points[6].y = y+dy*0.25;
112
points[7].x = x1; points[7].y = y;
115
case 'R': /* right zigzag */
116
GetLeftAnglePoints(points, x1, x2, 7, y, dy);
117
points[3].x = x2; points[3].y = y+dy;
118
points[4].x = MAX(x2-3, midp); points[4].y = y+dy*0.75;
119
points[5].x = x2; points[5].y = y+dy*0.5;
120
points[6].x = MAX(x2-3, midp); points[6].y = y+dy*0.25;
121
points[7].x = x2; points[7].y = y;
124
case 'W': /* two zigzag lines */
125
points[0].x = x1; points[0].y = y;
126
points[1].x = x2; points[1].y = y;
127
points[2].x = MAX(x2-3, midp); points[2].y = y+dy*0.25;
128
points[3].x = x2; points[3].y = y+dy*0.5;
129
points[4].x = MAX(x2-3, midp); points[4].y = y+dy*0.75;
130
points[5].x = x2; points[5].y = y+dy;
131
points[6].x = x1; points[6].y = y+dy;
132
points[7].x = MIN(x1+3, midp); points[7].y = y+dy*0.75;
133
points[8].x = x1; points[8].y = y+dy*0.5;
134
points[9].x = MIN(x1+3, midp); points[9].y = y+dy*0.25;
137
case 'A': /* Aligned, so two angles */
139
else if (x2-x1 <= 18) dx = 4;
142
points[0].x = MIN(midp, x1+dx); points[0].y = y;
144
points[1].x = x2; /* points[1].y = y; */
145
points[3].x = x2; /* points[3].y = y + dy; */
148
points[1].x = MAX(midp, x2-dx);
149
points[3].x = MAX(midp, x2-dx);
151
points[2].x = x2; points[2].y = y+0.5*dy;
152
points[4].x = MIN(midp, x1+dx); points[4].y = y+dy;
153
points[5].x = x1; points[5].y = y+0.5*dy;
155
points[1].y = y; points[3].y = y+dy;
159
case 'U': /* Un..., special for query */
160
points[0].x = x1; points[0].y = y;
161
points[1].x = x2; points[1].y = y;
162
points[2].x = x2; points[2].y = y+dy;
163
points[3].x = x1; points[3].y = y+dy;
167
PrtMes(MAILto, "VASTSRV (VastGraph)",
168
"Error in GetPoints -- didn't choose points", NULL, FALSE);
175
#define HTMLurl "href=\"%s%s?sdid=%d&viewali=View&action=0&alitype=h"
176
#define VSHTMLurl "href=\"%s%s?chaindom=%d&viewali=View&action=0&alitype=h"
179
BlockMapOrImg(Boolean ismap, Int4 x, Int4 y, Int4 x0, Int4 from, Int4 to,
180
Int4 tick_from, Int4 tick_to, Int2 color, Int4 dy, Int4 pre_t,
181
Int4 next_f, Boolean isaligned, Int4 Fsid, VastPageDataPtr vpp,
182
Int4 iSlv, Int4 numhitsdisplayed, CharPtr JobID, CharPtr pcPass,
185
char altstr[200], str[MAX_TBUFF], str2[20], strnum[MAX_TBUFF];
190
CalCoor(&x1, &x2, x, from, to, pix_per_res, MaxSeqImgSize);
191
if (iSlv < 0) if (x1-x0 <2) x1 = x0+2;
196
if (dy==8) sprintf(altstr, "Unaligned residues ");
197
else sprintf(altstr, "Maximal aligned region: from residues ");
198
sprintf(str, "%d to %d, ", tick_from, tick_to);
199
StringCat(altstr, str);
200
StringCat(altstr,"click for multiple alignment with neighbors.");
201
sprintf(strnum, "%d%%2C", Fsid*10);
202
for (i=0; i< numhitsdisplayed; i++) {
203
sprintf(str2, "%d%%2C", vpp[i].bBsfId);
204
StringCat(strnum, str2);
209
"Aligned residues %d to %d, click for sequence alignment.",
213
fprintf(File, "<area shape=rect coords=%d,%d,%d,%d ",
216
if (JobID) fprintf(File, VSHTMLurl, URLcgi, CGIname, Fsid);
217
else fprintf(File, HTMLurl, URLcgi, CGIname, aSdi);
219
fprintf(File, "&nbr_complexity=0&allbsfid=%s", strnum);
221
else fprintf(File, "&nbr_complexity=1&hit=%d", vpp[iSlv].bBsfId);
222
if (JobID) fprintf(File, "&vsid=%s&pass=%s", JobID, pcPass);
224
fprintf(File, " alt=\"%s\" ", altstr);
225
fprintf(File, "ONMOUSEOVER=\"self.status=\'%s\'; return true\">\n", altstr);
228
if (isaligned == TRUE) {
233
GetLeftAnglePoints(points, x1, x2, 7, y, dy);
234
points[3].x = x2; points[3].y = y+dy;
235
points[4].x = x2; points[4].y = y;
238
else GetPoints(points, &n, "A", x1, x2, y, dy);
240
gdImageFilledPolygon(im, points, n, color);
244
GetRightAnglePoints(points, x1, x2, 7, y, dy);
245
points[3].x = x1; points[3].y = y+dy;
246
points[4].x = x1; points[4].y = y;
247
gdImageFilledPolygon(im, points, 5, color);
249
else gdImageFilledRectangle(im, x1, y, x2, y+dy, color);
251
else gdImageFilledRectangle(im, x1, y, x2, y+dy, color);
256
} /* end of BlockImg */
259
#define EntrezLink "href=\"%s?cmd=Retrieve&db=%s&list_uids=%d&dopt=%s\""
261
static void NameMapOrImg(Boolean ismap, Int4 *x, Int4 y, CharPtr pdbname,
262
Char chainname, Int4 iDomain, Int4 iGi, Int4 seqlen,
263
CharPtr pcSlaveName, FILE *File)
266
Char cTmp[10], str[10], altstr[MAX_TBUFF];
269
sprintf(cTmp, "%s %c", pdbname, chainname);
271
sprintf(str, " %d", iDomain);
272
StringCat(cTmp, str);
275
sprintf(altstr, "%s", pdbname);
276
if (chainname != ' ') {
277
sprintf(str, "_%c", chainname);
278
StringCat(altstr, str);
281
StringCat(altstr, "_");
282
sprintf(str, "%d", iDomain);
283
StringCat(altstr, str);
285
fprintf(File, "<area shape=rect coords=%d,%d,%d,%d ",
286
*x, y, *x+StrLen(cTmp)*FontBW, y+FontBH);
287
if (pcSlaveName != NULL) {
288
sprintf(str, ": %d", seqlen);
289
StringCat(altstr, str),
290
StringCat(altstr, " residues");
291
if (!iDomain) StringCat(altstr, ", ");
293
if (chainname != ' ') sprintf(str, " on chain %c, ", chainname);
294
else sprintf(str, " on chain, ");
295
StringCat(altstr, str);
297
StringCat(altstr, pcSlaveName);
298
fprintf(File, "href=\"%s%s?uid=%s", URLcgi, MMDBCGIname, pdbname);
299
fprintf(File, "&form=6&db=t&Dopt=s\" ");
302
StringCat(altstr, ", click for Entrez sequence summary");
303
fprintf(File, EntrezLink, ENTREZurl, "protein", iGi, "GenPept");
306
fprintf(File, "alt=\"%s\" ", altstr);
307
fprintf(File, "ONMOUSEOVER=\"self.status=\'%s\'; return true\">\n",
311
gdImageString(im, gdFont7X13b, *x, y, cTmp, blue);
313
x0 = *x + StrLen(pdbname)*FontBW;
314
gdImageLine(im, *x, y, x0, y, blue);
316
if (chainname != ' ') gdImageLine(im, x0, y, x0+FontBW, y, blue);
318
if (iDomain) gdImageLine(im, x0, y, x0+FontBW, y, blue);
323
} /* end NameMapOrImg */
326
static void PrintAliMap(Int4 x1, Int4 y1, Int4 x2, Int4 y2, Int4 tick_f,
327
Int4 tick_t, Int4 Fsid, VastPageDataPtr vpp, Int4 iSlv, CharPtr JobID,
328
CharPtr pcPass, FILE *File)
330
char cTmp[MAX_TBUFF], str[100];
332
sprintf(cTmp, "Aligned residues %d to %d, click for sequence alignment",
334
fprintf(File, "<area shape=rect coords=%d,%d,%d,%d ",
336
if (JobID) fprintf(File, VSHTMLurl, URLcgi, CGIname, Fsid);
337
else fprintf(File, HTMLurl, URLcgi, CGIname, aSdi);
338
fprintf(File, "&nbr_complexity=1&hit=%d", vpp[iSlv].bBsfId);
339
if (JobID) fprintf(File, "&vsid=%s&pass=%s", JobID, pcPass);
341
fprintf(File, " alt=\"%s\" ", cTmp);
342
fprintf(File, "ONMOUSEOVER=\"self.status=\'%s\'; return true\"", cTmp);
343
fprintf(File, ">\n");
349
InsertOnSlaveMapOrImg(Boolean ismap, Int4 x, Int4 y, Int4 x0, Int4 from,
350
Int4 to, Int4 tick_from, Int4 tick_to, Int4 pre_to, Int4 next_from,
351
IntvlPairDataPtr ipdp, Int4 *segNo,Int4 segNum, Int4 Fsid,
352
VastPageDataPtr vpp, Int4 iSlv, CharPtr JobID, CharPtr pcPass, FILE *File)
355
Int4 x1, x2, dy,i, idx, next, f_res, t_res;
360
t_res = ipdp[idx-1].mstto;
361
CalCoor(&x1, &x2, x, from, t_res, pix_per_res, MaxSeqImgSize);
362
if (x1-x0 < 2) x1 = x0+2;
363
x2 -= 1.0 + MIN(0, (Int4)(pix_per_res/2.0));
365
PrintAliMap(x1, y, x2, y+dy, tick_from, ipdp[idx-1].slvto,
366
Fsid, vpp, iSlv, JobID, pcPass, File);
371
GetLeftAnglePoints(points, x1, x2, 7, y, dy);
372
points[3].x = x2; points[3].y = y+dy;
373
points[4].x = x2; points[4].y = y;
376
gdImageFilledPolygon(im, points, n, red);
379
gdImageFilledRectangle(im, x1, y, x2, y+dy, red);
382
for (i=0; i< segNum; i++) {
384
f_res = ipdp[idx].mstfrom;
385
CalCoor(&x1, NULL, x, f_res, 0, pix_per_res, MaxSeqImgSize);
386
x1 += 1.0 + MIN(0, (Int4)(pix_per_res/2.0));
387
/* if (ismap == FALSE) gdImageFilledRectangle(im, x2, y, x1, y+dy, sky); */
390
t_res = ipdp[next].mstfrom-1;
391
CalCoor(NULL, &x2, x, 0, t_res, pix_per_res, MaxSeqImgSize);
392
x2 -= 1.0 + MIN(0, (Int4)(pix_per_res/2.0));
394
PrintAliMap(x1, y, x2, y+dy, ipdp[idx].slvfrom, ipdp[next].slvfrom-1,
395
Fsid, vpp, iSlv, JobID, pcPass, File);
396
else gdImageFilledRectangle(im, x1, y, x2, y+dy, red);
400
CalCoor(NULL, &x2, x, 0, to, pix_per_res, MaxSeqImgSize);
402
PrintAliMap(x1, y, x2, y+dy, ipdp[idx].slvfrom, tick_to, Fsid,
403
vpp, iSlv, JobID, pcPass, File);
407
GetRightAnglePoints(points, x1, x2, 7, y, dy);
408
points[3].x = points[4].x = x1;
409
points[3].y = y+dy; points[4].y = y;
411
gdImageFilledPolygon(im, points, 5, red);
414
else gdImageFilledRectangle(im, x1, y, x2, y+dy, red);
419
} /* end InsertOnSlaveMap... */
425
AlignmentMapOrImg(Boolean ismap, Int4 x, Int4 y, Int4 Fsid, Int4 iSlv,
426
Int4 seqlen_s, VastPageDataPtr vpp, CharPtr stats, Int2 sortnamelen,
427
CharPtr JobID, CharPtr pcPass, FILE *File)
429
char pdbId_s[5], chnLett_s;
430
CharPtr pcSlaveName = NULL;
432
Int4 x0=-1, dy, from_m,from_s;
433
Int4 to_m, to_s, ali_from_m, ali_to_m=0, ali_from_s=0;
434
Int4 ali_to_s=-1, pre_to_s=0, segNo[20];
435
Int4 segNum = 0, domNo_s;
441
pcSlaveName = (CharPtr) MemNew ((size_t)(2*DBStrSize+4));
442
pcSlaveName[0] = '\0';
443
if(vpp[iSlv].name[0] != '\0' || vpp[iSlv].name2[0] != '\0') {
444
if(vpp[iSlv].name[0] != '\0')
445
strcpy(pcSlaveName,vpp[iSlv].name);
446
if(vpp[iSlv].name2[0] != '\0')
447
strcat(pcSlaveName,vpp[iSlv].name2);
451
StrCut(pdbId_s, vpp[iSlv].bDomName, 1, 4);
452
chnLett_s = (vpp[iSlv].bDomName)[4];
453
domNo_s = (Int4)atoi(vpp[iSlv].bDomName+5);
454
ipdp = vpp[iSlv].Ipdp;
456
NameMapOrImg(ismap, &x, y, pdbId_s, chnLett_s, domNo_s, 0, seqlen_s,
459
if (ismap==TRUE) MemFree(pcSlaveName);
461
for (i = 0; i< vpp[iSlv].IpdpLen; i++) {
462
from_m = ipdp[i].mstfrom;
463
to_m = ipdp[i].mstto;
464
from_s = ipdp[i].slvfrom;
465
to_s = ipdp[i].slvto;
467
/* red piece for aligned region */
474
if (i && from_m == ali_to_m+1) {
475
if (from_s > ali_to_s+1) segNo[segNum++] = i;
481
x0 = BlockMapOrImg(ismap, x, y, x0, ali_from_m, ali_to_m,
482
ali_from_s, ali_to_s, red, dy, pre_to_s, 0, TRUE, Fsid,
483
vpp, iSlv, 0, JobID, pcPass, File);
485
x0 = InsertOnSlaveMapOrImg(ismap, x, y, x0, ali_from_m,
486
ali_to_m, ali_from_s, ali_to_s, pre_to_s, 0, ipdp,
487
segNo, segNum, Fsid, vpp, iSlv, JobID, pcPass, File);
489
for (j = ali_from_m-1; j< ali_to_m; j++) QueryBit[j] = '1';
491
if (!pre_to_s) pre_to_s = ali_to_s;
503
} /* for (i = 0 ... */
506
/* rectangle with red color from from_m to to_m ---- aligned block */
509
x0 =BlockMapOrImg(ismap, x, y, x0, ali_from_m, ali_to_m, ali_from_s,
510
ali_to_s, red, dy, pre_to_s, 1, TRUE, Fsid, vpp, iSlv, 0,
511
JobID, pcPass, File);
513
x0 = InsertOnSlaveMapOrImg(ismap, x, y, x0, ali_from_m, ali_to_m,
514
ali_from_s, ali_to_s, pre_to_s, 1, ipdp, segNo, segNum,
515
Fsid, vpp, iSlv, JobID, pcPass, File);
517
for (j = ali_from_m-1; j< ali_to_m; j++) QueryBit[j] = '1';
521
x =GraphWidth - (MAX(sortnamelen, StrLen(stats)) + StrLen(stats))*FontBW/2.0;
523
gdImageString(im, gdFont7X13b, x, y, stats, blue);
525
} /* end of AlignImg() */
531
GetLeft4Points(Int4 x1, Int4 x2, Int4 y1, Int4 y2, gdPointPtr points)
535
points[i].x = x2; points[i++].y = y1;
536
points[i].x = x1; points[i++].y = y1+2;
537
points[i].x = x1; points[i++].y = y2-2;
538
points[i].x = x2; points[i++].y = y2;
546
GetRight4Points(Int4 x1, Int4 x2, Int4 y1, Int4 y2, gdPointPtr points)
550
points[i].x = x1; points[i++].y = y2;
551
points[i].x = x2; points[i++].y = y2-2;
552
points[i].x = x2; points[i++].y = y1+2;
553
points[i].x = x1; points[i++].y = y1;
557
#define CDDsrv "href=\"%s?ascbin=2&maxaln=10&seltype=3&uid=%s&aln=%s&querygi=%d&querynm=%s&version=%s\""
558
#define CDDOpt "db=cdd&term="
559
#define DomOpt "db=structure&cmd=Display&dopt=structure_domains&from_uid="
562
static void QueryMapOrImg(Boolean ismap, Int4 x, Int4 y, CharPtr pcPDB,
563
Int4 iMMDBid, Int4 Fsid, Char cChain, Int4 domNo, Int4 gi,
564
Int4 seqlen, DomIntvlDataPtr dip, Int4 domintvl_no, VastPageDataPtr vpp,
565
Int4 numhitsdisplayed, CharPtr JobID, CharPtr pcPass,FILE *File)
567
char cTmp[MAX_TBUFF], shortname[MAX_TBUFF], str[MAX_TBUFF];
568
char defline[MAX_TBUFF], def2[MAX_TBUFF], *chtmp;
569
char cdalign[MAX_TBUFF], querynm[MAX_TBUFF];
570
char definition[MAX_TBUFF];
573
Int2 i, color, char_num;
574
Int4 alinumseg,j, x0=-1,y0, x1, x2, y1, y2, len, dont, x_ori, numseg;
575
Int4Ptr starts, lens;
576
Int4 index, ntick, tick, right, dy=0, from, to, len1, len2, minali;
578
SeqAnnotPtr sap = NULL;
579
SeqAlignPtr salp= NULL;
580
static Int4 ticksteps[9] = {5, 10, 20, 25, 50, 100, 200, 150, 500};
584
NameMapOrImg(ismap, &x, y, pcPDB, cChain, 0, gi, seqlen, NULL, File);
593
Int4 color, k, l, dy, pre_t, next_f, y0;
598
case '0': color=gray; aliflag = FALSE; dy = 8;
599
pre_t = next_f = 1; y0 = y1;
601
case '1': color = red; aliflag = TRUE; dy = 14;
603
minali = 1; pre_t = 0;
611
while (k< seqlen && bitj == QueryBit[k]) k++;
615
while (l< seqlen && QueryBit[l] != bitj) l++;
616
if (l >= seqlen) next_f = 1;
620
x0 = BlockMapOrImg(ismap, x, y0, x0, ++j, k, j, k, color, dy, pre_t,
621
next_f, aliflag, Fsid, vpp, -1, numhitsdisplayed, JobID,
627
if (ismap == FALSE) {
631
CalCoor(NULL, &right, x, 0, seqlen, pix_per_res, MaxSeqImgSize);
634
if (QueryBit[0] == '1') gdImageLine(im, x, y, x, y2, red);
635
else gdImageLine(im, x, y1, x, y2, red);
636
if (QueryBit[seqlen-1] == '1') gdImageLine(im, right, y, right, y2, red);
637
else gdImageLine(im, right, y1, right, y2, red);
641
gdImageString(im, gdFont6X12, x, y2, "1", red);
642
sprintf(cTmp, "%d", seqlen);
643
gdImageString(im, gdFont6X12, right-(StrLen(cTmp)-1)*FontMW, y2, cTmp, red);
647
for (i=0; i< 9; i++) {
648
ntick = seqlen/ticksteps[i];
656
dont = right - StrLen(cTmp)*FontMW;
657
for (i=1; i<=ntick; i++){
658
x1 = (Int4)(x+(float)(i*tick-1) * pix_per_res);
659
if (x1 > dont) continue;
661
if (QueryBit[i*tick-1] == '1') gdImageLine(im, x1, y, x1, y2, red);
662
else gdImageLine(im, x1, y1, x1, y2, red);
664
sprintf(cTmp, "%d", i*tick);
665
len = StrLen(cTmp)*FontMW/2;
668
if (x2<dont && (x2-x0 > len)) {
669
gdImageString(im, gdFont6X12, x1, y2-FontMH, cTmp, red);
675
/* "3d Domains" & "CDs" */
679
if (domintvl_no > 1) {
680
x = x_ori; y += FontBH+5;
683
NameMapOrImg(ismap, &x, y, "3d Dom.", ' ', 0, 0, 0, NULL, NULL);
685
fprintf(File, "<area shape=rect coords=%d,%d,%d,%d ",
686
x, y, x+StrLen("3d Dom.")*FontBW, y+FontBH);
687
sprintf(cTmp, "Click for Entrez 3d Domains");
688
fprintf(File, "href=\"%s?%s%d\" alt=\"%s\" ",
689
ENTREZurl, DomOpt, iMMDBid, cTmp);
690
fprintf(File,"ONMOUSEOVER=\"self.status=\'%s\'; return true\">\n",cTmp);
694
if (!domNo) domintvl_no = 1;
695
for (i = 0; i< domintvl_no; i++) {
697
if (domNo && !dip[i].domNo) continue;
700
if (dip[i].domNo != domNo) {
701
if (ismap == FALSE) color = gray;
706
if (ismap == FALSE) color = red;
710
CalCoor(&x1, &x2, x, dip[i].frm, dip[i].tu, pix_per_res, MaxSeqImgSize);
713
sprintf(cTmp, "Residue %d to %d", dip[i].frm, dip[i].tu);
714
StringCat(cTmp, ", click for structure neighbors");
716
fprintf(File, "<area shape=rect coords=%d,%d,%d,%d ",
719
fprintf(File, "href=\"%s%s?chaindom=%d", URLcgi, CGIname,
720
(Fsid+(dip[i].domNo - domNo)));
723
fprintf(File, "href=\"%s%s?sdid=%d", URLcgi, CGIname,
724
LongDomIdToSdi(Fsid +(dip[i].domNo - domNo)));
726
fprintf(File, "&form=6&db=t&Dopt=s\" alt=\"%s\" ", cTmp);
727
fprintf(File, "ONMOUSEOVER=\"self.status=\'%s\'; return true\">\n",
734
if (dip[i].domNo != domNo) {
735
if (dip[i].frm == 1) {
736
points[0].x = x1; points[0].y = y1;
737
points[1].x = x1; points[1].y = y2;
741
GetLeft4Points(x1, MIN((x1+x2)/2, x1+2), y1, y2,points);
745
if (dip[i].tu == seqlen) {
746
points[n].x = x2; points[n++].y = y2;
747
points[n].x = x2; points[n++].y = y1;
750
GetRight4Points(MAX((x1+x2)/2, x2-2), x2, y1, y2, points+n);
753
gdImageFilledPolygon(im, points, n, color);
756
gdImageFilledRectangle(im, x1, y1, x2, y2-2, color);
758
if (dip[i].domNo) sprintf(cTmp, "%d", dip[i].domNo);
759
else sprintf(cTmp, "Chain %c", cChain);
760
if (x2-x1>StrLen(cTmp)*FontBW) {
761
x0 = (x1+x2-StrLen(cTmp)*FontBW)/2.0;
762
gdImageString(im, gdFont7X13b, x0, y+1, cTmp, white);
766
} /* for (i=0; i< domintvl_no */
771
if (Dart_Gi2Sap(dartcon, gi, &sap, NULL) && (sap != NULL)) {
773
unsigned *Pssmlist, *PssmId, count;
774
Int2 *iColor, CdNum, thisColor=0, *iClus;
777
Char CDDdb[1024], Version[1024];
778
Dart_Version(dartcon, CDDdb, 100, Version, 1024);
780
StrCut(Version, Version, StrLen(CDDdb)+2, StrLen(Version));
782
if (!Dart_CdNum(dartcon, &count))
783
PrtMes("chenj@ncbi.nlm.nih.gov",
784
"MmdbSrv", "Can't do Dart_CdNum()", NULL, FALSE);
785
Pssmlist = (unsigned *) MemNew (count * sizeof (unsigned));
787
end = head = NewOverLoc(seqlen);
788
head->y = y0 = y+7+FontBH;
791
for (salp = (SeqAlignPtr)sap->data, CdNum=0; salp!=NULL;
792
salp=salp->next, CdNum++);
794
iColor = (Int2Ptr) MemNew (CdNum * sizeof(Int2));
795
PssmId = (unsigned *) MemNew (CdNum * sizeof(unsigned));
796
dsp = (DenseSegPtr *) MemNew (CdNum * sizeof(DenseSegPtr));
797
CddName = (CharPtr *) MemNew (CdNum * sizeof(CharPtr));
798
for (j=0; j< CdNum; j++) CddName[j] = (CharPtr) MemNew (30);
799
iClus = (Int2Ptr) MemNew (CdNum * sizeof(Int2));
801
for (salp = (SeqAlignPtr)sap->data, i=0; salp!=NULL; salp=salp->next, i++) {
802
dsp[i] = (DenseSegPtr)salp->segs;
803
PssmId[i] = GetPSSMID(dsp[i]);
807
Dart_CDGi2Acc(dartcon, PssmId[i], CddName[i], 30);
811
strtmp = GetCDDName(dsp[i]);
812
sprintf(CddName[i], strtmp);
818
for (i=0; i< CdNum; i++) {
820
if (iClus[i] >= 0) continue;
822
if (ismap == FALSE) iColor[i] = (thisColor++) % iNcolors;
825
if (Dart_Related(dartcon, CddName[i],Pssmlist,count,&NumRows, NULL)) {
830
PrtMes("chenj@ncbi.nlm.nih.gov", "VASTSRV",
831
"Dart_Related(): NumRows>MaxPssm", NULL, FALSE);
833
for (j=0; j< NumRows; j++) {
834
for (k=i+1; k< CdNum; k++)
835
if (PssmId[k] == Pssmlist[j]) {
836
if (ismap == FALSE) iColor[k] = iColor[i];
844
sprintf(querynm, "%s%c(query)", pcPDB, cChain);
845
for (i=0; i< StrLen(querynm); i++)
846
if (isalpha(querynm[i])) querynm[i] = tolower(querynm[i]);
847
if (querynm[4] == ' ') querynm[4] = '+';
849
for (i=0; i< CdNum; i++) {
851
numseg = (dsp[i])->numseg;
852
starts = (dsp[i])->starts;
853
lens = (dsp[i])->lens;
854
from = starts[0] + 1;
855
to = starts[(numseg-1)*2] + lens[numseg-1];
857
CalCoor(&x1, &x2, x, from, to, pix_per_res, MaxSeqImgSize);
858
y = GetY1(head, &end, from, to, seqlen, iClus[i], 5);
862
Dart_Acc2Info(dartcon, CddName[i], shortname, MAX_TBUFF, defline,
863
MAX_TBUFF, definition, MAX_TBUFF);
866
if (StrLen(defline) == 254) strcpy((defline+StrLen(defline)-3), "...");
867
if (defline[StrLen(defline)-1] != '.') StringCat(defline, ".");
869
chtmp = strchr(defline, ';');
870
sprintf(str, "%s:", CddName[i]);
871
sprintf(def2, defline);
873
strncpy(def2, def2, (chtmp-defline-1));
874
def2[chtmp-defline]='.';
875
def2[chtmp-defline+1]='\0';
878
chtmp = strchr(defline, '.');
880
strncpy(def2, def2, (chtmp-defline));
881
def2[chtmp-defline+1]='\0';
884
StringCat(def2, ".");
886
StringCat(str, def2);
887
StringCat(str, " Click for the CD alignment.");
892
for (j=0; j< numseg; j++) {
894
if (starts[index]!= -1 && starts[index+1] != -1) {
895
sprintf(str, ",%d,%d,%d", starts[index+1], starts[index],
897
StringCat(cdalign, str);
901
sprintf(str, "%d", alinumseg);
902
StringCat(str, cdalign);
904
fprintf(File, "<area shape=rect coords=%d,%d,%d,%d ",
906
fprintf(File, CDDsrv, CDDurl, CddName[i], str, gi, querynm, Version);
907
fprintf(File, "alt=\"%s: %s %s\" ", CddName[i], defline,
908
"Click for CD alignment");
909
fprintf(File, "ONMOUSEOVER=\"self.status=\'%s\'; return true\">\n",
912
StringCat(cTmp, "+OR+");
913
StringCat(cTmp, CddName[i]);
914
StringCat(cTmp, "[ACCN]");
917
else { /* ismap == FALSE */
919
gdImageRoundRectangle(im, x1, y, x2, y2, 8, 5,
920
iDartCol[iColor[i]], 1);
922
len1 = StrLen(shortname)*FontBW;
923
len2 = StrLen(shortname)*FontMW;
925
if (iColor[i] == 2 || iColor[i] == 4 || iColor[i] == 0) color=black;
927
gdImageString(im, gdFont7X13b, (x1+x2-len1)/2, y+1,
929
else if ((x2-x1) > len2)
930
gdImageString(im, gdFont6X12, (x1+x2-len2)/2, y+1,
933
char_num = (x2-x1)/FontBW;
934
if (char_num >= 3) strcpy(&(shortname[char_num-3]), "...");
935
else switch (char_num) {
936
case 1: strcpy(shortname, "."); break;
937
case 2: strcpy(shortname, "..");
939
gdImageString(im, gdFont7X13b, x1+2, y+1, shortname, color);
954
NameMapOrImg(ismap, &x, head->y+2, "CDs", ' ', 0, 0, 0, NULL, NULL);
956
sprintf(str, "Click for Entrez Conserved Domains.");
957
fprintf(File, "<area shape=rect coords=%d,%d,%d,%d ",
958
x, head->y+dy, x+StrLen("CDs")*FontBW, head->y+dy+FontBH);
959
fprintf(File, "href=\"%s?%s%s\" alt=\"%s\" ",
960
ENTREZurl, CDDOpt, cTmp+4, str);
961
fprintf(File, "ONMOUSEOVER=\"self.status=\'%s\'; return true\">\n",str);
969
for (i=0; i< CdNum; i++) MemFree(CddName[i]);
975
} /* end of QueryMapOrImg */
978
#define MaxDipLen 120
980
void ImgMapOrDraw(Boolean ismap, Int4 Fsid, VastPageDataPtr vpp,
981
Int4 numhitsdisplayed, Int4 iKept, CharPtr selnbrstring,
982
CharPtr selsdidstring, SortBy sortby,
983
SubSetID subsetnum, Int4 pagenum, Int4 StartLoc, CharPtr JobID,
984
CharPtr pcPass, FILE *File)
986
char stats[100], str[100], a_pdbId[5];
988
DomIntvlData dip[MaxDipLen];
990
Int4 i, a_MMDBid, a_chainid, a_domNo, a_gi=0, a_seqlen, b_seqlen;
991
Int4 b_MMDBid, b_chainid;
992
Int4 x, y, a_domintvl_no=0;
993
static char SortBy_name[6][10] ={"Ali_Len", "Score", "P_value",
994
"Rmsd", "Ali_Res.", "%Id."};
995
static char altstr[6][100]={"Number of Aligned Residues",
998
"Room-mean square deviation",
999
"Number of Aligned Residues",
1002
a_MMDBid = Fsid/10000;
1003
a_chainid = (Fsid % 10000) / 100;
1005
StrCut(a_pdbId, vpp[0].aDomName, 1, 4);
1006
a_chainLett = vpp[0].aDomName[4];
1007
a_domNo = (Int4) atol(vpp[0].aDomName+5);
1011
constructDomIntvlData(a_MMDBid, a_chainid, dip, MaxDipLen);
1013
a_seqlen = dip[0].tu;
1014
a_gi = constructGi(a_MMDBid, a_chainid);
1018
BiostrucPtr a_bstp = NULL;
1019
BioseqPtr bsqp = NULL;
1020
BioseqSetPtr bssp = NULL;
1021
BiostrucResidueGraphSetPtr stdDictionary;
1022
Char AsnPath[MAX_TBUFF], str[10];
1023
ObjectIdPtr objidp = NULL;
1024
SeqEntryPtr sep = NULL;
1025
SeqIdPtr sip = NULL;
1027
sprintf(AsnPath, VSPATH);
1028
StringCat(AsnPath, JobID);
1029
StringCat(AsnPath, "/b");
1030
StringCat(AsnPath, a_pdbId);
1032
a_bstp = FetchBS(AsnPath, 0, ONECOORDRES, 1, POWER_VIEW);
1034
aipr = AsnIoOpen("bstdt", "rb");
1035
stdDictionary = BiostrucResidueGraphSetAsnRead(aipr, NULL);
1037
aipr = AsnIoClose(aipr);
1039
sep = (SeqEntryPtr) MakeBioseqs(a_bstp, stdDictionary);
1042
PrtMes(MAILto, "VASTSRV (VastGraph, VS1)",
1043
"Unable to get SeqEntry", NULL, FALSE);
1045
if (sep->choice == 2){
1048
bssp = (BioseqSetPtr)sep->data.ptrvalue;
1049
sep = (SeqEntryPtr) bssp->seq_set;
1050
while (i< a_chainid) {
1055
PrtMes(MAILto, "VASTSRV (VastGraph, VS2)",
1056
"Unable to get SeqEntry", NULL, FALSE);
1059
bsqp = (BioseqPtr)sep->data.ptrvalue;
1062
if (sip->choice == SEQID_LOCAL) {
1063
sprintf(str, "%s %c %d", a_pdbId, a_chainLett, a_domNo);
1064
objidp = (ObjectIdPtr)sip->data.ptrvalue;
1065
if (!StringNCmp(objidp->str, str, 6)) {
1066
a_seqlen = bsqp->length;
1073
BiostrucFree(a_bstp);
1076
pix_per_res= (float)MaxSeqImgSize/(float)a_seqlen;
1077
QueryBit = (CharPtr) MemNew ((size_t)(a_seqlen+1));
1078
for (i=0; i< a_seqlen; i++) QueryBit[i] = '0';
1082
x = GraphWidth - StrLen(SortBy_name[sortby])*FontBW;
1083
if (ismap == TRUE) {
1085
sprintf(str, "%s. Click for a printable table.", altstr[sortby]);
1087
fprintf(File, "<area shape=rect coords=%d,%d,%d,%d ",
1088
x, 25, GraphWidth, 25+FontBH);
1089
fprintf(File, "href=");
1090
if (JobID) fprintf(File, VSParURL, URLcgi, CGIname, Fsid, sortby);
1091
else fprintf(File, ParURL, URLcgi, CGIname, aSdi, sortby);
1092
if (selnbrstring == NULL && selsdidstring == NULL) {
1094
fprintf(File, PageSubsetURL, pagenum, subsetnum, subsetnum);
1095
else fprintf(File, "schsub=Find");
1098
fprintf(File, "schsub=Find");
1099
if (selnbrstring) fprintf(File, "&selnbr=%s", selnbrstring);
1100
if (selsdidstring) fprintf(File, "&selsdid=%s", selsdidstring);
1104
for (i=0; i< iKept; i++)
1105
fprintf(File, "&hit=%d", vpp[i].bBsfId);
1106
if (JobID) fprintf(File, "&vsid=%s&pass=%s", JobID, pcPass);
1107
fprintf(File, "&table=y\" alt=\"%s\" ", str);
1108
fprintf(File, "ONMOUSEOVER=\"self.status=\'%s\'; return true\">\n", str);
1111
NameMapOrImg(ismap, &x, 25, SortBy_name[sortby], ' ', 0, 0, 0,
1115
for (i=0; i< numhitsdisplayed; i++) {
1117
b_MMDBid = vpp[i].bBsfId / 100000;
1118
b_chainid = (vpp[i].bBsfId % 100000) / 1000;
1119
b_seqlen = constructChainLength(b_MMDBid, b_chainid);
1121
if (!sortby || sortby==4) sprintf(stats, "%d", vpp[i].nres);
1123
if (sortby == 1) f = (float) vpp[i].vScore;
1124
else if (sortby == 2)f = (float) vpp[i].mlogp;
1125
else if (sortby == 3) f = (float) vpp[i].rmsd;
1126
else f = (float) vpp[i].pcntId;
1127
f /= (float) ASP_SCALE_FACTOR;
1128
if (sortby == 1 || sortby == 3) sprintf(stats, "%.1f", f);
1129
else if (sortby == 5)sprintf(stats, "%.1f", f*100.0);
1132
/* adjust for database size */
1135
f = (float) exp(-LOG_10*f);
1136
sprintf(stats, "%.4f", f);
1138
else sprintf(stats, "10e-%.1f", f);
1142
AlignmentMapOrImg(ismap, x, y, Fsid, i, b_seqlen, vpp, stats,
1143
StrLen(SortBy_name[sortby]), JobID, pcPass, File);
1148
/* draw query domain as a ruller */
1151
QueryMapOrImg(ismap, x, y, a_pdbId, a_MMDBid, Fsid, a_chainLett, a_domNo,
1152
a_gi, a_seqlen, dip, a_domintvl_no, vpp, numhitsdisplayed,
1153
JobID, pcPass, File);
1155
} /* ImgMapOrDraw */
1159
void DrawStrucNbr(Int4 Fsid, VastPageDataPtr vpp, Int4 numhitsdisplayed,
1160
Int4 iKept, CharPtr selnbrstring, CharPtr selsdidstring,
1162
SubSetID subsetnum, Int4 pagenum, Int2 ImageSize,
1163
CharPtr JobID, CharPtr pcPass)
1168
printf("Content-type: image/gif\n\n");
1169
im = gdImageCreate(GraphWidth, ImageSize);
1170
white = gdImageColorAllocate(im, 255, 255, 255);
1171
black = gdImageColorAllocate(im, 0, 0, 0);
1172
blue = gdImageColorAllocate(im, 0, 0, 255);
1173
red = gdImageColorAllocate(im, 255, 0, 0);
1174
/* magenta = gdImageColorAllocate(im, 255, 0, 255); */
1175
gray = gdImageColorAllocate(im, 102, 102, 102);
1177
/* Dart Color scheme */
1180
iDartCol[2] = gdImageColorAllocate(im, 0, 255, 0); /* green */
1181
iDartCol[3] = gdImageColorAllocate(im, 204,102, 0); /* orange */
1182
iDartCol[4] = gdImageColorAllocate(im, 204,204, 0); /* yeller */
1183
iDartCol[0] = gdImageColorAllocate(im, 153,204,255); /* sky b */
1184
iDartCol[6] = gdImageColorAllocate(im, 102,153, 0); /* spring */
1185
iDartCol[7] = gdImageColorAllocate(im, 204,102,153); /* lavender */
1186
iDartCol[8] = gdImageColorAllocate(im, 0,204,204); /* cyan */
1187
iDartCol[9] = gdImageColorAllocate(im, 153,153, 0); /* brown */
1188
iDartCol[10] = gdImageColorAllocate(im, 153, 51,255); /* violet */
1189
iDartCol[11] = gdImageColorAllocate(im, 0,153,153); /* blue-green */
1190
iDartCol[12] = gdImageColorAllocate(im, 0,204,102); /* teal */
1192
StartLoc = ImageSize - numhitsdisplayed*30;
1193
ImgMapOrDraw(FALSE, Fsid, vpp, numhitsdisplayed, iKept, selnbrstring,
1194
selsdidstring, sortby, subsetnum, pagenum, StartLoc, JobID,
1197
gdImageGif(im, stdout);
1200
} /* DrawStrucNeig */