| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#include <p7_config.h> |
| 30 |
|
| 31 |
#include <stdio.h> |
| 32 |
#include <stdlib.h> |
| 33 |
#include <string.h> |
| 34 |
|
| 35 |
#ifdef HMMER_THREADS |
| 36 |
#include <pthread.h> |
| 37 |
#endif |
| 38 |
|
| 39 |
#ifndef __APPLE_ALTIVEC__ |
| 40 |
#include <altivec.h> |
| 41 |
#endif |
| 42 |
|
| 43 |
#include "easel.h" |
| 44 |
|
| 45 |
#include "hmmer.h" |
| 46 |
#include "impl_vmx.h" |
| 47 |
|
| 48 |
static uint32_t v3f_fmagic = 0xb3e6e6f6; |
| 49 |
static uint32_t v3f_pmagic = 0xb3e6f0f6; |
| 50 |
|
| 51 |
static uint32_t v3e_fmagic = 0xb3e5e6f6; |
| 52 |
static uint32_t v3e_pmagic = 0xb3e5f0f6; |
| 53 |
|
| 54 |
static uint32_t v3d_fmagic = 0xb3e4e6f6; |
| 55 |
static uint32_t v3d_pmagic = 0xb3e4f0f6; |
| 56 |
|
| 57 |
static uint32_t v3c_fmagic = 0xb3e3e6f6; |
| 58 |
static uint32_t v3c_pmagic = 0xb3e3f0f6; |
| 59 |
|
| 60 |
static uint32_t v3b_fmagic = 0xb3e2e6f3; |
| 61 |
static uint32_t v3b_pmagic = 0xb3e2f0f3; |
| 62 |
|
| 63 |
static uint32_t v3a_fmagic = 0xe8b3e6f3; |
| 64 |
static uint32_t v3a_pmagic = 0xe8b3f0f3; |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
int |
| 93 |
p7_oprofile_Write(FILE *ffp, FILE *pfp, P7_OPROFILE *om) |
| 94 |
{ |
| 95 |
int Q4 = p7O_NQF(om->M); |
| 96 |
int Q8 = p7O_NQW(om->M); |
| 97 |
int Q16 = p7O_NQB(om->M); |
| 98 |
int n = strlen(om->name); |
| 99 |
int x; |
| 100 |
|
| 101 |
|
| 102 |
if (fwrite((char *) &(v3f_fmagic), sizeof(uint32_t), 1, ffp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 103 |
if (fwrite((char *) &(om->M), sizeof(int), 1, ffp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 104 |
if (fwrite((char *) &(om->abc->type), sizeof(int), 1, ffp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 105 |
if (fwrite((char *) &n, sizeof(int), 1, ffp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 106 |
if (fwrite((char *) om->name, sizeof(char), n+1, ffp) != n+1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 107 |
if (fwrite((char *) &(om->max_length),sizeof(int), 1, ffp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 108 |
if (fwrite((char *) &(om->tbm_b), sizeof(uint8_t), 1, ffp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 109 |
if (fwrite((char *) &(om->tec_b), sizeof(uint8_t), 1, ffp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 110 |
if (fwrite((char *) &(om->tjb_b), sizeof(uint8_t), 1, ffp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 111 |
if (fwrite((char *) &(om->scale_b), sizeof(float), 1, ffp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 112 |
if (fwrite((char *) &(om->base_b), sizeof(uint8_t), 1, ffp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 113 |
if (fwrite((char *) &(om->bias_b), sizeof(uint8_t), 1, ffp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 114 |
|
| 115 |
for (x = 0; x < om->abc->Kp; x++) |
| 116 |
if (fwrite( (char *) om->rbv[x], sizeof(vector unsigned char), Q16, ffp) != Q16) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 117 |
|
| 118 |
if (fwrite((char *) om->evparam, sizeof(float), p7_NEVPARAM, ffp) != p7_NEVPARAM) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 119 |
if (fwrite((char *) om->offs, sizeof(off_t), p7_NOFFSETS, ffp) != p7_NOFFSETS) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 120 |
if (fwrite((char *) om->compo, sizeof(float), p7_MAXABET, ffp) != p7_MAXABET) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 121 |
if (fwrite((char *) &(v3f_fmagic), sizeof(uint32_t), 1, ffp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 122 |
|
| 123 |
|
| 124 |
if (fwrite((char *) &(v3f_pmagic), sizeof(uint32_t), 1, pfp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 125 |
if (fwrite((char *) &(om->M), sizeof(int), 1, pfp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 126 |
if (fwrite((char *) &(om->abc->type), sizeof(int), 1, pfp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 127 |
if (fwrite((char *) &n, sizeof(int), 1, pfp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 128 |
if (fwrite((char *) om->name, sizeof(char), n+1, pfp) != n+1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 129 |
|
| 130 |
if (om->acc == NULL) { |
| 131 |
n = 0; |
| 132 |
if (fwrite((char *) &n, sizeof(int), 1, pfp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 133 |
} else { |
| 134 |
n = strlen(om->acc); |
| 135 |
if (fwrite((char *) &n, sizeof(int), 1, pfp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 136 |
if (fwrite((char *) om->acc, sizeof(char), n+1, pfp) != n+1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 137 |
} |
| 138 |
|
| 139 |
if (om->desc == NULL) { |
| 140 |
n = 0; |
| 141 |
if (fwrite((char *) &n, sizeof(int), 1, pfp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 142 |
} else { |
| 143 |
n = strlen(om->desc); |
| 144 |
if (fwrite((char *) &n, sizeof(int), 1, pfp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 145 |
if (fwrite((char *) om->desc, sizeof(char), n+1, pfp) != n+1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 146 |
} |
| 147 |
|
| 148 |
if (fwrite((char *) om->rf, sizeof(char), om->M+2, pfp) != om->M+2) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 149 |
if (fwrite((char *) om->mm, sizeof(char), om->M+2, pfp) != om->M+2) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 150 |
if (fwrite((char *) om->cs, sizeof(char), om->M+2, pfp) != om->M+2) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 151 |
if (fwrite((char *) om->consensus, sizeof(char), om->M+2, pfp) != om->M+2) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 152 |
|
| 153 |
|
| 154 |
if (fwrite((char *) om->twv, sizeof(vector signed short), 8*Q8, pfp) != 8*Q8) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 155 |
for (x = 0; x < om->abc->Kp; x++) |
| 156 |
if (fwrite( (char *) om->rwv[x], sizeof(vector signed short), Q8, pfp) != Q8) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 157 |
for (x = 0; x < p7O_NXSTATES; x++) |
| 158 |
if (fwrite( (char *) om->xw[x], sizeof(int16_t), p7O_NXTRANS, pfp) != p7O_NXTRANS) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 159 |
if (fwrite((char *) &(om->scale_w), sizeof(float), 1, pfp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 160 |
if (fwrite((char *) &(om->base_w), sizeof(int16_t), 1, pfp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 161 |
if (fwrite((char *) &(om->ddbound_w), sizeof(int16_t), 1, pfp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 162 |
if (fwrite((char *) &(om->ncj_roundoff), sizeof(float), 1, pfp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 163 |
|
| 164 |
|
| 165 |
if (fwrite((char *) om->tfv, sizeof(vector float), 8*Q4, pfp) != 8*Q4) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 166 |
for (x = 0; x < om->abc->Kp; x++) |
| 167 |
if (fwrite( (char *) om->rfv[x], sizeof(vector float), Q4, pfp) != Q4) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 168 |
for (x = 0; x < p7O_NXSTATES; x++) |
| 169 |
if (fwrite( (char *) om->xf[x], sizeof(float), p7O_NXTRANS, pfp) != p7O_NXTRANS) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 170 |
|
| 171 |
if (fwrite((char *) om->cutoff, sizeof(float), p7_NCUTOFFS, pfp) != p7_NCUTOFFS) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 172 |
if (fwrite((char *) &(om->nj), sizeof(float), 1, pfp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 173 |
if (fwrite((char *) &(om->mode), sizeof(int), 1, pfp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 174 |
if (fwrite((char *) &(om->L) , sizeof(int), 1, pfp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 175 |
if (fwrite((char *) &(v3f_pmagic), sizeof(uint32_t), 1, pfp) != 1) ESL_EXCEPTION_SYS(eslEWRITE, "oprofile write failed"); |
| 176 |
return eslOK; |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
int |
| 233 |
p7_oprofile_ReadMSV(P7_HMMFILE *hfp, ESL_ALPHABET **byp_abc, P7_OPROFILE **ret_om) |
| 234 |
{ |
| 235 |
P7_OPROFILE *om = NULL; |
| 236 |
ESL_ALPHABET *abc = NULL; |
| 237 |
uint32_t magic; |
| 238 |
off_t roff; |
| 239 |
int M, Q16; |
| 240 |
int x,n; |
| 241 |
int alphatype; |
| 242 |
int status; |
| 243 |
|
| 244 |
hfp->errbuf[0] = '\0'; |
| 245 |
if (hfp->ffp == NULL) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "no MSV profile file; hmmpress probably wasn't run"); |
| 246 |
if (feof(hfp->ffp)) { status = eslEOF; goto ERROR; } |
| 247 |
|
| 248 |
|
| 249 |
roff = ftello(hfp->ffp); |
| 250 |
|
| 251 |
if (! fread( (char *) &magic, sizeof(uint32_t), 1, hfp->ffp)) { status = eslEOF; goto ERROR; } |
| 252 |
if (magic == v3a_fmagic) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "this is an outdated HMM database format (3/a); please hmmpress your HMM file again"); |
| 253 |
if (magic == v3b_fmagic) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "this is an outdated HMM database format (3/b); please hmmpress your HMM file again"); |
| 254 |
if (magic == v3c_fmagic) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "this is an outdated HMM database format (3/c); please hmmpress your HMM file again"); |
| 255 |
if (magic == v3d_fmagic) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "this is an outdated HMM database format (3/d); please hmmpress your HMM file again"); |
| 256 |
if (magic == v3e_fmagic) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "this is an outdated HMM database format (3/e); please hmmpress your HMM file again"); |
| 257 |
if (magic != v3f_fmagic) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "bad magic; not an HMM database?"); |
| 258 |
|
| 259 |
if (! fread( (char *) &M, sizeof(int), 1, hfp->ffp)) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "failed to read model size M"); |
| 260 |
if (! fread( (char *) &alphatype, sizeof(int), 1, hfp->ffp)) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "failed to read alphabet type"); |
| 261 |
Q16 = p7O_NQB(M); |
| 262 |
|
| 263 |
|
| 264 |
if (byp_abc == NULL || *byp_abc == NULL) { |
| 265 |
if ((abc = esl_alphabet_Create(alphatype)) == NULL) ESL_XFAIL(eslEMEM, hfp->errbuf, "allocation failed: alphabet"); |
| 266 |
} else { |
| 267 |
abc = *byp_abc; |
| 268 |
if (abc->type != alphatype) |
| 269 |
ESL_XFAIL(eslEINCOMPAT, hfp->errbuf, "Alphabet type mismatch: was %s, but current profile says %s", |
| 270 |
esl_abc_DecodeType(abc->type), esl_abc_DecodeType(alphatype)); |
| 271 |
} |
| 272 |
|
| 273 |
if ((om = p7_oprofile_Create(M, abc)) == NULL) ESL_XFAIL(eslEMEM, hfp->errbuf, "allocation failed: oprofile"); |
| 274 |
om->M = M; |
| 275 |
om->roff = roff; |
| 276 |
|
| 277 |
if (! fread((char *) &n, sizeof(int), 1, hfp->ffp)) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "failed to read name length"); |
| 278 |
ESL_ALLOC(om->name, sizeof(char) * (n+1)); |
| 279 |
if (! fread((char *) om->name, sizeof(char), n+1, hfp->ffp)) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "failed to read name"); |
| 280 |
|
| 281 |
if (! fread((char *) &(om->max_length), sizeof(int), 1, hfp->ffp)) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "failed to read max_length"); |
| 282 |
if (! fread((char *) &(om->tbm_b), sizeof(uint8_t), 1, hfp->ffp)) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "failed to read tbm"); |
| 283 |
if (! fread((char *) &(om->tec_b), sizeof(uint8_t), 1, hfp->ffp)) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "failed to read tec"); |
| 284 |
if (! fread((char *) &(om->tjb_b), sizeof(uint8_t), 1, hfp->ffp)) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "failed to read tjb"); |
| 285 |
if (! fread((char *) &(om->scale_b), sizeof(float), 1, hfp->ffp)) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "failed to read scale"); |
| 286 |
if (! fread((char *) &(om->base_b), sizeof(uint8_t), 1, hfp->ffp)) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "failed to read base"); |
| 287 |
if (! fread((char *) &(om->bias_b), sizeof(uint8_t), 1, hfp->ffp)) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "failed to read bias"); |
| 288 |
for (x = 0; x < abc->Kp; x++) |
| 289 |
if (! fread((char *) om->rbv[x], sizeof(vector unsigned char), Q16, hfp->ffp)) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "failed to read msv scores at %d [residue %c]", x, abc->sym[x]); |
| 290 |
if (! fread((char *) om->evparam, sizeof(float), p7_NEVPARAM, hfp->ffp)) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "failed to read stat params"); |
| 291 |
if (! fread((char *) om->offs, sizeof(off_t), p7_NOFFSETS, hfp->ffp)) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "failed to read hmmpfam offsets"); |
| 292 |
if (! fread((char *) om->compo, sizeof(float), p7_MAXABET, hfp->ffp)) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "failed to read model composition"); |
| 293 |
if (! fread( (char *) &magic, sizeof(uint32_t), 1, hfp->ffp)) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "no sentinel magic: .h3f file corrupted?"); |
| 294 |
|
| 295 |
if (magic != v3f_fmagic) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "bad sentinel magic; .h3f file corrupted?"); |
| 296 |
|
| 297 |
|
| 298 |
om->eoff = ftello(hfp->ffp) - 1;; |
| 299 |
|
| 300 |
if (byp_abc != NULL) *byp_abc = abc; |
| 301 |
*ret_om = om; |
| 302 |
return eslOK; |
| 303 |
|
| 304 |
ERROR: |
| 305 |
if (abc != NULL && (byp_abc == NULL || *byp_abc == NULL)) esl_alphabet_Destroy(abc); |
| 306 |
if (om != NULL) p7_oprofile_Destroy(om); |
| 307 |
*ret_om = NULL; |
| 308 |
return status; |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
int |
| 350 |
p7_oprofile_ReadInfoMSV(P7_HMMFILE *hfp, ESL_ALPHABET **byp_abc, P7_OPROFILE **ret_om) |
| 351 |
{ |
| 352 |
P7_OPROFILE *om = NULL; |
| 353 |
ESL_ALPHABET *abc = NULL; |
| 354 |
uint32_t magic; |
| 355 |
off_t roff; |
| 356 |
int M, Q16; |
| 357 |
int n; |
| 358 |
int alphatype; |
| 359 |
int status; |
| 360 |
|
| 361 |
hfp->errbuf[0] = '\0'; |
| 362 |
if (hfp->ffp == NULL) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "no MSV profile file; hmmpress probably wasn't run"); |
| 363 |
if (feof(hfp->ffp)) { status = eslEOF; goto ERROR; } |
| 364 |
|
| 365 |
|
| 366 |
roff = ftello(hfp->ffp); |
| 367 |
|
| 368 |
if (! fread( (char *) &magic, sizeof(uint32_t), 1, hfp->ffp)) { status = eslEOF; goto ERROR; } |
| 369 |
if (magic == v3a_fmagic) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "this is an outdated HMM database format (3/a); please hmmpress your HMM file again"); |
| 370 |
if (magic == v3b_fmagic) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "this is an outdated HMM database format (3/b); please hmmpress your HMM file again"); |
| 371 |
if (magic == v3c_fmagic) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "this is an outdated HMM database format (3/c); please hmmpress your HMM file again"); |
| 372 |
if (magic == v3d_fmagic) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "this is an outdated HMM database format (3/d); please hmmpress your HMM file again"); |
| 373 |
if (magic == v3e_fmagic) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "this is an outdated HMM database format (3/e); please hmmpress your HMM file again"); |
| 374 |
if (magic != v3f_fmagic) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "bad magic; not an HMM database?"); |
| 375 |
|
| 376 |
if (! fread( (char *) &M, sizeof(int), 1, hfp->ffp)) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "failed to read model size M"); |
| 377 |
if (! fread( (char *) &alphatype, sizeof(int), 1, hfp->ffp)) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "failed to read alphabet type"); |
| 378 |
Q16 = p7O_NQB(M); |
| 379 |
|
| 380 |
|
| 381 |
if (byp_abc == NULL || *byp_abc == NULL) { |
| 382 |
if ((abc = esl_alphabet_Create(alphatype)) == NULL) ESL_XFAIL(eslEMEM, hfp->errbuf, "allocation failed: alphabet"); |
| 383 |
} else { |
| 384 |
abc = *byp_abc; |
| 385 |
if (abc->type != alphatype) |
| 386 |
ESL_XFAIL(eslEINCOMPAT, hfp->errbuf, "Alphabet type mismatch: was %s, but current profile says %s", |
| 387 |
esl_abc_DecodeType(abc->type), esl_abc_DecodeType(alphatype)); |
| 388 |
} |
| 389 |
|
| 390 |
if ((om = p7_oprofile_Create(M, abc)) == NULL) ESL_XFAIL(eslEMEM, hfp->errbuf, "allocation failed: oprofile"); |
| 391 |
om->M = M; |
| 392 |
om->roff = roff; |
| 393 |
|
| 394 |
|
| 395 |
om->name = NULL; |
| 396 |
if (!fread((char *) &n, sizeof(int), 1, hfp->ffp)) ESL_XFAIL(eslEFORMAT, hfp->errbuf, "failed to read name length"); |
| 397 |
roff += (sizeof(int) * 3); |
| 398 |
roff += sizeof(int) + n + 1; |
| 399 |
roff += (sizeof(float) + sizeof(uint8_t) * 5); |
| 400 |
roff += (sizeof(vector signed char) * abc->Kp * Q16); |
| 401 |
roff += (sizeof(float) * p7_NEVPARAM); |
| 402 |
roff += (sizeof(off_t) * p7_NOFFSETS); |
| 403 |
roff += (sizeof(float) * p7_MAXABET); |
| 404 |
roff += sizeof(uint32_t); |
| 405 |
|
| 406 |
|
| 407 |
p7_oprofile_Position(hfp, roff); |
| 408 |
om->eoff = ftello(hfp->ffp) - 1; |
| 409 |
|
| 410 |
if (byp_abc != NULL) *byp_abc = abc; |
| 411 |
*ret_om = om; |
| 412 |
return eslOK; |
| 413 |
|
| 414 |
ERROR: |
| 415 |
if (abc != NULL && (byp_abc == NULL || *byp_abc == NULL)) esl_alphabet_Destroy(abc); |
| 416 |
if (om != NULL) p7_oprofile_Destroy(om); |
| 417 |
*ret_om = NULL; |
| 418 |
return status; |
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
int |
| 435 |
p7_oprofile_ReadBlockMSV(P7_HMMFILE *hfp, ESL_ALPHABET **byp_abc, P7_OM_BLOCK *hmmBlock) |
| 436 |
{ |
| 437 |
int i; |
| 438 |
int size = 0; |
| 439 |
int status = eslOK; |
| 440 |
|
| 441 |
hmmBlock->count = 0; |
| 442 |
for (i = 0; i < hmmBlock->listSize; ++i) |
| 443 |
{ |
| 444 |
status = p7_oprofile_ReadMSV(hfp, byp_abc, &hmmBlock->list[i]); |
| 445 |
if (status != eslOK) break; |
| 446 |
size += hmmBlock->list[i]->M; |
| 447 |
++hmmBlock->count; |
| 448 |
} |
| 449 |
|
| 450 |
|
| 451 |
if (status == eslEOF && i > 0) status = eslOK; |
| 452 |
|
| 453 |
return status; |
| 454 |
} |
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
int |
| 486 |
p7_oprofile_ReadRest(P7_HMMFILE *hfp, P7_OPROFILE *om) |
| 487 |
{ |
| 488 |
uint32_t magic; |
| 489 |
int M, Q4, Q8; |
| 490 |
int x,n; |
| 491 |
char *name = NULL; |
| 492 |
int alphatype; |
| 493 |
int status; |
| 494 |
|
| 495 |
#ifdef HMMER_THREADS |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
if (hfp->syncRead) |
| 500 |
{ |
| 501 |
if (pthread_mutex_lock (&hfp->readMutex) != 0) ESL_EXCEPTION(eslESYS, "mutex lock failed"); |
| 502 |
} |
| 503 |
#endif |
| 504 |
|
| 505 |
hfp->rr_errbuf[0] = '\0'; |
| 506 |
if (hfp->pfp == NULL) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "no MSV profile file; hmmpress probably wasn't run"); |
| 507 |
|
| 508 |
|
| 509 |
if (fseeko(hfp->pfp, om->offs[p7_POFFSET], SEEK_SET) != 0) ESL_EXCEPTION(eslESYS, "fseeko() failed"); |
| 510 |
|
| 511 |
if (! fread( (char *) &magic, sizeof(uint32_t), 1, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read magic"); |
| 512 |
if (magic == v3a_pmagic) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "this is an outdated HMM database format (3/a); please hmmpress your HMM file again"); |
| 513 |
if (magic == v3b_pmagic) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "this is an outdated HMM database format (3/b); please hmmpress your HMM file again"); |
| 514 |
if (magic == v3c_pmagic) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "this is an outdated HMM database format (3/c); please hmmpress your HMM file again"); |
| 515 |
if (magic == v3d_pmagic) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "this is an outdated HMM database format (3/d); please hmmpress your HMM file again"); |
| 516 |
if (magic == v3e_pmagic) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "this is an outdated HMM database format (3/e); please hmmpress your HMM file again"); |
| 517 |
if (magic != v3f_pmagic) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "bad magic; not an HMM database file?"); |
| 518 |
|
| 519 |
if (! fread( (char *) &M, sizeof(int), 1, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read model size M"); |
| 520 |
if (! fread( (char *) &alphatype, sizeof(int), 1, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read alphabet type"); |
| 521 |
if (! fread( (char *) &n, sizeof(int), 1, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read name length"); |
| 522 |
if (M != om->M) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "p/f model length mismatch"); |
| 523 |
if (alphatype != om->abc->type) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "p/f alphabet type mismatch"); |
| 524 |
|
| 525 |
ESL_ALLOC(name, sizeof(char) * (n+1)); |
| 526 |
if (! fread( (char *) name, sizeof(char), n+1, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read name"); |
| 527 |
if (strcmp(name, om->name) != 0) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "p/f name mismatch"); |
| 528 |
|
| 529 |
if (! fread((char *) &n, sizeof(int), 1, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read accession length"); |
| 530 |
if (n > 0) { |
| 531 |
ESL_ALLOC(om->acc, sizeof(char) * (n+1)); |
| 532 |
if (! fread( (char *) om->acc, sizeof(char), n+1, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read accession"); |
| 533 |
} |
| 534 |
if (! fread((char *) &n, sizeof(int), 1, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read description length"); |
| 535 |
if (n > 0) { |
| 536 |
ESL_ALLOC(om->desc, sizeof(char) * (n+1)); |
| 537 |
if (! fread( (char *) om->desc, sizeof(char), n+1, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read description"); |
| 538 |
} |
| 539 |
|
| 540 |
if (! fread((char *) om->rf, sizeof(char), M+2, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read rf annotation"); |
| 541 |
if (! fread((char *) om->mm, sizeof(char), M+2, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read mm annotation"); |
| 542 |
if (! fread((char *) om->cs, sizeof(char), M+2, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read cs annotation"); |
| 543 |
if (! fread((char *) om->consensus, sizeof(char), M+2, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read consensus annotation"); |
| 544 |
|
| 545 |
Q4 = p7O_NQF(om->M); |
| 546 |
Q8 = p7O_NQW(om->M); |
| 547 |
|
| 548 |
if (! fread((char *) om->twv, sizeof(vector signed short), 8*Q8, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read <tu>, vitfilter transitions"); |
| 549 |
for (x = 0; x < om->abc->Kp; x++) |
| 550 |
if (! fread( (char *) om->rwv[x], sizeof(vector signed short), Q8, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read <ru>[%d], vitfilter emissions for sym %c", x, om->abc->sym[x]); |
| 551 |
for (x = 0; x < p7O_NXSTATES; x++) |
| 552 |
if (! fread( (char *) om->xw[x], sizeof(int16_t), p7O_NXTRANS, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read <xu>[%d], vitfilter special transitions", x); |
| 553 |
if (! fread((char *) &(om->scale_w), sizeof(float), 1, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read scale_w"); |
| 554 |
if (! fread((char *) &(om->base_w), sizeof(int16_t), 1, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read base_w"); |
| 555 |
if (! fread((char *) &(om->ddbound_w), sizeof(int16_t), 1, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read ddbound_w"); |
| 556 |
if (! fread((char *) &(om->ncj_roundoff), sizeof(float), 1, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read ddbound_w"); |
| 557 |
|
| 558 |
if (! fread((char *) om->tfv, sizeof(vector float), 8*Q4, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read <tf> transitions"); |
| 559 |
for (x = 0; x < om->abc->Kp; x++) |
| 560 |
if (! fread( (char *) om->rfv[x], sizeof(vector float), Q4, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read <rf>[%d] emissions for sym %c", x, om->abc->sym[x]); |
| 561 |
for (x = 0; x < p7O_NXSTATES; x++) |
| 562 |
if (! fread( (char *) om->xf[x], sizeof(float), p7O_NXTRANS, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read <xf>[%d] special transitions", x); |
| 563 |
|
| 564 |
if (! fread((char *) om->cutoff, sizeof(float), p7_NCUTOFFS, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read Pfam score cutoffs"); |
| 565 |
if (! fread((char *) &(om->nj), sizeof(float), 1, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read nj"); |
| 566 |
if (! fread((char *) &(om->mode), sizeof(int), 1, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read mode"); |
| 567 |
if (! fread((char *) &(om->L) , sizeof(int), 1, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read L"); |
| 568 |
if (! fread( (char *) &magic, sizeof(uint32_t), 1, hfp->pfp)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "no sentinel magic: .h3p file corrupted?"); |
| 569 |
|
| 570 |
if (magic != v3f_pmagic) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "bad sentinel magic; .h3p file corrupted?"); |
| 571 |
|
| 572 |
#ifdef HMMER_THREADS |
| 573 |
if (hfp->syncRead) |
| 574 |
{ |
| 575 |
if (pthread_mutex_unlock (&hfp->readMutex) != 0) ESL_EXCEPTION(eslESYS, "mutex unlock failed"); |
| 576 |
} |
| 577 |
#endif |
| 578 |
|
| 579 |
free(name); |
| 580 |
return eslOK; |
| 581 |
|
| 582 |
ERROR: |
| 583 |
|
| 584 |
#ifdef HMMER_THREADS |
| 585 |
if (hfp->syncRead) |
| 586 |
{ |
| 587 |
if (pthread_mutex_unlock (&hfp->readMutex) != 0) ESL_EXCEPTION(eslESYS, "mutex unlock failed"); |
| 588 |
} |
| 589 |
#endif |
| 590 |
|
| 591 |
if (name != NULL) free(name); |
| 592 |
return status; |
| 593 |
} |
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
P7_OM_BLOCK * |
| 612 |
p7_oprofile_CreateBlock(int count) |
| 613 |
{ |
| 614 |
int i = 0; |
| 615 |
|
| 616 |
P7_OM_BLOCK *block = NULL; |
| 617 |
int status = eslOK; |
| 618 |
|
| 619 |
ESL_ALLOC(block, sizeof(*block)); |
| 620 |
|
| 621 |
block->count = 0; |
| 622 |
block->listSize = 0; |
| 623 |
block->list = NULL; |
| 624 |
|
| 625 |
ESL_ALLOC(block->list, sizeof(P7_OPROFILE *) * count); |
| 626 |
block->listSize = count; |
| 627 |
|
| 628 |
for (i = 0; i < count; ++i) |
| 629 |
{ |
| 630 |
block->list[i] = NULL; |
| 631 |
} |
| 632 |
|
| 633 |
return block; |
| 634 |
|
| 635 |
ERROR: |
| 636 |
if (block != NULL) |
| 637 |
{ |
| 638 |
if (block->list != NULL) free(block->list); |
| 639 |
free(block); |
| 640 |
} |
| 641 |
|
| 642 |
return NULL; |
| 643 |
} |
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
void |
| 651 |
p7_oprofile_DestroyBlock(P7_OM_BLOCK *block) |
| 652 |
{ |
| 653 |
int i; |
| 654 |
|
| 655 |
if (block == NULL) return; |
| 656 |
|
| 657 |
if (block->list != NULL) |
| 658 |
{ |
| 659 |
for (i = 0; i < block->listSize; ++i) |
| 660 |
{ |
| 661 |
if (block->list[i] != NULL) p7_oprofile_Destroy(block->list[i]); |
| 662 |
} |
| 663 |
free(block->list); |
| 664 |
} |
| 665 |
|
| 666 |
free(block); |
| 667 |
return; |
| 668 |
} |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
int |
| 685 |
p7_oprofile_Position(P7_HMMFILE *hfp, off_t offset) |
| 686 |
{ |
| 687 |
if (hfp->ffp == NULL) ESL_EXCEPTION(eslEFORMAT, hfp->errbuf, "no MSV profile file; hmmpress probably wasn't run"); |
| 688 |
if (hfp->do_stdin) ESL_EXCEPTION(eslEINVAL, "can't Position() in standard input"); |
| 689 |
if (hfp->do_gzip) ESL_EXCEPTION(eslEINVAL, "can't Position() in a gzipped file"); |
| 690 |
if (offset < 0) ESL_EXCEPTION(eslEINVAL, "bad offset"); |
| 691 |
|
| 692 |
if (fseeko(hfp->ffp, offset, SEEK_SET) != 0) ESL_EXCEPTION(eslESYS, "fseeko() failed"); |
| 693 |
|
| 694 |
return eslOK; |
| 695 |
} |
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
#ifdef p7IO_BENCHMARK |
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
#include <p7_config.h> |
| 711 |
|
| 712 |
#include <stdlib.h> |
| 713 |
#include <stdio.h> |
| 714 |
|
| 715 |
#include "easel.h" |
| 716 |
#include "esl_getopts.h" |
| 717 |
#include "esl_stopwatch.h" |
| 718 |
|
| 719 |
#include "hmmer.h" |
| 720 |
|
| 721 |
static ESL_OPTIONS options[] = { |
| 722 |
|
| 723 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 724 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 725 |
}; |
| 726 |
static char usage[] = "[-options] <HMM MSV profile file>"; |
| 727 |
static char banner[] = "benchmark driver for profile input"; |
| 728 |
|
| 729 |
int |
| 730 |
main(int argc, char **argv) |
| 731 |
{ |
| 732 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 1, argc, argv, banner, usage); |
| 733 |
ESL_STOPWATCH *w = esl_stopwatch_Create(); |
| 734 |
ESL_ALPHABET *abc = NULL; |
| 735 |
char *msvfile = esl_opt_GetArg(go, 1); |
| 736 |
FILE *msvfp = NULL; |
| 737 |
P7_OPROFILE *om = NULL; |
| 738 |
int nmodel = 0; |
| 739 |
uint64_t totM = 0; |
| 740 |
int status; |
| 741 |
|
| 742 |
esl_stopwatch_Start(w); |
| 743 |
|
| 744 |
if ((msvfp = fopen(msvfile, "r")) == NULL) p7_Fail("Failed to open MSV file %s for reading.\n", msvfile); |
| 745 |
|
| 746 |
while ((status = p7_oprofile_ReadMSV(msvfp, &abc, NULL, &om)) == eslOK) |
| 747 |
{ |
| 748 |
nmodel++; |
| 749 |
totM += om->M; |
| 750 |
|
| 751 |
p7_oprofile_Destroy(om); |
| 752 |
} |
| 753 |
if (status == eslEFORMAT) p7_Fail("bad file format in profile file %s", msvfile); |
| 754 |
else if (status == eslEINCOMPAT) p7_Fail("profile file %s contains different alphabets", msvfile); |
| 755 |
else if (status != eslEOF) p7_Fail("Unexpected error in reading profiles from %s", msvfile); |
| 756 |
|
| 757 |
esl_stopwatch_Stop(w); |
| 758 |
esl_stopwatch_Display(stdout, w, "# CPU time: "); |
| 759 |
printf("# number of models: %d\n", nmodel); |
| 760 |
printf("# total M: %" PRId64 "\n", totM); |
| 761 |
|
| 762 |
fclose(msvfp); |
| 763 |
esl_alphabet_Destroy(abc); |
| 764 |
esl_stopwatch_Destroy(w); |
| 765 |
esl_getopts_Destroy(go); |
| 766 |
return 0; |
| 767 |
} |
| 768 |
#endif |
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
#ifdef p7IO_TESTDRIVE |
| 776 |
|
| 777 |
static void |
| 778 |
utest_ReadWrite(P7_HMM *hmm, P7_OPROFILE *om) |
| 779 |
{ |
| 780 |
char *msg = "oprofile read/write unit test failure"; |
| 781 |
ESL_ALPHABET *abc = NULL; |
| 782 |
P7_OPROFILE *om2 = NULL; |
| 783 |
char tmpfile[16] = "esltmpXXXXXX"; |
| 784 |
char *mfile = NULL; |
| 785 |
char *ffile = NULL; |
| 786 |
char *pfile = NULL; |
| 787 |
char *ssifile = NULL; |
| 788 |
FILE *fp = NULL; |
| 789 |
FILE *mfp = NULL; |
| 790 |
FILE *ffp = NULL; |
| 791 |
FILE *pfp = NULL; |
| 792 |
ESL_NEWSSI *nssi = NULL; |
| 793 |
P7_HMMFILE *hfp = NULL; |
| 794 |
uint16_t fh = 0; |
| 795 |
float tolerance = 0.001; |
| 796 |
char errbuf[eslERRBUFSIZE]; |
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
if ( esl_tmpfile_named(tmpfile, &fp) != eslOK) esl_fatal(msg); |
| 802 |
if ( esl_sprintf(&mfile, "%s.h3m", tmpfile) != eslOK) esl_fatal(msg); |
| 803 |
if ( esl_sprintf(&ffile, "%s.h3f", tmpfile) != eslOK) esl_fatal(msg); |
| 804 |
if ( esl_sprintf(&pfile, "%s.h3p", tmpfile) != eslOK) esl_fatal(msg); |
| 805 |
if ( esl_sprintf(&ssifile, "%s.h3i", tmpfile) != eslOK) esl_fatal(msg); |
| 806 |
|
| 807 |
if ( esl_newssi_Open(ssifile, TRUE, &nssi) != eslOK) esl_fatal(msg); |
| 808 |
if (( mfp = fopen(mfile, "wb")) == NULL) esl_fatal(msg); |
| 809 |
if (( ffp = fopen(ffile, "wb")) == NULL) esl_fatal(msg); |
| 810 |
if (( pfp = fopen(pfile, "wb")) == NULL) esl_fatal(msg); |
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
if ((om->offs[p7_MOFFSET] = ftello(mfp)) == -1) esl_fatal(msg); |
| 817 |
if ((om->offs[p7_FOFFSET] = ftello(ffp)) == -1) esl_fatal(msg); |
| 818 |
if ((om->offs[p7_POFFSET] = ftello(pfp)) == -1) esl_fatal(msg); |
| 819 |
|
| 820 |
if ( p7_hmmfile_WriteASCII(fp, -1, hmm) != eslOK) esl_fatal(msg); |
| 821 |
if ( p7_hmmfile_WriteBinary(mfp, -1, hmm) != eslOK) esl_fatal(msg); |
| 822 |
if ( p7_oprofile_Write(ffp, pfp, om) != eslOK) esl_fatal(msg); |
| 823 |
|
| 824 |
if ( esl_newssi_AddFile(nssi, tmpfile, 0, &fh) != eslOK) esl_fatal(msg); |
| 825 |
if ( esl_newssi_AddKey (nssi, hmm->name, fh, om->offs[p7_MOFFSET], 0, 0) != eslOK) esl_fatal(msg); |
| 826 |
if ( esl_newssi_Write(nssi) != eslOK) esl_fatal(msg); |
| 827 |
|
| 828 |
fclose(fp); |
| 829 |
fclose(mfp); |
| 830 |
fclose(ffp); |
| 831 |
fclose(pfp); |
| 832 |
esl_newssi_Close(nssi); |
| 833 |
|
| 834 |
|
| 835 |
if ( p7_hmmfile_Open(tmpfile, NULL, &hfp, NULL) != eslOK) esl_fatal(msg); |
| 836 |
if ( p7_oprofile_ReadMSV(hfp, &abc, &om2) != eslOK) esl_fatal(msg); |
| 837 |
if ( p7_oprofile_ReadRest(hfp, om2) != eslOK) esl_fatal(msg); |
| 838 |
|
| 839 |
|
| 840 |
if ( p7_oprofile_Compare(om, om2, tolerance, errbuf) != eslOK) esl_fatal("%s\n%s", msg, errbuf); |
| 841 |
|
| 842 |
p7_oprofile_Destroy(om2); |
| 843 |
p7_hmmfile_Close(hfp); |
| 844 |
esl_alphabet_Destroy(abc); |
| 845 |
remove(ssifile); |
| 846 |
remove(ffile); |
| 847 |
remove(pfile); |
| 848 |
remove(mfile); |
| 849 |
remove(tmpfile); |
| 850 |
|
| 851 |
free(ssifile); |
| 852 |
free(mfile); |
| 853 |
free(ffile); |
| 854 |
free(pfile); |
| 855 |
} |
| 856 |
|
| 857 |
#endif |
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
#ifdef p7IO_TESTDRIVE |
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
#include <p7_config.h> |
| 870 |
|
| 871 |
#include "easel.h" |
| 872 |
#include "esl_alphabet.h" |
| 873 |
#include "esl_getopts.h" |
| 874 |
|
| 875 |
#include "hmmer.h" |
| 876 |
#include "impl_vmx.h" |
| 877 |
|
| 878 |
static ESL_OPTIONS options[] = { |
| 879 |
|
| 880 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 881 |
{ "-s", eslARG_INT, "42", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0 }, |
| 882 |
{ "-M", eslARG_INT, "45", NULL, NULL, NULL, NULL, NULL, "size of random model to sample", 0 }, |
| 883 |
{ "-L", eslARG_INT, "45", NULL, NULL, NULL, NULL, NULL, "configure model for length <n>", 0 }, |
| 884 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 885 |
}; |
| 886 |
static char usage[] = "[-options]"; |
| 887 |
static char banner[] = "test driver for VMX Forward, Backward implementations"; |
| 888 |
|
| 889 |
int |
| 890 |
main(int argc, char **argv) |
| 891 |
{ |
| 892 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 0, argc, argv, banner, usage); |
| 893 |
ESL_RANDOMNESS *r = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s")); |
| 894 |
ESL_ALPHABET *abc = NULL; |
| 895 |
P7_BG *bg = NULL; |
| 896 |
P7_HMM *hmm = NULL; |
| 897 |
P7_OPROFILE *om = NULL; |
| 898 |
int M = esl_opt_GetInteger(go, "-M"); |
| 899 |
int L = esl_opt_GetInteger(go, "-L"); |
| 900 |
|
| 901 |
|
| 902 |
if ((abc = esl_alphabet_Create(eslAMINO)) == NULL) esl_fatal("failed to create alphabet"); |
| 903 |
if ((bg = p7_bg_Create(abc)) == NULL) esl_fatal("failed to create null model"); |
| 904 |
if (( p7_oprofile_Sample(r, abc, bg, M, L, &hmm, NULL, &om)) != eslOK) esl_fatal("failed to sample HMM and profile"); |
| 905 |
|
| 906 |
|
| 907 |
utest_ReadWrite(hmm, om); |
| 908 |
|
| 909 |
p7_oprofile_Destroy(om); |
| 910 |
p7_hmm_Destroy(hmm); |
| 911 |
p7_bg_Destroy(bg); |
| 912 |
esl_alphabet_Destroy(abc); |
| 913 |
esl_randomness_Destroy(r); |
| 914 |
esl_getopts_Destroy(go); |
| 915 |
return eslOK; |
| 916 |
} |
| 917 |
|
| 918 |
#endif |
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
#ifdef p7IO_EXAMPLE |
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
#include <p7_config.h> |
| 931 |
|
| 932 |
#include <stdlib.h> |
| 933 |
#include <stdio.h> |
| 934 |
|
| 935 |
#include "easel.h" |
| 936 |
#include "esl_getopts.h" |
| 937 |
|
| 938 |
#include "hmmer.h" |
| 939 |
|
| 940 |
static ESL_OPTIONS options[] = { |
| 941 |
|
| 942 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 943 |
{ "-v", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "verbose: print model info as they're read", 0 }, |
| 944 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 945 |
}; |
| 946 |
static char usage[] = "[-options] <HMM file>"; |
| 947 |
static char banner[] = "example of writing MSV profile part"; |
| 948 |
|
| 949 |
int |
| 950 |
main(int argc, char **argv) |
| 951 |
{ |
| 952 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 1, argc, argv, banner, usage); |
| 953 |
ESL_ALPHABET *abc = NULL; |
| 954 |
char *hmmfile = esl_opt_GetArg(go, 1); |
| 955 |
P7_HMMFILE *hfp = NULL; |
| 956 |
P7_HMM *hmm = NULL; |
| 957 |
P7_BG *bg = NULL; |
| 958 |
P7_PROFILE *gm = NULL; |
| 959 |
P7_OPROFILE *om = NULL; |
| 960 |
char *fname = NULL; |
| 961 |
char *pname = NULL; |
| 962 |
FILE *ffp = NULL; |
| 963 |
FILE *pfp = NULL; |
| 964 |
int nmodel = 0; |
| 965 |
uint64_t totM = 0; |
| 966 |
int status; |
| 967 |
char errbuf[eslERRBUFSIZE]; |
| 968 |
|
| 969 |
status = p7_hmmfile_Open(hmmfile, NULL, &hfp, errbuf); |
| 970 |
if (status == eslENOTFOUND) p7_Fail("File existence/permissions problem in trying to open HMM file %s.\n%s\n", hmmfile, errbuf); |
| 971 |
else if (status == eslEFORMAT) p7_Fail("File format problem in trying to open HMM file %s.\n%s\n", hmmfile, errbuf); |
| 972 |
else if (status != eslOK) p7_Fail("Unexpected error %d in opening HMM file %s.\n%s\n", status, hmmfile, errbuf); |
| 973 |
|
| 974 |
esl_sprintf(&fname, "%s.h3f", hmmfile); |
| 975 |
esl_sprintf(&pname, "%s.h3f", hmmfile); |
| 976 |
if ((ffp = fopen(fname, "wb")) == NULL) p7_Fail("failed to open %s\n", fname); |
| 977 |
if ((pfp = fopen(pname, "wb")) == NULL) p7_Fail("failed to open %s\n", pname); |
| 978 |
free(fname); |
| 979 |
free(pname); |
| 980 |
|
| 981 |
while ((status = p7_hmmfile_Read(hfp, &abc, &hmm)) == eslOK) |
| 982 |
{ |
| 983 |
if (nmodel == 0) { |
| 984 |
bg = p7_bg_Create(abc); |
| 985 |
p7_bg_SetLength(bg, 400); |
| 986 |
} |
| 987 |
|
| 988 |
if (esl_opt_GetBoolean(go, "-v")) printf("%s\n", hmm->name); |
| 989 |
nmodel++; |
| 990 |
totM += hmm->M; |
| 991 |
|
| 992 |
gm = p7_profile_Create(hmm->M, abc); |
| 993 |
p7_ProfileConfig(hmm, bg, gm, 400, p7_LOCAL); |
| 994 |
om = p7_oprofile_Create(gm->M, abc); |
| 995 |
p7_oprofile_Convert(gm, om); |
| 996 |
|
| 997 |
p7_oprofile_Write(ffp, pfp, om); |
| 998 |
|
| 999 |
p7_profile_Destroy(gm); |
| 1000 |
p7_oprofile_Destroy(om); |
| 1001 |
p7_hmm_Destroy(hmm); |
| 1002 |
} |
| 1003 |
if (status == eslEFORMAT) p7_Fail("bad file format in HMM file %s", hmmfile); |
| 1004 |
else if (status == eslEINCOMPAT) p7_Fail("HMM file %s contains different alphabets", hmmfile); |
| 1005 |
else if (status != eslEOF) p7_Fail("Unexpected error in reading HMMs from %s", hmmfile); |
| 1006 |
|
| 1007 |
fclose(ffp); |
| 1008 |
fclose(pfp); |
| 1009 |
p7_bg_Destroy(bg); |
| 1010 |
p7_hmmfile_Close(hfp); |
| 1011 |
esl_alphabet_Destroy(abc); |
| 1012 |
esl_getopts_Destroy(go); |
| 1013 |
return 0; |
| 1014 |
} |
| 1015 |
#endif |
| 1016 |
|
| 1017 |
|