JPRED-2 Add alscript to the Git repository
[jpred.git] / sources / alscript / src / alscript.c
1 /****************************************************************************
2
3  ALSCRIPT - Sequence alignment to PostScript
4
5    Copyright:  Geoffrey J. Barton (1992,1993,1997)
6    email: geoff@ebi.ac.uk
7
8    Please see the file README for limitations on the use of this program.
9
10 All use of this program must cite:  Barton, G. J. (1993), ALSCRIPT: A Tool to
11 Format Multiple Sequence Alignments, Protein Engineering, Volume 6, No. 1, 
12 pp. 37-40.
13
14  $Id: alscript.c,v 1.2 1998/09/17 16:54:59 geoff Exp $
15  $Log: alscript.c,v $
16  Revision 1.2  1998/09/17 16:54:59  geoff
17  Check consistency with archive
18
19
20 ****************************************************************************
21
22 ALSCRIPT is a program for producing pretty versions of multiple sequence aligments.
23 ALSCRIPT will also format single sequences.
24 A full description of the program is given in the file "alscript.doc".
25
26 Ways of running alscript:
27
28 1.  Interactive mode:  just type alscript.
29     You will be prompted for a command file name.  The command file will
30     define the AMPS blocfile, and name of the file to store the PostScript
31     output - see alscript.doc for details.
32     
33 2.  alscript <command_file> has same effect as 1, But does not prompt for the command file
34     e.g.  alscript example1.com
35
36 3.  alscript -q < <blocfile> > <PostScript>
37     Quick mode - uses default commands, reads alignment from stdin, writes PostScript
38     to stdout.
39     e.g. alscript -q < example1.blc > example1.ps
40     
41 4.  alscript -f <command_file>
42     Similar effect to 2.
43
44 5.  alscript -f <command_file> -s
45     Silent operation:  No messages are written to stderr, unless fatal.
46     Silent operation may be toggled by the silent_mode command in the command file.
47
48 6.  alscript -f <command_file> -p < <blocfile> > <PostScript>
49     Make alscript work like a pipe - blocfile is read from stdin, postscript is written
50     to stdout.  Messages are written to stderr.  To supress messages include
51     the -s flag too
52     e.g. alscript -f example1.com -p -s < example1.blc > example1.ps
53
54 Using alscript as a pipe has the advantage of allowing the blocfile to
55 be created on the fly by the programs msf2blc or clus2blc.  For example
56 if we have a GCG .msf file called "pileup.msf" we can run alscript with
57 default shading/fonts and send the results straight to the PostScript
58 printer "lpr" as follows:
59
60 msf2blc -q < pileup.msf | alscript -q -s | lpr
61
62 See alps.c for revision history;
63 fprintf(std_err,"\n Version 2.0 - 23 May 1995\n");
64
65 */
66
67 #include <stdio.h>
68 #include <stdlib.h>
69 #include <string.h>
70 #include "array.h"
71 #include "gjutil.h"
72 #include "version.h"
73
74 int MAXtlen = 500;
75 int MAXnbloc = 500;
76 int MAXilen = 50;
77 int precis = 100;
78 int MAXslen = 8000;
79 int MAXnseq;
80
81 void ALwritestddefs(FILE *);
82 int alps(char *command_file,int silent, int pipe, int single);
83
84 main(int argc,char *argv[])
85 {
86   char *alps_file;
87   int silent;
88   int quick;
89   int i;
90   int pipe;
91   int singlepage; /* flag for EPS output */
92   FILE *fp;
93   char *Alscript_Version = ALSCRIPT_VERSION;
94
95   extern FILE *std_out,*std_err,*std_in;
96
97   silent = 0;
98   quick = 0;
99   pipe = 0;
100
101   alps_file = NULL;
102   
103   /* initialize the file streams for GJ... routines */
104   GJinitfile();
105
106   singlepage = 0;
107   
108   if(argc > 1){
109     /* check for -f option - if present, then define name for command file */
110     i = 1;
111     while(i<argc){
112         if(argv[i][0] == '-'){
113             if(strcmp(argv[i],"-f")==0){
114                 /* command file name */
115                 alps_file = GJstrdup(argv[++i]);
116             }else if(strcmp(argv[i],"-s")==0){
117                 /* silent mode */
118                 silent = 1;
119             }else if(strcmp(argv[i],"-q")==0){
120                 /* quick mode - defines its own command file */
121                 quick = 1;
122                 pipe = 1;
123             }else if(strcmp(argv[i],"-p")==0){
124                 /* send all output to std_out rather than the file defined in the command file */
125                 pipe = 1;
126                 silent = 1;
127             }else if(strcmp(argv[i],"-single")==0){
128                 /* single page mode - will generate a BoundingBox */
129                 singlepage = 1;
130             }
131             ++i;
132         }else if(i == 1){
133             /* we have just defined the alscript command file */
134             alps_file = GJstrdup(argv[1]);
135             break;
136         }
137     }
138   }
139
140   if(!silent){    
141     fprintf(std_err,"\nALSCRIPT  (ALignment to PostScript)\n");
142
143     fprintf(std_err,"%s\n",Alscript_Version);
144     fprintf(std_err,"\nSee ALSCRIPT.DOC for details\n");
145
146     fprintf(std_err,"\nPlease Reference: Barton, G. J. (1993), Protein Engineering, 6, 37-40.\n");
147
148     fprintf(std_err,"\nBy: G. J. Barton\n");
149     fprintf(std_err,"\nCopyright: Geoffrey J. Barton (1992,1997)\n");
150     fprintf(std_err,"email: geoff@ebi.ac.uk\n\n");
151
152     fprintf(std_err,"Initial Defaults:\n");
153     fprintf(std_err,"Maximum number of sequences:\t %d \t(Change using MAX_NSEQ command)\n",MAXnbloc);
154     fprintf(std_err,"Maximum sequence length:\t %d \t(Change using MAX_SEQ_LEN command)\n",MAXslen);
155     fprintf(std_err,"Maximum identifier length:\t %d \t(Change using MAX_ID_LEN command)\n",MAXilen);
156   }
157
158   if(alps_file == NULL && !quick){
159     fprintf(std_err,"Enter ALscript Command File name: ");
160     alps_file = (char *) GJmalloc(sizeof(char) * MAXtlen);
161     fscanf(std_in,"%s",alps_file);
162   }
163
164   if(quick){
165     /* create an alscript command file */
166     fp = GJfopen("ALPSQ.COM","w",1);
167     ALwritestddefs(fp);
168     GJfclose(fp,1);
169     alps_file = GJstrdup("ALPSQ.COM");
170   }
171
172   if(!silent)fprintf(std_err,"ALscript Command File: %s\n",alps_file);
173
174   if(alps(alps_file,silent,pipe,singlepage) == 1){
175     if(!silent)fprintf(std_err,"ALscript Finished\n");
176     exit(0);
177   }else{
178     error("Error in ALscript",1);
179   }
180 }
181
182 /* Write an alscript command file with some standard definitions */
183
184 void ALwritestddefs(FILE *alps_file)
185 {
186     fprintf(alps_file,"#ALSCRIPT - Default definitions\n");
187     fprintf(alps_file,"#For explanation of commands see file: alscript.doc\n");
188     fprintf(alps_file,"#Input from stdin and output to stdout by default\n");
189     fprintf(alps_file,"#block_file ?\n");
190     fprintf(alps_file,"#output_file ?\n");
191     fprintf(alps_file,"landscape\n");
192     fprintf(alps_file,"number_seqs\n");
193     fprintf(alps_file,"pointsize 8\n");
194     fprintf(alps_file,"define_font 0 Helvetica DEFAULT\n");
195     fprintf(alps_file,"define_font 1 Helvetica REL 0.5 \n");
196     fprintf(alps_file,"define_font 2 Helvetica-Bold DEFAULT\n");
197     fprintf(alps_file,"define_font 3 Times-Bold DEFAULT\n");
198     fprintf(alps_file,"define_font 4 Helvetica-BoldOblique DEFAULT\n");
199     fprintf(alps_file,"setup\n");
200     fprintf(alps_file,"mask SETUP\n");
201     fprintf(alps_file,"mask LEGAL \"ARNDCQEGHILKMFPSTWYVBZX\"\n");    
202     fprintf(alps_file,"mask FRE ALL\n");
203     fprintf(alps_file,"mask SHADE ALL 0\n");
204     fprintf(alps_file,"mask INVERSE ALL\n");
205     fprintf(alps_file,"mask SHADE ALL 0\n");
206     fprintf(alps_file,"mask RESET\n");
207     fprintf(alps_file,"#shade_chars GP ALL 0\n");
208     fprintf(alps_file,"#inverse_chars GP ALL \n");
209     fprintf(alps_file,"#shade_chars LIVAWYFM ALL 0.8 \n");
210     fprintf(alps_file,"font_chars DEKRH ALL 4\n");
211 }
212
213
214
215
216
217
218
219
220
221
222
223