| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#include "config.h" |
| 5 |
|
| 6 |
#include <stdio.h> |
| 7 |
#include <stdlib.h> |
| 8 |
#include <string.h> |
| 9 |
#include <math.h> |
| 10 |
|
| 11 |
#include "easel.h" |
| 12 |
#include "esl_alphabet.h" |
| 13 |
#include "esl_sqio.h" |
| 14 |
#include "esl_msa.h" |
| 15 |
#include "esl_stopwatch.h" |
| 16 |
#include "esl_getopts.h" |
| 17 |
|
| 18 |
#include "hmmer.h" |
| 19 |
|
| 20 |
#include "infernal.h" |
| 21 |
|
| 22 |
static ESL_OPTIONS options[] = { |
| 23 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show help", 0}, |
| 24 |
{ "--regress", eslARG_INFILE,NULL, NULL, NULL, NULL, NULL, NULL, "save regression test data to file <f>", 0}, |
| 25 |
{ "--scoreonly",eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "do score only for full CYK/inside stage to save memory",0}, |
| 26 |
{ "--smallonly",eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "skip full CYK/inside, do divide&conquer only", 0}, |
| 27 |
{ "--stringent",eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "require the two parse trees to be indentical", 0}, |
| 28 |
{0,0,0,0,0,0,0,0,0,0}, |
| 29 |
}; |
| 30 |
static char usage[] = "Usage: truncyk_check [-options] <cmfile> <sequence file>"; |
| 31 |
|
| 32 |
int |
| 33 |
main(int argc, char **argv) |
| 34 |
{ |
| 35 |
int status; |
| 36 |
char *cmfile; |
| 37 |
ESL_ALPHABET *abc; |
| 38 |
char *seqfile; |
| 39 |
int format; |
| 40 |
CM_FILE *cmfp; |
| 41 |
ESL_SQFILE *sqfp; |
| 42 |
CM_t *cm; |
| 43 |
ESL_SQ *seq; |
| 44 |
ESL_STOPWATCH *watch; |
| 45 |
float sc1, sc2; |
| 46 |
Parsetree_t *tr1, *tr2; |
| 47 |
float ptsc1, ptsc2; |
| 48 |
int v, model_len; |
| 49 |
float bsc; |
| 50 |
|
| 51 |
int do_local; |
| 52 |
int do_scoreonly; |
| 53 |
int do_smallonly; |
| 54 |
int compare_stringently; |
| 55 |
char *regressfile; |
| 56 |
FILE *regressfp; |
| 57 |
|
| 58 |
ESL_GETOPTS *go; |
| 59 |
char errbuf[eslERRBUFSIZE]; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
go = esl_getopts_Create(options); |
| 66 |
if (esl_opt_ProcessCmdline(go, argc, argv) != eslOK) esl_fatal("Failed to parse command line: %s\n", go->errbuf); |
| 67 |
if (esl_opt_VerifyConfig(go) != eslOK) esl_fatal("Failed to parse command line: %s\n", go->errbuf); |
| 68 |
|
| 69 |
if (esl_opt_GetBoolean(go, "-h") == TRUE) { |
| 70 |
puts(usage); |
| 71 |
puts("\n where options are:"); |
| 72 |
esl_opt_DisplayHelp(stdout, go, 0, 2, 80); |
| 73 |
return 0; |
| 74 |
} |
| 75 |
|
| 76 |
if (esl_opt_ArgNumber(go) != 2) esl_fatal("Incorrect number of command line arguments.\n%s\n", usage); |
| 77 |
cmfile = esl_opt_GetArg(go, 1); |
| 78 |
seqfile = esl_opt_GetArg(go, 2); |
| 79 |
|
| 80 |
|
| 81 |
abc = NULL; |
| 82 |
do_local = TRUE; |
| 83 |
do_scoreonly = esl_opt_GetBoolean(go,"--scoreonly"); |
| 84 |
do_smallonly = esl_opt_GetBoolean(go,"--smallonly"); |
| 85 |
compare_stringently = esl_opt_GetBoolean(go,"--stringent"); |
| 86 |
regressfile = esl_opt_GetString(go,"--regress"); |
| 87 |
format = eslSQFILE_UNKNOWN; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
watch = esl_stopwatch_Create(); |
| 94 |
|
| 95 |
if ( esl_sqfile_Open(seqfile, format, NULL, &sqfp) != eslOK ) |
| 96 |
cm_Die("Failed to open sequence database file %s\n%s\n", seqfile, usage); |
| 97 |
|
| 98 |
if((status = cm_file_Open(cmfile, NULL, FALSE, &cmfp, errbuf)) != eslOK) |
| 99 |
cm_Die("Failed to open covariance model save file\n"); |
| 100 |
if ((status = cm_file_Read(cmfp, TRUE, &abc, &cm)) != eslOK) |
| 101 |
cm_Die("Failed to read a CM from cm file\n"); |
| 102 |
if (cm == NULL) |
| 103 |
cm_Die("CM file empty?\n"); |
| 104 |
|
| 105 |
|
| 106 |
if (regressfile != NULL) { |
| 107 |
if ((regressfp = fopen(regressfile, "w")) == NULL) |
| 108 |
cm_Die("Failed to open regression test file %s", regressfile); |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
if (do_local) cm->config_opts |= CM_CONFIG_LOCAL; |
| 117 |
if ((status = cm_Configure(cm, errbuf, -1)) != eslOK) return status; |
| 118 |
SetMarginalScores_reproduce_i27(cm); |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
if((cm->el_selfsc * cm->W) < IMPOSSIBLE) |
| 127 |
cm->el_selfsc = (IMPOSSIBLE / (cm->W+1)); |
| 128 |
|
| 129 |
seq = esl_sq_Create(); |
| 130 |
while ( esl_sqio_Read(sqfp, seq) == eslOK ) |
| 131 |
{ |
| 132 |
|
| 133 |
|
| 134 |
if (seq->n == 0) continue; |
| 135 |
|
| 136 |
if (seq->dsq == NULL) |
| 137 |
esl_sq_Digitize(abc, seq); |
| 138 |
|
| 139 |
tr1 = tr2 = NULL; |
| 140 |
|
| 141 |
|
| 142 |
model_len = 0; |
| 143 |
for ( v = 0; v < cm->M; v++ ) |
| 144 |
{ |
| 145 |
if ( cm->stid[v] == MATP_MP ) model_len += 2; |
| 146 |
else if ( cm->stid[v] == MATL_ML ) model_len += 1; |
| 147 |
else if ( cm->stid[v] == MATR_MR ) model_len += 1; |
| 148 |
} |
| 149 |
|
| 150 |
bsc = sreLOG2(2.0/(model_len*(model_len+1))); |
| 151 |
|
| 152 |
if (! do_smallonly) { |
| 153 |
printf("Full inside algorithm:\n"); |
| 154 |
printf("----------------------\n"); |
| 155 |
esl_stopwatch_Start(watch); |
| 156 |
if (do_scoreonly) { |
| 157 |
sc1 = TrCYK_Inside(cm, seq->dsq, seq->n, 0, 1, seq->n, PLI_PASS_5P_AND_3P_ANY, TRUE, FALSE, NULL); |
| 158 |
printf("%-12s : %.2f\n", seq->name, sc1); |
| 159 |
} else { |
| 160 |
sc1 = TrCYK_Inside(cm, seq->dsq, seq->n, 0, 1, seq->n, PLI_PASS_5P_AND_3P_ANY, TRUE, FALSE, &tr1); |
| 161 |
ParsetreeDump(stdout, tr1, cm, seq->dsq); |
| 162 |
|
| 163 |
ParsetreeScore(cm, NULL, NULL, tr1, seq->dsq, FALSE, &ptsc1, NULL, NULL, NULL, NULL); |
| 164 |
ptsc1 += bsc; |
| 165 |
printf("%-12s : %.2f %.2f\n", seq->name, sc1, ptsc1); |
| 166 |
} |
| 167 |
esl_stopwatch_Stop(watch); |
| 168 |
esl_stopwatch_Display(stdout, watch, "CPU time: "); |
| 169 |
puts(""); |
| 170 |
} |
| 171 |
|
| 172 |
printf("Divide and conquer algorithm:\n"); |
| 173 |
printf("-------------------------------\n"); |
| 174 |
esl_stopwatch_Start(watch); |
| 175 |
sc2 = TrCYK_DnC(cm, seq->dsq, seq->n, 0, 1, seq->n, PLI_PASS_5P_AND_3P_ANY, TRUE, &tr2); |
| 176 |
ParsetreeDump(stdout, tr2, cm, seq->dsq); |
| 177 |
|
| 178 |
ParsetreeScore(cm, NULL, NULL, tr2, seq->dsq, FALSE, &ptsc2, NULL, NULL, NULL, NULL); |
| 179 |
ptsc2 += bsc; |
| 180 |
printf("%-12s : %.2f %.2f\n", seq->name, sc2, ptsc2); |
| 181 |
esl_stopwatch_Stop(watch); |
| 182 |
esl_stopwatch_Display(stdout, watch, "CPU time: "); |
| 183 |
puts(""); |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
if (tr1 != NULL && fabs(sc1 - ptsc1) >= 0.01) |
| 191 |
cm_Die("TrCYKInside score differs from its parse tree's score\n"); |
| 192 |
if (tr2 != NULL && fabs(sc2 - ptsc2) >= 0.01) |
| 193 |
cm_Die("TrCYKDivideAndConquer score differs from its parse tree's score\n"); |
| 194 |
if (!do_smallonly && fabs(sc1 - sc2) >= 0.01) |
| 195 |
cm_Die("TrCYKInside score differs from TrCYKDivideAndConquer\n"); |
| 196 |
if (tr1 != NULL && tr2 != NULL && |
| 197 |
compare_stringently && !ParsetreeCompare(tr1, tr2)) |
| 198 |
cm_Die("Parse trees for TrCYKInside and TrCYKDivideAndConquer differ\n"); |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
if (regressfile != NULL) { |
| 203 |
if (tr1 != NULL) ParsetreeDump(regressfp, tr1, cm, seq->dsq); |
| 204 |
if (tr2 != NULL) ParsetreeDump(regressfp, tr2, cm, seq->dsq); |
| 205 |
} |
| 206 |
|
| 207 |
if (tr1 != NULL) FreeParsetree(tr1); |
| 208 |
if (tr2 != NULL) FreeParsetree(tr2); |
| 209 |
|
| 210 |
|
| 211 |
esl_sq_Destroy(seq); |
| 212 |
seq = esl_sq_Create(); |
| 213 |
} |
| 214 |
esl_sq_Destroy(seq); |
| 215 |
|
| 216 |
if (regressfile != NULL) fclose(regressfp); |
| 217 |
FreeCM(cm); |
| 218 |
cm_file_Close(cmfp); |
| 219 |
esl_sqfile_Close(sqfp); |
| 220 |
esl_stopwatch_Destroy(watch); |
| 221 |
|
| 222 |
return EXIT_SUCCESS; |
| 223 |
} |