| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#include <p7_config.h> |
| 8 |
|
| 9 |
#include <stdlib.h> |
| 10 |
#include <stdio.h> |
| 11 |
#include <string.h> |
| 12 |
|
| 13 |
#include "hmmer.h" |
| 14 |
#include "easel.h" |
| 15 |
|
| 16 |
static int h2_multiline(FILE *fp, const char *pfx, char *s); |
| 17 |
static int printprob(FILE *fp, int fieldwidth, float p, float null); |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
int |
| 55 |
p7_h2io_WriteASCII(FILE *fp, P7_HMM *hmm) |
| 56 |
{ |
| 57 |
P7_BG *bg; |
| 58 |
int k; |
| 59 |
int x; |
| 60 |
int ts; |
| 61 |
float pmove,ploop; |
| 62 |
int status; |
| 63 |
|
| 64 |
if ((bg = p7_bg_Create(hmm->abc)) == NULL) { status = eslEMEM; goto ERROR; } |
| 65 |
|
| 66 |
|
| 67 |
if (fprintf(fp, "HMMER2.0 [converted from %s]\n", HMMER_VERSION) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 68 |
if (fprintf(fp, "NAME %s\n", hmm->name) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 69 |
if (hmm->acc && fprintf(fp, "ACC %s\n", hmm->acc) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 70 |
if (hmm->desc && fprintf(fp, "DESC %s\n", hmm->desc) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 71 |
if (fprintf(fp, "LENG %d\n", hmm->M) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 72 |
|
| 73 |
if (hmm->abc->type == eslAMINO) { if (fprintf(fp, "ALPH Amino\n") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); } |
| 74 |
else if (hmm->abc->type == eslDNA) { if (fprintf(fp, "ALPH Nucleic\n") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); } |
| 75 |
else if (hmm->abc->type == eslRNA) { if (fprintf(fp, "ALPH Nucleic\n") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); } |
| 76 |
else ESL_XEXCEPTION(eslEINVAL, "Only protein, DNA, RNA HMMs can be saved in H2 format"); |
| 77 |
|
| 78 |
if (fprintf(fp, "RF %s\n", (hmm->flags & p7H_RF) ? "yes" : "no") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 79 |
if (fprintf(fp, "CS %s\n", (hmm->flags & p7H_CS) ? "yes" : "no") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 80 |
if (fprintf(fp, "MAP %s\n", (hmm->flags & p7H_MAP) ? "yes" : "no") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 81 |
|
| 82 |
|
| 83 |
if (hmm->comlog != NULL) { if ( (status = h2_multiline(fp, "COM ", hmm->comlog)) != eslOK) goto ERROR; } |
| 84 |
if (hmm->nseq != -1) { if ( fprintf (fp, "NSEQ %d\n", hmm->nseq) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); } |
| 85 |
if (hmm->ctime != NULL) { if ( fprintf (fp, "DATE %s\n", hmm->ctime) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); } |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
if (hmm->flags & p7H_GA) { if (fprintf(fp, "GA %.1f %.1f\n", hmm->cutoff[p7_GA1], hmm->cutoff[p7_GA2]) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); } |
| 90 |
if (hmm->flags & p7H_TC) { if (fprintf(fp, "TC %.1f %.1f\n", hmm->cutoff[p7_TC1], hmm->cutoff[p7_TC2]) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); } |
| 91 |
if (hmm->flags & p7H_NC) { if (fprintf(fp, "NC %.1f %.1f\n", hmm->cutoff[p7_NC1], hmm->cutoff[p7_NC2]) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); } |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
if (fputs("XT ", fp) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 96 |
pmove = ( (hmm->abc->type == eslAMINO) ? 1./351. : 1./1001.); |
| 97 |
ploop = ( (hmm->abc->type == eslAMINO) ? 350./351. : 1000./1001.); |
| 98 |
if ( (status = printprob(fp, 6, pmove, 1.0)) != eslOK) goto ERROR; |
| 99 |
if ( (status = printprob(fp, 6, ploop, 1.0)) != eslOK) goto ERROR; |
| 100 |
if ( (status = printprob(fp, 6, 0.5, 1.0)) != eslOK) goto ERROR; |
| 101 |
if ( (status = printprob(fp, 6, 0.5, 1.0)) != eslOK) goto ERROR; |
| 102 |
if ( (status = printprob(fp, 6, pmove, 1.0)) != eslOK) goto ERROR; |
| 103 |
if ( (status = printprob(fp, 6, ploop, 1.0)) != eslOK) goto ERROR; |
| 104 |
if ( (status = printprob(fp, 6, pmove, 1.0)) != eslOK) goto ERROR; |
| 105 |
if ( (status = printprob(fp, 6, ploop, 1.0)) != eslOK) goto ERROR; |
| 106 |
if (fputc('\n', fp) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 107 |
|
| 108 |
|
| 109 |
if (fprintf(fp, "NULT ") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 110 |
if ( (status = printprob(fp, 6, ploop, 1.0)) != eslOK) goto ERROR; |
| 111 |
if ( (status = printprob(fp, 6, pmove, 1.0)) != eslOK) goto ERROR; |
| 112 |
if (fputc('\n', fp) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 113 |
|
| 114 |
|
| 115 |
if (fputs("NULE ", fp) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 116 |
for (x = 0; x < hmm->abc->K; x++) |
| 117 |
{ if ( (status = printprob(fp, 6, bg->f[x], 1./(float)hmm->abc->K)) != eslOK) goto ERROR; } |
| 118 |
if (fputc('\n', fp) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
if (fprintf(fp, "HMM ") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 124 |
for (x = 0; x < hmm->abc->K; x++) |
| 125 |
{ if (fprintf(fp, " %c ", hmm->abc->sym[x]) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); } |
| 126 |
if (fprintf(fp, "\n") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 127 |
if (fprintf(fp, " %6s %6s %6s %6s %6s %6s %6s %6s %6s\n", |
| 128 |
"m->m", "m->i", "m->d", "i->m", "i->i", "d->m", "d->d", "b->m", "m->e") < 0) |
| 129 |
ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 130 |
|
| 131 |
|
| 132 |
if (fprintf(fp, " ") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 133 |
if ( (status = printprob(fp, 6, 1.-hmm->t[0][p7H_MD], 1.0)) != eslOK) goto ERROR; |
| 134 |
if (fprintf(fp, " %6s", "*") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 135 |
if ( (status = printprob(fp, 6, hmm->t[0][p7H_MD], 1.0)) != eslOK) goto ERROR; |
| 136 |
if (fputc('\n', fp) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 137 |
|
| 138 |
for (k = 1; k <= hmm->M; k++) |
| 139 |
{ |
| 140 |
|
| 141 |
if (fprintf(fp, " %5d ", k) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 142 |
for (x = 0; x < hmm->abc->K; x++) |
| 143 |
if ( (status = printprob(fp, 6, hmm->mat[k][x], bg->f[x])) != eslOK) goto ERROR; |
| 144 |
if (hmm->flags & p7H_MAP) |
| 145 |
{ if (fprintf(fp, " %5d", hmm->map[k]) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); } |
| 146 |
if (fputc('\n', fp) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 147 |
|
| 148 |
if (fprintf(fp, " %5c ", hmm->flags & p7H_RF ? hmm->rf[k] : '-') < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 149 |
for (x = 0; x < hmm->abc->K; x++) |
| 150 |
if ( (status = printprob(fp, 6, ((k < hmm->M) ? hmm->ins[k][x] : 0.0), bg->f[x])) != eslOK) goto ERROR; |
| 151 |
if (fputc('\n', fp) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 152 |
|
| 153 |
if (fprintf(fp, " %5c ", hmm->flags & p7H_CS ? hmm->cs[k] : '-') < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 154 |
for (ts = 0; ts < 7; ts++) |
| 155 |
if ( (status = printprob(fp, 6, ((k < hmm->M) ? hmm->t[k][ts] : 0.0), 1.0)) != eslOK) goto ERROR; |
| 156 |
if ( (status = printprob(fp, 6, ((k==1) ? hmm->t[0][p7H_MM] : 0.0), 1.0)) != eslOK) goto ERROR; |
| 157 |
if ( (status = printprob(fp, 6, ((k<hmm->M) ? 0.0: 1.0), 1.0)) != eslOK) goto ERROR; |
| 158 |
if (fputc('\n', fp) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 159 |
|
| 160 |
} |
| 161 |
if (fputs("//\n", fp) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 162 |
|
| 163 |
p7_bg_Destroy(bg); |
| 164 |
return eslOK; |
| 165 |
|
| 166 |
ERROR: |
| 167 |
p7_bg_Destroy(bg); |
| 168 |
return status; |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
static int |
| 200 |
h2_multiline(FILE *fp, const char *pfx, char *s) |
| 201 |
{ |
| 202 |
char *sptr = s; |
| 203 |
char *end = NULL; |
| 204 |
int n = 0; |
| 205 |
|
| 206 |
do { |
| 207 |
end = strchr(sptr, '\n'); |
| 208 |
|
| 209 |
if (end != NULL) |
| 210 |
{ |
| 211 |
n = end - sptr; |
| 212 |
if (fprintf(fp, "%s ", pfx) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 213 |
if (fwrite(sptr, sizeof(char), n, fp) != n) ESL_EXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 214 |
if (fprintf(fp, "\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 215 |
sptr += n + 1; |
| 216 |
} |
| 217 |
else |
| 218 |
{ |
| 219 |
if (fprintf(fp, "%s %s\n", pfx, sptr) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); |
| 220 |
} |
| 221 |
} while (end != NULL && *sptr != '\0'); |
| 222 |
return eslOK; |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
static int |
| 235 |
printprob(FILE *fp, int fieldwidth, float p, float null) |
| 236 |
{ |
| 237 |
if (p == 0.0) { if (fprintf(fp, " %*s", fieldwidth, "*") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); } |
| 238 |
else if (null == 1.0 && p == 1.0) { if (fprintf(fp, " %*d", fieldwidth, 0) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); } |
| 239 |
else { if (fprintf(fp, " %*d", fieldwidth, (int) floor(0.5 + 1442.695 * log(p/null))) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "h2 profile write failed"); } |
| 240 |
return eslOK; |
| 241 |
} |
| 242 |
|
| 243 |
|