File: commline.c

package info (click to toggle)
codonw 1.4.4-4
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 1,060 kB
  • sloc: ansic: 11,227; makefile: 209; sh: 170; perl: 36
file content (755 lines) | stat: -rwxr-xr-x 32,502 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
/**************************************************************************/
/* CodonW codon usage analysis package                                    */
/* Copyright (C) 2005            John F. Peden                            */
/* This program is free software; you can redistribute                    */
/* it and/or modify it under the terms of the GNU General Public License  */
/* as published by the Free Software Foundation; version 2 of the         */
/* License,                                                               */
/*                                                                        */
/* This program is distributed in the hope that it will be useful, but    */
/* WITHOUT ANY WARRANTY; without even the implied warranty of             */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the           */
/* GNU General Public License for more details.                           */
/* You should have received a copy of the GNU General Public License along*/
/* with this program; if not, write to the Free Software Foundation, Inc.,*/
/* 675 Mass Ave, Cambridge, MA 02139, USA.                                */
/*                                                                        */
/*                                                                        */
/* The author can be contacted by email (jfp#hanson-codonw@yahoo.com Anti-*/
/* Spam please change the # in my email to an _)                          */
/*                                                                        */
/* For the latest version and information see                             */
/* http://codonw.sourceforge.net 					  */
/**************************************************************************/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include "codonW.h"

/************** process_command_line  *************************************/
/* The command line is passed to this function for processing. The name of*/
/* the programme is read, and based on this, CodonW will emulate several  */
/* useful codon usage analysis programmes routinely used in our laboratory*/
/* all other command line arguments are read. Unrecognised arguments are  */
/* reported to the user, arguments not preceded by a dash are assumed to  */
/* be filenames. The input, output and bulk output files to be precise    */
/**************************************************************************/
int proc_comm_line( int *pargc , char ***pargv)
{
    char    *p;
    char    c;
    int     n;
    char    prog_name[64];
    char    root[MAX_FILENAME_LEN];

/* decide how to process argc[0] which will be the name of the programme  */
#if defined (_WINDOWS) || defined (_DOS) || defined ( WIN32 )
    if ( (p = strrchr(**pargv, '\\')) != NULL )
        strncpy(prog_name, p+1 , 63);
    else
        strncpy(prog_name, **pargv, 10);
#elif defined (BSD) || defined(SYSV) || defined (UNIX)  || defined (LINUX) /* Must be unix   */
    if ( (p = strrchr(**pargv, '/')) != NULL )
        strncpy(prog_name, p+1, 63);
    else
        strncpy(prog_name, **pargv, 10);
#elif defined(VMS) || defined (OPENVMS)          /* maybe VMS or OPENVMS  */
    if ( (p = strrchr(**pargv, ']')) != NULL )
        strncpy(prog_name, p+1, 63);
    else
        strncpy(prog_name, **pargv, 10);
#else
    printf("UNRECOGNISED SYSTEM type won't be able to impersonate other programmes\n");
    strcpy(prog_name, "codon");	               /* OK I give up          */
#endif

  if ( (p = strrchr(prog_name, '.')) != NULL )  /* remove file extension  */
      *p = '\0';                                /* tidy.exe -> tidy       */

     /* first call to garg initialises the function  with the command line*/
     /* parameters and the number of arguments, subsequent calls strip    */
     /* these off one by one                                              */

     /* has the user asked for help               ????????????            */
  if ((p = garg(*pargc, *pargv, "-h", GARG_EXACT)) ||
      (p = garg(0, NULL, "-help", GARG_EXACT))){
      printf(
	       "codonW [inputfile] [outputfile] [bulkoutfile] [options]\n"
	       "General options and defaults:\n"
	       " -h(elp)\tThis help message\n"
	       " -nomenu\tPrevent the menu interface being displayed\n"
               " -nowarn\tPrevent warnings about sequences being displayed\n"
	       " -silent\tOverwrite files silently\n"
	       " -totals\tConcatenate all genes in inputfile\n"
	       " -machine\tMachine readable output\n"
	       " -human\t\tHuman readable output\n"
	       " -code N\tGenetic code as defined under menu 3 option 5\n"
	       " -f_type N\tFop/CBI codons as defined by menu 3 option 6\n"
	       " -c_type N\tCai fitness values as defined by menu 3 option 7\n"
	       " -t (char)\tColumn separator to be used in output files "
                    "(comma,tab,space)\n"
               "\nCodon usage indices and Amino acid indices \n"
	       " -cai\t\tcalculate Codon Adaptation Index (CAI)\n"
	       " -fop\t\tcalculate Frequency of OPtimal codons index (FOP)\n"
	       " -cbi\t\tcalculate Codon Bias Index (CBI)\n"
	       " -enc\t\tEffective Number of Codons (ENc)\n"
	       " -gc\t\tG+C content of gene (all 3 codon positions)\n"
	       " -gcs3\t\tGC of synonymous codons 3rd positions\n"
	       " -sil_base\tBase composition at synonymous third codon "
		   "positions\n"

               );
	pause;
	printf(
	       " -L_sym\t\tNumber of synonymous codons\n"
	       " -L_aa\t\tTotal number of synonymous and non-synonymous codons\n"
	       " -all_indices\t\tAll the above indices\n"
	       " -aro\t\tCalculate aromaticity of protein\n"
	       " -hyd\t\tCalculate hydropathicity of protein\n"
	       " -cai_file  {file}\tUser input file of CAI values\n"
	       " -cbi_file  {file}\tUser input file of CBI values\n"
	       " -fop_file  {file}\tUser input file of Fop values\n"
               "\nCorrespondence analysis (COA) options \n"
	       " -coa_cu \tCOA of codon usage frequencies\n"
	       " -coa_rscu\tCOA of Relative Synonymous Codon Usage\n"
	       " -coa_aa\tCOA of amino acid usage frequencies\n"
	       " -coa_expert\tGenerate detailed(expert) statistics on COA\n"
	       " -coa_axes N\tSelect number of axis to record\n"
	       " -coa_num N\tSelect number of genes to use to identify "
           "optimal codons\n"
	       "\t\tvalues can be whole numbers or a percentage (5 or 10%%)\n"
	       "\nBulk output options | only one can be selected per analysis\n"
	       " -aau\t\tAmino Acid Usage (AAU)\n"
	       " -raau\t\tRelative Amino Acid Usage (RAAU)\n"
	       " -cu\t\tCodon Usage (CU) (default)\n"
	       );
	pause;
	printf(
	       " -cutab\t\tTabulation of codon usage\n"
	       " -cutot\t\tTabulation of dataset's codon usage\n"
	       " -rscu\t\tRelative Synonymous Codon Usage (RSCU)\n"
	       " -fasta\t\tfasta format\n"
	       " -tidy\t\tfasta format\n"
	       " -reader\tReader format (codons are separated by spaces)\n"
	       " -transl\tConceptual translation of DNA to amino acid\n"
	       " -base\t\tDetailed report of codon G+C composition\n"
	       " -dinuc\t\tDinucleotide usage of the three codon pos.\n"
	       " -noblk\t\tNo bulk output to be written to file\n"
	       "\nWhere {file} represents an input filename, and N an integer"
           " value"
            );
        pause;
        my_exit(99,"");             /* after writing out help quit         */
    }


/* These parameters are normally set in menu3 ie. the defaults menu        */
/* for a explanation of the various GARG_FLAGS see gargs                   */

/* -silent stops warnings about file about to be overwritten               */
    if (garg(0, NULL, "-silent", GARG_THERE))
        pm->verbose = FALSE;


/* -total  causes sequences to be concatenated and treated as one sequence */
    if (  garg(0, NULL, "-total" ,  GARG_THERE))
        pm->totals = TRUE;

/* -machine or -human determines for whom the output should be formatted   */
    if (p = garg(0, NULL, "-human", GARG_THERE))
        pm->seq_format = 'H';
    if (p = garg(0, NULL, "-mach",  GARG_THERE))
        pm->seq_format = 'M';

/* -code determines the genetic code                                       */
    if (p = garg(0, NULL, "-code", GARG_NEXT | GARG_EXACT)) {
        strcpy(pm->junk, p);
        n=0;
        while ( isdigit( (int) pm->junk[n]) && pm->junk[n] != '\0')
            n++;
        if ( n != (int)strlen(pm->junk)
             || atoi(pm->junk) < 0 || atoi(pm->junk) > NumGeneticCodes ) {
            printf( "FATAL: The value for genetic code %s is invalid\n",
			         pm->junk);
            my_exit(99,"Fatal error in genetic code value");
        } else {
            pm->code = (char) atoi(p);              /* define genetic code */
	    initilize_point(pm->code, pm->f_type, pm->c_type);
        }
    }

/* -f_type selects which of the predefined fop values to use               */
/* NB. The fop is selected with the integer value corresponding to the menu*/
/* choice under the defaults menu. It must be in the range 1-NumFopSpecies */


  if (p = garg(0, NULL, "-f_type", GARG_NEXT | GARG_EXACT))  {
        strcpy(pm->junk, p);
        n = 0;
        while ( isdigit( (int) pm->junk[n])  && pm->junk[n] != '\0')
            n++;
        if ( n != (int)strlen(pm->junk) || atoi(pm->junk) < 0 ||
		atoi(pm->junk) >= NumFopSpecies ) {
            printf("FATAL: The value for fop_type %s is not valid\n",
			        pm->junk);
            my_exit(99,"Fatal error in Fop value");
        } else {
            pm->f_type = (char) atoi(p);  /* define organism type for Fop  */
	    initilize_point(pm->code, pm->f_type, pm->c_type);
        }
    }

/* -d_type selects which of the predefined CAI values to use               */
/* NB. The CAI is selected with the integer value corresponding to the menu*/
/* choice under the defaults menu. It must be in the range 1-NumCAISpecies */
    if (p = garg(0, NULL, "-c_type", GARG_NEXT | GARG_EXACT))  {
        strcpy(pm->junk,p);
        n = 0;
        while ( isdigit( (int) pm->junk[n])  && pm->junk[n] != '\0')
            n++;
        if ( n != (int)strlen(pm->junk) || atoi(pm->junk) < 0 ||
		atoi(pm->junk) >= NumCaiSpecies) {
            printf("FATAL: The value for cai_type %s is not valid\n",
			       pm->junk);
            my_exit(99,"Fatal error in CAI type value");

        } else {
            pm->c_type = (char) atoi(p);  /* define organism type for CAI  */
	    initilize_point(pm->code, pm->f_type, pm->c_type);
        }
    }


/* Command line arguments for the indices menu (4)                        */
/* The presence of any of these flags, cause the relevant indices to be   */
/* calculated                                                             */
/* Indices are CAI, FOP, CBI, Nc, GC, GC3s, Lsyn, Laa, silent_base        */
/* composition, hydropathicity, aromaticity                               */
    if (p = garg(0, NULL, "-cai" ,  GARG_EXACT))
        pm->cai = TRUE;
    if (p = garg(0, NULL, "-fop" ,  GARG_EXACT))
        pm->fop = TRUE;
    if (p = garg(0, NULL, "-cbi" ,  GARG_EXACT))
        pm->cbi = TRUE;
    if (p = garg(0, NULL, "-enc" ,  GARG_EXACT))
        pm->enc = TRUE;
    if (p = garg(0, NULL, "-gc" ,  GARG_EXACT))
        pm->gc = TRUE;
    if (p = garg(0, NULL, "-gc3s" ,  GARG_EXACT))
        pm->gc3s = TRUE;
    if (p = garg(0, NULL, "-sil_base" ,  GARG_EXACT))
        pm->sil_base = TRUE;
    if (p = garg(0, NULL, "-L_sym" ,  GARG_EXACT))
        pm->L_sym = TRUE;
    if (p = garg(0, NULL, "-L_aa" ,  GARG_EXACT))
        pm->L_aa = TRUE;
    if (p = garg(0, NULL, "-hyd" ,  GARG_EXACT))
        pm->hyd = TRUE;
    if (p = garg(0, NULL, "-aro" ,  GARG_EXACT))
        pm->aro = TRUE;
/* Turns on all the above indices                                         */
    if (p = garg(0, NULL, "-all_indices" ,  GARG_EXACT)){
        pm->cai = TRUE;
        pm->fop = TRUE;
        pm->cbi = TRUE;
        pm->enc = TRUE;
        pm->gc = TRUE;
        pm->gc3s = TRUE;
        pm->sil_base = TRUE;
        pm->L_sym = TRUE;
        pm->L_aa = TRUE;
        pm->hyd = TRUE;
        pm->aro = TRUE;
    }

/* This section in used to input the filenames for personal choices of Fop */
/* CBI or CAI values. The name is tested to make sure the file is readable */
/* the pointer to the file is then assign to the relevant pointer in the   */
/* struct Z_menu and then processed properly in codon_us.c                 */

/* Fop                                                                     */
    if (p = garg(0, NULL, "-fop_file", GARG_NEXT | GARG_EXACT)) {
        if ( (pm->fopfile = open_file( "", p, "r", FALSE)) == NULL ) {
            printf("Could not open Fop file - %s\n", p);
            my_exit(1,"commline open fop file");
        } else
            strncpy(pm->fop_filen, pm->junk, MAX_FILENAME_LEN - 1);
 /* idiot catch, if you load personal fop values you want to calculate fop */
	pm->fop=TRUE;
    }

/* CAI                                                                     */
    if (p = garg(0, NULL, "-cai_file", GARG_NEXT | GARG_EXACT)) {
        if ( (pm->caifile = open_file( "", p, "r", FALSE)) == NULL ) {
            printf("Could not open CAI file - %s\n", p);
            my_exit(1,"commline failed error");
        } else
            strncpy(pm->cai_filen, pm->junk, MAX_FILENAME_LEN - 1);
	pm->cai=TRUE;                                  /* idiot catch          */
    }
/* CBI                                                                     */
     if (p = garg(0, NULL, "-cbi_file", GARG_NEXT | GARG_EXACT)) {
        if ( (pm->cbifile = open_file( "", p, "r", FALSE)) == NULL ) {
            printf("Could not open CBI file - %s\n", p);
            my_exit(1,"Commline failed to open file");
        } else
            strncpy(pm->cbi_filen, pm->junk, MAX_FILENAME_LEN - 1);
        pm->cbi = TRUE;                          /* idiot catch            */
    }


/* This section changes the default correspondence menu choices normally   */
/* set in menu menu 5.                                                     */
/* Note only one of -coa_cu -coa_rscu -coa_aa can be chosen                */
    if (p = garg(0, NULL, "-coa_cu"   ,  GARG_EXACT))
        pm->coa = 'c';
    if (p = garg(0, NULL, "-coa_rscu" ,  GARG_EXACT))
        pm->coa = 'r';
    if (p = garg(0, NULL, "-coa_aa"   ,  GARG_EXACT))
        pm->coa = 'a';
    if (p = garg(0, NULL, "-coa_expert",  GARG_EXACT)) /* detailed inertia */
        (coa.level='e');                               /* analysis         */


/* These are options selectable under the advanced COA menu                */
/* This first option -coa_axes changes the number of axis recorded to file */
    if (p = garg(0, NULL, "-coa_axes", GARG_NEXT | GARG_EXACT)){
      if ( isdigit( (int) *p) ){
      n = (char)atoi(p);
      /* just check that correspondence analysis has been selected         */
      if ( pm->coa == 'a' && (n > 20 || n<0)  || ( n<0 || n>59 )) {
        fprintf(pm->my_err,"Value %d is out of range for Number COA Axis "
            "adjusting to max value\n",n);
        if ( pm->coa == 'a' ) pcoa->axis = 20; else  pcoa->axis = 59;
        }else{
           pcoa->axis = (char) n;
           }
      }
      }

/* Select the size of dataset to use to identify optimal codons            */
    if (p = garg(0, NULL, "-coa_num",  GARG_NEXT|GARG_EXACT))  {
        strcpy (pm->junk,p) ;
        if( (p=strchr ( pm->junk,'%')) != NULL) {
              p='\0';
              pcoa->fop_gene=atoi(pm->junk)*-1;
        }else {
               pcoa->fop_gene=atoi(pm->junk);
        }
    }


/* These option are mutually exclusive and are normally selected using the */
/* the bulk output menu (menu 8)                                           */

    if ( p = garg(0, NULL, "-raau", GARG_EXACT))
        pm->bulk = 'L';
    if ( p = garg(0, NULL, "-cu"  , GARG_EXACT))
        pm->bulk = 'C';
    if ( p = garg(0, NULL, "-cutab", GARG_THERE))
        pm->bulk = 'O';
    if ( p = garg(0, NULL, "-cutot", GARG_THERE)){
       pm->bulk   = 'C';
       pm->totals =TRUE;
    }
    if ( p = garg(0, NULL, "-reader", GARG_EXACT))
        pm->bulk = 'R';
    if ( p = garg(0, NULL, "-rscu", GARG_EXACT))
        pm->bulk = 'S';
    if ( p = garg(0, NULL, "-tidy", GARG_EXACT))
        pm->bulk = 'T';
    if ( p = garg(0, NULL, "-fasta", GARG_EXACT))
        pm->bulk = 'T';
    if ( p = garg(0, NULL, "-aau", GARG_EXACT))
        pm->bulk = 'A';
    if ( p = garg(0, NULL, "-transl", GARG_THERE))
        pm->bulk = 'N';
    if ( p = garg(0, NULL, "-base", GARG_THERE))
        pm->bulk = 'B';
    if (p = garg(0, NULL,  "-dinuc", GARG_THERE))
        pm->bulk = 'D';
    if (p = garg(0, NULL,  "-noblk", GARG_EXACT))
        pm->bulk = 'X';

/* -t is used to change the column separator used in the output files     */
/* at present it must be a space, tab or comma                            */
/* Must occur after -transl or it misreads transl as a seperator          */
    if (p = garg(0, NULL, "-t"   , GARG_NEXT | GARG_SUBSQ)) {
        strcpy(pm->junk, p);
        n = 0;
        do {
            c = pm->junk[n++];
        } while ( strchr("'\"\0", (int) c) != NULL );
        if ( strchr ("\t, ", (int) c) == NULL ) {
            printf( "WARNING: The chosen separator %s is unsuitable use"
                    "comma, tab or space\n", pm->junk);
        } else {
            pm->seperator = c;
        }
    }


/* These options are commandline specific, ie. they do not have an        */
/* menu option                                                            */

/* prevents the menu system from being displayed, everything is           */
/* assumed to have been given on the command line                         */

    if (p = garg(0, NULL, "-nomenu", GARG_EXACT))
        pm->menu = FALSE;

/* prevents warnings about possible problems with the sequence data       */
/* being displayed, i.e. partial codons, stop codons, start codons        */

    if (p = garg(0, NULL, "-nowarn", GARG_THERE))
        pm->warn = FALSE;



/* This section tries to identify the name used to call CodonW and it that*/
/* name concurs with one of those tested for, certain commandline options */
/* are assumed and the programme becomes much less interactive            */

/* First step is to convert programme name to lower case                  */
    for ( n=0; *(prog_name + n) != '\0'; n++)
        *(prog_name + n) = (char) tolower( (int) *(prog_name + n));


/* special options designed to unify code used by several auxiliary       */
/* programmes. In essence CodonW will impersonate other commonly used     */
/* codon usage analysis programmes if called using a special name         */

    if ( !strcmp(prog_name, "raau") || !strcmp(prog_name+7, "raau"))
        pm->bulk = 'L';
    else if ( !strcmp(prog_name, "cu") || !strcmp(prog_name+7, "cu"))
        pm->bulk = 'C';
    else if ( !strcmp(prog_name, "cutab") || !strcmp(prog_name+7, "cutab"))
        pm->bulk = 'O';
    else if ( !strcmp(prog_name, "reader") || !strcmp(prog_name+7, "reader"))
        pm->bulk = 'R';
    else if ( !strcmp(prog_name, "rscu") || !strcmp(prog_name+7, "rscu"))
        pm->bulk = 'S';
    else if ( !strcmp(prog_name, "tidy") || !strcmp(prog_name+7, "tidy"))
        pm->bulk = 'T';
    else if ( !strcmp(prog_name, "aau") || !strcmp(prog_name+7, "aau"))
        pm->bulk = 'A';
    else if ( !strcmp(prog_name, "dinuc") || !strcmp(prog_name+7, "dinuc"))
        pm->bulk = 'D';
    else if ( !strcmp(prog_name, "transl") || !strcmp(prog_name+7, "transl"))
        pm->bulk = 'N';
    else if ( !strcmp(prog_name, "bases") || !strcmp(prog_name+7, "bases"))
        pm->bulk = 'B';
    else if ( !strcmp(prog_name, "base3s") || !strcmp(prog_name+7, "base3s")) {
        pm->prog     = 's' ;
        pm->menu     = FALSE;
        pm->sil_base = TRUE;
    } else if ( !strcmp(prog_name, "cai") || !strcmp(prog_name+7, "cai")) {
        pm->prog   = 'c';
        pm->menu   = FALSE;
        pm->cai    = TRUE;
    } else if ( !strcmp(prog_name, "fop") || !strcmp(prog_name+7, "fop")) {
        pm->prog   = 'f';
        pm->menu   = FALSE;
        pm->fop    = TRUE;
    } else if ( !strcmp(prog_name, "gc3s") || !strcmp(prog_name+7, "gc3s")) {
        pm->prog   = '3';
	pm->menu   = FALSE;
        pm->gc3s   = TRUE;
    } else if ( !strcmp(prog_name, "gc") || !strcmp(prog_name+7, "gc")) {
        pm->prog   = 'g';
        pm->menu   = FALSE;
        pm->gc     = TRUE;
    } else if ( !strcmp(prog_name, "enc") || !strcmp(prog_name+7, "enc")) {
        pm->prog   = 'e';
        pm->menu   = FALSE;
        pm->enc    = TRUE;
    } else if ( !strcmp(prog_name, "cbi") || !strcmp(prog_name+7, "cbi")) {
        pm->prog   = 'i';
        pm->menu   = FALSE;
        pm->cbi    = TRUE;
    } else if ( !strcmp(prog_name, "cutot")  || !strcmp(prog_name+7, "cutot")) {
        pm->bulk   = 'C';
        pm->menu   = FALSE;
        pm->totals =TRUE;
    } else {
       pm->codonW=TRUE;       /* if argc[0] is not recognised assume codons*/
                              /* if blk output is still X then assume cu   */
       if (pm->bulk=='X') pm->bulk='C';
       }


    if (!pm->codonW ) {       /* we appear to be impersonating another prog*/
                              /* now we switch to the correct greeting     */
        if (pm->bulk && pm->bulk!='X'){
	    pm->seperator='\000';     /* stop chars being converted by tidy*/
            switch (pm->bulk) {
            case 'R':
                printf("\t\t\tREADER Formatting Program\n");
                break;
            case 'T':
                printf("\t\t\tTIDY   Formatting Program\n");
                break;
            case 'S':
                printf("\tRelative Synonymous Codon Usage\n");
                break;
            case 'B':
                printf("\t\t\tBase composition calculation\n");
                break;
            case 'C':
	            (pm->totals)?
                printf("\t\t\tTotal Codon Usage Tabulation\n"):
                printf("\t\t\tCodon Usage\n");
                break;
            case 'L':
                printf("\tRelative Amino Acid Usage Calculating \n");
                break;
            case 'D':
                printf("\t\t\tDi-Nucleotide frequencies Program\n");
                break;
            case 'A':
                printf("\t\t\tAmino Acid Usage Calculating Program\n");
                break;
            case 'N':
                printf("\t\tDNA 2 AA translating Program\n");
                break;
            case 'O':
                printf("\tCodon usage tabulation Program\n");
                break;
            case 'G':
                printf("\tTotal Codon usage tabulation\n");
                break;
            default:
                 {
                    fprintf(stderr, "Sorry:- could not recognise BULK option"
                                    " -%c (Use -h for help)", pm->bulk);
                    my_exit(99,"bad option commandline");
                }
            }
	 }
        else if (pm->prog)
            switch (pm->prog) {
            case 's':
                printf("\t\t\tSilent base G+C+A+T Calculating Program\n");
                break;
            case 'e':
                printf("\t\tNc Calculating Program\n");
                break;
            case 'f':
                printf("\t\tFop Calculating Program\n");
                break;
            case 'c':
                printf("\t\t\tCAI Calculating Program\n");
                break;
            case '3':
                printf("\t\t\tGC3s Calculating Program\n");
                break;
            case 'g':
                printf("\t\t\tG+C Calculating Program\n");
                break;
            case 'i':
                printf("\t\t\tCodon Bias Index Calculating Program\n");
                break;
            default:
                 {
                    fprintf(stderr, "Sorry:- could not recognise ");
                    fprintf(stderr, "argument -%c (Use -h for help)",
                        pm->prog);
                    my_exit(99,"commline");
                }                             /* matches default          */
            }
        else
            fprintf( stderr, "unknown error type in commline.c" );
    }                                         /* matched if (!pm->codonW) */


/* By this point we should have processed all the command line arguments  */
/* so now we test for any remaining, these are unrecognised               */

    while (p = garg(0, NULL, "-", GARG_THERE))
      if ( pm->menu )
        printf("Unrecognised argument %s\n", p);
      else {
          /* if we are running without a menu then abort this run         */
          sprintf ( pm->junk,"Unrecognised argument %s", p);
	      my_exit ( 99 , pm->junk);
    }

/* Anything remaining should be file names                                */
/* The first name should be the input file name                           */

    if ( p = garg(0, NULL, "", GARG_THERE)) {
        if ( (pm->inputfile = open_file( "", p, "r", FALSE)) == NULL )  {
            printf("Could not open input file - %s\n", p );
            my_exit(1,"failed to open file in proc_commline");
        } else
            strncpy(pm->curr_infilename, pm->junk, MAX_FILENAME_LEN - 1);
    }
/* The second should be the output filename                               */
    if ( p = garg(0, NULL, "", GARG_THERE)) {
        if ( (pm->outputfile = open_file( "", p, "w",
            (int) pm->verbose)) == NULL ) {
            printf("Could not open output file - %s\n", p );
            my_exit(1,"commline out file");
        } else
            strncpy(pm->curr_outfilename, pm->junk, MAX_FILENAME_LEN - 1);
    }

/* The third which only occurs if the programme is running as CodonW      */

    if ( pm->codonW && (p = garg(0, NULL, "", GARG_THERE)) ) {
        if ( (pm->tidyoutfile = open_file( "", p, "w",
            (int) pm->verbose)) == NULL ) {
            printf("Could not open blkoutput file - %s\n", p );
            my_exit(1,"commline blk outfile");
        } else
            strncpy(pm->curr_tidyoutname, pm->junk, MAX_FILENAME_LEN - 1);
    }

/* Now check the command line is empty ... it should be at this point     */
    while (p = garg(0, NULL, "", GARG_THERE))
        printf("This command line parameter was not recognised %s\n", p);

/* IF no file name was found on the command line and the programme is     */
/* impersonating another programme or we decided not to use the menu      */
/* we need to load an input file name                                     */

    if ( (!pm->codonW || !pm->menu) && !pm->inputfile ){
      if ( (pm->inputfile = open_file( "input filename", "input.dat",
          "r", FALSE)) == NULL )  {
	   printf("Could not open input file - %s\n", p );
	   my_exit(1,"commline inputfile");
      }
     strncpy(pm->curr_infilename, pm->junk, MAX_FILENAME_LEN - 1);
    }

/* If we have an input filename but no output then we must prompt for the */
/* output filename                                                        */

    if ( pm->inputfile  && !pm->outputfile ) {
      /* If we are trying to impersonate another programme use this method*/
      /* but make sure that we know what this other programme is called   */
      if ( !pm->codonW && strlen (prog_name) ){
        strcpy(pm->curr_outfilename, prog_name);
        strcat(pm->curr_outfilename, ".def");
      } else {

	/* Use the input filename as a root filename                      */
	strncpy(root, pm->curr_infilename, MAX_FILENAME_LEN - 5);
	for (n = (int) strlen(root); n && root[n]!='.'  ; --n);
	if ( n  ) root[n] = '\0';               /* find root of filename  */

	strcpy(pm->curr_outfilename, root);
        strcat(pm->curr_outfilename, ".out");
      }                                        /* matchs else             */

      /* now we know the suggested name for the output file lets open it  */
      if ( pm->verbose ) {
	if ( (pm->outputfile = open_file( "indices output filename",
	 pm->curr_outfilename, "w",(int) pm->verbose)) == NULL )
	                  my_exit(1,"commline");
	strncpy(pm->curr_outfilename, pm->junk, MAX_FILENAME_LEN - 1);
      }else{
	if ( (pm->outputfile = open_file( "",
	 pm->curr_outfilename, "w",(int) pm->verbose)) == NULL )
	                  my_exit(1,"commline");
	strncpy(pm->curr_outfilename, pm->junk, MAX_FILENAME_LEN - 1);
      }

    }                                          /* match if ( pm->inputfile */



    /* we had a commandline inputfile name and output filename but none    */
    /* for bulkoutput .. we prompt to save having to use menu 1            */
    if ( pm->inputfile && ! pm->tidyoutfile ){
      if ( pm->codonW ) {
                       	      /* Use the input filename as a root filename */
	strncpy(root, pm->curr_infilename  , MAX_FILENAME_LEN - 5);

	for (n = (int) strlen(root); n && root[n]!='.'  ; --n);
	if ( n  ) root[n] = '\0';               /* find root of filename  */

	strcpy(pm->curr_tidyoutname, root);
        strcat(pm->curr_tidyoutname, ".blk");

    /* now we know the suggested name for the output file lets open it     */
	if( pm->verbose) {
	  if ( (pm->tidyoutfile = open_file( "bulk output filename",
		 pm->curr_tidyoutname, "w",(int) pm->verbose)) == NULL )
	    my_exit(1,"commline");
	strncpy(pm->curr_tidyoutname, pm->junk, MAX_FILENAME_LEN - 1);
	}else{
	  if ( (pm->tidyoutfile = open_file( "",
	      pm->curr_tidyoutname, "w",(int) pm->verbose)) == NULL )
	    my_exit(1,"commline");
	strncpy(pm->curr_tidyoutname, pm->junk, MAX_FILENAME_LEN - 1);
	}
      }else{
	/* only use one output file when impersonating other programmes        */
    /* just in case we make blkout and output the same file                */
	pm->tidyoutfile = pm->outputfile;
      }
    }
return 1;
}
/****************** Garg     ***********************************************/
/* This subroutine strips of the commandline arguments and passes them back*/
/* to the calling function. Each time it is called with argc and argv non  */
/* null the commandline is refreshed. If called with these are null args   */
/* a commandline pre-stored is used, this commandline is striped arg by arg*/
/* as they are identified                                                  */
/* This subroutine was developed as a collaboration with Colin McFarlane   */
/* GARG_EXACT           The argument must match targ exactly               */
/* GARG_THERE           The targ may be sub-string of the argument         */
/* GARG_SUBSQ           The string immediate after targ is returned        */
/* GARG_NEXT            The next argument after targ is returned           */
/* else                 return NULL                                        */
/***************************************************************************/
char           *garg(int argc, char *argv[], const char *targ, int mode)
{
  static char    *argw[MAX_ARGS];
  static int      done[MAX_ARGS];
  static int      argn;

  int             arg = 1, nc;

  if (argv) {
    if (--argc < 1)
      return NULL;
    for (argn = 0; argn < argc; argn++) {
      argw[argn] = argv[argn + 1];
      done[argn] = 0;
    }
  }
  nc = mode & GARG_EXACT ? BUFSIZ : strlen(targ);

  for (arg = 0; arg < argn; arg++)
    if ((0 == strncmp(targ, argw[arg], nc)) && !done[arg]) {
      done[arg] = 1;
      if (mode & GARG_THERE)
        return argw[arg];
      if (mode & GARG_SUBSQ)
        return &argw[arg][nc];
      if (mode & GARG_NEXT) {
        done[++arg < argn ? arg : --arg] = 1;
        return argw[arg];
      }
      return argw[arg];
    }
  return NULL;
}