1 /************************************************************
2 * HMMER - Biological sequence analysis with profile HMMs
3 * Copyright (C) 1992-1999 Washington University School of Medicine
6 * This source code is distributed under the terms of the
7 * GNU General Public License. See the files COPYING and LICENSE
9 ************************************************************/
12 * SRE, Wed Aug 5 11:05:03 1998 [St. Louis]
14 * Create an SSI index file for an HMM database.
16 * CVS $Id: hmmindex.c,v 1.1.1.1 2005/03/22 08:34:03 cmzmasek Exp $
31 static char banner[] = "hmmindex -- create SSI index for an HMM database";
33 static char usage[] = "\
34 Usage: hmmindex [-options] <hmmfile>\n\
35 Available options are:\n\
36 -h : print short usage and version info, then exit\n\
39 static char experts[] = "\
42 static struct opt_s OPTIONS[] = {
43 { "-h", TRUE, sqdARG_NONE },
45 #define NOPTIONS (sizeof(OPTIONS) / sizeof(struct opt_s))
48 main(int argc, char **argv)
50 char *hmmfile; /* HMM file to open */
51 SSIINDEX *ssi; /* SSI index in memory */
52 char *ssifile; /* name of SSI index on disk */
53 HMMFILE *hmmfp; /* opened hmm file pointer */
54 struct plan7_s *hmm; /* a hidden Markov model */
55 int idx, nhmm; /* counter over HMMs */
56 int npri, nsec; /* # of names, accessions */
57 int fh; /* file handle */
58 int status; /* return status from SSI call */
60 char *optname; /* name of option found by Getopt() */
61 char *optarg; /* argument found by Getopt() */
62 int optind; /* index in argv[] */
64 /***********************************************
65 * Parse the command line
66 ***********************************************/
68 while (Getopt(argc, argv, OPTIONS, NOPTIONS, usage,
69 &optind, &optname, &optarg))
71 if (strcmp(optname, "-h") == 0)
73 Banner(stdout, banner);
80 if (argc - optind != 1) Die("Incorrect number of arguments.\n%s\n", usage);
81 hmmfile = argv[optind++];
83 /***********************************************
84 * Open our input HMM file, make sure all is well with the output SSI filename
85 ***********************************************/
87 if ((hmmfp = HMMFileOpen(hmmfile, NULL)) == NULL)
88 Die("failed to open HMM file %s for reading.", hmmfile);
89 if (hmmfp->ssi != NULL)
90 Die("SSI index already exists for %s.\nPlease delete it first.", hmmfile);
92 ssifile = MallocOrDie(strlen(hmmfile) + 5);
93 sprintf(ssifile, "%s%s", hmmfile, ".ssi");
94 if (FileExists(ssifile)) /* shouldn't happen */
95 Die("An SSI file %s already exists; please delete it first", ssifile);
97 if ((ssi = SSICreateIndex(hmmfp->mode)) == NULL)
98 Die("Failed to initialize the SSI index structure");
99 if (SSIAddFileToIndex(ssi, hmmfile, hmmfp->is_binary, &fh) != 0)
100 Die("SSIAddFileToIndex() failed");
102 /***********************************************
104 ***********************************************/
106 Banner(stdout, banner);
107 printf("HMM file: %s\n", hmmfile);
108 if (hmmfp->mode == SSI_OFFSET_I64)
109 printf("Index file mode: 64-bit (large HMM file)\n");
110 printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n\n");
112 /***********************************************
113 * Get offsets and names for every model; store in keylist
114 ***********************************************/
116 printf("Determining offsets for %s, please be patient...\n", hmmfile);
118 nhmm = npri = nsec = 0;
119 while (HMMFileRead(hmmfp, &hmm))
122 Die("HMM file %s may be corrupt or in incorrect format; parse failed", hmmfile);
124 /* record name of HMM as the primary retrieval key */
125 status = SSIAddPrimaryKeyToIndex(ssi, hmm->name, fh, &(hmmfp->offset), NULL, 0);
126 if (status != 0) Die("SSIAddPrimaryKeyToIndex() failed");
129 /* record accession of HMM as a secondary retrieval key */
130 if (hmm->flags & PLAN7_ACC) {
131 status = SSIAddSecondaryKeyToIndex(ssi, hmm->acc, hmm->name);
132 if (status != 0) Die("SSIAddSecondaryKeyToIndex() failed");
141 /***********************************************
142 * Output the SSI file
143 ***********************************************/
145 status = SSIWriteIndex(ssifile, ssi);
146 if (status != 0) Die("SSIWriteIndex() failed");
148 printf("Complete.\n");
149 printf("HMM file: %s\n", hmmfile);
150 printf("SSI index: %s\n", ssifile);
151 printf("# of HMMS: %d\n", nhmm);
152 printf("HMM names: %d\n", npri);
153 printf("HMM accessions: %d\n", nsec);
156 /***********************************************
158 ***********************************************/