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 14:26:51 1998 [St. Louis]
14 * Recover a specific HMM file from an HMM database, using
15 * an SSI index (created with hmmindex).
17 * CVS $Id: hmmfetch.c,v 1.1.1.1 2005/03/22 08:34:14 cmzmasek Exp $
32 static char banner[] = "hmmfetch -- retrieve specific HMM from an HMM database";
34 static char usage[] = "\
35 Usage: hmmfetch [-options] <hmmfile> <HMM name>\n\
36 Available options are:\n\
37 -h : print short usage and version info, then exit\n\
38 -n : interpret <HMM name> instead as an HMM number\n\
41 static char experts[] = "\
44 static struct opt_s OPTIONS[] = {
45 { "-h", TRUE, sqdARG_NONE },
46 { "-n", TRUE, sqdARG_NONE },
48 #define NOPTIONS (sizeof(OPTIONS) / sizeof(struct opt_s))
52 main(int argc, char **argv)
54 char *hmmfile; /* HMM file to open */
55 char *key; /* HMM name to retrieve */
56 HMMFILE *hmmfp; /* opened hmm file pointer */
57 struct plan7_s *hmm; /* a hidden Markov model */
59 char *optname; /* name of option found by Getopt() */
60 char *optarg; /* argument found by Getopt() */
61 int optind; /* index in argv[] */
63 int by_number; /* fetch by number, not name */
64 int nhmm; /* hmm number */
66 /***********************************************
67 * Parse the command line
68 ***********************************************/
72 while (Getopt(argc, argv, OPTIONS, NOPTIONS, usage,
73 &optind, &optname, &optarg))
75 if (strcmp(optname, "-n") == 0) by_number = TRUE;
76 else if (strcmp(optname, "-h") == 0)
78 Banner(stdout, banner);
85 if (argc - optind != 2) Die("Incorrect number of arguments.\n%s\n", usage);
86 hmmfile = argv[optind++];
89 /***********************************************
90 * Open HMM file, make sure SSI index exists
91 ***********************************************/
93 if ((hmmfp = HMMFileOpen(hmmfile, "HMMERDB")) == NULL)
94 Die("failed to open HMM file %s for reading.", hmmfile);
95 if (hmmfp->ssi == NULL)
96 Die("There is no SSI index for %s; you need to use hmmindex on it.", hmmfile);
98 /***********************************************
99 * find key in hmmfile; get HMM; show as ASCII
100 ***********************************************/
103 if (! IsInt(key)) Die("%s does not appear to be a number.", key);
105 if (! HMMFilePositionByIndex(hmmfp, nhmm))
106 Die("failed to position %s to HMM #%d", hmmfile, nhmm);
108 if (! HMMFilePositionByName(hmmfp, key))
109 Die("No such hmm %s in HMM file %s\n", key, hmmfile);
112 if (! HMMFileRead(hmmfp, &hmm))
113 Die("Unexpected end of HMM file");
115 Die("HMM file %s may be corrupt or in incorrect format; parse failed", hmmfile);
117 WriteAscHMM(stdout, hmm);
122 /***********************************************
124 ***********************************************/