| 1 |
|
| 2 |
|
| 3 |
#include <p7_config.h> |
| 4 |
|
| 5 |
#include <stdio.h> |
| 6 |
#include <stdlib.h> |
| 7 |
#include <string.h> |
| 8 |
|
| 9 |
#undef HMMER_THREADS |
| 10 |
|
| 11 |
#include "easel.h" |
| 12 |
#include "esl_alphabet.h" |
| 13 |
#include "esl_getopts.h" |
| 14 |
#include "esl_mpi.h" |
| 15 |
#include "esl_msa.h" |
| 16 |
#include "esl_msafile.h" |
| 17 |
#include "esl_msaweight.h" |
| 18 |
#include "esl_msacluster.h" |
| 19 |
#include "esl_vectorops.h" |
| 20 |
#include "esl_regexp.h" |
| 21 |
|
| 22 |
#include "hmmer.h" |
| 23 |
|
| 24 |
typedef struct { |
| 25 |
P7_BG *bg; |
| 26 |
P7_BUILDER *bld; |
| 27 |
} WORKER_INFO; |
| 28 |
|
| 29 |
|
| 30 |
#define ALPHOPTS "--amino,--dna,--rna" |
| 31 |
#define CONOPTS "--fast,--hand" |
| 32 |
#define WGTOPTS "--wgsc,--wblosum,--wpb,--wnone,--wgiven" |
| 33 |
#define RANGEOPTS "--modelrange,--alirange,--ali2model,--model2ali" |
| 34 |
|
| 35 |
static ESL_OPTIONS options[] = { |
| 36 |
|
| 37 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 1 }, |
| 38 |
{ "-o", eslARG_OUTFILE,FALSE, NULL, NULL, NULL, NULL, NULL, "direct summary output to file <f>, not stdout", 1 }, |
| 39 |
|
| 40 |
{ "--amino", eslARG_NONE, FALSE, NULL, NULL, ALPHOPTS, NULL, NULL, "input alignment is protein sequence data", 2 }, |
| 41 |
{ "--dna", eslARG_NONE, FALSE, NULL, NULL, ALPHOPTS, NULL, NULL, "input alignment is DNA sequence data", 2 }, |
| 42 |
{ "--rna", eslARG_NONE, FALSE, NULL, NULL, ALPHOPTS, NULL, NULL, "input alignment is RNA sequence data", 2 }, |
| 43 |
|
| 44 |
{ "--fast", eslARG_NONE,"default",NULL, NULL, CONOPTS, NULL, NULL, "assign cols w/ >= symfrac residues as consensus", 3 }, |
| 45 |
{ "--hand", eslARG_NONE, FALSE, NULL, NULL, CONOPTS, NULL, NULL, "manual construction (requires reference annotation)", 3 }, |
| 46 |
{ "--symfrac", eslARG_REAL, "0.5", NULL, "0<=x<=1", NULL, "--fast", NULL, "sets sym fraction controlling --fast construction", 3 }, |
| 47 |
{ "--fragthresh",eslARG_REAL, "0.5", NULL, "0<=x<=1", NULL, NULL, NULL, "if L <= x*alen, tag sequence as a fragment", 3 }, |
| 48 |
|
| 49 |
|
| 50 |
{ "--wpb", eslARG_NONE,"default",NULL, NULL, WGTOPTS, NULL, NULL, "Henikoff position-based weights", 4 }, |
| 51 |
{ "--wgsc", eslARG_NONE, NULL, NULL, NULL, WGTOPTS, NULL, NULL, "Gerstein/Sonnhammer/Chothia tree weights", 4 }, |
| 52 |
{ "--wblosum", eslARG_NONE, NULL, NULL, NULL, WGTOPTS, NULL, NULL, "Henikoff simple filter weights", 4 }, |
| 53 |
{ "--wnone", eslARG_NONE, NULL, NULL, NULL, WGTOPTS, NULL, NULL, "don't do any relative weighting; set all to 1", 4 }, |
| 54 |
{ "--wgiven", eslARG_NONE, NULL, NULL, NULL, WGTOPTS, NULL, NULL, "use weights as given in MSA file", 4 }, |
| 55 |
{ "--wid", eslARG_REAL, "0.62", NULL,"0<=x<=1", NULL,"--wblosum", NULL, "for --wblosum: set identity cutoff", 4 }, |
| 56 |
|
| 57 |
{ "--modelrange", eslARG_STRING, NULL, NULL, NULL, NULL, NULL, RANGEOPTS, "range(s) for mask(s) in model coordinates", 5 }, |
| 58 |
{ "--alirange", eslARG_STRING, NULL, NULL, NULL, NULL, NULL, RANGEOPTS, "range(s) for mask(s) in alignment coordinates", 5 }, |
| 59 |
{ "--appendmask", eslARG_NONE, NULL, NULL, NULL, NULL, NULL, NULL, "add to existing mask (default ignores the existing mask)", 5 }, |
| 60 |
{ "--model2ali", eslARG_STRING, NULL, NULL, NULL, NULL, NULL, RANGEOPTS, "print msa column range for each input model range; no postmsa", 5 }, |
| 61 |
{ "--ali2model", eslARG_STRING, NULL, NULL, NULL, NULL, NULL, RANGEOPTS, "print model range for each input msa column range; no postmsa", 5 }, |
| 62 |
|
| 63 |
|
| 64 |
{ "--informat", eslARG_STRING, NULL, NULL, NULL, NULL, NULL, NULL, "assert input alifile is in format <s> (no autodetect)", 8 }, |
| 65 |
{ "--outformat", eslARG_STRING, "Stockholm", NULL, NULL, NULL, NULL, NULL, "output alignment in format <s>", 2 }, |
| 66 |
{ "--seed", eslARG_INT, "42", NULL, "n>=0", NULL, NULL, NULL, "set RNG seed to <n> (if 0: one-time arbitrary seed)", 8 }, |
| 67 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 68 |
}; |
| 69 |
|
| 70 |
|
| 71 |
static char usage[] = "[-options] <msafile> <postmsafile>"; |
| 72 |
static char banner[] = "append modelmask line to a multiple sequence alignment"; |
| 73 |
|
| 74 |
static int output_header(const ESL_GETOPTS *go, FILE *ofp, char *alifile, char *postmsafile); |
| 75 |
|
| 76 |
|
| 77 |
static int |
| 78 |
process_commandline(int argc, char **argv, ESL_GETOPTS **ret_go, char **ret_alifile, char **ret_postalifile) |
| 79 |
{ |
| 80 |
ESL_GETOPTS *go = esl_getopts_Create(options); |
| 81 |
int status; |
| 82 |
|
| 83 |
if (esl_opt_ProcessEnvironment(go) != eslOK) { if (printf("Failed to process environment:\n%s\n", go->errbuf) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); goto FAILURE; } |
| 84 |
if (esl_opt_ProcessCmdline(go, argc, argv) != eslOK) { if (printf("Failed to parse command line:\n%s\n", go->errbuf) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); goto FAILURE; } |
| 85 |
if (esl_opt_VerifyConfig(go) != eslOK) { if (printf("Failed to parse command line:\n%s\n", go->errbuf) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); goto FAILURE; } |
| 86 |
|
| 87 |
|
| 88 |
if (esl_opt_GetBoolean(go, "-h") == TRUE) |
| 89 |
{ |
| 90 |
p7_banner(stdout, argv[0], banner); |
| 91 |
esl_usage(stdout, argv[0], usage); |
| 92 |
|
| 93 |
if (puts("\nBasic options:") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); |
| 94 |
esl_opt_DisplayHelp(stdout, go, 1, 2, 80); |
| 95 |
|
| 96 |
if (puts("\nMask range options (format: --xxx 10-20,30-40 ) :") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); |
| 97 |
esl_opt_DisplayHelp(stdout, go, 5, 2, 80); |
| 98 |
|
| 99 |
if (puts("\nOptions for selecting alphabet rather than guessing it:") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); |
| 100 |
esl_opt_DisplayHelp(stdout, go, 2, 2, 80); |
| 101 |
|
| 102 |
if (puts("\nAlternative model construction strategies:") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); |
| 103 |
esl_opt_DisplayHelp(stdout, go, 3, 2, 80); |
| 104 |
|
| 105 |
if (puts("\nAlternative relative sequence weighting strategies:") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); |
| 106 |
esl_opt_DisplayHelp(stdout, go, 4, 2, 80); |
| 107 |
|
| 108 |
if (puts("\nOther options:") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); |
| 109 |
esl_opt_DisplayHelp(stdout, go, 8, 2, 80); |
| 110 |
exit(0); |
| 111 |
} |
| 112 |
|
| 113 |
if (esl_opt_ArgNumber(go) > 2) { if (puts("Incorrect number of command line arguments.") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); goto FAILURE; } |
| 114 |
if ((*ret_alifile = esl_opt_GetArg(go, 1)) == NULL) { if (puts("Failed to get <msafile> argument on command line") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); goto FAILURE; } |
| 115 |
if (esl_opt_IsUsed(go, "--alirange") || esl_opt_IsUsed(go, "--modelrange") ) { |
| 116 |
if ((*ret_postalifile = esl_opt_GetArg(go, 2)) == NULL) { if (puts("Failed to get <postmsafile> argument on command line") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); goto FAILURE; } |
| 117 |
} |
| 118 |
|
| 119 |
if (strcmp(*ret_alifile, "-") == 0 && ! esl_opt_IsOn(go, "--informat")) |
| 120 |
{ if (puts("Must specify --informat to read <alifile> from stdin ('-')") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); goto FAILURE; } |
| 121 |
|
| 122 |
|
| 123 |
*ret_go = go; |
| 124 |
return eslOK; |
| 125 |
|
| 126 |
FAILURE: |
| 127 |
esl_usage(stdout, argv[0], usage); |
| 128 |
puts("\nwhere basic options are:"); |
| 129 |
esl_opt_DisplayHelp(stdout, go, 1, 2, 80); |
| 130 |
printf("\nTo see more help on other available options, do:\n %s -h\n\n", argv[0]); |
| 131 |
esl_getopts_Destroy(go); |
| 132 |
exit(1); |
| 133 |
|
| 134 |
ERROR: |
| 135 |
if (go) esl_getopts_Destroy(go); |
| 136 |
exit(status); |
| 137 |
} |
| 138 |
|
| 139 |
static int |
| 140 |
output_header(const ESL_GETOPTS *go, FILE *ofp, char *alifile, char *postmsafile) |
| 141 |
{ |
| 142 |
p7_banner(ofp, go->argv[0], banner); |
| 143 |
|
| 144 |
if (fprintf(ofp, "# input alignment file: %s\n", alifile) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 145 |
|
| 146 |
if (esl_opt_IsUsed(go, "--alirange") || esl_opt_IsUsed(go, "--modelrange") ) { |
| 147 |
if (fprintf(ofp, "# output alignment file: %s\n", postmsafile) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 148 |
} |
| 149 |
|
| 150 |
if (esl_opt_IsUsed(go, "--alirange") && fprintf(ofp, "# alignment range: %s\n", esl_opt_GetString(go, "--alirange")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 151 |
if (esl_opt_IsUsed(go, "--modelrange") && fprintf(ofp, "# model range: %s\n", esl_opt_GetString(go, "--modelrange"))< 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 152 |
if (esl_opt_IsUsed(go, "--appendmask") && fprintf(ofp, "# add to existing mask: [on]\n" )< 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 153 |
|
| 154 |
if (esl_opt_IsUsed(go, "--model2ali") && fprintf(ofp, "# ali ranges for model range: %s\n", esl_opt_GetString(go, "--model2ali")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 155 |
if (esl_opt_IsUsed(go, "--ali2model") && fprintf(ofp, "# model ranges for ali range: %s\n", esl_opt_GetString(go, "--ali2model")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 156 |
|
| 157 |
|
| 158 |
if (esl_opt_IsUsed(go, "-o") && fprintf(ofp, "# output directed to file: %s\n", esl_opt_GetString(go, "-o")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 159 |
if (esl_opt_IsUsed(go, "--amino") && fprintf(ofp, "# input alignment is asserted as: protein\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 160 |
if (esl_opt_IsUsed(go, "--dna") && fprintf(ofp, "# input alignment is asserted as: DNA\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 161 |
if (esl_opt_IsUsed(go, "--rna") && fprintf(ofp, "# input alignment is asserted as: RNA\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 162 |
if (esl_opt_IsUsed(go, "--fast") && fprintf(ofp, "# model architecture construction: fast/heuristic\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 163 |
if (esl_opt_IsUsed(go, "--hand") && fprintf(ofp, "# model architecture construction: hand-specified by RF annotation\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 164 |
if (esl_opt_IsUsed(go, "--symfrac") && fprintf(ofp, "# sym fraction for model structure: %.3f\n", esl_opt_GetReal(go, "--symfrac")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 165 |
if (esl_opt_IsUsed(go, "--fragthresh") && fprintf(ofp, "# seq called frag if L <= x*alen: %.3f\n", esl_opt_GetReal(go, "--fragthresh")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 166 |
if (esl_opt_IsUsed(go, "--wpb") && fprintf(ofp, "# relative weighting scheme: Henikoff PB\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 167 |
if (esl_opt_IsUsed(go, "--wgsc") && fprintf(ofp, "# relative weighting scheme: G/S/C\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 168 |
if (esl_opt_IsUsed(go, "--wblosum") && fprintf(ofp, "# relative weighting scheme: BLOSUM filter\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 169 |
if (esl_opt_IsUsed(go, "--wnone") && fprintf(ofp, "# relative weighting scheme: none\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 170 |
if (esl_opt_IsUsed(go, "--wid") && fprintf(ofp, "# frac id cutoff for BLOSUM wgts: %f\n", esl_opt_GetReal(go, "--wid")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 171 |
if (esl_opt_IsUsed(go, "--seed")) { |
| 172 |
if (esl_opt_GetInteger(go, "--seed") == 0 && fprintf(ofp,"# random number seed: one-time arbitrary\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 173 |
else if ( fprintf(ofp,"# random number seed set to: %d\n", esl_opt_GetInteger(go, "--seed")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 174 |
} |
| 175 |
|
| 176 |
if (fprintf(ofp, "# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 177 |
return eslOK; |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
int |
| 197 |
p7_Alimask_MakeModel2AliMap(ESL_MSA *msa, int do_hand, float symfrac, int *model2ali_map) |
| 198 |
{ |
| 199 |
int i = 0; |
| 200 |
int apos, idx; |
| 201 |
float r; |
| 202 |
float totwgt; |
| 203 |
|
| 204 |
i = 0; |
| 205 |
if ( do_hand ) { |
| 206 |
if (msa->rf == NULL) p7_Fail("Model file does not contain an RF line, required for --hand.\n"); |
| 207 |
|
| 208 |
for (apos = 1; apos <= msa->alen; apos++) { |
| 209 |
if (!esl_abc_CIsGap(msa->abc, msa->rf[apos-1]) ) { |
| 210 |
model2ali_map[i] = apos; |
| 211 |
i++; |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
} else { |
| 216 |
|
| 217 |
for (apos = 1; apos <= msa->alen; apos++) |
| 218 |
{ |
| 219 |
r = totwgt = 0.; |
| 220 |
for (idx = 0; idx < msa->nseq; idx++) |
| 221 |
{ |
| 222 |
if (esl_abc_XIsResidue(msa->abc, msa->ax[idx][apos])) { r += msa->wgt[idx]; totwgt += msa->wgt[idx]; } |
| 223 |
else if (esl_abc_XIsGap(msa->abc, msa->ax[idx][apos])) { totwgt += msa->wgt[idx]; } |
| 224 |
else if (esl_abc_XIsMissing(msa->abc, msa->ax[idx][apos])) continue; |
| 225 |
} |
| 226 |
|
| 227 |
if (r > 0. && r / totwgt >= symfrac) { |
| 228 |
model2ali_map[i] = apos; |
| 229 |
i++; |
| 230 |
} |
| 231 |
} |
| 232 |
} |
| 233 |
return i; |
| 234 |
} |
| 235 |
|
| 236 |
int |
| 237 |
main(int argc, char **argv) |
| 238 |
{ |
| 239 |
ESL_GETOPTS *go = NULL; |
| 240 |
ESL_MSA *msa = NULL; |
| 241 |
FILE *ofp = NULL; |
| 242 |
ESL_ALPHABET *abc = NULL; |
| 243 |
char *alifile; |
| 244 |
ESL_MSAFILE *afp = NULL; |
| 245 |
int infmt = eslMSAFILE_UNKNOWN; |
| 246 |
int outfmt = eslMSAFILE_STOCKHOLM; |
| 247 |
char *postmsafile; |
| 248 |
FILE *postmsafp = NULL; |
| 249 |
int mask_range_cnt = 0; |
| 250 |
uint32_t mask_starts[100]; |
| 251 |
uint32_t mask_ends[100]; |
| 252 |
uint32_t min_mask_start = 0xFFFFFFFF; |
| 253 |
uint32_t max_mask_end = 0; |
| 254 |
int64_t pos1, pos2; |
| 255 |
char *rangestr; |
| 256 |
char *rangestr_ptr; |
| 257 |
char *range; |
| 258 |
int *model2ali_map = NULL; |
| 259 |
int model_len = 0; |
| 260 |
int keep_mm; |
| 261 |
int i,j; |
| 262 |
int status; |
| 263 |
|
| 264 |
|
| 265 |
impl_Init(); |
| 266 |
alifile = NULL; |
| 267 |
postmsafile = NULL; |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
process_commandline(argc, argv, &go, &alifile, &postmsafile); |
| 272 |
keep_mm = esl_opt_IsUsed(go, "--appendmask"); |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
ofp = NULL; |
| 279 |
infmt = eslMSAFILE_UNKNOWN; |
| 280 |
afp = NULL; |
| 281 |
abc = NULL; |
| 282 |
|
| 283 |
if (esl_opt_IsOn(go, "--informat")) { |
| 284 |
infmt = esl_msafile_EncodeFormat(esl_opt_GetString(go, "--informat")); |
| 285 |
if (infmt == eslMSAFILE_UNKNOWN) p7_Fail("%s is not a recognized input sequence file format\n", esl_opt_GetString(go, "--informat")); |
| 286 |
} |
| 287 |
|
| 288 |
|
| 289 |
outfmt = esl_msafile_EncodeFormat(esl_opt_GetString(go, "--outformat")); |
| 290 |
if (outfmt == eslMSAFILE_UNKNOWN) p7_Fail(argv[0], "%s is not a recognized output MSA file format\n", esl_opt_GetString(go, "--outformat")); |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
if (esl_opt_IsUsed(go, "--alirange")) { |
| 297 |
esl_strdup(esl_opt_GetString(go, "--alirange"), -1, &rangestr) ; |
| 298 |
} else if (esl_opt_IsUsed(go, "--modelrange")) { |
| 299 |
esl_strdup(esl_opt_GetString(go, "--modelrange"), -1, &rangestr) ; |
| 300 |
} else if (esl_opt_IsUsed(go, "--model2ali")) { |
| 301 |
esl_strdup(esl_opt_GetString(go, "--model2ali"), -1, &rangestr) ; |
| 302 |
} else if (esl_opt_IsUsed(go, "--ali2model")) { |
| 303 |
esl_strdup(esl_opt_GetString(go, "--ali2model"), -1, &rangestr) ; |
| 304 |
} else |
| 305 |
esl_fatal("Must specify mask range with --modelrange, --alirange, --model2ali, or --ali2model"); |
| 306 |
|
| 307 |
rangestr_ptr = rangestr; |
| 308 |
|
| 309 |
while ( (status = esl_strtok(&rangestr, ",", &range) ) == eslOK) { |
| 310 |
status = esl_regexp_ParseCoordString(range, &pos1, &pos2); |
| 311 |
if (status == eslESYNTAX) esl_fatal("Range flags take coords <from>..<to>; %s not recognized", range); |
| 312 |
if (status == eslFAIL) esl_fatal("Failed to find <from> or <to> coord in %s", range); |
| 313 |
if (pos1 > pos2) esl_fatal("In range (%s) <from> can not be larger than <to>", range); |
| 314 |
|
| 315 |
if (pos1<min_mask_start) min_mask_start = pos1; |
| 316 |
if (pos2>max_mask_end) max_mask_end = pos2; |
| 317 |
|
| 318 |
mask_starts[mask_range_cnt] = (uint32_t) pos1; |
| 319 |
mask_ends[mask_range_cnt] = (uint32_t) pos2; |
| 320 |
mask_range_cnt++; |
| 321 |
} |
| 322 |
free(rangestr_ptr); |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
if (esl_opt_GetBoolean(go, "--amino")) abc = esl_alphabet_Create(eslAMINO); |
| 332 |
else if (esl_opt_GetBoolean(go, "--dna")) abc = esl_alphabet_Create(eslDNA); |
| 333 |
else if (esl_opt_GetBoolean(go, "--rna")) abc = esl_alphabet_Create(eslRNA); |
| 334 |
else abc = NULL; |
| 335 |
|
| 336 |
status = esl_msafile_Open(&abc, alifile, NULL, infmt, NULL, &afp); |
| 337 |
if (status != eslOK) esl_msafile_OpenFailure(afp, status); |
| 338 |
|
| 339 |
if (esl_opt_IsUsed(go, "--alirange") || esl_opt_IsUsed(go, "--modelrange") ) { |
| 340 |
postmsafp = fopen(postmsafile, "w"); |
| 341 |
if (postmsafp == NULL) p7_Fail("Failed to open MSA output file %s for writing", postmsafile); |
| 342 |
} |
| 343 |
|
| 344 |
if (esl_opt_IsUsed(go, "-o")) |
| 345 |
{ |
| 346 |
ofp = fopen(esl_opt_GetString(go, "-o"), "w"); |
| 347 |
if (ofp == NULL) p7_Fail("Failed to open -o output file %s\n", esl_opt_GetString(go, "-o")); |
| 348 |
} |
| 349 |
else ofp = stdout; |
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
output_header(go, ofp, alifile, postmsafile); |
| 356 |
|
| 357 |
|
| 358 |
if ((status = esl_msafile_Read(afp, &msa)) != eslOK) esl_msafile_ReadFailure(afp, status); |
| 359 |
|
| 360 |
if (min_mask_start <= 0) esl_fatal("Mask ranges can not start before position 1; start %d is invalid", min_mask_start); |
| 361 |
|
| 362 |
if (esl_opt_IsUsed(go, "--alirange") || esl_opt_IsUsed(go, "--ali2model")) |
| 363 |
if (max_mask_end > msa->alen) esl_fatal("Maximum mask range %d exceeds alignment length %lld", max_mask_end, msa->alen); |
| 364 |
|
| 365 |
|
| 366 |
if (esl_opt_IsUsed(go, "--alirange") || esl_opt_IsUsed(go, "--modelrange") ) { |
| 367 |
|
| 368 |
if (msa->mm == NULL) { |
| 369 |
ESL_ALLOC(msa->mm, msa->alen); |
| 370 |
keep_mm = FALSE; |
| 371 |
} |
| 372 |
|
| 373 |
if (!keep_mm) |
| 374 |
for (i=0; i<msa->alen; i++) msa->mm[i] = '.'; |
| 375 |
|
| 376 |
} |
| 377 |
|
| 378 |
|
| 379 |
if (esl_opt_IsUsed(go, "--modelrange") || esl_opt_IsUsed(go, "--model2ali") || esl_opt_IsUsed(go, "--ali2model") ) { |
| 380 |
ESL_MSAWEIGHT_CFG *cfg = esl_msaweight_cfg_Create(); |
| 381 |
float symfrac = esl_opt_GetReal(go, "--symfrac"); |
| 382 |
int do_hand = esl_opt_IsOn(go, "--hand"); |
| 383 |
|
| 384 |
cfg->ignore_rf = (do_hand ? FALSE : TRUE); |
| 385 |
|
| 386 |
|
| 387 |
if (esl_opt_IsOn(go, "--wnone") ) { esl_vec_DSet(msa->wgt, msa->nseq, 1.); } |
| 388 |
else if (esl_opt_IsOn(go, "--wgiven") ) ; |
| 389 |
else if (esl_opt_IsOn(go, "--wpb") ) status = esl_msaweight_PB_adv(cfg, msa, NULL); |
| 390 |
else if (esl_opt_IsOn(go, "--wgsc") ) status = esl_msaweight_GSC(msa); |
| 391 |
else if (esl_opt_IsOn(go, "--wblosum")) status = esl_msaweight_BLOSUM(msa, esl_opt_GetReal(go, "--wid")); |
| 392 |
|
| 393 |
esl_msaweight_cfg_Destroy(cfg); |
| 394 |
|
| 395 |
if ( esl_msa_MarkFragments_old(msa, esl_opt_GetReal(go, "--fragthresh")) != eslOK) |
| 396 |
esl_fatal("esl_msa_MarkFragments_old() failed unexpectedly"); |
| 397 |
|
| 398 |
|
| 399 |
ESL_ALLOC(model2ali_map, sizeof(int) * (msa->alen+1)); |
| 400 |
model_len = p7_Alimask_MakeModel2AliMap(msa, do_hand, symfrac, model2ali_map ); |
| 401 |
|
| 402 |
if (esl_opt_IsUsed(go, "--modelrange") || esl_opt_IsUsed(go, "--model2ali")) |
| 403 |
if (max_mask_end >model_len) esl_fatal("Maximum mask range %d exceeds computed model length %lld", max_mask_end, model_len); |
| 404 |
|
| 405 |
if ( esl_opt_IsUsed(go, "--model2ali") ) { |
| 406 |
|
| 407 |
printf ("model coordinates alignment coordinates\n"); |
| 408 |
for (i=0; i<mask_range_cnt; i++) |
| 409 |
printf ("%8d..%-8d -> %8d..%-8d\n", mask_starts[i], mask_ends[i], model2ali_map[mask_starts[i]-1], model2ali_map[mask_ends[i]-1]); |
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
} else if ( esl_opt_IsUsed(go, "--ali2model") ) { |
| 418 |
|
| 419 |
int alistart = 0; |
| 420 |
int aliend = 0; |
| 421 |
printf ("alignment coordinates model coordinates\n"); |
| 422 |
for (i=0; i<mask_range_cnt; i++) { |
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
alistart=0; |
| 428 |
while (model2ali_map[alistart] < mask_starts[i] ) alistart++; |
| 429 |
aliend = alistart; |
| 430 |
while (aliend < model_len && model2ali_map[aliend] <= mask_ends[i]) aliend++; |
| 431 |
aliend--; |
| 432 |
|
| 433 |
if (model2ali_map[alistart] > mask_ends[i]) |
| 434 |
printf(" %8d..%-8d -> -..- (no map)\n", mask_starts[i], mask_ends[i]); |
| 435 |
else |
| 436 |
printf (" %8d..%-8d -> %8d..%-8d\n", model2ali_map[alistart], model2ali_map[aliend], alistart+1, aliend+1); |
| 437 |
} |
| 438 |
} else { |
| 439 |
|
| 440 |
for (i=0; i<mask_range_cnt; i++) { |
| 441 |
mask_starts[i] = model2ali_map[mask_starts[i]-1]; |
| 442 |
mask_ends[i] = model2ali_map[mask_ends[i]-1]; |
| 443 |
} |
| 444 |
} |
| 445 |
} |
| 446 |
|
| 447 |
if (esl_opt_IsUsed(go, "--alirange") || esl_opt_IsUsed(go, "--modelrange") ) { |
| 448 |
|
| 449 |
for (i=0; i<mask_range_cnt; i++) |
| 450 |
for (j=mask_starts[i]; j<=mask_ends[i]; j++) |
| 451 |
msa->mm[j-1] = 'm'; |
| 452 |
|
| 453 |
if ((status = esl_msafile_Write(postmsafp, msa, outfmt)) != eslOK) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); |
| 454 |
} |
| 455 |
|
| 456 |
if (esl_opt_IsOn(go, "-o")) fclose(ofp); |
| 457 |
if (postmsafp) fclose(postmsafp); |
| 458 |
if (afp) esl_msafile_Close(afp); |
| 459 |
if (msa) esl_msa_Destroy(msa); |
| 460 |
if (abc) esl_alphabet_Destroy(abc); |
| 461 |
if (model2ali_map) free(model2ali_map); |
| 462 |
|
| 463 |
esl_getopts_Destroy(go); |
| 464 |
return 0; |
| 465 |
|
| 466 |
ERROR: |
| 467 |
return eslFAIL; |
| 468 |
} |
| 469 |
|