| 1 |
#include "config.h" |
| 2 |
|
| 3 |
#include <stdio.h> |
| 4 |
#include <stdlib.h> |
| 5 |
|
| 6 |
#include "easel.h" |
| 7 |
#include "esl_alphabet.c" |
| 8 |
#include "esl_msa.h" |
| 9 |
#include "esl_sqio.h" |
| 10 |
|
| 11 |
#include "hmmer.h" |
| 12 |
|
| 13 |
#include "infernal.h" |
| 14 |
|
| 15 |
int |
| 16 |
main(int argc, char **argv) |
| 17 |
{ |
| 18 |
char *cmfile; |
| 19 |
ESL_ALPHABET *abc; |
| 20 |
char *seqfile; |
| 21 |
ESL_SQFILE *sqfp; |
| 22 |
int format; |
| 23 |
CM_FILE *cmfp; |
| 24 |
CM_t *cm; |
| 25 |
ESL_SQ *seq; |
| 26 |
float sc, rev_sc; |
| 27 |
Parsetree_t *tr; |
| 28 |
Fancyali_t *fali; |
| 29 |
Fancyali_t *rev_fali; |
| 30 |
|
| 31 |
int do_local; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
int optind; |
| 37 |
|
| 38 |
int status; |
| 39 |
char errbuf[eslERRBUFSIZE]; |
| 40 |
|
| 41 |
cmfile = seqfile = NULL; |
| 42 |
abc = NULL; |
| 43 |
sqfp = NULL; |
| 44 |
cmfp = NULL; |
| 45 |
cm = NULL; |
| 46 |
seq = NULL; |
| 47 |
tr = NULL; |
| 48 |
fali = NULL; |
| 49 |
rev_fali = NULL; |
| 50 |
format = eslSQFILE_UNKNOWN; |
| 51 |
do_local = TRUE; |
| 52 |
|
| 53 |
|
| 54 |
optind = 1; |
| 55 |
|
| 56 |
if ( argc - optind != 2 ) cm_Die("Incorrect number of arguments\n"); |
| 57 |
cmfile = argv[optind++]; |
| 58 |
seqfile = argv[optind++]; |
| 59 |
|
| 60 |
if((status = cm_file_Open(cmfile, NULL, FALSE, &cmfp, errbuf)) != eslOK) |
| 61 |
cm_Die("Failed to open covariance model save file\n"); |
| 62 |
if ((status = cm_file_Read(cmfp, TRUE, &abc, &cm)) != eslOK) |
| 63 |
cm_Die("Failed to read a CM from cm file\n"); |
| 64 |
if (cm == NULL) |
| 65 |
cm_Die("CM file empty?\n"); |
| 66 |
cm_file_Close(cmfp); |
| 67 |
|
| 68 |
if ( esl_sqfile_Open(seqfile, format, NULL, &sqfp) != eslOK ) |
| 69 |
cm_Die("Failed to open sequence database file\n"); |
| 70 |
|
| 71 |
if (do_local) cm->config_opts |= CM_CONFIG_LOCAL; |
| 72 |
|
| 73 |
if((status = cm_Configure(cm, errbuf, -1)) != eslOK) cm_Die(errbuf); |
| 74 |
|
| 75 |
|
| 76 |
seq = esl_sq_Create(); |
| 77 |
while ( esl_sqio_Read(sqfp, seq) == eslOK ) |
| 78 |
{ |
| 79 |
if (seq->n == 0) continue; |
| 80 |
|
| 81 |
int i0 = 1; |
| 82 |
int j0 = seq->n; |
| 83 |
|
| 84 |
if (seq->dsq == NULL) |
| 85 |
esl_sq_Digitize(abc, seq); |
| 86 |
sc = TrCYK_DnC(cm, seq->dsq, seq->n, 0, i0, j0, PLI_PASS_5P_AND_3P_ANY, TRUE, &tr); |
| 87 |
|
| 88 |
fali = CreateFancyAli(cm->abc, tr, cm, cm->cmcons, seq->dsq, FALSE, NULL); |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
FreeParsetree(tr); |
| 95 |
|
| 96 |
revcomp(abc, seq, seq); |
| 97 |
rev_sc = TrCYK_DnC(cm,seq->dsq, seq->n, 0, i0, j0, PLI_PASS_5P_AND_3P_ANY, TRUE, &tr); |
| 98 |
rev_fali = CreateFancyAli(cm->abc, tr, cm, cm->cmcons,seq->dsq, FALSE, NULL); |
| 99 |
|
| 100 |
FreeParsetree(tr); |
| 101 |
|
| 102 |
if (sc > rev_sc) |
| 103 |
{ |
| 104 |
printf("sequence: %s\n", seq->name); |
| 105 |
printf("score: %.2f\n",sc); |
| 106 |
PrintFancyAli(stdout, fali, 0, FALSE, FALSE, 60); |
| 107 |
} |
| 108 |
else |
| 109 |
{ |
| 110 |
printf("sequence: %s (reversed)\n", seq->name); |
| 111 |
printf("score: %.2f\n",rev_sc); |
| 112 |
PrintFancyAli(stdout, fali, seq->n, TRUE, FALSE, 60); |
| 113 |
} |
| 114 |
|
| 115 |
FreeFancyAli(fali); |
| 116 |
FreeFancyAli(rev_fali); |
| 117 |
|
| 118 |
esl_sq_Destroy(seq); |
| 119 |
seq = esl_sq_Create(); |
| 120 |
|
| 121 |
} |
| 122 |
esl_sq_Destroy(seq); |
| 123 |
|
| 124 |
FreeCM(cm); |
| 125 |
esl_sqfile_Close(sqfp); |
| 126 |
|
| 127 |
return EXIT_SUCCESS; |
| 128 |
} |