JPRED-2 Add alscript to the Git repository
[jpred.git] / sources / alscript / src / alsnum.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include "gjutil.h"
4 #include "array.h"
5
6 int Agetbloc(FILE *,struct seqdat *,int *);
7
8 int MAXtlen = 500;
9 int MAXnbloc = 500;
10 int MAXilen = 50;
11 int precis = 100;
12 int MAXslen = 8000;
13 int MAXnseq;
14
15 /* alsnum:  Aim - produce TEXT commands for ALSCRIPT that will generate numbers
16    corresponding to a given sequence in the blockfile.
17
18    Usage:
19
20    alsnum  <seqnum> <startnum> <interval> <position> < blockfile > output
21
22    Where:
23
24    seqnum:    The number of the sequence in the blockfile.
25    
26    startnum:  The number to use for the first residue in the sequence (e.g. 1).
27
28    interval:  The numbering interval (e.g. 10).
29
30    position:  Where to place the text in the alscript output (ie the Y coordinate).
31
32
33    ALL ARGUMENTS ARE REQUIRED
34
35
36    G. J. Barton (25 May 1993).
37
38    $Id: alsnum.c,v 1.2 1998/09/17 16:54:59 geoff Exp $
39    $Log: alsnum.c,v $
40    Revision 1.2  1998/09/17 16:54:59  geoff
41    Check consistency with archive
42
43
44 */
45
46 main(int argc,char *argv[])
47
48 {
49
50   extern FILE *std_in,*std_out,*std_err;
51   extern int MAXtlen,MAXnbloc;
52   extern int MAXilen,precis,MAXslen;
53
54   int seqnum,startnum,interval,position;
55   int nseq;
56   int *nums;
57   int nval;
58   int i;
59
60   struct seqdat *bloc;
61
62   GJinitfile();
63
64   if(argc != 5){
65     fprintf(std_err,
66     "Usage:    alsnum  <seqnum> <startnum> <interval> <position> < blockfile > output\n");
67     exit(0);
68   }
69
70   seqnum = atoi(argv[1]);
71   startnum = atoi(argv[2]);
72   interval = atoi(argv[3]);
73   position = atoi(argv[4]);
74
75   nseq = 0;
76   bloc = (struct seqdat *) malloc(sizeof(struct seqdat) * MAXnbloc);
77   mcheck((char *) bloc,"Cannot get space for bloc");
78   if(!Agetbloc(std_in,bloc,&nseq))error("Cannot read bloc file",1); 
79
80   /* have read block file */
81
82   nums = (int *) GJmalloc(sizeof(int) * bloc[seqnum].slen);
83
84   nval = startnum;
85
86   /* get the array of numbers - use blank . or - as non-amino acid character */
87   for(i=1;i<bloc[seqnum].slen-1;++i){
88     if(bloc[seqnum].seq[i] == ' ' ||
89        bloc[seqnum].seq[i] == '.' ||
90        bloc[seqnum].seq[i] == '-' ){
91       nums[i] = 0;
92     }else{
93       nums[i] = nval;
94       ++nval;
95     }
96   }
97
98   
99   /* now go down the array and output TEXT commands at interval intervals */
100
101   fprintf(std_out,"# Text commands created for numbering\n");
102   fprintf(std_out,"# Sequence Number: %d\n",seqnum);
103   fprintf(std_out,"# Starting Number: %d\n",startnum);
104   fprintf(std_out,"# Interval:        %d\n",interval);
105   fprintf(std_out,"# Position:        %d\n",position);
106   
107   for(i=1;i<bloc[seqnum].slen-1;++i){
108     if(nums[i] != 0 && (float) (nums[i]/interval) == (float)nums[i]/(float)interval){
109       fprintf(std_out,"TEXT %d %d \"%d\"\n",i,position,nums[i]);
110     }
111   }
112
113   exit(0);
114 }
115   
116
117
118
119
120
121
122
123
124