| 1 |
|
| 2 |
|
| 3 |
#include <esl_config.h> |
| 4 |
|
| 5 |
#include <stdio.h> |
| 6 |
#include <string.h> |
| 7 |
#include <ctype.h> |
| 8 |
|
| 9 |
#include "easel.h" |
| 10 |
#include "esl_getopts.h" |
| 11 |
#include "esl_sq.h" |
| 12 |
#include "esl_msa.h" |
| 13 |
#include "esl_msafile.h" |
| 14 |
#include "esl_wuss.h" |
| 15 |
|
| 16 |
static char banner[] = "calculate accuracy of RNA secondary structure predictions"; |
| 17 |
|
| 18 |
static char usage[] = "\ |
| 19 |
[-options] <trusted file> <test file>\n\ |
| 20 |
Both files must be in Stockholm format with secondary structure markup.\n\ |
| 21 |
Sequences must occur in the same order in the two files.\n\ |
| 22 |
The markup must be in WUSS notation.\n\ |
| 23 |
\n"; |
| 24 |
|
| 25 |
static ESL_OPTIONS options[] = { |
| 26 |
|
| 27 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "help; show brief info on version and usage", 0 }, |
| 28 |
{ "-m", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "use Mathews'relaxed criterion for correctness; allow +/-1 slip", 0 }, |
| 29 |
{ "-p", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "count pseudoknotted base pairs", 0 }, |
| 30 |
{ "--quiet", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "suppress verbose header", 0 }, |
| 31 |
{ 0,0,0,0,0,0,0,0,0,0 }, |
| 32 |
}; |
| 33 |
|
| 34 |
int |
| 35 |
main(int argc, char **argv) |
| 36 |
{ |
| 37 |
ESL_GETOPTS *go; |
| 38 |
int kstatus, tstatus; |
| 39 |
int fmt; |
| 40 |
char *kfile, *tfile; |
| 41 |
ESL_MSAFILE *kfp, *tfp; |
| 42 |
ESL_MSA *ka, *ta; |
| 43 |
int64_t klen, tlen; |
| 44 |
int *kct, *tct; |
| 45 |
int i; |
| 46 |
int pos; |
| 47 |
|
| 48 |
int nseq; |
| 49 |
int nseq_rejected; |
| 50 |
|
| 51 |
int kpairs; |
| 52 |
int tpairs; |
| 53 |
int kcorrect; |
| 54 |
int tcorrect; |
| 55 |
|
| 56 |
int tot_kpairs; |
| 57 |
int tot_tpairs; |
| 58 |
int tot_kcorrect; |
| 59 |
int tot_tcorrect; |
| 60 |
int tot_positions; |
| 61 |
|
| 62 |
int status; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
go = esl_getopts_Create(options); |
| 69 |
if (esl_opt_ProcessCmdline(go, argc, argv) != eslOK || |
| 70 |
esl_opt_VerifyConfig(go) != eslOK) |
| 71 |
{ |
| 72 |
printf("Failed to parse command line: %s\n", go->errbuf); |
| 73 |
esl_usage(stdout, argv[0], usage); |
| 74 |
printf("\nTo see more help on available options, do %s -h\n\n", argv[0]); |
| 75 |
exit(1); |
| 76 |
} |
| 77 |
|
| 78 |
if (esl_opt_GetBoolean(go, "-h") ) |
| 79 |
{ |
| 80 |
esl_banner(stdout, argv[0], banner); |
| 81 |
esl_usage (stdout, argv[0], usage); |
| 82 |
puts("\n where options are:"); |
| 83 |
esl_opt_DisplayHelp(stdout, go, 0, 2, 80); |
| 84 |
exit(EXIT_SUCCESS); |
| 85 |
} |
| 86 |
|
| 87 |
if (esl_opt_ArgNumber(go) != 2) |
| 88 |
{ |
| 89 |
printf("Incorrect number of command line arguments.\n"); |
| 90 |
esl_usage(stdout, argv[0], usage); |
| 91 |
printf("\nTo see more help on available options, do %s -h\n\n", argv[0]); |
| 92 |
exit(1); |
| 93 |
} |
| 94 |
|
| 95 |
kfile = esl_opt_GetArg(go, 1); |
| 96 |
tfile = esl_opt_GetArg(go, 2); |
| 97 |
|
| 98 |
if (! esl_opt_GetBoolean(go, "--quiet")) |
| 99 |
esl_banner(stdout, argv[0], banner); |
| 100 |
|
| 101 |
fmt = eslMSAFILE_STOCKHOLM; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
if ( (status = esl_msafile_Open(NULL, kfile, NULL, fmt, NULL, &kfp)) != eslOK) esl_msafile_OpenFailure(kfp, status); |
| 108 |
if ( (status = esl_msafile_Open(NULL, tfile, NULL, fmt, NULL, &tfp)) != eslOK) esl_msafile_OpenFailure(tfp, status); |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
tot_kpairs = tot_kcorrect = 0; |
| 116 |
tot_tpairs = tot_tcorrect = 0; |
| 117 |
nseq = nseq_rejected = 0; |
| 118 |
tot_positions = 0; |
| 119 |
|
| 120 |
printf("%20s %17s %17s\n", "", "[sensitivity]", "[PPV]"); |
| 121 |
|
| 122 |
while ( (kstatus = esl_msafile_Read(kfp, &ka)) != eslEOF) |
| 123 |
{ |
| 124 |
if ( kstatus != eslOK) esl_msafile_ReadFailure(kfp, kstatus); |
| 125 |
if ( (tstatus = esl_msafile_Read(tfp, &ta)) != eslOK) esl_msafile_ReadFailure(tfp, tstatus); |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
if (ka->nseq != ta->nseq) esl_fatal("trusted, test alignments don't have same seq #\n"); |
| 130 |
if (ka->ss == NULL) esl_fatal("trusted alignment has no secondary structure annotation\n"); |
| 131 |
if (ta->ss == NULL) esl_fatal("test alignment has no secondary structure annotation\n"); |
| 132 |
|
| 133 |
for (i = 0; i < ka->nseq; i++) |
| 134 |
{ |
| 135 |
nseq++; |
| 136 |
printf("%-20s ", ka->sqname[i]); |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
if (ta->ss[i] == NULL) |
| 142 |
{ |
| 143 |
printf("[REJECTED: no predicted structure]\n"); |
| 144 |
nseq_rejected++; |
| 145 |
continue; |
| 146 |
} |
| 147 |
if (ka->ss[i] == NULL) |
| 148 |
{ |
| 149 |
printf("[REJECTED: no trusted structure]\n"); |
| 150 |
nseq_rejected++; |
| 151 |
continue; |
| 152 |
} |
| 153 |
if (strcmp(ka->sqname[i], ta->sqname[i]) != 0) |
| 154 |
{ |
| 155 |
printf("[REJECTED: test seq name is %s]\n", ta->sqname[i]); |
| 156 |
nseq_rejected++; |
| 157 |
continue; |
| 158 |
} |
| 159 |
|
| 160 |
esl_strdealign(ka->ss[i], ka->aseq[i], "-_.~", NULL); |
| 161 |
esl_strdealign(ka->aseq[i], ka->aseq[i], "-_.~", &klen); |
| 162 |
|
| 163 |
esl_strdealign(ta->ss[i], ta->aseq[i], "-_.~", NULL); |
| 164 |
esl_strdealign(ta->aseq[i], ta->aseq[i], "-_.~", &tlen); |
| 165 |
|
| 166 |
if (klen != tlen) |
| 167 |
{ |
| 168 |
printf("[REJECTED: seq lengths not identical]\n"); |
| 169 |
nseq_rejected++; |
| 170 |
continue; |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
if (! esl_opt_GetBoolean(go, "-p")) |
| 175 |
{ |
| 176 |
esl_wuss_nopseudo(ka->ss[i], ka->ss[i]); |
| 177 |
esl_wuss_nopseudo(ta->ss[i], ta->ss[i]); |
| 178 |
} |
| 179 |
|
| 180 |
ESL_ALLOC(kct, sizeof(int) * (klen+1)); |
| 181 |
ESL_ALLOC(tct, sizeof(int) * (tlen+1)); |
| 182 |
if (esl_wuss2ct(ka->ss[i], klen, kct) != eslOK) |
| 183 |
{ |
| 184 |
printf("[REJECTED: bad trusted structure]\n"); |
| 185 |
nseq_rejected++; |
| 186 |
continue; |
| 187 |
} |
| 188 |
if (esl_wuss2ct(ta->ss[i], tlen, tct) != eslOK) |
| 189 |
{ |
| 190 |
printf("[REJECTED: bad test structure]\n"); |
| 191 |
nseq_rejected++; |
| 192 |
continue; |
| 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 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
tpairs = tcorrect = 0; |
| 241 |
kpairs = kcorrect = 0; |
| 242 |
for (pos = 1; pos <= klen; pos++) |
| 243 |
{ |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
if (kct[pos] > pos) |
| 248 |
{ |
| 249 |
kpairs++; |
| 250 |
|
| 251 |
if (esl_opt_GetBoolean(go, "-m")) { |
| 252 |
if (tct[pos] == kct[pos] || |
| 253 |
(pos > 1 && tct[pos-1] == kct[pos]) || |
| 254 |
(pos < klen && tct[pos+1] == kct[pos]) || |
| 255 |
(tct[pos]> 0 && tct[pos] == kct[pos]-1) || |
| 256 |
(tct[pos]> 0 && tct[pos] == kct[pos]+1)) |
| 257 |
kcorrect++; |
| 258 |
} else { |
| 259 |
if (tct[pos] == kct[pos]) kcorrect++; |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
if (tct[pos] > pos) |
| 267 |
{ |
| 268 |
tpairs++; |
| 269 |
|
| 270 |
if (esl_opt_GetBoolean(go, "-m")) { |
| 271 |
if (kct[pos] == tct[pos] || |
| 272 |
(pos > 1 && kct[pos-1] == tct[pos]) || |
| 273 |
(pos < tlen && kct[pos+1] == tct[pos]) || |
| 274 |
(kct[pos]> 0 && kct[pos] == tct[pos]-1) || |
| 275 |
(kct[pos]> 0 && kct[pos] == tct[pos]+1)) |
| 276 |
tcorrect++; |
| 277 |
} else { |
| 278 |
if (kct[pos] == tct[pos]) tcorrect++; |
| 279 |
} |
| 280 |
} |
| 281 |
} |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
tot_tpairs += tpairs; |
| 289 |
tot_tcorrect += tcorrect; |
| 290 |
tot_kpairs += kpairs; |
| 291 |
tot_kcorrect += kcorrect; |
| 292 |
tot_positions += klen; |
| 293 |
|
| 294 |
|
| 295 |
printf(" == %5d %5d %5.2f%% %5d %5d %5.2f%%\n", |
| 296 |
kcorrect, kpairs, 100. * (float) kcorrect/ (float) kpairs, |
| 297 |
tcorrect, tpairs, 100. * (float) tcorrect/ (float) tpairs); |
| 298 |
|
| 299 |
free(tct); |
| 300 |
free(kct); |
| 301 |
} |
| 302 |
esl_msa_Destroy(ka); |
| 303 |
esl_msa_Destroy(ta); |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
puts("\n"); |
| 309 |
if (nseq_rejected > 0) { |
| 310 |
printf("%d total sequences; %d counted towards comparison; %d rejected\n", |
| 311 |
nseq, nseq-nseq_rejected, nseq_rejected); |
| 312 |
printf("(grep \"REJECTED\" in the output to identify the problems)\n\n"); |
| 313 |
} |
| 314 |
|
| 315 |
printf("Overall prediction accuracy (%d sequences, %d positions)\n", |
| 316 |
nseq - nseq_rejected, tot_positions); |
| 317 |
printf(" %d/%d trusted pairs predicted (%.2f%% sensitivity)\n", |
| 318 |
tot_kcorrect, tot_kpairs, |
| 319 |
100. * (float) tot_kcorrect/ (float) tot_kpairs); |
| 320 |
printf(" %d/%d predicted pairs correct (%.2f%% PPV)\n", |
| 321 |
tot_tcorrect, tot_tpairs, |
| 322 |
100. * (float) tot_tcorrect/ (float) tot_tpairs); |
| 323 |
puts(""); |
| 324 |
|
| 325 |
esl_getopts_Destroy(go); |
| 326 |
esl_msafile_Close(tfp); |
| 327 |
esl_msafile_Close(kfp); |
| 328 |
return 0; |
| 329 |
|
| 330 |
ERROR: |
| 331 |
return status; |
| 332 |
} |
| 333 |
|
| 334 |
|
| 335 |
|