home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / apps / science / clustalv / amenu.c next >
C/C++ Source or Header  |  1994-02-19  |  50KB  |  2,057 lines

  1. /* Menus and command line interface for CLUSTAL V  */
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #include <stdlib.h>
  7. #include "clustalv.h"
  8.  
  9.  
  10. /*
  11. *    Prototypes
  12. */
  13.  
  14. extern void     getstr(char *,char *);
  15. extern double    getreal(char *,double,double);
  16. extern int        getint(char *,int,int,int);
  17. extern void        do_system(void);
  18. extern void        make_pamo(int);
  19. extern int        readseqs(int);
  20. extern void        get_path(char *,char *);
  21. extern void        show_pair(void);
  22. extern void        upgma(int);
  23. extern void        myers(int);
  24. extern void     phylogenetic_tree(void);
  25. extern void        bootstrap_tree(void);
  26. extern void        error(char *,...);
  27. extern int              SeqGCGCheckSum(char *, int);
  28.  
  29.  
  30. void init_amenu(void);
  31. void parse_params(void);
  32. void main_menu(void);
  33. FILE * open_output_file(char *, char *, char *, char *);
  34. #if UNIX
  35. FILE * open_path(char *);
  36. #endif
  37.  
  38. static Boolean check_param(char *, char *, char *, int *);
  39. static void get_help(int);            /* Help procedure */
  40. static void pair_menu(void);
  41. static void multi_menu(void);
  42. static void multiple_align_menu(void);          /* multiple alignments menu */
  43. static void profile_align_menu(void);           /* profile       "      "   */
  44. static void phylogenetic_tree_menu(void);       /* NJ trees/distances menu  */
  45. static void read_matrix(void);
  46. static void seq_input(void);
  47. static void align(void);
  48. static void make_tree(void);
  49. static void get_tree(void);
  50. static Boolean user_mat(char *);
  51. static void clustal_out(FILE *);
  52. static void nbrf_out(FILE *);
  53. static void gcg_out(FILE *);
  54. static void phylip_out(FILE *);
  55. static Boolean open_alignment_output(char *);
  56. static void create_alignment_output(void);
  57. static void reset(void);
  58. static void profile_input(int);           /* DES read a profile */
  59. static void format_options_menu(void);          /* format of alignment output */
  60. static void profile_align(void);                /* Align 2 alignments */
  61.  
  62. /*
  63. *     Global variables
  64. */
  65.  
  66. char *lin1, *lin2, *lin3;
  67.  
  68. extern char *amino_acid_order;
  69. extern char *nucleic_acid_order;
  70. extern void *ckalloc(size_t);
  71. extern Boolean        percent,is_weight,dnaflag;
  72. extern int        wind_gap,ktup,window,signif;
  73. extern int               dna_wind_gap, dna_ktup, dna_window, dna_signif;
  74. extern int              prot_wind_gap,prot_ktup,prot_window,prot_signif;
  75. extern unsigned int boot_ran_seed;
  76. extern int      gap_open,      gap_extend;
  77. extern int  dna_gap_open,  dna_gap_extend;
  78. extern int prot_gap_open, prot_gap_extend;
  79. extern int boot_ntrials;        /* number of bootstrap trials */
  80. extern int        xover,big_pam;
  81. extern char *params;
  82. extern char        seqname[],treename[];
  83. extern char     *matptr,pam100mt[],pam250mt[],idmat[];
  84. extern int        nseqs,nblocks;
  85. extern int         weights[21][21];
  86. extern FILE *    tree;
  87. extern FILE *clustal_outfile, *gcg_outfile, *nbrf_outfile, *phylip_outfile;
  88. extern char **    names, **titles;
  89. extern int *seqlen_array;
  90. extern char **seq_array;
  91. extern char ntrials;        /* number of bootstrap trials (trees.c) */
  92.  
  93. Boolean usemenu;
  94. char mtrxnam[FILENAMELEN+1];
  95. Boolean explicit_dnaflag;  /* Explicit setting of sequence type on comm.line*/
  96. Boolean output_clustal, output_nbrf, output_phylip, output_gcg;
  97. Boolean empty;
  98. Boolean profile1_empty, profile2_empty;   /* whether or not profiles   */
  99. int profile1_nseqs;           /* have been filled; the no. of seqs in prof 1*/
  100. Boolean tossgaps, kimura;
  101. int  matnum;
  102. static char clustal_outname[FILENAMELEN+1], gcg_outname[FILENAMELEN+1];
  103. static char  phylip_outname[FILENAMELEN+1],nbrf_outname[FILENAMELEN+1];
  104.  
  105. static char *pam_matrix_name[] = {
  106.         "PAM 100",
  107.         "PAM 250",
  108.         "Identity matrix",
  109.         "user defined"   };
  110.         
  111. char usermat[210];
  112.  
  113. void init_amenu()
  114. {
  115.     matnum=2;
  116.     empty=TRUE;
  117.     explicit_dnaflag = FALSE;     
  118.     profile1_empty=TRUE;     /* DES */
  119.     profile2_empty=TRUE;     /* DES */
  120.     output_clustal = TRUE;
  121.     output_gcg     = FALSE;
  122.     output_phylip  = FALSE;
  123.     output_nbrf    = FALSE;
  124.  
  125.     lin1 = (char *)ckalloc( (MAXLINE+1) * sizeof (char) );
  126.     lin2 = (char *)ckalloc( (MAXLINE+1) * sizeof (char) );
  127.     lin3 = (char *)ckalloc( (MAXLINE+1) * sizeof (char) );
  128. }
  129.  
  130.  
  131.  
  132.  
  133. static Boolean check_param(char *paramstr, char *probe, char *arg, int *len)
  134. {
  135.     int i,j,k,paramlen;
  136.     char testarg[80];
  137.  
  138.     paramlen = strlen(paramstr);
  139.     i = 1;
  140.     while(i < paramlen) {
  141.         for(j=i+1; j<=paramlen      &&
  142.             paramstr[j] != '/'  &&
  143.             paramstr[j] != EOS; j++) ;
  144.         for(k=i+1; k<j; k++)
  145.             if(paramstr[k] == '=') {
  146.                    strncpy(testarg,¶mstr[i],k-i);
  147.                 if(!strncmp(testarg,probe,k-i)){
  148.                     strncpy(arg,¶mstr[k+1],j-k-1);
  149.                     arg[j-k-1] = EOS;
  150.                     *len = strlen(arg);
  151.                     return TRUE;
  152.                 }
  153.             }
  154.         strncpy(testarg,¶mstr[i],j-i);
  155.         if(!strncmp(testarg,probe,j-i)) {
  156.             *len = 0;
  157.             arg[0] = EOS;
  158.             return TRUE;
  159.         }
  160.         i = j + 1;
  161.     }
  162.     return FALSE;
  163. }
  164.  
  165.  
  166.  
  167.  
  168. #if UNIX
  169. FILE *open_path(char *fname)  /* to open in read-only file fname searching for 
  170.                  it through all path directories */
  171. {
  172. #define Mxdir 70
  173.         char dir[Mxdir+1], *path, *deb, *fin;
  174.         FILE *fich;
  175.         int lf, ltot;
  176.  
  177.         path=getenv("PATH");     /* get the list of path directories, 
  178.                     separated by :
  179.                     */
  180.         if (path == NULL ) return fopen(fname,"r");
  181.         lf=strlen(fname);
  182.         deb=path;
  183.         do
  184.                 {
  185.                 fin=strchr(deb,':');
  186.                 if(fin!=NULL)
  187.                         { strncpy(dir,deb,fin-deb); ltot=fin-deb; }
  188.                 else
  189.                         { strcpy(dir,deb); ltot=strlen(dir); }
  190.                 /* now one directory is in string dir */
  191.                 if( ltot + lf + 1 <= Mxdir)
  192.                         {
  193.                         dir[ltot]='/';
  194.                         strcpy(dir+ltot+1,fname); /* now dir is appended with fi
  195.    lename */
  196.                         if( (fich = fopen(dir,"r") ) != NULL) break;
  197.                         }
  198.                 else fich = NULL;
  199.                 deb=fin+1;
  200.                 }
  201.         while (fin != NULL);
  202.         return fich;
  203. }
  204. #endif
  205.  
  206.  
  207.  
  208. static void get_help(int help_pointer)    /* Help procedure */
  209. {    
  210.     FILE *help_file;
  211.     int  i, number, nlines;
  212.     Boolean found_help;
  213.     char temp[MAXLINE+1];
  214.     char *digits = "0123456789";
  215.     char *help_marker    = ">>HELP<<";
  216.  
  217. #if MSDOS
  218.     char *help_file_name = "clustalv.hlp";
  219. #else
  220.     char *help_file_name = "clustalv_help";
  221. #endif
  222.  
  223. #if VMS
  224.         if((help_file=fopen(help_file_name,"r","rat=cr","rfm=var"))==NULL) {
  225. #else
  226. #if UNIX
  227.         if((help_file=open_path(help_file_name))==NULL) {
  228. #else
  229.         if((help_file=fopen(help_file_name,"r"))==NULL) {
  230. #endif
  231. #endif
  232.         error("Cannot open help file [%s]",help_file_name);
  233.         return;
  234.     }
  235.  
  236.     nlines = 0;
  237.     number = -1;
  238.     found_help = FALSE;
  239.  
  240.     while(TRUE) {
  241.         if(fgets(temp,MAXLINE+1,help_file) == NULL) {
  242.             if(!found_help)
  243.                 error("No help found in help file");
  244.             fclose(help_file);
  245.             return;
  246.         }
  247.         if(strstr(temp,help_marker)) {
  248.             for(i=0; i<MAXLINE; i++)
  249.                 if(strchr(digits, temp[i])) {
  250.                     number = temp[i] - '0';
  251.                     break;
  252.                 }
  253.         }
  254.         if(number == help_pointer) {
  255.             found_help = TRUE;
  256.             while(fgets(temp,MAXLINE+1,help_file)) {
  257.                 if(strstr(temp, help_marker)){
  258.                       if(usemenu) {
  259.                         fprintf(stdout,"\n");
  260.                             getstr("Press [RETURN] to continue",lin2);
  261.                       }
  262.                     fclose(help_file);
  263.                     return;
  264.                 }
  265.                    fputs(temp,stdout);
  266.                    ++nlines;
  267.                    if(usemenu) {
  268.                       if(nlines >= PAGE_LEN) {
  269.                             fprintf(stdout,"\n");
  270.                           getstr("Press [RETURN] to continue or  X  to stop",lin2);
  271.                          if(toupper(*lin2) == 'X') {
  272.                            fclose(help_file);
  273.                            return;
  274.                          }
  275.                          else
  276.                            nlines = 0;
  277.                    }
  278.                    }
  279.             }
  280.             if(usemenu) {
  281.                 fprintf(stdout,"\n");
  282.                 getstr("Press [RETURN] to continue",lin2);
  283.             }
  284.             fclose(help_file);
  285.         }
  286.     }
  287.  
  288. }
  289.  
  290.  
  291. void parse_params()
  292. {
  293.     int i,j,k,len,lenp,temp;
  294.     char probe[80], param_arg[80];
  295.     int param_arg_len;
  296.  
  297.     Boolean do_align, do_tree, do_boot, do_profile, do_something;
  298.  
  299. /* command line switches for PARAMETERS **************************/
  300.     static char *fixedgapst     = "fixedgap";
  301.     static char *floatgapst     = "floatgap";
  302.     static char *kimurast        = "kimura";
  303.     static char *ktuplest          = "ktuple";
  304.     static char *matrixst        = "matrix";
  305.     static char *outputst        = "output";
  306.     static char *pairgapst      = "pairgap";
  307.     static char *scorest        = "score";
  308.     static char *seedst        = "seed";
  309.     static char *topdiagsst     = "topdiags";
  310.     static char *tossgapsst        = "tossgaps";
  311.     static char *transitionsst     = "transitions";
  312.     static char *typest        = "type";
  313.     static char *windowst           = "window";
  314.  
  315. /* command line switches for DATA       **************************/
  316.     static char *infilest        = "infile";
  317.     static char *profile1st        = "profile1";
  318.     static char *profile2st        = "profile2";
  319.  
  320. /* command line switches for VERBS      **************************/
  321.     static char *alignst        = "align";
  322.     static char *bootstrapst    = "bootstrap";
  323.     static char *checkst        = "check";        /*  /check = /help */
  324.     static char *helpst           = "help";
  325.     static char *treest        = "tree";
  326.  
  327.     fprintf(stdout,"\n\n\n");
  328.     fprintf(stdout," CLUSTAL V ... Multiple Sequence Alignments\n\n\n");
  329.  
  330.     do_align = do_tree = do_boot = do_profile = do_something = FALSE;
  331.  
  332.     *seqname=EOS;
  333.  
  334.     len=strlen(params);
  335.     for(i=0;i<len;++i) params[i]=tolower(params[i]);
  336.  
  337.     if(check_param(params, helpst,  param_arg, ¶m_arg_len) ||
  338.        check_param(params, checkst, param_arg, ¶m_arg_len) ) {
  339.         get_help(9);
  340.         exit(1);
  341.     }
  342.  
  343.  
  344. /*****************************************************************************/
  345. /*  Check to see if sequence type is explicitely stated..override ************/
  346. /* the automatic checking (DNA or Protein).   /type=d or /type=p *************/
  347. /*****************************************************************************/
  348.     if(check_param(params, typest, param_arg, ¶m_arg_len)) 
  349.         if(param_arg_len > 0) {
  350.             if(param_arg[0] == 'p') {
  351.                 dnaflag = FALSE;
  352.                 explicit_dnaflag = TRUE;
  353.                 fprintf(stdout,
  354.                 "\nSequence type explicitely set to Protein\n");
  355.             }
  356.             else if(param_arg[0] == 'd') {
  357.                 fprintf(stdout,
  358.                 "\nSequence type explicitely set to DNA\n");
  359.                 dnaflag = TRUE;
  360.                 explicit_dnaflag = TRUE;
  361.             }
  362.             else
  363.                 fprintf(stdout,"\nUnknown sequence type %s\n",
  364.                 param_arg);
  365.         }
  366.  
  367.  
  368. /***************************************************************************
  369. *   check to see if 1st parameter does not start with '/' i.e. look for an *
  370. *   input file as first parameter.   The input file can also be specified  *
  371. *   by /infile=fname.                                                      *
  372. ****************************************************************************/
  373.  
  374.     for (i=0; params[i] != '/' && params[i] != EOS; i++) ;
  375.     if(i > 0) {
  376.         strncpy(seqname, ¶ms[0], i);
  377.         seqname[i] = EOS;
  378.         nseqs = readseqs(1);
  379.         if(nseqs < 2) {
  380.                     fprintf(stderr,
  381.             "\nNo. of seqs. read = %d. No alignment!\n",nseqs);
  382.             exit(1);
  383.         }
  384.         for(i = 1; i<=nseqs; i++) 
  385.             fprintf(stdout,"Sequence %d: %-*.s   %6.d %s\n",
  386.             i,MAXNAMES,names[i],seqlen_array[i],dnaflag?"bp":"aa");
  387.         empty = FALSE;
  388.         do_something = TRUE;
  389.     }
  390.  
  391. /**************************************************/
  392. /*  Look for /infile=file.ext on the command line */
  393. /**************************************************/
  394.  
  395.     if(check_param(params, infilest, param_arg, ¶m_arg_len)) {
  396.         if(param_arg_len == 0) {
  397.             error("Bad sequence file name");
  398.             exit(1);
  399.         }
  400.         strncpy(seqname, param_arg, param_arg_len);
  401. /*        seqname[param_arg_len-1] = EOS;  */
  402.         nseqs = readseqs(1);
  403.         if(nseqs < 2) {
  404.                     fprintf(stderr,
  405.             "\nNo. of seqs. read = %d. No alignment!\n",nseqs);
  406.             exit(1);
  407.         }
  408.         for(i = 1; i<=nseqs; i++) 
  409.             fprintf(stdout,"Sequence %d: %-*.s   %6.d %s\n",
  410.             i,MAXNAMES,names[i],seqlen_array[i],dnaflag?"bp":"aa");
  411.         empty = FALSE;
  412.         do_something = TRUE;
  413.     }
  414.  
  415. /*********************************************************/
  416. /* Look for /profile1=file.ext  AND  /profile2=file2.ext */
  417. /* You must give both file names OR neither.             */
  418. /*********************************************************/
  419.  
  420.     if(check_param(params, profile1st, param_arg, ¶m_arg_len)) {
  421.         if(param_arg_len == 0) {
  422.             error("Bad profile 1 file name");
  423.             exit(1);
  424.         }
  425.         strncpy(seqname, param_arg, param_arg_len);
  426. /*        seqname[param_arg_len-1] = EOS;    */
  427.         profile_input(1);
  428.         if(nseqs <= 0) 
  429.             exit(1);
  430.     }
  431.  
  432.     if(check_param(params, profile2st, param_arg, ¶m_arg_len)) {
  433.         if(param_arg_len == 0) {
  434.             error("Bad profile 2 file name");
  435.             exit(1);
  436.         }
  437.         if(profile1_empty) {
  438.             error("Only 1 profile file (profile 2) specified.");
  439.             exit(1);
  440.         }
  441.         strncpy(seqname, param_arg, param_arg_len);
  442. /*        seqname[param_arg_len-1] = EOS;    */
  443.         profile_input(2);
  444.         if(nseqs > profile1_nseqs) 
  445.             do_something = do_profile = TRUE;
  446.         else {
  447.             error("No sequences read from profile 2");
  448.             exit(1);
  449.         }
  450.     }
  451.  
  452. /*************************************************************************/
  453. /* Look for /tree or /bootstrap or /align ********************************/
  454. /*************************************************************************/
  455.  
  456.     if(check_param(params, treest, param_arg, ¶m_arg_len))
  457.         if(empty) {
  458.             error("Cannot draw tree.  No input alignment file");
  459.             exit(1);
  460.         }
  461.         else 
  462.             do_tree = TRUE;
  463.  
  464.     if(check_param(params, bootstrapst, param_arg, ¶m_arg_len))
  465.         if(empty) {
  466.             error("Cannot bootstrap tree. No input alignment file");
  467.             exit(1);
  468.         }
  469.         else {
  470.             temp = 0;
  471.             if(param_arg_len > 0) sscanf(param_arg,"%d",&temp);
  472.             if(temp > 0)          boot_ntrials = temp;
  473.             do_boot = TRUE;
  474.         }
  475.  
  476.     if(check_param(params, alignst, param_arg, ¶m_arg_len))
  477.         if(empty) {
  478.             error("Cannot align sequences.  No input file");
  479.             exit(1);
  480.         }
  481.         else 
  482.             do_align = TRUE;
  483.  
  484.     if( (!do_tree) && (!do_boot) && (!empty) && (!do_profile) ) 
  485.         do_align = TRUE;
  486.  
  487.     if(!do_something) {
  488.         error("No input file(s) specified");
  489.         exit(1);
  490.     }
  491.  
  492.     
  493.     if(dnaflag) {
  494.         gap_open   = dna_gap_open;
  495.         gap_extend = dna_gap_extend;
  496.         ktup       = dna_ktup;
  497.         window     = dna_window;
  498.         signif     = dna_signif;
  499.         wind_gap   = dna_wind_gap;
  500.     }
  501.     else {
  502.         gap_open   = prot_gap_open;
  503.         gap_extend = prot_gap_extend;
  504.         ktup       = prot_ktup;
  505.         window     = prot_window;
  506.         signif     = prot_signif;
  507.         wind_gap   = prot_wind_gap;
  508.     }
  509.  
  510.  
  511. /****************************************************************************/
  512. /* look for parameters on command line  e.g. gap penalties, k-tuple etc.    */
  513. /****************************************************************************/
  514.  
  515. /*** ? /kimura  */
  516.     if(check_param(params, kimurast, param_arg, ¶m_arg_len))
  517.         kimura = TRUE;
  518.  
  519.  
  520. /*** ? /tossgaps */
  521.     if(check_param(params, tossgapsst, param_arg, ¶m_arg_len))
  522.         tossgaps = TRUE;
  523.  
  524.  
  525. /*** ? /score=percent or /score=absolute */
  526.     if(check_param(params, scorest, param_arg, ¶m_arg_len))
  527.         if(param_arg_len > 0) {
  528.             if(param_arg[0] == 'p')
  529.                 percent = TRUE;
  530.             else if(param_arg[0] == 'a') 
  531.                 percent = FALSE;
  532.             else
  533.                 fprintf(stdout,"\nUnknown SCORE type: %s\n",
  534.                 param_arg);
  535.         }
  536.  
  537.  
  538. /*** ? /transitions */
  539.     if(check_param(params, transitionsst, param_arg, ¶m_arg_len))
  540.         is_weight = FALSE;
  541.  
  542.  
  543. /*** ? /seed=n */
  544.     if(check_param(params, seedst, param_arg, ¶m_arg_len)) {
  545.         temp = 0;
  546.         if(param_arg_len > 0) sscanf(param_arg,"%d",&temp);
  547.         if(temp > 0) boot_ran_seed = temp;
  548.     fprintf(stdout,"\ntemp = %d; seed = %u;\n",temp,boot_ran_seed);
  549.     }
  550.  
  551.  
  552. /*** ? /output=PIR, GCG or PHYLIP  Only 1 can be switched on at a time */
  553.     if(check_param(params, outputst, param_arg, ¶m_arg_len))
  554.         if(param_arg_len > 0) {
  555.             if(param_arg[0] == 'g')  {    /* GCG */
  556.                 output_gcg     = TRUE;
  557.                 output_clustal = FALSE;
  558.             }
  559.             else if(param_arg[0] == 'p') 
  560.                 if(param_arg[1] == 'i') {
  561.                     output_nbrf    = TRUE;
  562.                     output_clustal = FALSE;
  563.                 }
  564.                 else if(param_arg[1] == 'h') {
  565.                     output_phylip  = TRUE;
  566.                     output_clustal = FALSE;
  567.                 }
  568.                 else
  569.                     fprintf(stdout,"\nUnknown OUTPUT type: %s\n",
  570.                     param_arg);
  571.             else
  572.                 fprintf(stdout,"\nUnknown OUTPUT type: %s\n",
  573.                 param_arg);
  574.         }
  575.  
  576.  
  577. /*** ? /ktuple=n */
  578.     if(check_param(params, ktuplest, param_arg, ¶m_arg_len)) {
  579.         temp = 0;
  580.         if(param_arg_len > 0) sscanf(param_arg,"%d",&temp);
  581.         if(temp > 0) {
  582.             if(dnaflag) {
  583.                 if(temp <= 4) { 
  584.                     ktup         = temp;
  585.                     dna_ktup     = ktup;
  586.                     wind_gap     = ktup + 4;
  587.                     dna_wind_gap = wind_gap;
  588.                 }
  589.             }
  590.             else {
  591.                 if(temp <= 2) {
  592.                     ktup          = temp;
  593.                     prot_ktup     = ktup;
  594.                     wind_gap      = ktup + 3;
  595.                     prot_wind_gap = wind_gap;
  596.                 }
  597.             }
  598.         }
  599.     }
  600.  
  601.  
  602. /*** ? /pairgap=n */
  603.     if(check_param(params, pairgapst, param_arg, ¶m_arg_len)) {
  604.         temp = 0;
  605.         if(param_arg_len > 0) sscanf(param_arg,"%d",&temp);
  606.         if(temp > 0)
  607.             if(dnaflag) {
  608.                 if(temp > ktup) {
  609.                     wind_gap     = temp;
  610.                     dna_wind_gap = wind_gap;
  611.                 }
  612.             }
  613.             else {
  614.                 if(temp > ktup) {
  615.                     wind_gap      = temp;
  616.                     prot_wind_gap = wind_gap;
  617.                 }
  618.             }
  619.     }
  620.     
  621.  
  622. /*** ? /topdiags=n   */
  623.     if(check_param(params, topdiagsst, param_arg, ¶m_arg_len)) {
  624.         temp = 0;
  625.         if(param_arg_len > 0) sscanf(param_arg,"%d",&temp);
  626.         if(temp > 0)
  627.             if(dnaflag) {
  628.                 if(temp > ktup) { 
  629.                     signif       = temp;
  630.                     dna_signif   = signif;
  631.                 }
  632.             }
  633.             else {
  634.                 if(temp > ktup) {
  635.                     signif        = temp;
  636.                     prot_signif   = signif;
  637.                 }
  638.             }
  639.     }
  640.     
  641.  
  642. /*** ? /window=n  */
  643.     if(check_param(params, windowst, param_arg, ¶m_arg_len)) {
  644.         temp = 0;
  645.         if(param_arg_len > 0) sscanf(param_arg,"%d",&temp);
  646.         if(temp > 0)
  647.             if(dnaflag) {
  648.                 if(temp > ktup) { 
  649.                     window       = temp;
  650.                     dna_window   = window;
  651.                 }
  652.             }
  653.             else {
  654.                 if(temp > ktup) {
  655.                     window        = temp;
  656.                     prot_window   = window;
  657.                 }
  658.             }
  659.     }
  660.  
  661.  
  662. /*** ? /matrix=pam100, or ID or file.ext (user's file)  */
  663.     if(check_param(params, matrixst, param_arg, ¶m_arg_len))
  664.         if(param_arg_len > 0) {
  665.             if( !strcmp(param_arg, "pam100") )  {
  666.                 matptr = pam100mt;
  667.                 make_pamo(0);
  668.                 prot_gap_open   = 13;
  669.                 prot_gap_extend = 13;
  670.                 if(!dnaflag) gap_open   = prot_gap_open;
  671.                 if(!dnaflag) gap_extend = prot_gap_extend;
  672.                 matnum = 1;
  673.             }
  674.             else if( !strcmp(param_arg, "id") )  {
  675.                 matptr = idmat;
  676.                 make_pamo(0);
  677.                 matnum = 3;
  678.             }
  679.             else if(user_mat(param_arg))
  680.                 matnum = 4;
  681.             else
  682.                 fprintf(stdout,"\nUnknown MATRIX type: %s\n",
  683.                 param_arg);
  684.         }
  685.  
  686.  
  687. /*** ? /fixedgap=n  */
  688.     if(check_param(params, fixedgapst, param_arg, ¶m_arg_len)) {
  689.         temp = 0;
  690.         if(param_arg_len > 0)
  691.             sscanf(param_arg,"%d",&temp);
  692.         if(temp > 0)
  693.             if(dnaflag) {
  694.                     gap_open     = temp;
  695.                     dna_gap_open = gap_open;
  696.             }
  697.             else {
  698.                     gap_open      = temp;
  699.                     prot_gap_open = gap_open;
  700.             }
  701.     }
  702.  
  703.  
  704. /*** ? /floatgap=n   */
  705.     if(check_param(params, floatgapst, param_arg, ¶m_arg_len)) {
  706.         temp = 0;
  707.         if(param_arg_len > 0)
  708.             sscanf(param_arg,"%d",&temp);
  709.         if(temp > 0)
  710.             if(dnaflag) {
  711.                     gap_extend      = temp;
  712.                     dna_gap_extend  = gap_extend;
  713.             }
  714.             else {
  715.                     gap_extend      = temp;
  716.                     prot_gap_extend = gap_extend;
  717.             }
  718.     }
  719.  
  720.  
  721. /****************************************************************************/
  722. /* Now do whatever has been requested ***************************************/
  723. /****************************************************************************/
  724.  
  725.     if(do_profile)
  726.         profile_align();
  727.  
  728.     if(do_align)
  729.         align();
  730.  
  731.     if(do_tree)
  732.         phylogenetic_tree();
  733.  
  734.     if(do_boot)
  735.         bootstrap_tree();
  736.  
  737.     exit(1);
  738.  
  739. /*******whew!***now*go*home****/
  740. }
  741.  
  742.  
  743.  
  744.  
  745.  
  746.  
  747.  
  748. void main_menu()
  749. {
  750.     while(TRUE) {
  751.         fprintf(stdout,"\n\n\n");
  752.         fprintf(stdout," **************************************************************\n");
  753.         fprintf(stdout," ********* CLUSTAL V ... Multiple Sequence Alignments  ********\n");
  754.         fprintf(stdout," **************************************************************\n");
  755.         fprintf(stdout,"\n\n");
  756.         
  757.         fprintf(stdout,"     1. Sequence Input From Disc\n");
  758.         fprintf(stdout,"     2. Multiple Alignments\n");
  759.         fprintf(stdout,"     3. Profile Alignments\n");
  760.         fprintf(stdout,"     4. Phylogenetic trees\n");
  761.         fprintf(stdout,"\n");
  762.         fprintf(stdout,"     S. Execute a system command\n");
  763.         fprintf(stdout,"     H. HELP\n");
  764.         fprintf(stdout,"     X. EXIT (leave program)\n\n\n");
  765.         
  766.         getstr("Your choice",lin1);
  767.  
  768.         switch(toupper(*lin1)) {
  769.             case '1': seq_input();
  770.                 break;
  771.             case '2': multiple_align_menu();
  772.                 break;
  773.             case '3': profile_align_menu();
  774.                 break;
  775.             case '4': phylogenetic_tree_menu();
  776.                 break;
  777.             case 'S': do_system();
  778.                 break;
  779.             case '?':
  780.             case 'H': get_help(1);
  781.                 break;
  782.             case 'Q':
  783.             case 'X': exit(0);
  784.                 break;
  785.             default: fprintf(stderr,"\n\nUnrecognised Command\n\n");
  786.                 break;
  787.         }
  788.     }
  789. }
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799. static void multiple_align_menu()
  800. {
  801.     while(TRUE)
  802.     {
  803.         fprintf(stdout,"\n\n\n");
  804.         fprintf(stdout,"******Multiple*Alignment*Menu******\n");
  805.         fprintf(stdout,"\n\n");
  806.  
  807.  
  808.         fprintf(stdout,"    1.  Do complete multiple alignment now\n");
  809.         fprintf(stdout,"    2.  Produce dendrogram file only\n");
  810.         fprintf(stdout,"    3.  Use old dendrogram file\n");
  811.         fprintf(stdout,"    4.  Pairwise alignment parameters\n");
  812.         fprintf(stdout,"    5.  Multiple alignment parameters\n");
  813.         fprintf(stdout,"    6.  Output format options\n");
  814.         fprintf(stdout,"\n");
  815.         fprintf(stdout,"    S.  Execute a system command\n");
  816.         fprintf(stdout,"    H.  HELP\n");
  817.         fprintf(stdout,"    or press [RETURN] to go back to main menu\n\n\n");
  818.  
  819.         getstr("Your choice",lin1);
  820.         if(*lin1 == EOS) return;
  821.  
  822.         switch(toupper(*lin1))
  823.         {
  824.         case '1': align();
  825.             break;
  826.         case '2': make_tree();
  827.             break;
  828.         case '3': get_tree();
  829.             break;
  830.         case '4': pair_menu();
  831.             break;
  832.         case '5': multi_menu();
  833.             break;
  834.         case '6': format_options_menu();
  835.             break;
  836.         case 'S': do_system();
  837.             break;
  838.         case '?':
  839.         case 'H': get_help(2);
  840.             break;
  841.         case 'Q':
  842.         case 'X': return;
  843.  
  844.         default: fprintf(stderr,"\n\nUnrecognised Command\n\n");
  845.             break;
  846.         }
  847.     }
  848. }
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858. static void profile_align_menu()
  859. {
  860.     while(TRUE)
  861.     {
  862.     fprintf(stdout,"\n\n\n");
  863.         fprintf(stdout,"******Profile*Alignment*Menu******\n");
  864.         fprintf(stdout,"\n\n");
  865.  
  866.         fprintf(stdout,"    1.  Input 1st. profile/sequence\n");
  867.         fprintf(stdout,"    2.  Input 2nd. profile/sequence\n");
  868.         fprintf(stdout,"    3.  Do alignment now\n");
  869.         fprintf(stdout,"    4.  Alignment parameters\n");
  870.         fprintf(stdout,"    5.  Output format options\n");
  871.         fprintf(stdout,"\n");
  872.         fprintf(stdout,"    S.  Execute a system command\n");
  873.         fprintf(stdout,"    H.  HELP\n");
  874.         fprintf(stdout,"    or press [RETURN] to go back to main menu\n\n\n");
  875.  
  876.         getstr("Your choice",lin1);
  877.         if(*lin1 == EOS) return;
  878.  
  879.         switch(toupper(*lin1))
  880.         {
  881.         case '1': profile_input(1);      /* 1 => 1st profile */
  882.             break;
  883.         case '2': profile_input(2);      /* 2 => 2nd profile */
  884.             break;
  885.         case '3': profile_align();       /* align the 2 alignments now */
  886.             break;
  887.         case '4': multi_menu();
  888.             break;
  889.         case '5': format_options_menu();
  890.             break;
  891.         case 'S': do_system();
  892.             break;
  893.         case '?':
  894.         case 'H': get_help(6);
  895.             break;
  896.         case 'Q':
  897.         case 'X': return;
  898.  
  899.         default: fprintf(stderr,"\n\nUnrecognised Command\n\n");
  900.             break;
  901.         }
  902.     }
  903. }
  904.  
  905.  
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915. static void phylogenetic_tree_menu()
  916. {
  917.     while(TRUE)
  918.     {
  919.         fprintf(stdout,"\n\n\n");
  920.         fprintf(stdout,"******Phylogenetic*tree*Menu******\n");
  921.         fprintf(stdout,"\n\n");
  922.  
  923.         fprintf(stdout,"    1.  Input an alignment\n");
  924.         fprintf(stdout,"    2.  Exclude positions with gaps?        ");
  925.     if(tossgaps)
  926.         fprintf(stdout,"= ON\n");
  927.     else
  928.         fprintf(stdout,"= OFF\n");
  929.         fprintf(stdout,"    3.  Correct for multiple substitutions? ");
  930.     if(kimura)
  931.         fprintf(stdout,"= ON\n");
  932.     else
  933.         fprintf(stdout,"= OFF\n");
  934.         fprintf(stdout,"    4.  Draw tree now\n");
  935.         fprintf(stdout,"    5.  Bootstrap tree\n");
  936.         fprintf(stdout,"\n");
  937.         fprintf(stdout,"    S.  Execute a system command\n");
  938.         fprintf(stdout,"    H.  HELP\n");
  939.         fprintf(stdout,"    or press [RETURN] to go back to main menu\n\n\n");
  940.  
  941.         getstr("Your choice",lin1);
  942.         if(*lin1 == EOS) return;
  943.  
  944.         switch(toupper(*lin1))
  945.         {
  946.                 case '1': seq_input();
  947.                     break;
  948.             case '2': tossgaps ^= TRUE;
  949.                     break;
  950.               case '3': kimura ^= TRUE;;
  951.                     break;
  952.             case '4': phylogenetic_tree();
  953.                     break;
  954.             case '5': bootstrap_tree();
  955.                     break;
  956.             case 'S': do_system();
  957.                     break;
  958.                 case '?':
  959.             case 'H': get_help(7);
  960.                     break;
  961.                 case 'Q':
  962.             case 'X': return;
  963.  
  964.             default: fprintf(stderr,"\n\nUnrecognised Command\n\n");
  965.                 break;
  966.         }
  967.     }
  968. }
  969.  
  970.  
  971.  
  972.  
  973.  
  974.  
  975. static void format_options_menu()      /* format of alignment output */
  976. {    
  977.     char path[FILENAMELEN+1];
  978.  
  979.     while(TRUE) {
  980.     fprintf(stdout,"\n\n\n");
  981.     fprintf(stdout," ********* Format of Alignment Output *********\n");
  982.     fprintf(stdout,"\n\n");
  983.     fprintf(stdout,"     1. Toggle CLUSTAL format output   =  %s\n",
  984.                     (!output_clustal) ? "OFF" : "ON");
  985.     fprintf(stdout,"     2. Toggle NBRF/PIR format output  =  %s\n",
  986.                     (!output_nbrf) ? "OFF" : "ON");
  987.     fprintf(stdout,"     3. Toggle GCG format output       =  %s\n",
  988.                     (!output_gcg) ? "OFF" : "ON");
  989.     fprintf(stdout,"     4. Toggle PHYLIP format output    =  %s\n\n",
  990.                     (!output_phylip) ? "OFF" : "ON");
  991.       if(empty)
  992.     fprintf(stdout,"\n");
  993.       else
  994.     fprintf(stdout,"     5. Create alignment output file(s) now?\n");
  995.     fprintf(stdout,"     H. HELP\n\n\n");    
  996.     
  997.         getstr("Enter number (or [RETURN] to exit)",lin2);
  998.         if(*lin2 == EOS) return;
  999.         
  1000.         switch(toupper(*lin2)) {
  1001.             case '1':
  1002.                 output_clustal ^= TRUE;
  1003.                 break;
  1004.             case '2':
  1005.                           output_nbrf ^= TRUE;
  1006.                   break;
  1007.             case '3':
  1008.                           output_gcg ^= TRUE;
  1009.                   break;
  1010.             case '4':
  1011.                           output_phylip ^= TRUE;
  1012.                   break;
  1013.             case '5':
  1014.                 if(empty) break;
  1015.                 get_path(seqname,path);
  1016.                 if(!open_alignment_output(path)) break;
  1017.                 create_alignment_output();
  1018.                 break;
  1019.             case '?':
  1020.             case 'H':
  1021.                 get_help(5);
  1022.                 break;
  1023.             default:
  1024.                 fprintf(stderr,"\n\nUnrecognised Command\n\n");
  1025.                 break;
  1026.         }
  1027.     }
  1028. }
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041. static void pair_menu()
  1042. {
  1043.     if(dnaflag) {
  1044.         ktup     = dna_ktup;
  1045.         window   = dna_window;
  1046.         signif   = dna_signif;
  1047.         wind_gap = dna_wind_gap;
  1048.     }
  1049.     else {
  1050.         ktup     = prot_ktup;
  1051.         window   = prot_window;
  1052.         signif   = prot_signif;
  1053.         wind_gap = prot_wind_gap;
  1054.     }
  1055.  
  1056.     while(TRUE) {
  1057.         lin3 = percent ? "Percentage" : "Absolute";
  1058.     
  1059.         fprintf(stdout,"\n\n\n");
  1060.         fprintf(stdout," ********* WILBUR/LIPMAN PAIRWISE ALIGNMENT PARAMETERS *********\n");
  1061.         fprintf(stdout,"\n\n");
  1062.  
  1063.         fprintf(stdout,"     1. Toggle Scoring Method  :%s\n",lin3);
  1064.         fprintf(stdout,"     2. Gap Penalty            :%d\n",wind_gap);
  1065.         fprintf(stdout,"     3. K-tuple                :%d\n",ktup);
  1066.         fprintf(stdout,"     4. No. of top diagonals   :%d\n",signif);
  1067.         fprintf(stdout,"     5. Window size            :%d\n\n",window);
  1068.         fprintf(stdout,"     H. HELP\n\n\n");
  1069.         
  1070.         getstr("Enter number (or [RETURN] to exit)",lin2);
  1071.         if( *lin2 == EOS) {
  1072.             if(dnaflag) {
  1073.                 dna_ktup      = ktup;
  1074.                 dna_window    = window;
  1075.                 dna_signif    = signif;
  1076.                 dna_wind_gap  = wind_gap;
  1077.             }
  1078.             else {
  1079.                 prot_ktup     = ktup;
  1080.                 prot_window   = window;
  1081.                 prot_signif   = signif;
  1082.                 prot_wind_gap = wind_gap;
  1083.             }
  1084.             return;
  1085.         }
  1086.         
  1087.         switch(toupper(*lin2)) {
  1088.             case '1':
  1089.                 percent ^= TRUE;
  1090.                 break;
  1091.             case '2':
  1092.                 fprintf(stdout,"Gap Penalty Currently: %d\n",wind_gap);
  1093.                 wind_gap=getint("Enter number",1,500,wind_gap);
  1094.                 break;
  1095.             case '3':
  1096.                 fprintf(stdout,"K-tuple Currently: %d\n",ktup);
  1097.                 ktup=getint("Enter number",1,4,ktup);
  1098.                 break;
  1099.             case '4':
  1100.                 fprintf(stdout,"Top diagonals Currently: %d\n",signif);
  1101.                 signif=getint("Enter number",1,MAXLEN,signif);
  1102.                 break;
  1103.             case '5':
  1104.                 fprintf(stdout,"Window size Currently: %d\n",window);
  1105.                 window=getint("Enter number",1,50,window);
  1106.                 break;
  1107.             case '?':
  1108.             case 'H':
  1109.                 get_help(3);
  1110.                 break;
  1111.             default:
  1112.                 fprintf(stderr,"\n\nUnrecognised Command\n\n");
  1113.                 break;
  1114.         }
  1115.     }
  1116. }
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.  
  1129. static void multi_menu()
  1130. {
  1131.     if(dnaflag) {
  1132.         gap_open   = dna_gap_open;
  1133.         gap_extend = dna_gap_extend;
  1134.     }
  1135.     else {
  1136.         gap_open   = prot_gap_open;
  1137.         gap_extend = prot_gap_extend;
  1138.     }
  1139.  
  1140.     while(TRUE) {
  1141.         lin3 = is_weight ? "Weighted" :"Unweighted";
  1142.  
  1143.         fprintf(stdout,"\n\n\n");
  1144.         fprintf(stdout," ********* MYERS/MILLER MULTIPLE ALIGNMENT PARAMETERS *********\n");
  1145.         fprintf(stdout,"\n\n");
  1146.         
  1147.         fprintf(stdout,"     1. Fixed Gap Penalty       :%d\n",gap_open);
  1148.         fprintf(stdout,"     2. Floating Gap Penalty    :%d\n",gap_extend);
  1149.         fprintf(stdout,"     3. Toggle Transitions (DNA):%s\n",lin3);
  1150.         fprintf(stdout,"     4. Protein weight matrix   :%s\n\n"
  1151.                     ,pam_matrix_name[matnum-1]);
  1152.         fprintf(stdout,"     H. HELP\n\n\n");        
  1153.  
  1154.         getstr("Enter number (or [RETURN] to exit)",lin2);
  1155.  
  1156.         if(*lin2 == EOS) {
  1157.             if(dnaflag) {
  1158.                 dna_gap_open    = gap_open;
  1159.                 dna_gap_extend  = gap_extend;
  1160.             }
  1161.             else {
  1162.                 prot_gap_open   = gap_open;
  1163.                 prot_gap_extend = gap_extend;
  1164.             }
  1165.             return;
  1166.         }
  1167.         
  1168.         switch(toupper(*lin2)) {
  1169.             case '1':
  1170.             fprintf(stdout,"Fixed Gap Penalty Currently: %d\n",gap_open);
  1171.                 gap_open=getint("Enter number",1,100,gap_open);
  1172.                 break;
  1173.             case '2':
  1174.                 fprintf(stdout,"Floating Gap Penalty Currently: %d\n",gap_extend);
  1175.                 gap_extend=getint("Enter number",1,100,gap_extend);
  1176.                 break;
  1177.             case '3':
  1178.                 is_weight ^= TRUE;
  1179.                 break;
  1180.             case '4':
  1181.                 read_matrix();
  1182.                 break;
  1183.             case '?':
  1184.             case 'H':
  1185.                 get_help(4);
  1186.                 break;
  1187.             default:
  1188.                 fprintf(stderr,"\n\nUnrecognised Command\n\n");
  1189.                 break;
  1190.         }
  1191.     }
  1192. }
  1193.  
  1194.  
  1195.  
  1196.  
  1197.  
  1198.  
  1199.  
  1200.  
  1201.  
  1202.  
  1203.  
  1204. static void read_matrix()
  1205. {    static char userfile[FILENAMELEN+1];
  1206.     
  1207.     while(TRUE)
  1208.     {
  1209.         fprintf(stdout,"\n\n\n");
  1210.         fprintf(stdout," ********* PROTEIN WEIGHT MATRIX MENU *********\n");
  1211.         fprintf(stdout,"\n\n");
  1212.         
  1213.         
  1214.         fprintf(stdout,"     1. %s\n",pam_matrix_name[0]);
  1215.         fprintf(stdout,"     2. %s\n",pam_matrix_name[1]);
  1216.         fprintf(stdout,"     3. %s\n",pam_matrix_name[2]);
  1217.         fprintf(stdout,"     4. %s\n\n",pam_matrix_name[3]);
  1218.         fprintf(stdout,"     H. HELP\n\n");
  1219.         fprintf(stdout,
  1220. "     -- Current matrix is the %s ",pam_matrix_name[matnum-1]);
  1221.         if(matnum == 4) fprintf(stdout,"(file = %s)",userfile);
  1222.         fprintf(stdout,"--\n");
  1223.         
  1224.             
  1225.         getstr("\n\nEnter number (or [RETURN] to exit)",lin2);
  1226.         if(*lin2 == EOS) return;
  1227.  
  1228.         switch(toupper(*lin2))  {
  1229.             case '1':
  1230.                 matptr=pam100mt;
  1231.                 make_pamo(0);
  1232.                 prot_gap_open   = 13;
  1233.                 prot_gap_extend = 13;
  1234.                 matnum=1;
  1235.                 break;
  1236.             case '2':
  1237.                 matptr=pam250mt;
  1238.                 make_pamo(0);
  1239.                 prot_gap_open   = 10;
  1240.                 prot_gap_extend = 10;
  1241.                 matnum=2;
  1242.                 break;
  1243.             case '3':
  1244.                 matptr=idmat;
  1245.                 make_pamo(0);
  1246.                 prot_gap_open   = 10;
  1247.                 prot_gap_extend = 10;
  1248.                 matnum=3;
  1249.                 break;
  1250.             case '4':
  1251.                 if(user_mat(userfile)) matnum=4;
  1252.                 break;
  1253.             case '?':
  1254.             case 'H':
  1255.                 get_help(8);
  1256.                 break;
  1257.             default:
  1258.                 fprintf(stderr,"\n\nUnrecognised Command\n\n");
  1259.                 break;
  1260.         }
  1261.     }
  1262. }
  1263.  
  1264.  
  1265. static Boolean user_mat(char *str)
  1266. {
  1267.     int i,j,nv,pos,idx,val;
  1268.     FILE *infile;
  1269.     
  1270.     if(usemenu)
  1271.         getstr("Enter name of the matrix file",lin2);
  1272.     else
  1273.         strcpy(lin2,str);
  1274.  
  1275.     if(*lin2 == EOS) return FALSE;
  1276.     
  1277.     if((infile=fopen(lin2,"r"))==NULL) {
  1278.         error("Cannot find matrix file [%s]",lin2);
  1279.         return FALSE;
  1280.     }
  1281.  
  1282.     strcpy(str,lin2);
  1283.     strcpy(mtrxnam,lin2);
  1284.     
  1285.     idx=0;
  1286.     for(i=0;i<20;++i) 
  1287.         for(j=0;j<=i;++j) {
  1288.             if( fscanf(infile,"%d",&val) == EOF) {
  1289.                 error("Input matrix has too few values");
  1290.                 return FALSE;
  1291.             }
  1292.             usermat[idx++]=(char)val;
  1293.         }
  1294.  
  1295.     fclose(infile);
  1296.     matptr=usermat;
  1297.     make_pamo(0);
  1298.     return TRUE;
  1299. }
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310. static void seq_input()
  1311. {
  1312.     char c;
  1313.         int i;
  1314.     
  1315.     if(usemenu) {
  1316. fprintf(stdout,"\n\nSequences should all be in 1 file.\n"); 
  1317. fprintf(stdout,
  1318. "\n3 formats accepted:  NBRF/PIR, EMBL/SwissProt, Pearson (Fasta).\n");
  1319. fprintf(stdout,
  1320. "\nGCG users should use TOPIR to convert their sequence files before use.\n\n\n");
  1321.     }
  1322.  
  1323.     
  1324.        nseqs = readseqs(1);        /* DES   1 is the first seq to be read */
  1325.        if(nseqs < 0)               /* file could not be opened */
  1326.            { 
  1327.                nseqs = 0;
  1328.                empty = TRUE;
  1329.            }
  1330.        else if(nseqs == 0)         /* no sequences */
  1331.            {
  1332.            error("No sequences in file!  Bad format?");
  1333.                empty = TRUE;
  1334.            }
  1335.        else if(nseqs == 1)
  1336.            {
  1337.                error("Only one sequence in file!");
  1338.                empty = TRUE;
  1339.                nseqs = 0;
  1340.            }
  1341.        else 
  1342.            {
  1343.         fprintf(stdout,"\nSequences assumed to be %s \n\n",
  1344.             dnaflag?"DNA":"PROTEIN");
  1345.                 for(i=1; i<=nseqs; i++) {
  1346.                         fprintf(stdout,"Sequence %d: %-*.s   %6.d %s\n",
  1347.                         i,MAXNAMES,names[i],seqlen_array[i],dnaflag?"bp":"aa");
  1348.                 }    
  1349.             if(dnaflag) {
  1350.                 gap_open   = dna_gap_open;
  1351.                 gap_extend = dna_gap_extend;
  1352.             }
  1353.             else {
  1354.                 gap_open   = prot_gap_open;
  1355.                 gap_extend = prot_gap_extend;
  1356.             }
  1357.             empty=FALSE;
  1358.        }
  1359.     
  1360. }
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368. static void profile_input(int profile_no)   /* DES  read a profile   */
  1369. {                                           /* profile_no is 1 or 2  */
  1370.     char c;
  1371.         int local_nseqs, i;
  1372.     
  1373.         if(profile_no == 2 && profile1_empty) 
  1374.            {
  1375.              error("You must read in profile number 1 first");
  1376.              return;
  1377.            }
  1378.  
  1379.  
  1380.     if(profile_no == 1)     /* for the 1st profile */
  1381.       {
  1382.        local_nseqs = readseqs(1); /* (1) means 1st seq to be read = no. 1 */
  1383.        if(local_nseqs < 0)               /* file could not be opened */
  1384.            return;
  1385.        else if(local_nseqs == 0)         /* no sequences  */
  1386.            {
  1387.            error("No sequences in file!  Bad format?");
  1388.            return;
  1389.            }
  1390.        else 
  1391.            {                 /* success; found some seqs. */
  1392.                 nseqs = profile1_nseqs = local_nseqs;
  1393.         fprintf(stdout,"\nNo. of seqs=%d\n",nseqs);
  1394.         profile1_empty=FALSE;
  1395.         profile2_empty=TRUE;
  1396.        }
  1397.       }
  1398.     else
  1399.       {                    /* first seq to be read = profile1_nseqs + 1 */
  1400.        local_nseqs = readseqs(profile1_nseqs+1); 
  1401.        if(local_nseqs < 0)               /* file could not be opened */
  1402.                profile2_empty = TRUE;
  1403.        else if(local_nseqs == 0)         /* no sequences */
  1404.            {
  1405.            error("No sequences in file!  Bad format?");
  1406.                profile2_empty = TRUE;
  1407.            }
  1408.        else 
  1409.            {
  1410.         fprintf(stdout,"\nNo. of seqs in profile=%d\n",local_nseqs);
  1411.                 nseqs = profile1_nseqs + local_nseqs;
  1412.                 fprintf(stdout,"\nTotal no. of seqs     =%d\n",nseqs);
  1413.         profile2_empty=FALSE;
  1414.         empty = FALSE;
  1415.        }
  1416.  
  1417.       }
  1418.     
  1419.     fprintf(stdout,"\nSequences assumed to be %s \n\n",
  1420.         dnaflag?"DNA":"PROTEIN");
  1421.         for(i=profile2_empty?1:profile1_nseqs+1; i<=nseqs; i++) {
  1422.                 fprintf(stdout,"Sequence %d: %-*.s   %6.d %s\n",
  1423.                    i,MAXNAMES,names[i],seqlen_array[i],dnaflag?"bp":"aa");
  1424.         }    
  1425.     if(dnaflag) {
  1426.         gap_open   = dna_gap_open;
  1427.         gap_extend = dna_gap_extend;
  1428.     }
  1429.     else {
  1430.         gap_open   = prot_gap_open;
  1431.         gap_extend = prot_gap_extend;
  1432.     }
  1433. }
  1434.  
  1435.  
  1436.  
  1437.  
  1438.  
  1439.  
  1440. FILE *  open_output_file(char *prompt,      char *path, 
  1441.                 char *file_name,   char *file_extension)
  1442.  
  1443. {    static char temp[FILENAMELEN+1];
  1444.     static char local_prompt[MAXLINE];
  1445.     FILE * file_handle;
  1446.  
  1447.     strcpy(file_name,path);
  1448.     strcat(file_name,file_extension);
  1449.     strcpy(local_prompt,prompt);
  1450.     strcat(local_prompt," [%s]: ");          
  1451.  
  1452.     if(usemenu) {
  1453.         fprintf(stdout,local_prompt,file_name);
  1454.         gets(temp);
  1455.         if(*temp != EOS) strcpy(file_name,temp);
  1456.     }
  1457.  
  1458. #if VMS
  1459.     if((file_handle=fopen(file_name,"w","rat=cr","rfm=var"))==NULL) {
  1460. #else
  1461.     if((file_handle=fopen(file_name,"w"))==NULL) {
  1462. #endif
  1463.         error("Cannot open output file [%s]",file_name);
  1464.         return NULL;
  1465.     }
  1466.     return file_handle;
  1467. }
  1468.  
  1469.  
  1470.  
  1471.  
  1472.  
  1473.  
  1474.  
  1475.  
  1476.  
  1477.  
  1478.  
  1479. static void align()
  1480.     char path[FILENAMELEN+1],temp[FILENAMELEN+1];
  1481.     int oldmax,oldneut;
  1482.     
  1483.     if(empty && usemenu) {
  1484.         error("No sequences in memory. Load sequences first.");
  1485.         return;
  1486.     }
  1487.  
  1488.     get_path(seqname,path);
  1489.     
  1490.     if(!open_alignment_output(path)) return;
  1491.  
  1492.     if((tree = open_output_file(
  1493.             "\nEnter a name for the dendrogram file     ",
  1494.             path,treename,"dnd"))==NULL) return;
  1495.     
  1496.     fclose(tree);
  1497.     
  1498.     if(dnaflag) {
  1499.         ktup     = dna_ktup;
  1500.         window   = dna_window;
  1501.         signif   = dna_signif;
  1502.         wind_gap = dna_wind_gap;
  1503.     }
  1504.     else {
  1505.         ktup     = prot_ktup;
  1506.         window   = prot_window;
  1507.         signif   = prot_signif;
  1508.         wind_gap = prot_wind_gap;
  1509.     }
  1510.  
  1511.     reset();
  1512.     
  1513.     fprintf(stdout,"\nStart of Pairwise alignments\n");
  1514.     fprintf(stdout,"Aligning...\n");
  1515.     show_pair();
  1516.     upgma(nseqs);
  1517.     
  1518.     if((tree=fopen(treename,"r"))==NULL) {
  1519.         error("Cannot open file [%s]",treename);
  1520.         return;
  1521.     }
  1522.     
  1523.     oldneut=xover;
  1524.     oldmax=big_pam;
  1525.     myers(0);
  1526.     big_pam=oldmax;
  1527.     xover=oldneut;
  1528.     fclose(tree);
  1529.     
  1530.     fprintf(stdout,"\n\n\n");
  1531.     fprintf(stdout,"Consensus length = %d\n",seqlen_array[1]);
  1532.     
  1533.     create_alignment_output();
  1534. }
  1535.  
  1536.  
  1537.  
  1538.  
  1539.  
  1540.  
  1541.  
  1542.  
  1543.  
  1544. static void make_tree()
  1545. {
  1546.     char path[FILENAMELEN+1],temp[FILENAMELEN+1];
  1547.     
  1548.     if(empty) {
  1549.         error("No sequences in memory. Load sequences first.");
  1550.         return;
  1551.     }
  1552.  
  1553.     get_path(seqname,path);
  1554.  
  1555.     strcpy(treename,path);
  1556.     strcat(treename,"dnd");
  1557.     
  1558.     fprintf(stdout,"\nEnter a name for the DENDROGRAM file [%s]: ",treename);
  1559.     gets(temp);
  1560.     if(*temp != EOS)
  1561.         strcpy(treename,temp);
  1562.     
  1563. #if VMS
  1564.     if((tree=fopen(treename,"w","rat=cr","rfm=var"))==NULL) {
  1565. #else
  1566.     if((tree=fopen(treename,"w"))==NULL) {
  1567. #endif
  1568.         error("Cannot open file [%s]",treename);
  1569.         return;
  1570.     }
  1571.     fclose(tree);
  1572.     
  1573.     if(dnaflag) {
  1574.         ktup     = dna_ktup;
  1575.         window   = dna_window;
  1576.         signif   = dna_signif;
  1577.         wind_gap = dna_wind_gap;
  1578.     }
  1579.     else {
  1580.         ktup     = prot_ktup;
  1581.         window   = prot_window;
  1582.         signif   = prot_signif;
  1583.         wind_gap = prot_wind_gap;
  1584.     }
  1585.  
  1586.     reset();
  1587.     fprintf(stdout,"\nStart of Pairwise alignments\n");
  1588.     fprintf(stdout,"Aligning...\n");
  1589.     show_pair();
  1590.     upgma(nseqs);
  1591.     
  1592.     fprintf(stdout,"\nDENDROGRAM file created [%s]\n",treename);
  1593. }
  1594.  
  1595.  
  1596.  
  1597.  
  1598.  
  1599.  
  1600.  
  1601.  
  1602.  
  1603. static void get_tree()
  1604. {
  1605.     char path[FILENAMELEN+1],temp[MAXLINE+1];
  1606.     int count,oldmax,oldneut;
  1607.     
  1608.     if(empty) {
  1609.         error("No sequences in memory. Load sequences first.");
  1610.         return;
  1611.     }
  1612.  
  1613.     get_path(seqname,path);
  1614.     
  1615.     strcpy(treename,path);
  1616.     strcat(treename,"dnd");
  1617.     
  1618.     fprintf(stdout,"\nEnter a name for the DENDROGRAM file      [%s]:",treename);
  1619.     gets(temp);
  1620.     if(*temp != EOS)
  1621.         strcpy(treename,temp);
  1622.     
  1623.     if((tree=fopen(treename,"r"))==NULL) {
  1624.         error("Cannot open file [%s]",treename);
  1625.         return;
  1626.     }
  1627.     
  1628.     count=0;
  1629.     
  1630.     while(fgets(temp,MAXLINE+1,tree)!=NULL) ++count;
  1631.     
  1632.     fclose(tree);
  1633.     
  1634.     if(++count != nseqs) {
  1635.         error("Dendrogram file is not consistent with the sequence data");
  1636.         return;
  1637.     }
  1638.     
  1639.     if(!open_alignment_output(path)) return;
  1640.  
  1641.     reset();
  1642.     
  1643.     if((tree=fopen(treename,"r"))==NULL) {
  1644.         error("Cannot open file [%s]",treename);
  1645.         return;
  1646.     }
  1647.     
  1648.     oldmax=big_pam;
  1649.     oldneut=xover;
  1650.     myers(0);
  1651.     xover=oldneut;
  1652.     big_pam=oldmax;
  1653.     fclose(tree);
  1654.  
  1655.     fprintf(stdout,"\n\n\n");
  1656.     fprintf(stdout,"Consensus length = %d\n",seqlen_array[1]);
  1657.  
  1658.     create_alignment_output();
  1659. }
  1660.  
  1661.  
  1662.  
  1663.  
  1664.  
  1665.  
  1666.  
  1667.  
  1668.  
  1669.  
  1670. static void profile_align()
  1671. {
  1672.     char path[FILENAMELEN+1],temp[MAXLINE+1];
  1673.     int count,oldmax,oldneut;
  1674.     
  1675.     if(profile2_empty) {
  1676.         error("No sequences in memory. Load sequences first.");
  1677.         return;
  1678.     }
  1679.  
  1680.     get_path(seqname,path);
  1681.     
  1682.     if(!open_alignment_output(path)) return;
  1683.  
  1684.     reset();
  1685.         
  1686.     oldmax=big_pam;
  1687.     oldneut=xover;
  1688.     myers(1);
  1689.     xover=oldneut;
  1690.     big_pam=oldmax;
  1691.  
  1692.     fprintf(stdout,"\n\n\n");
  1693.     fprintf(stdout,"Consensus length = %d\n",seqlen_array[1]);
  1694.  
  1695.     create_alignment_output();
  1696. }
  1697.  
  1698.  
  1699.  
  1700.  
  1701.  
  1702.  
  1703.  
  1704.  
  1705. static void clustal_out(FILE *clusout)
  1706. {
  1707.     static char seq1[MAXLEN+1];
  1708.     char         temp[MAXLINE];
  1709.     int val,i,j,k,a,b,len;
  1710.     int chunks,ident,lv1,pos,ptr,copt,flag;
  1711.  
  1712.  
  1713.     fprintf(clusout,"CLUSTAL V multiple sequence alignment\n\n\n");
  1714.  
  1715.     len=seqlen_array[1];
  1716.     
  1717.     chunks = len/LINELENGTH;
  1718.     if(len % LINELENGTH != 0)
  1719.         ++chunks;
  1720.         
  1721.     for(lv1=1;lv1<=chunks;++lv1) {
  1722.         pos = ((lv1-1)*LINELENGTH)+1;
  1723.         ptr = (len<pos+LINELENGTH-1) ? len : pos+LINELENGTH-1;
  1724.         for(i=1;i<=nseqs;++i) {
  1725.             for(j=pos;j<=ptr;++j) {
  1726.                 val=seq_array[i][j];
  1727.                 if(val==0 || val>20)
  1728.                     seq1[j]='X';
  1729.                 else
  1730.                     if(val<0) seq1[j]='-';
  1731.                 else {
  1732.                     if(dnaflag)
  1733.                         seq1[j]=nucleic_acid_order[val];
  1734.                     else
  1735.                         seq1[j]=amino_acid_order[val];
  1736.                 }
  1737.             }
  1738.             strncpy(temp,&seq1[pos],ptr-pos+1);
  1739.             temp[ptr-pos+1]=EOS;
  1740.             fprintf(clusout,"%-15s %s\n",names[i],temp);
  1741.         }
  1742.     
  1743.         copt = ((nseqs*nseqs) - nseqs) / 2;
  1744.         for(i=pos;i<=ptr;++i) {
  1745.             seq1[i]=' ';
  1746.             ident=0;
  1747.             for(j=1;j<=nseqs;++j)
  1748.                 if(seq_array[1][i] == seq_array[j][i])
  1749.                     ++ident;
  1750.             if(ident==nseqs)
  1751.                 seq1[i]='*';
  1752.             else {
  1753.                 if(!dnaflag) {
  1754.                     ident=flag=0;
  1755.                     for(j=1;j<=nseqs;++j) {
  1756.                         for(k=j+1;k<=nseqs;++k)
  1757.                             if(seq_array[j][i]>0 && seq_array[k][i]>0) {
  1758.                                 if(weights[seq_array[j][i]][seq_array[k][i]]<xover)
  1759.                                     ++ident;
  1760.                                 else {
  1761.                                     flag=TRUE;
  1762.                                     break;
  1763.                                 }
  1764.                             }
  1765.                             else {
  1766.                                 flag=TRUE;
  1767.                                 break;
  1768.                             }
  1769.                             if(flag)
  1770.                                 break;
  1771.                     }
  1772.                     if(flag)
  1773.                         continue;
  1774.                     if(ident==copt)
  1775.                         seq1[i]='.';
  1776.                 }
  1777.             }
  1778.         }
  1779.         strncpy(temp,&seq1[pos],ptr-pos+1);
  1780.         temp[ptr-pos+1]=EOS;
  1781. /* "bugfix" Cornelius Krasel 19.02.94
  1782.         fprintf(clusout,"                %s\n\n",temp);
  1783.    is replaced by: */
  1784.         fprintf(clusout,"               %s\n\n",temp);
  1785.         ++nblocks;
  1786.     }
  1787.     
  1788. /*
  1789.     fprintf(stdout,"\nEnd of Multiple Alignment\n\n");
  1790.     fprintf(clusout,"\nEnd of Multiple Alignment\n\n");
  1791.     fprintf(clusout,"\nKey:\n     Identity:     #\n     Conservative: ^\n\n");
  1792.  
  1793.     fprintf(clusout,"\nParameters:\n\n");
  1794.     fprintf(clusout,"Ktup:         %d\nWilbur Gap:   %d\nCutoff:       %d\nDiagonal:     %d\n",
  1795.     ktup,wind_gap,signif,window);
  1796.     fprintf(clusout,"Fixed Gap:    %d\nFloating Gap: %d\n\n",gap_open,gap_extend);
  1797.  
  1798.     fprintf(clusout,"Sequences were: ");
  1799.     fprintf(clusout,dnaflag ? "Nucleic Acid\n" : "Proteins\n");
  1800.     fprintf(clusout,percent ? "Percentage" : "Absolute");
  1801.     fprintf(clusout," Identities Were Scored\n");
  1802.     if(dnaflag) {
  1803.         fprintf(clusout,"Nucleotide Transitions: ");
  1804.         fprintf(clusout,is_weight ? "WEIGHTED\n" : "UNWEIGHTED\n");
  1805.     }
  1806.     fprintf(clusout,"Sequence Input file: %s\n",seqname);
  1807.     fprintf(clusout,"Matrix used: ");
  1808.     if(matptr==idmat)
  1809.         fprintf(clusout,"No penalty\n");
  1810.     else
  1811.         if(matptr==pam250mt)
  1812.             fprintf(clusout,"PAM 250\n");
  1813.     else
  1814.         if(matptr==pam100mt)
  1815.             fprintf(clusout,"PAM 100\n");
  1816.     else
  1817.         fprintf(clusout,"%s\n",mtrxnam);
  1818. */
  1819. }
  1820.  
  1821.  
  1822.  
  1823.  
  1824.  
  1825.  
  1826. static void gcg_out(FILE *gcgout)
  1827. {
  1828. /*        static char *aacids = "XCSTPAGNDEQHRKMILVFYW";*/
  1829. /*    static char *nbases = "XACGT";    */
  1830.     char seq[MAXLEN+1], residue;
  1831.     int all_checks[MAXN+1];
  1832.     int i,j,k,len,val,check,chunks,block,pos1,pos2;    
  1833.     long grand_checksum;
  1834.     
  1835.     len = seqlen_array[1];
  1836.  
  1837.     for(i=1; i<=nseqs; i++) {
  1838.         for(j=1; j<=len; j++) {
  1839.             val = seq_array[i][j];
  1840.             if(val == 0 || val > 20) 
  1841.                 residue = 'X';
  1842.             else if(val < 0) 
  1843.                 residue = '.';
  1844.             else {
  1845.                 if(dnaflag)
  1846.                     residue = nucleic_acid_order[val];
  1847.                 else
  1848.                     residue = amino_acid_order[val];
  1849.             }
  1850.             seq[j] = residue;
  1851.         }
  1852.         all_checks[i] = SeqGCGCheckSum(seq+1, len);
  1853.     }    
  1854.  
  1855.     grand_checksum = 0;
  1856.     for(i=1; i<=nseqs; i++) grand_checksum += all_checks[i];
  1857.     grand_checksum = grand_checksum % 10000;
  1858.     fprintf(gcgout,"\n\n   MSF:%5d  Type: ",len);
  1859.     if(dnaflag)
  1860.         fprintf(gcgout,"N");
  1861.     else
  1862.         fprintf(gcgout,"P");
  1863.     fprintf(gcgout,"    Check:%6d   .. \n\n", grand_checksum);
  1864.     for(i=1; i<=nseqs; i++) 
  1865. /*        for(j=0; j<MAXNAMES; j++) 
  1866.             if(names[i][j] == ' ')  names[i][j] = '_';     */
  1867.         fprintf(gcgout,
  1868.             " Name: %-15s oo  Len:%5d  Check:%6d  Weight:  1.00\n",
  1869.             names[i],len,all_checks[i]);
  1870.     fprintf(gcgout,"\n//\n");  
  1871.  
  1872.     chunks = len/GCG_LINELENGTH;
  1873.     if(len % GCG_LINELENGTH != 0) ++chunks;
  1874.  
  1875.     for(block=1; block<=chunks; block++) {
  1876.         fprintf(gcgout,"\n\n");
  1877.         pos1 = ((block-1) * GCG_LINELENGTH) + 1;
  1878.         pos2 = (len<pos1+GCG_LINELENGTH-1)? len : pos1+GCG_LINELENGTH-1;
  1879.         for(i=1; i<=nseqs; i++) {
  1880.             fprintf(gcgout,"\n%-15s ",names[i]);
  1881.             for(j=pos1, k=1; j<=pos2; j++, k++) {
  1882.                 val = seq_array[i][j];
  1883.                 if(val == 0 || val > 20) 
  1884.                     residue = 'X';
  1885.                 else if(val < 0) 
  1886.                     residue = '.';
  1887.                 else {
  1888.                     if(dnaflag)
  1889.                         residue = nucleic_acid_order[val];
  1890.                     else
  1891.                         residue = amino_acid_order[val];
  1892.                 }
  1893.                 fprintf(gcgout,"%c",residue);
  1894.                 if(j % 10 == 0) fprintf(gcgout," ");
  1895.             }
  1896.         }
  1897.     }
  1898.     fprintf(gcgout,"\n\n");
  1899. }
  1900.  
  1901.  
  1902.  
  1903. static void phylip_out(FILE *phyout)
  1904. {
  1905. /*      static char *aacids = "XCSTPAGNDEQHRKMILVFYW";*/
  1906. /*        static char *nbases = "XACGT";    */
  1907.     char residue;
  1908.     int i,j,k,len,val,chunks,block,pos1,pos2;    
  1909.     
  1910.     len = seqlen_array[1];
  1911.  
  1912.  
  1913.     chunks = len/GCG_LINELENGTH;
  1914.     if(len % GCG_LINELENGTH != 0) ++chunks;
  1915.  
  1916.     fprintf(phyout,"%6d %6d",nseqs,len);
  1917.  
  1918.     for(block=1; block<=chunks; block++) {
  1919.         pos1 = ((block-1) * GCG_LINELENGTH) + 1;
  1920.         pos2 = (len<pos1+GCG_LINELENGTH-1)? len : pos1+GCG_LINELENGTH-1;
  1921.         for(i=1; i<=nseqs; i++) {
  1922.             if(block == 1) 
  1923.                 fprintf(phyout,"\n%-10s ",names[i]);
  1924.             else
  1925.                 fprintf(phyout,"\n           ");
  1926.             for(j=pos1, k=1; j<=pos2; j++, k++) {
  1927.                 val = seq_array[i][j];
  1928.                 if(val == 0 || val > 20) 
  1929.                     residue = 'X';
  1930.                 else if(val < 0) 
  1931.                     residue = '-';
  1932.                 else {
  1933.                     if(dnaflag)
  1934.                         residue = nucleic_acid_order[val];
  1935.                     else
  1936.                         residue = amino_acid_order[val];
  1937.                 }
  1938.                 fprintf(phyout,"%c",residue);
  1939.                 if(j % 10 == 0) fprintf(phyout," ");
  1940.             }
  1941.         }
  1942.         fprintf(phyout,"\n");
  1943.     }
  1944. }
  1945.  
  1946.  
  1947.  
  1948.  
  1949.  
  1950. static void nbrf_out(FILE *nbout)
  1951. {
  1952. /*      static char *aacids = "XCSTPAGNDEQHRKMILVFYW";*/
  1953. /*        static char *nbases = "XACGT";    */
  1954.     char seq[MAXLEN+1], residue;
  1955.     int i,j,len,val;    
  1956.     
  1957.     len = seqlen_array[1];
  1958.  
  1959.     for(i=1; i<=nseqs; i++) {
  1960.         fprintf(nbout, dnaflag ? ">DL;" : ">P1;");
  1961.         fprintf(nbout, "%s\n%s\n", names[i], titles[i]);
  1962.         for(j=1; j<=len; j++) {
  1963.             val = seq_array[i][j];
  1964.             if(val == 0 || val > 20) 
  1965.                 residue = 'X';
  1966.             else if(val < 0) 
  1967.                 residue = '-';
  1968.             else {
  1969.                 if(dnaflag)
  1970.                     residue = nucleic_acid_order[val];
  1971.                 else
  1972.                     residue = amino_acid_order[val];
  1973.             }
  1974.             seq[j] = residue;
  1975.         }
  1976.         for(j=1; j<=len; j++) {
  1977.             fprintf(nbout,"%c",seq[j]);
  1978.             if((j % LINELENGTH == 0) || (j == len)) 
  1979.                 fprintf(nbout,"\n");
  1980.         }
  1981.         fprintf(nbout,"*\n");
  1982.     }    
  1983. }
  1984.  
  1985.  
  1986. static Boolean open_alignment_output(char *path)
  1987. {
  1988.     if(output_clustal) 
  1989.         if((clustal_outfile = open_output_file(
  1990.                 "\nEnter a name for the CLUSTAL output file ",path,
  1991.             clustal_outname,"aln"))==NULL) return FALSE;
  1992.     if(output_nbrf) 
  1993.         if((nbrf_outfile = open_output_file(
  1994.                 "\nEnter a name for the NBRF/PIR output file",path,
  1995.             nbrf_outname,"pir"))==NULL) return FALSE;
  1996.     if(output_gcg) 
  1997.         if((gcg_outfile = open_output_file(
  1998.                 "\nEnter a name for the GCG output file     ",path,
  1999.             gcg_outname,"msf"))==NULL) return FALSE;
  2000.     if(output_phylip) 
  2001.         if((phylip_outfile = open_output_file(
  2002.                 "\nEnter a name for the PHYLIP output file  ",path,
  2003.             phylip_outname,"phy"))==NULL) return FALSE;
  2004.     return TRUE;
  2005. }
  2006.  
  2007.  
  2008.  
  2009.  
  2010.  
  2011. static void create_alignment_output()
  2012. {
  2013.     if(output_clustal) {
  2014.         clustal_out(clustal_outfile);
  2015.         fclose(clustal_outfile);
  2016.         fprintf(stdout,"\nCLUSTAL-Alignment file created  [%s]\n",clustal_outname);
  2017.     }
  2018.     if(output_nbrf)  {
  2019.         nbrf_out(nbrf_outfile);
  2020.         fclose(nbrf_outfile);
  2021.         fprintf(stdout,"\nNBRF/PIR-Alignment file created [%s]\n",nbrf_outname);
  2022.     }
  2023.     if(output_gcg)  {
  2024.         gcg_out(gcg_outfile);
  2025.         fclose(gcg_outfile);
  2026.         fprintf(stdout,"\nGCG-Alignment file created      [%s]\n",gcg_outname);
  2027.     }
  2028.     if(output_phylip)  {
  2029.         phylip_out(phylip_outfile);
  2030.         fclose(phylip_outfile);
  2031.         fprintf(stdout,"\nPHYLIP-Alignment file created   [%s]\n",phylip_outname);
  2032.     }
  2033. }
  2034.  
  2035.  
  2036.  
  2037.  
  2038.  
  2039.  
  2040. static void reset()   /* remove gaps from older alignments (code = -1) */
  2041. {              /* EXCEPT for gaps that were INPUT with the seqs.*/
  2042.     register int i,j,sl;                /* which have  code = -2  */
  2043.     
  2044.     for(i=1;i<=nseqs;++i) {
  2045.         sl=0;
  2046.         for(j=1;j<=seqlen_array[i];++j) {
  2047.             if(seq_array[i][j] == -1) continue;
  2048.             ++sl;
  2049.             seq_array[i][sl]=seq_array[i][j];
  2050.         }
  2051.         seqlen_array[i]=sl;
  2052.     }
  2053. }
  2054.  
  2055.  
  2056.