1 /*
2 * $Id: mmdbgraph.c,v 1.2 2003/01/15 16:09:59 chenj Exp $
3 *
4 *
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
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 have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 *
30 * Author: Jie Chen
31 *
32 *
33 * $Log: mmdbgraph.c,v $
34 * Revision 1.2 2003/01/15 16:09:59 chenj
35 * add uid as argument in ChainScaleMapOrImg()
36 *
37 * Revision 1.1.1.1 2002/12/04 21:12:08 chenj
38 * Imported sources
39 *
40 *
41 *============================================================================
42 */
43
44
45 #include <ncbi.h>
46 #include <mmdbapi.h>
47 #include "mmdbuti.h"
48
49 Int4 *ColorIdx, white, black, blue, red, gray;
50
51 extern Boolean psok;
52 Int4 maxseqlen;
53 extern Char MAILTO[PATH_MAX], Database[PATH_MAX];
54 double pix_per_res;
55
56
57 /* infered from gui_ctools/cn3d/cn3d_colors.cpp */
58
59 Uint1 cycle1[10][3] =
60 {
61 255, 0, 255, /* magenta 0 */
62 0, 0, 255, /* blue 1 */
63 139, 87, 66, /* brown 2 */
64 0, 255, 127, /* lightgreen 3 */
65 179, 179, 179, /* lightgray 4 */
66 255, 165, 0, /* gold 5 */
67 255, 114, 86, /* pink 6 */
68 0, 255, 0, /* green 7 */
69 0, 255, 255, /* cyan 8 */
70 255, 236, 139, /* yellowtint 9 */
71 };
72
73
74
ModelMapOrImg(Boolean ismap,gdImagePtr im,Int4 uid,PMSD pmsd,Int4 chain1,Int4 chain2,IntervalHead ** DomHead,Int4Ptr DomIdx,FILE * File)75 Int4 ModelMapOrImg(Boolean ismap, gdImagePtr im, Int4 uid, PMSD pmsd,
76 Int4 chain1, Int4 chain2, IntervalHead **DomHead, Int4Ptr DomIdx, FILE *File)
77 {
78 PDNMM pdnmm, pdnmm1;
79 PMMD pmmd;
80 Int4 i,x, y, colidx, r, g, b;
81
82 pdnmm = (PDNMM)pmsd->pdnmmHead;
83 pdnmm1 = PdnmmforChainX(pdnmm, chain1);
84 pdnmm = pdnmm1;
85
86 /* Protein Chains */
87
88 maxseqlen = MaxSeqLenProOrDRna(pmsd, 1);
89 pix_per_res = (float)MaxSeqImgSize/(float)(maxseqlen-1);
90
91 if (maxseqlen) {
92 for (i = chain1; i <= chain2; i++, pdnmm = pdnmm->next) {
93
94 pmmd = pdnmm->data.ptrvalue;
95
96 if ((pmmd->bWhat) & (AM_DNA || AM_RNA)) break;
97 if ((pmmd->bWhat) & AM_PROT) {
98
99 /* Name */
100 if (i == 1 || i==chain1) y = 50;
101 else y += 60;
102 x =ChainNameMapOrImg(ismap, im, 0, y, pmsd, pmmd,1,File);
103
104 /* Chain & Domains */
105
106 x += 30;
107 y =ChainDomMapOrImg(ismap,im,x,y,uid,pmmd,DomIdx,DomHead,File);
108
109 /* Conservative Domain Image */
110
111 y = ConsDomMapOrImg(ismap, im, x, y, pmsd, pmmd, File);
112
113 } /* AM_PROT */
114
115 } /* end for (i=chain1 */
116
117 } /* end Protein Chains */
118
119
120 /* Nucleotide Chains */
121 maxseqlen = MaxSeqLenProOrDRna(pmsd, 0);
122 pix_per_res = (float)MaxSeqImgSize/(float)(maxseqlen-1);
123
124 if (maxseqlen) {
125 for (i = chain1, pdnmm = pdnmm1; i <= chain2; i++, pdnmm =pdnmm->next){
126
127 pmmd = pdnmm->data.ptrvalue;
128
129 if ((pmmd->bWhat) & (AM_DNA | AM_RNA)) {
130
131 Int4 labelcol;
132
133 /* Name */
134 if (i==1 || i == chain1) y = 50;
135 else y += 80;
136 x = ChainNameMapOrImg(ismap, im, 0, y, pmsd, pmmd, 0, File);
137
138 /* Chain Image */
139
140 if (ismap == FALSE) {
141 x += 9;
142 colidx = ColorIdx[DomIdx[pmmd->iChainId]];
143 r = cycle1[colidx][0];
144 g = cycle1[colidx][1];
145 b = cycle1[colidx][2];
146 labelcol = white;
147 if (colidx==3 || colidx==4 || colidx==5 || colidx==7
148 || colidx==8 || colidx==9)
149 labelcol = black;
150 ChainScaleMapOrImg(ismap, im, x, y, pmmd, 0, 0,
151 gdImageColorAllocate(im, r, g, b), labelcol, File);
152 }
153
154 } /* AM_DNA | AM_RNA */
155
156 } /* end nucleotide Chains */
157
158 } /* end maxseqlen */
159
160 return(y);
161
162 } /* end of ModelMapOrImg */
163
164
165
166 Int4
DrawImg(Int4Ptr Uid,Int2 chain1,Int2 chain2,Int2 imgsize)167 DrawImg(Int4Ptr Uid, Int2 chain1, Int2 chain2, Int2 imgsize)
168 {
169 Boolean hasDomain = FALSE;
170 BiostrucFeaturePtr domain_bfp;
171 BiostrucPtr bsp=NULL;
172 gdImagePtr im;
173 Int4 i, uid, cnt, *DomIdx;
174 IntervalHead *tmp_head;
175 PDNMS ModelStruc=NULL;
176 PDNMM pdnmm, pdnmm1;
177 PMSD pmsd;
178 IntervalHead **DomHead;
179
180 uid = *Uid;
181
182 bsp = openBSP(uid, 3, 0, TRUE, FALSE, FALSE, &psok, Database);
183 if (!bsp) {
184 Char str[10];
185
186 sprintf(str, "%d", uid);
187 PrtMes(NULL, "MMDBSRV (MMDBGraph)",
188 "No such structure available in MMDB: uid = ", str, TRUE);
189 return 0;
190 }
191
192 ModelStruc = MakeAModelstruc(bsp);
193 pmsd = (PMSD) ModelStruc->data.ptrvalue;
194 pdnmm = pmsd->pdnmmHead;
195 cnt = ChainCount(pmsd);
196 if (!cnt) return 0;
197
198 ColorIdx = (Int4Ptr) MemNew (cnt * sizeof(Int4));
199 DomHead = (IntervalHead **) MemNew (cnt * sizeof(IntervalHead *));
200 for (i=0; i< cnt; i++) {
201 ColorIdx[i] = -1;
202 DomHead[i] = NULL;
203 }
204 CalDomIdx(pdnmm, &DomIdx);
205
206 GetDomFeaPtr(bsp, &hasDomain, &domain_bfp);
207 CheckDomColIdx(domain_bfp, pdnmm, DomHead, DomIdx, ColorIdx, hasDomain, TRUE);
208
209 GroupingChains(pmsd);
210
211 im = gdImageCreate(GraphWidth, imgsize);
212 white = gdImageColorAllocate(im, 255, 255, 255);
213 black = gdImageColorAllocate(im, 0, 0, 0);
214 blue = gdImageColorAllocate(im, 0, 0, 225);
215 red = gdImageColorAllocate(im, 255, 0, 0);
216 gray = gdImageColorAllocate(im, (Uint1)102, (Uint1)102, (Uint1)102);
217
218 printf("Content-type: image/gif\n\n");
219 ModelMapOrImg(FALSE, im, uid,pmsd, chain1, chain2,DomHead,DomIdx,NULL);
220 gdImageGif(im, stdout);
221 gdImageDestroy(im);
222
223 free(ColorIdx);
224 for (i = 0; i< cnt; i++)
225 if (DomHead[i] != NULL) {
226 for (tmp_head = DomHead[i]; tmp_head != NULL;
227 tmp_head=tmp_head->next)
228 free(tmp_head);
229 free(DomHead[i]);
230 }
231 free(DomHead);
232 MemFree(DomIdx);
233 return 0;
234
235 } /* end DrawImg */
236
237
238
239