1 /* dispn.c associated subroutines for matching sequences */
3 /* $Name: fa_34_26_5 $ - $Id: c_dispn.c,v 1.21 2005/10/25 20:22:52 wrp Exp $ */
21 /* the seqca[] array has the following codes:
22 0 - no alignment symbol
29 the map_sym arrays determine the value to be displayed with each
30 type of aligned residue
33 static char *map_sym_0 =" ..: ";
34 static char *map_sym_1 =" Xxx ";
35 static char *map_sym_2 =" . ";
37 static char *map_sym_10=" mzp=-";
39 static char *map_sym_10=" ..:-";
43 discons(FILE *fd, struct mngmsg m_msg, struct pstruct pst,
44 char *seqc0, char *seqc0a, char *seqc1, char *seqca, int nc,
45 int n0, int n1, char *name0, char *name1, int nml,
46 struct a_struct *aln, long loffset)
48 char line[3][MAXOUT], cline[2][MAXOUT+10], *clinep[2];
49 int il, i, lend, loff, id;
50 int del0, del1, ic, ll0, ll1, ll01, cl0, cl1, rl0, rl1;
54 int ioff0, ioff00, ioff1, ioff10;
55 long qqoff, lloff, qoffset;
56 int llsgn, llfact, qlsgn, qlfact, qfx0, qfxn, lfx0, lfxn;
59 char blank[MAX_UID], afmt[32];
61 memset(blank,' ',sizeof(blank)-1);
62 blank[sizeof(blank)-1]='\0';
66 sprintf(afmt,"%%-%ds %%s\n",nml);
70 strncpy(afmt,"%-6s %s\n",sizeof(afmt));
72 if (pst.ext_sq_set) sq = pst.sqx; else sq = pst.sq;
77 if (aln->qlfact == 0) {qlfact = 1;}
78 else qlfact = aln->qlfact;
79 if (aln->qlrev == 1) {
92 if (aln->llfact == 0) {llfact = 1;}
93 else llfact = aln->llfact;
95 if (aln->llrev == 1) {
108 if ((m_msg.markx & MX_M9SUMM) && m_msg.show_code != 1) { l_llen += 40; }
110 if ((m_msg.markx & MX_ATYPE)==2) name01=name1;
118 if (m_msg.markx& MX_AMAP && (m_msg.markx & MX_ATYPE)==7) return;
120 /* set *map_sym_p to correct match symbol */
121 if ((m_msg.markx&MX_ATYPE)==1) {map_sym_p = map_sym_1;}
122 else if ((m_msg.markx&MX_ATYPE)==2) {map_sym_p = map_sym_2;}
123 else if (m_msg.markx&MX_M10FORM) {map_sym_p = map_sym_10;}
124 else {map_sym_p = map_sym_0;}
126 if (m_msg.markx & MX_ASEP) {
127 fprintf(fd,">%s ..\n",name0);
128 for (i=0; i<nc && seqc0[i]; i++) {
129 /* if (seqc0[i]=='-') fputc('.',fd); else */
131 if (i%50 == 49) fputc('\n',fd);
133 if ((i-1)%50 != 49) fputc('\n',fd);
134 fprintf(fd,">%s ..\n",name1);
135 for (i=0; i<nc && seqc1[i]; i++) {
136 /* if (seqc1[i]=='-') fputc('.',fd); else */
138 if (i%50 == 49) fputc('\n',fd);
140 if ((i-1)%50 != 49) fputc('\n',fd);
144 if (m_msg.markx & MX_M10FORM) {
145 fprintf(fd,">%s ..\n",name0);
146 fprintf(fd,"; sq_len: %d\n",n0);
147 fprintf(fd,"; sq_offset: %ld\n",m_msg.sq0off);
148 fprintf(fd,"; sq_type: %c\n",m_msg.sqtype[0]);
149 fprintf(fd,"; al_start: %ld\n",aln->d_start0);
150 fprintf(fd,"; al_stop: %ld\n",aln->d_stop0);
151 fprintf(fd,"; al_display_start: %ld\n",
152 qoffset+qlsgn*ioff0*aln->llmult+qfx0);
155 for (i=0; i<nc && seqc0[i]; i++) {
156 if (!have_res && seqc0[i]==' ') fputc('-',fd);
157 else if (seqc0[i]==' ') break;
162 if (i%50 == 49) fputc('\n',fd);
164 if ((i-1)%50!=49 || seqc0[i-1]==' ') fputc('\n',fd);
165 fprintf(fd,">%s ..\n",name1);
166 fprintf(fd,"; sq_len: %d\n",n1);
167 fprintf(fd,"; sq_type: %c\n",m_msg.sqtype[0]);
168 fprintf(fd,"; al_start: %ld\n",aln->d_start1);
169 fprintf(fd,"; al_stop: %ld\n",aln->d_stop1);
170 fprintf(fd,"; al_display_start: %ld\n",loffset+llsgn*ioff1+lfx0);
173 for (i=0; i<nc && seqc1[i]; i++) {
174 if (!have_res && seqc1[i]==' ') fputc('-',fd);
175 else if (seqc1[i]==' ') break;
180 if (i%50 == 49) fputc('\n',fd);
182 if ((i-1)%50!=49 || seqc1[i-1]==' ') fputc('\n',fd);
184 fprintf(fd,"; al_cons:\n");
185 for (i=0,del0=0,id=ioff0; id-del0<aln->amax0 && i < nc; i++,id++) {
186 if (seqc0[i] == '\0' || seqc1[i] == '\0') break;
187 if (seqc0[i]=='-' || seqc0[i]==' ' || seqc0[i]=='\\') del0++;
188 else if (seqc0[i]=='/') del0++;
189 if (id-del0<aln->amin0) fputc(' ',fd);
190 else if (seqc0[i]=='-'||seqc1[i]=='-') fputc('-',fd);
191 else fputc(map_sym_10[seqca[i]],fd);
193 if (i%50 == 49) fputc('\n',fd);
195 if ((i-1)%50!=49 || seqc1[i-1]==' ') fputc('\n',fd);
200 memset(line[0],' ',MAXOUT);
201 memset(line[1],' ',MAXOUT);
202 memset(line[2],' ',MAXOUT);
204 /* cl0 indicates whether a coordinate should be printed over the first
205 sequence; cl1 indicates a coordinate for the second;
209 for (il=0; il<(nc+l_llen-1)/l_llen; il++) {
211 lend=min(l_llen,nc-loff);
215 memset(cline[0],' ',MAXOUT+1);
216 memset(cline[1],' ',MAXOUT+1);
219 for (i=0; i<lend; i++, ic++,ioff0++,ioff1++) {
220 cl0 = cl1 = rl0 = rl1 = YES;
221 if ((line[0][i]=seqc0[ic])=='-' || seqc0[ic]=='\\') {
224 else if (seqc0[ic]=='/') {
227 if ((line[2][i]=seqc1[ic])=='-' || seqc1[ic]=='\\') {
230 else if (seqc1[ic]=='/') {
234 if (seqc0[ic]==' ') {del0++; cl0=rl0=NO;}
236 if (seqc1[ic]==' ') {del1++; cl1=rl1=NO;}
239 qqoff = m_msg.sq0off - 1 + qoffset + (long)qlsgn*ioff00 +
240 (long)qlsgn*qlfact*(ioff0-del0-ioff00);
241 if (cl0 && qqoff%10 == 9) {
242 sprintf(&clinep[0][i-qfxn],"%8ld",qqoff+1l);
243 clinep[0][i+8-qfxn]=' ';
246 else if (cl0 && qqoff== -1) {
247 sprintf(&clinep[0][i-qfxn],"%8ld",0l);
248 clinep[0][i+8-qfxn]=' ';
251 else if (rl0 && (qqoff+1)%10 == 0) {
252 sprintf(&clinep[0][i-qfxn],"%8ld",qqoff+1);
253 clinep[0][i+8-qfxn]=' ';
256 /* the lloff coordinate of a residue is the sum of:
257 m_msg.sq1off-1 - the user defined coordinate
258 loffset - the offset into the library sequence
259 llsgn*ioff10 - the offset into the beginning of the alignment
260 (given in the "natural" coordinate system,
261 except for tfasta3 which provides context)
262 llsgn*llfact*(ioff1-del1-ioff10)
263 - the position in the consensus aligment, -gaps
266 lloff = m_msg.sq1off-1 + loffset + aln->frame +
267 (long)llsgn*aln->llmult*ioff10 +
268 (long)llsgn*llfact*(ioff1-del1-ioff10);
270 if (cl1 && lloff%10 == 9) {
271 sprintf(&clinep[1][i-lfxn],"%8ld",lloff+1l);
272 clinep[1][i+8-lfxn]=' ';
275 else if (cl1 && lloff== -1) {
276 sprintf(&clinep[1][i],"%8ld",0l);
277 clinep[1][i+8-lfxn]=' ';
280 else if (rl1 && (lloff+1)%10 == 0) {
281 sprintf(&clinep[1][i-lfxn],"%8ld",lloff+1);
282 clinep[1][i+8-lfxn]=' ';
286 if (ioff0-del0 >= aln->amin0 && ioff0-del0 <= aln->amax0) {
287 if (seqca[ic]==4) {line[1][i]=map_sym_p[4];}
288 else if ((m_msg.markx&MX_ATYPE)==2) line[1][i]=line[2][i];
289 else line[1][i] = map_sym_p[seqca[ic]];
291 else if ((m_msg.markx&MX_ATYPE)==2) line[1][i]=line[2][i];
295 for (ic=ic_save,i=0; i<lend; ic++,i++) {
296 if (seqc0a[ic]!= ' ') clinep[0][i+7-qfxn] = seqc0a[ic];
300 line[0][lend]=line[1][lend]=line[2][lend]=0;
301 clinep[0][lend+7]=clinep[1][lend+7]=0;
304 if ((m_msg.markx&MX_ATYPE)==2 && (!aln->showall || ll0)) ll1=0;
306 if (ll0) fprintf(fd,"%s%s\n",blank,clinep[0]);
307 if (ll0) fprintf(fd,afmt,name0,line[0]);
308 if (ll01) fprintf(fd,afmt,name01,line[1]);
309 if (ll1) fprintf(fd,afmt,name1,line[2]);
310 if (ll1) fprintf(fd,"%s%s\n",blank,clinep[1]);
314 static float gscale= -1.0;
317 disgraph(FILE *fd, int n0,int n1, float percent, int score,
318 int min0, int min1, int max0, int max1, long sq0off,
319 char *name0, char *name1, int nml,
322 int i, gstart, gstop, gend;
325 char afmt[16], afmtf[64];
328 sprintf(afmt,"%%-%ds",nml);
331 strncpy(afmt,"%-6s",sizeof(afmt));
333 strncpy(afmtf,afmt,sizeof(afmtf));
334 strncat(afmtf," %4ld-%4ld: %5.1f%%:%s:\n",sizeof(afmtf));
337 memset(line,' ',llen);
341 gscale = (float)llen/(float)n0;
342 if ((markx&MX_ATYPE) == 7 )
343 fprintf(fd,afmtf,name0,sq0off,sq0off+n0-1,100.0,line);
346 gstart = (int)(gscale*(float)min0+0.5);
347 gstop = (int)(gscale*(float)max0+0.5);
348 gend = gstop+(int)(gscale*(float)(n1-max1));
350 if (gstop >= llen) gstop = llen-1;
351 if (gend >= llen) gend = llen-1;
352 for (i=0; i<gstart; i++) line[i]=' ';
353 for (; i<gstop; i++) line[i]='-';
354 for (; i<llen; i++) line[i]=' ';
359 if (markx & MX_AMAP) {
360 if ((markx & MX_ATYPE)==7) { /* markx==4 - no alignment */
361 strncpy(afmtf,afmt,sizeof(afmtf));
362 strncat(afmtf," %4ld-%4ld:%4d %5.1f%%:%s\n",sizeof(afmtf));
363 fprintf(fd,afmtf,name1,min0+sq0off,max0+sq0off-1,score,percent,line);
367 strncpy(&afmtf[1],afmt,sizeof(afmtf)-1);
368 strncat(afmtf," %4ld-%4ld:%s\n",sizeof(afmtf));
369 fprintf(fd,afmtf, name1,min0+sq0off,max0+sq0off-1,line);
375 aancpy(char *to, char *from, int count, struct pstruct pst)
380 if (pst.ext_sq_set) {
390 while (count-- && *from) {
391 if (*from <= nsq) *tp++ = sq[*(from++)];
392 else *tp++ = *from++;
398 r_memcpy(dest,src,cnt)
402 while (cnt--) *dest++ = *src++;
406 l_memcpy(dest,src,cnt)
412 while (cnt--) *--dest = *--src;
415 /* this routine now indexs from 1 (rather than 0) because sq starts
418 #define MAXSQ 50 /* must be same as upam.h */
420 void cal_coord(int n0, int n1, long sq0off, long loffset,
421 struct a_struct *aln)
424 int llsgn, qlsgn, qfx0, qfxn, lfx0, lfxn;
426 if (aln->qlrev == 1) {
427 qoffset = sq0off -1 + n0;
433 qoffset = sq0off - 1;
439 if (aln->llrev == 1) {
450 aln->d_start0 = qoffset+qlsgn*aln->amin0+qfx0;
451 aln->d_stop0 = qoffset+qlsgn*aln->amax0+qfxn;
452 aln->d_start1 = loffset+llsgn*aln->amin1*aln->llmult+lfx0+aln->frame;
453 aln->d_stop1 = loffset+llsgn*aln->amax1*aln->llmult+lfxn+aln->frame;