| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include <esl_config.h> |
| 7 |
#include <p7_config.h> |
| 8 |
|
| 9 |
#include <stdio.h> |
| 10 |
#include <stdlib.h> |
| 11 |
#include <string.h> |
| 12 |
|
| 13 |
#include "easel.h" |
| 14 |
#include "esl_alphabet.h" |
| 15 |
#include "esl_getopts.h" |
| 16 |
|
| 17 |
#include "hmmer.h" |
| 18 |
|
| 19 |
#include "infernal.h" |
| 20 |
|
| 21 |
#define OUTOPTS "-a,-b,-1,--mlhmm,--fhmm" |
| 22 |
|
| 23 |
static ESL_OPTIONS options[] = { |
| 24 |
|
| 25 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 26 |
{ "-a", eslARG_NONE,"default",NULL, NULL, OUTOPTS, NULL, NULL, "ascii: output models in INFERNAL 1.1 ASCII format", 0 }, |
| 27 |
{ "-b", eslARG_NONE, FALSE, NULL, NULL, OUTOPTS, NULL, NULL, "binary: output models in INFERNAL 1.1 binary format", 0 }, |
| 28 |
{ "-1", eslARG_NONE, FALSE, NULL, NULL, OUTOPTS, NULL, NULL, "output backward compatible Infernal v0.7-->v1.0.2 ASCII format", 0 }, |
| 29 |
{ "-o", eslARG_OUTFILE,FALSE, NULL, NULL, NULL, NULL, NULL, "save CM file to file <f>, not stdout", 0 }, |
| 30 |
{ "--mlhmm", eslARG_NONE, FALSE, NULL, NULL, OUTOPTS, NULL, NULL, "output maximum likelihood HMM for CM in HMMER3 format", 0 }, |
| 31 |
{ "--fhmm", eslARG_NONE, FALSE, NULL, NULL, OUTOPTS, NULL, NULL, "output filter HMM for CM in HMMER3 format", 0 }, |
| 32 |
|
| 33 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 34 |
}; |
| 35 |
static char usage[] = "[-options] <cmfile>"; |
| 36 |
static char banner[] = "convert CM file to a different Infernal format"; |
| 37 |
|
| 38 |
static int configure_model(CM_t *cm, char *errbuf); |
| 39 |
|
| 40 |
int |
| 41 |
main(int argc, char **argv) |
| 42 |
{ |
| 43 |
ESL_GETOPTS *go = cm_CreateDefaultApp(options, 1, argc, argv, banner, usage); |
| 44 |
ESL_ALPHABET *abc = NULL; |
| 45 |
char *cmfile = esl_opt_GetArg(go, 1); |
| 46 |
CM_FILE *cmfp = NULL; |
| 47 |
CM_t *cm = NULL; |
| 48 |
FILE *ofp = NULL; |
| 49 |
|
| 50 |
int fmtcode = -1; |
| 51 |
int status; |
| 52 |
char errbuf[eslERRBUFSIZE]; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
status = cm_file_Open(cmfile, NULL, TRUE, &cmfp, errbuf); |
| 62 |
if (status == eslENOTFOUND) cm_Fail("File existence/permissions problem in trying to open CM file %s.\n%s\n", cmfile, errbuf); |
| 63 |
else if (status == eslEFORMAT) cm_Fail("File format problem in trying to open CM file %s.\n%s\n", cmfile, errbuf); |
| 64 |
else if (status != eslOK) cm_Fail("Unexpected error %d in opening CM file %s.\n%s\n", status, cmfile, errbuf); |
| 65 |
|
| 66 |
|
| 67 |
if ( esl_opt_IsOn(go, "-o") ) { |
| 68 |
if ((ofp = fopen(esl_opt_GetString(go, "-o"), "w")) == NULL) ESL_FAIL(eslFAIL, errbuf, "Failed to open output file %s", esl_opt_GetString(go, "-o")); |
| 69 |
} |
| 70 |
else ofp = stdout; |
| 71 |
|
| 72 |
while ((status = cm_file_Read(cmfp, TRUE, &abc, &cm)) == eslOK) |
| 73 |
{ |
| 74 |
if(cmfp->format == CM_FILE_1 || esl_opt_GetBoolean(go, "--mlhmm")) { |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
if ((status = configure_model(cm, errbuf)) != eslOK) cm_Fail(errbuf); |
| 82 |
} |
| 83 |
|
| 84 |
if (esl_opt_GetBoolean(go, "--mlhmm")) { |
| 85 |
if((status = p7_hmm_AppendComlog (cm->mlp7, go->argc, go->argv)) != eslOK) cm_Fail("Failed to record command log"); |
| 86 |
} |
| 87 |
else if (esl_opt_GetBoolean(go, "--fhmm")) { |
| 88 |
if((status = p7_hmm_AppendComlog (cm->fp7, go->argc, go->argv)) != eslOK) cm_Fail("Failed to record command log"); |
| 89 |
} |
| 90 |
else { |
| 91 |
if((status = cm_AppendComlog (cm, go->argc, go->argv, FALSE , 0)) != eslOK) cm_Fail("Failed to record command log"); |
| 92 |
} |
| 93 |
|
| 94 |
if (esl_opt_GetBoolean(go, "-a") == TRUE) cm_file_WriteASCII (ofp, fmtcode, cm); |
| 95 |
else if (esl_opt_GetBoolean(go, "-b") == TRUE) cm_file_WriteBinary(ofp, fmtcode, cm, NULL); |
| 96 |
else if (esl_opt_GetBoolean(go, "-1") == TRUE) cm_file_Write1p0ASCII(ofp, cm); |
| 97 |
else if (esl_opt_GetBoolean(go, "--mlhmm") == TRUE) p7_hmmfile_WriteASCII(ofp, -1, cm->mlp7); |
| 98 |
else if (esl_opt_GetBoolean(go, "--fhmm") == TRUE) p7_hmmfile_WriteASCII(ofp, -1, cm->fp7); |
| 99 |
|
| 100 |
FreeCM(cm); |
| 101 |
} |
| 102 |
if (status == eslEFORMAT) cm_Fail("bad file format in CM file %s\n%s", cmfile, cmfp->errbuf); |
| 103 |
else if (status == eslEINCOMPAT) cm_Fail("CM file %s contains different alphabets\n%s", cmfile, cmfp->errbuf); |
| 104 |
else if (status != eslEOF) cm_Fail("Unexpected error in reading CMs from %s\n%s", cmfile, cmfp->errbuf); |
| 105 |
|
| 106 |
cm_file_Close(cmfp); |
| 107 |
|
| 108 |
if(esl_opt_IsOn(go, "-o")) fclose(ofp); |
| 109 |
esl_alphabet_Destroy(abc); |
| 110 |
esl_getopts_Destroy(go); |
| 111 |
return 0; |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
static int |
| 122 |
configure_model(CM_t *cm, char *errbuf) |
| 123 |
{ |
| 124 |
int status; |
| 125 |
int lmsvL, lvitL, lfwdL, gfwdL; |
| 126 |
int lmsvN, lvitN, lfwdN, gfwdN; |
| 127 |
float lftailp, gftailp; |
| 128 |
double fil_gfmu, fil_gflambda; |
| 129 |
|
| 130 |
|
| 131 |
cm->config_opts |= CM_CONFIG_QDB; |
| 132 |
if ((status = cm_Configure(cm, errbuf, -1)) != eslOK) return status; |
| 133 |
if ((status = cm_SetConsensus(cm, cm->cmcons, NULL)) != eslOK) ESL_FAIL(status, errbuf, "Failed to calculate consensus sequence"); |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
lmsvL = lvitL = 200; |
| 143 |
lfwdL = 100; |
| 144 |
gfwdL = ESL_MAX(100, 2.*cm->clen); |
| 145 |
lmsvN = lvitN = lfwdN = gfwdN = 200; |
| 146 |
lftailp = 0.055; |
| 147 |
gftailp = 0.065; |
| 148 |
|
| 149 |
|
| 150 |
if((status = cm_p7_Calibrate(cm->mlp7, errbuf, |
| 151 |
lmsvL, lvitL, lfwdL, gfwdL, |
| 152 |
lmsvN, lvitN, lfwdN, gfwdN, |
| 153 |
lftailp, |
| 154 |
gftailp, |
| 155 |
&fil_gfmu, &fil_gflambda)) |
| 156 |
!= eslOK) return status; |
| 157 |
if((status = cm_SetFilterHMM(cm, cm->mlp7, fil_gfmu, fil_gflambda)) != eslOK) ESL_FAIL(status, errbuf, "Unable to set the HMM filter for the CM"); |
| 158 |
|
| 159 |
return eslOK; |
| 160 |
} |
| 161 |
|