JPRED-2 Add sources of all binaries (except alscript) to Git
[jpred.git] / sources / pairwise / pairwise.c
1 /* Pairwise identity program.
2  *
3  * $Id
4  *
5  * Reads in a gapped alignment sequences in a FASTA file format.
6  * Assume gaps are represented by '-' characters.
7  *
8  * For each pair calculates the sequence percentage identity, see comments
9  * for pairwise() for details.
10  *
11  * Output is in the format for OC to read in, i.e. the number of sequences,
12  * followed by the sequence ID's, followed by the pairwise comparisons.
13  *
14  * Thu Dec  5 14:38:43 GMT 2002 Jon
15  * Added checking for eqilength sequences
16  *
17  * Thu Jul 24 12:14:04 BST 2003 Jon
18  * Moved FASTA reading into read_fasta function
19  * Checked into CVS
20  *
21  * */
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include "pairwise.h"
26
27 int
28 main (int argc, char **argv) {
29         FILE *fh;
30         struct fasta **seqs;
31         char **output;
32         int i = 0;
33
34         /* Read in the FASTA file */
35         if (argc == 2) 
36                 fh = xfopen(argv[1], "r");
37         else
38                 fh = stdin;
39
40         seqs = read_fasta(fh);
41         fclose(fh);
42
43         check_length(seqs);
44         output = do_pairwise(seqs);
45
46         for (i = 0; seqs[i] != NULL; i++)
47                 free_fasta(seqs[i]);
48         free(seqs);
49
50         for (i = 0; output[i] != NULL; i++) {
51                 printf("%s\n", output[i]);
52                 /*free(output[i]);*/
53         }
54         /*free(output);*/
55
56         return EXIT_SUCCESS;
57 }