1 /* @source pepnet application
2 **
3 ** Displays proteins as a helical net
4 ** @author Copyright (C) Alan Bleasby (ableasby@hgmp.mrc.ac.uk)
5 ** @@
6 **
7 ** Original program "PEPNET" in EGCG
8 ** This program is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License
10 ** as published by the Free Software Foundation; either version 2
11 ** of the License, or (at your option) any later version.
12 **
13 ** This program is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with this program; if not, write to the Free Software
20 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 ******************************************************************************/
22
23 #include "emboss.h"
24 #include <math.h>
25 #include <string.h>
26
27
28
29
30 static void pepnet_plotresidue(char c, float x, float y, const char *squares,
31 const char *circles, const char *diamonds);
32 static void pepnet_drawocta(float x, float y, float size);
33
34
35
36
37 /* @prog pepnet ***************************************************************
38 **
39 ** Displays proteins as a helical net
40 **
41 ******************************************************************************/
42
main(int argc,char ** argv)43 int main(int argc, char **argv)
44 {
45 AjPSeq seq = NULL;
46 AjPStr strand = NULL;
47 AjPStr substr = NULL;
48 AjPStr squares = NULL;
49 AjPStr diamonds = NULL;
50 AjPStr octags = NULL;
51 AjBool amphipathic;
52 AjPStr txt = NULL;
53 AjPGraph graph = NULL;
54
55 ajint begin;
56 ajint end;
57
58 ajint lc;
59
60 ajint i;
61 ajint j;
62 ajint r;
63
64 ajint count;
65 ajint pstart;
66 ajint pstop;
67
68 float xmin = 0.0;
69 float xmax = 150.0;
70 float ymin = 0.0;
71 float ymax = 112.5;
72
73 float xstart;
74 float ystart;
75 float ch = (float)1.8;
76 float xinc;
77 float yinc;
78 AjPStr fstr = NULL;
79
80 float x;
81 float y;
82
83
84 embInit("pepnet", argc, argv);
85
86
87 seq = ajAcdGetSeq("sequence");
88 graph = ajAcdGetGraph("graph");
89 octags = ajAcdGetString("octags");
90 squares = ajAcdGetString("squares");
91 diamonds = ajAcdGetString("diamonds");
92 amphipathic = ajAcdGetToggle("amphipathic");
93
94 ajStrFmtUpper(&octags);
95 ajStrFmtUpper(&squares);
96 ajStrFmtUpper(&diamonds);
97
98 if(amphipathic)
99 {
100 ajStrAssignC(&squares,"ACFGILMVWY");
101 ajStrAssignC(&diamonds,"");
102 ajStrAssignC(&octags,"");
103 }
104
105
106 substr = ajStrNew();
107 txt = ajStrNew();
108 fstr = ajStrNew();
109
110
111
112
113 begin = ajSeqGetBegin(seq);
114 end = ajSeqGetEnd(seq);
115
116 strand = ajSeqGetSeqCopyS(seq);
117
118 ajStrFmtUpper(&strand);
119 ajStrAssignSubC(&substr,ajStrGetPtr(strand),begin-1,end-1);
120
121 ajGraphAppendTitleS(graph, ajSeqGetUsaS(seq));
122
123 ajGraphOpenWin(graph, xmin,xmax,ymin,ymax);
124
125 for(count=begin-1,r=0;count<end;count+=231)
126 {
127 if (count > begin)
128 ajGraphNewpage(graph, ajFalse);
129 pstart=count;
130 pstop = AJMIN(end-1, count+230);
131
132 ajGraphicsSetCharscale(0.75);
133
134 xstart = 145.0;
135 ystart = 80.0;
136
137 yinc = ch * (float)2.5;
138 xinc = yinc / (float)2.5;
139
140 x = xstart;
141
142 for(i=pstart;i<=pstop;i+=7)
143 {
144 lc = i;
145 if(x < 10.0*xinc)
146 {
147 x = xstart;
148 ystart -= (float)7.5*yinc;
149 }
150 y=ystart;
151
152 ajFmtPrintS(&txt,"%d",i+1);
153
154 ajGraphicsSetFgcolour(RED);
155 ajGraphicsDrawposTextJustify(x-xinc,y-yinc-1,ajStrGetPtr(txt),0.5);
156
157 for(j=0;j<4;++j)
158 {
159 x -= xinc;
160 y += yinc;
161 if(lc <= pstop)
162 pepnet_plotresidue(*(ajStrGetPtr(substr)+r),x,y,
163 ajStrGetPtr(squares),ajStrGetPtr(octags),
164 ajStrGetPtr(diamonds));
165 ++r;
166 ++lc;
167 }
168 y=ystart+yinc/(float)2.0;
169
170 for(j=4;j<7;++j)
171 {
172 x -= xinc;
173 y += yinc;
174 if(lc <= pstop)
175 pepnet_plotresidue(*(ajStrGetPtr(substr)+r),x,y,
176 ajStrGetPtr(squares),ajStrGetPtr(octags),
177 ajStrGetPtr(diamonds));
178 ++r;
179 ++lc;
180 }
181 }
182 }
183
184 ajGraphicsClose();
185 ajGraphxyDel(&graph);
186
187 ajStrDel(&strand);
188 ajStrDel(&fstr);
189
190 ajSeqDel(&seq);
191 ajStrDel(&substr);
192
193 ajStrDel(&squares);
194 ajStrDel(&diamonds);
195 ajStrDel(&octags);
196 ajStrDel(&txt);
197
198 embExit();
199
200 return 0;
201 }
202
203
204
205
206 /* @funcstatic pepnet_drawocta ************************************************
207 **
208 ** Draw an octagon
209 **
210 ** @param [r] x [float] xpos
211 ** @param [r] y [float] xpos
212 ** @param [r] size [float] size
213 ** @@
214 ******************************************************************************/
215
pepnet_drawocta(float x,float y,float size)216 static void pepnet_drawocta(float x, float y, float size)
217 {
218 static float polyx[]=
219 {
220 (float)-0.05, (float)0.05, (float)0.1, (float)0.1, (float)0.05,
221 (float)-0.05, (float)-0.1, (float)-0.1, (float)-0.05
222 };
223 static float polyy[]=
224 {
225 (float)0.1, (float)0.1, (float)0.05, (float)-0.05, (float)-0.1,
226 (float)-0.1, (float)-0.05, (float)0.05, (float)0.1
227 };
228
229 ajint i;
230
231 for(i=0;i<8;++i)
232 ajGraphicsDrawposLine(x+polyx[i]*size,y+polyy[i]*size,x+polyx[i+1]*size,
233 y+polyy[i+1]*size);
234
235 return;
236 }
237
238
239
240
241 /* @funcstatic pepnet_plotresidue *********************************************
242 **
243 ** Plot a residue
244 **
245 ** @param [r] c [char] char to plot
246 ** @param [r] x [float] x coordinate
247 ** @param [r] y [float] y coordinate
248 ** @param [r] squares [const char*] residues for squares
249 ** @param [r] octags [const char*] residues for octagons
250 ** @param [r] diamonds [const char*] residues for diamonds
251 ** @@
252 ******************************************************************************/
253
pepnet_plotresidue(char c,float x,float y,const char * squares,const char * octags,const char * diamonds)254 static void pepnet_plotresidue(char c, float x, float y, const char *squares,
255 const char *octags, const char *diamonds)
256 {
257 static char cs[2];
258
259 cs[1] = '\0';
260 *cs=c;
261
262
263 ajGraphicsSetFgcolour(GREEN);
264
265 if(strstr(squares,cs))
266 {
267 ajGraphicsSetFgcolour(BLUE);
268 ajGraphicsDrawposBox(x-(float)1.5,y-(float)1.32,(float)3.0);
269 }
270
271 if(strstr(octags,cs))
272 {
273 ajGraphicsSetFgcolour(BLUEVIOLET);
274 pepnet_drawocta(x,y+(float)0.225,(float)20.0);
275 }
276
277 if(strstr(diamonds,cs))
278 {
279 ajGraphicsSetFgcolour(RED);
280 ajGraphicsDrawposDia(x-(float)2.5,y-(float)2.25,(float)5.0);
281 }
282
283 ajGraphicsDrawposTextJustify(x,y,cs,0.5);
284 ajGraphicsSetFgcolour(GREEN);
285
286 return;
287 }
288