source: tags/initial/GDE/MOLPHY/protst.c

Last change on this file was 2, checked in by oldcode, 24 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1/*
2 * protst.c   Adachi, J.   1996.03.12
3 * Copyright (C) 1993-1996 J. Adachi & M. Hasegawa, All rights reserved.
4 */
5
6#define MAIN_MODULE 1
7#include "protst.h"
8
9
10void
11copyright()
12{
13#ifndef NUC
14        fprintf(stderr, "ProtST %s (%s) ", VERSION, DATE );
15        fprintf(stderr, "Basic Statistics of Protein Sequences\n");
16#else
17        fprintf(stderr, "NucST %s (%s) ", VERSION, DATE );
18        fprintf(stderr, "Basic Statistics of Nucleic Acid Sequences\n");
19#endif
20        fprintf(stderr, "Copyright (C) 1993-1996 J. Adachi & M. Hasegawa. ");
21        fprintf(stderr, "All rights reserved.\n");
22/*      fprintf(stderr, "  ProtST comes with NO WARRANTY\n"); */
23}
24
25
26void
27usage()
28{
29        copyright();
30        fprintf(stderr, "Usage: %s [-%s] sequence_file\n", Prog_name, SWITCHES);
31        fprintf(stderr, " Help: %s -h\n", Prog_name);
32}
33
34
35void
36helpinfo()
37{
38        copyright();
39        fprintf(stderr,
40                "Usage: %s [switches] sequence_file\n",Prog_name);
41        fprintf(stderr, "Switches:\n");
42        fprintf(stderr, "-a      Alignments viewer\n");
43        fprintf(stderr, "-c num  column size\n");
44        fprintf(stderr, "-S      Sequential input format (PHYLIP)\n");
45        fprintf(stderr, "-I      Interleaved input format (other packages)\n");
46}
47
48static void prologue();
49static void pml();
50
51
52main(argc, argv)
53int argc;
54char **argv;
55{
56        FILE *seqfp;
57        int i, ch;
58        char **cpp;
59        extern int Optindex;   /* index of next argument */
60        extern char *Optargp;  /* pointer to argument of current option */
61
62        Tpmradix = TPMRADIX;
63        Ct0 = time(NULL);
64        if((Prog_name = strrchr(argv[0], DIR_CHAR)) != NULL )
65                Prog_name++;
66        else
67                Prog_name = argv[0];
68
69        while((ch = mygetopt(argc, argv, SWITCHES)) != -1 ) {
70                switch(ch) {
71                case 'a': Align_optn  = TRUE;  break;
72                case 'c': Colmn_optn = TRUE;
73                                cpp = &Optargp;
74                                if (i = strtol(Optargp, cpp, 10)) Maxcolumn = i;
75                                break;
76                case 'i': Info_optn   = TRUE;  break;
77                case 'I': Inlvd_optn  = TRUE;
78                          Seque_optn  = FALSE; break;
79                case 'L': Logfl_optn  = TRUE;  break;
80                case 'S': Seque_optn  = TRUE;
81                          Inlvd_optn  = FALSE; break;
82                case 'v': Verbs_optn  = TRUE;  break;
83                case 'w': Write_optn  = TRUE;  break;
84                case 'z': Debug_optn  = TRUE;  break;
85                case 'Z': Debug       = TRUE;  break;
86                case 'h':
87                case 'H': helpinfo(); exit(1);
88                default : usage(); exit(1);
89                }
90        }
91        if (Colmn_optn) {
92                Linesites  = ((Maxcolumn - 10) / 11) * 10;
93                Maxelement = ((Maxcolumn -  9) /  5);
94        } else {
95                Linesites  = LINESITES;
96                Maxelement = MAXELEMENT;
97        }
98
99#ifdef DEBUG
100        if (Debug) {
101                printf("argc = %d\n",argc);
102                for(i = 0; i < argc; i++) printf("argv[%d] = %s\n",i,argv[i]);
103                putchar('\n');
104                printf("\nOptindex = %d\n",Optindex);
105                printf("Optargp = %s\n",Optargp);
106        }
107#endif
108
109        if (Optindex == argc) {
110                seqfp = stdin;
111        } else if (Optindex + 1 == argc) {
112                if ((seqfp = fopen(argv[Optindex++], "r")) == NULL) {
113                        fprintf(stderr,"%s: can't open %s\n",Prog_name,argv[--Optindex]);
114                        exit(1);
115                }
116        } else {
117                fprintf(stderr, "%s: Inconsistent number of file in command line\n",
118                        Prog_name);
119                usage();
120                exit(1);
121        }
122        if (Logfl_optn) {
123                if ((Logfp = fopen(LOGFILE, "w")) == NULL) {
124                        fprintf(stderr,
125                                "%s: can't open log file: %s\n",Prog_name,LOGFILE);
126                        exit(1);
127                }
128        }
129
130        if (Verbs_optn) copyright();
131        prologue(seqfp, stdout);
132        if (seqfp != stdin) fclose(seqfp);
133        if (Logfl_optn) fclose(Logfp);
134
135        return 0;
136}
137
138
139/* #if 0 */
140/* void */
141/* header(ofp, maxspc, numsite, commentp) */
142/* FILE *ofp; */
143/* int *maxspc; */
144/* int *numsite; */
145/* char **commentp; */
146/* { */
147/*      time_t ct; */
148/*      char *datetime, *ip, *jp; */
149
150/*      fprintf(ofp, "%s %s  ", Prog_name, VERSION); */
151
152/*      ct = time(NULL); */
153/*      datetime = ctime(&ct); */
154/*      for (ip = datetime+11, jp = datetime+20; *jp != '\n'; ) *ip++ = *jp++; */
155/*      *ip = '\0'; */
156/*      fputs(datetime + 4, ofp); */
157/*      fputs("  ", ofp); */
158/*      fprintf(ofp, "  %d OTUs %d sites  %s\n", *maxspc, *numsite, *commentp); */
159/*      free_cvector(*commentp); */
160/* } /*_ header */ */
161/* #endif */
162
163 void
164header(ofp, maxspc, numsite, commentp)
165FILE *ofp;
166int *maxspc;
167int *numsite;
168char **commentp;
169{
170        char date[32];
171
172        strftime(date, 32, "%x", localtime(&Ct0));
173        fprintf(ofp, "%s %s(%s)", Prog_name, VERSION, date);
174        fprintf(ofp, " %d OTUs %d sites. %s\n", *maxspc, *numsite, *commentp);
175} /*_ header */
176
177
178static void
179prologue(ifp, ofp)
180FILE *ifp;
181FILE *ofp;
182{
183        ivector alias;
184        char *comment;
185
186        getsize(ifp, &Maxspc, &Maxsite, &comment);
187
188        header(ofp, &Maxspc, &Maxsite, &comment);
189        Identif = (char **)malloc((unsigned)Maxspc * sizeof(char *));
190        if (Identif == NULL) maerror("in prologue, Identif");
191        Sciname = (char **)malloc((unsigned)Maxspc * sizeof(char *));
192        if (Sciname == NULL) maerror("in prologue, Sciname");
193        Engname = (char **)malloc((unsigned)Maxspc * sizeof(char *));
194        if (Engname == NULL) maerror("in prologue, Engname");
195        Seqchar = new_cmatrix(Maxspc, Maxsite);
196        if (Seque_optn)
197                getseqs(ifp, Identif, Seqchar, Maxspc, Maxsite);
198        else if (Inlvd_optn)
199                getseqi(ifp, Identif, Seqchar, Maxspc, Maxsite);
200        else
201                getseq(ifp, Identif, Sciname, Engname, Seqchar, Maxspc, Maxsite);
202
203        getfreqepm(Seqchar, Freqemp, Maxspc, Maxsite);
204        alias = new_ivector(Maxsite);
205        radixsort(Seqchar, alias, Maxspc, Maxsite, &Numptrn);
206        Seqconint = new_imatrix(Maxspc, Numptrn);
207        Weight = new_ivector(Numptrn);
208        condenceseq(Seqchar, alias, Seqconint, Weight, Maxspc, Maxsite, Numptrn);
209        convseq(Seqconint, Maxspc, Numptrn);
210        free_ivector(alias);
211
212        Insdel = new_ivector(Maxsite);
213        seqinsdel(Seqchar, Maxspc, Maxsite, Insdel, &Numnoindel);
214
215        seqdiff(Seqchar, Maxspc, Maxsite, Insdel, Numnoindel);
216        if (!Align_optn && Maxspc > 28) putchar('\f');
217
218        seqfreq(Seqchar, Maxspc, Maxsite, Insdel, Numnoindel);
219/*      if (!Align_optn && Maxspc > 28) putchar('\f'); */
220
221        if (Info_optn) seqtran(Seqchar, Maxspc, Maxsite, Insdel, Numnoindel);
222/*      if (!Align_optn && Info_optn && Maxspc > 14) putchar('\f'); */
223
224        if (Align_optn) prsequence(ofp, Identif, Seqchar, Maxspc, Maxsite);
225        if (Write_optn && Info_optn && (Maxspc * Maxsite > 3600)) putchar('\f');
226
227        if (Write_optn && Info_optn)
228                prcondenceseq(Identif, Seqconint, Weight, Maxspc, Maxsite, Numptrn);
229
230        free_ivector(Insdel);
231}
Note: See TracBrowser for help on using the repository browser.