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, Thu Jul 15 18:49:19 1993
14 * Functions that I don't know quite where to put yet.
29 /* Function: Getword()
31 * Purpose: little function used by ReadPrior() and ReadHMM() to parse
32 * next valid field out of an open file, ignoring
33 * comments. '#' marks the beginning of a comment.
35 * Arg: fp - open file for reading
36 * type - sqdARG_INT, sqdARG_FLOAT, or sqdARG_STRING from squid.h
39 Getword(FILE *fp, int type)
41 static char buffer[512];
42 static char *sptr = NULL;
44 if (sptr != NULL) sptr = strtok(NULL, " \t\n");
48 if ((sptr = fgets(buffer, 512, fp)) == NULL) return NULL;
49 if ((sptr = strchr(buffer, '#')) != NULL) *sptr = '\0';
50 sptr = strtok(buffer, " \t\n");
55 if (strlen(sptr) == 0) {
56 Warn("Parse failed: expected string, got nothing");
62 Warn("Parse failed: expected integer, got %s", sptr);
68 Warn("Parse failed: expected real value, got %s", sptr);
78 /* Function: Getline()
80 * Purpose: Get the next non-blank, non-comment line from an open file.
81 * A comment line has '#' as the first non-whitespace character.
82 * Returns NULL if no line is found.
83 * Syntax is the same as fgets().
85 * Args: s - allocated storage for line
86 * n - number of characters allocated for s
89 * Return: Either s, or NULL if no new line is found.
92 Getline(char *s, int n, FILE *fp)
97 if (fgets(s, n, fp) == NULL) return NULL;
98 first = s; while (isspace((int) (*first))) first++;
99 } while (*first == '#' || *first == '\0');
104 /* Function: SetAutocuts()
105 * Date: SRE, Thu Jun 8 08:19:46 2000 [TW721 over Ireland]
107 * Purpose: Set score thresholds using the GA, TC, or NC information
110 * Args: thresh - score threshold structure. autocut must be set
111 * properly (CUT_GA, CUT_NC, or CUT_TC).
112 * hmm - HMM containing appropriate score cutoff info
114 * Returns: 1 on success.
115 * 0 if HMM does not have the score cutoffs available -- caller
116 * will have to decide on a fallback plan.
117 * Has no effect (and returns success) if autocut is
121 SetAutocuts(struct threshold_s *thresh, struct plan7_s *hmm)
123 if (thresh->autocut == CUT_GA) {
124 if (! (hmm->flags & PLAN7_GA)) return 0;
125 thresh->globT = hmm->ga1;
126 thresh->domT = hmm->ga2;
127 thresh->globE = thresh->domE = FLT_MAX;
128 } else if (thresh->autocut == CUT_NC) {
129 if (! (hmm->flags & PLAN7_NC)) return 0;
130 thresh->globT = hmm->nc1;
131 thresh->domT = hmm->nc2;
132 thresh->globE = thresh->domE = FLT_MAX;
133 } else if (thresh->autocut == CUT_TC) {
134 if (! (hmm->flags & PLAN7_TC)) return 0;
135 thresh->globT = hmm->tc1;
136 thresh->domT = hmm->tc2;
137 thresh->globE = thresh->domE = FLT_MAX;