| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include <esl_config.h> |
| 24 |
|
| 25 |
#include <stdlib.h> |
| 26 |
#include <stdio.h> |
| 27 |
#include <string.h> |
| 28 |
|
| 29 |
#include "easel.h" |
| 30 |
#include "esl_alphabet.h" |
| 31 |
#include "esl_distance.h" |
| 32 |
#include "esl_fileparser.h" |
| 33 |
#include "esl_getopts.h" |
| 34 |
#include "esl_msa.h" |
| 35 |
#include "esl_msafile.h" |
| 36 |
#include "esl_msafile2.h" |
| 37 |
#include "esl_sqio.h" |
| 38 |
#include "esl_stopwatch.h" |
| 39 |
#include "esl_vectorops.h" |
| 40 |
|
| 41 |
static char banner[] = "merge alignments based on their reference (RF) annotation"; |
| 42 |
static char usage1[] = "[options] <alignment file 1> <alignment file 2>"; |
| 43 |
static char usage2[] = "[options] --list <file listing n > 1 ali files to merge>\n\ |
| 44 |
\n\ |
| 45 |
Input alignments must be in Stockholm or Pfam format.\n\ |
| 46 |
Ouput format choices\n\ |
| 47 |
--------------------\n\ |
| 48 |
stockholm [default]\n\ |
| 49 |
pfam\n\ |
| 50 |
a2m\n\ |
| 51 |
psiblast\n\ |
| 52 |
afa"; |
| 53 |
|
| 54 |
static void read_list_file(char *listfile, char ***ret_alifile_list, int *ret_nalifile); |
| 55 |
static int update_maxgap_and_maxmis(ESL_MSA *msa, char *errbuf, int clen, int64_t alen, int *maxgap, int *maxmis); |
| 56 |
static int validate_and_copy_msa_annotation(const ESL_GETOPTS *go, int outfmt, ESL_MSA *mmsa, ESL_MSA **msaA, int clen, int nmsa, int alen_merged, int *maxgap, int *maxmis, char *errbuf); |
| 57 |
static int add_msa(ESL_MSA *mmsa, char *errbuf, ESL_MSA *msa_to_add, int *maxgap, int *maxmis, int clen, int alen_merged); |
| 58 |
static int inflate_string_with_gaps_and_missing(char *src_str, int64_t src_len, int64_t dst_len, int *ngapA, char gapchar, int *nmisA, char mischar, char **ret_dst_str); |
| 59 |
static int inflate_seq_with_gaps(const ESL_ALPHABET *abc, char *src_str, int64_t src_len, int64_t dst_len, int *ngapA, char gapchar, char **ret_dst_str); |
| 60 |
static int validate_no_nongaps_in_rf_gaps(const ESL_ALPHABET *abc, char *rf_str, char *other_str, int64_t len); |
| 61 |
static int determine_gap_columns_to_add(ESL_MSA *msa, int *maxgap, int *maxmis, int clen, int **ret_ngapA, int **ret_nmisA, int **ret_neitherA, char *errbuf); |
| 62 |
static void write_pfam_msa_top(FILE *fp, ESL_MSA *msa); |
| 63 |
static void write_pfam_msa_gc(FILE *fp, ESL_MSA *msa, int maxwidth); |
| 64 |
static int64_t maxwidth(char **s, int n); |
| 65 |
static int rfchar_is_nongap_nonmissing(const ESL_ALPHABET *abc, char rfchar); |
| 66 |
|
| 67 |
static ESL_OPTIONS options[] = { |
| 68 |
|
| 69 |
{ "--list", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, NULL, "command-line argument is a file that lists ali files to merge", 99 }, |
| 70 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, NULL, "help; show brief info on version and usage", 1 }, |
| 71 |
{ "-o", eslARG_OUTFILE, NULL, NULL, NULL, NULL,NULL, NULL, "output the final alignment to file <f>, not stdout", 1 }, |
| 72 |
{ "-v", eslARG_NONE, FALSE, NULL, NULL, NULL,"-o", NULL, "print info on merge to stdout; requires -o", 1 }, |
| 73 |
{ "--small", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, NULL, "use minimal RAM (RAM usage will be independent of aln sizes)", 1 }, |
| 74 |
{ "--rfonly", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, NULL, "remove all columns that are gaps in GC RF annotation", 1 }, |
| 75 |
{ "--informat", eslARG_STRING, FALSE, NULL, NULL, NULL,NULL, NULL, "NOT YET DISPLAYED", 99 }, |
| 76 |
{ "--outformat",eslARG_STRING, FALSE, NULL, NULL, NULL,NULL, NULL, "specify that output aln be format <s> (see choices above)", 1 }, |
| 77 |
{ "--rna", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL,"--amino,--rna", "alignments to merge are RNA alignments", 1 }, |
| 78 |
{ "--dna", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL,"--amino,--rna", "alignments to merge are DNA alignments", 1 }, |
| 79 |
{ "--amino", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL,"--dna,--rna", "alignments to merge are protein alignments", 1 }, |
| 80 |
{ "--stall", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, NULL, "arrest after start: for debugging under gdb", 99 }, |
| 81 |
{ 0,0,0,0,0,0,0,0,0,0 }, |
| 82 |
}; |
| 83 |
|
| 84 |
int |
| 85 |
main(int argc, char **argv) |
| 86 |
{ |
| 87 |
int status; |
| 88 |
ESL_GETOPTS *go = NULL; |
| 89 |
ESL_ALPHABET *abc = NULL; |
| 90 |
char *msafile1 = NULL; |
| 91 |
char *msafile2 = NULL; |
| 92 |
char *listfile = NULL; |
| 93 |
int infmt = eslMSAFILE_UNKNOWN; |
| 94 |
int outfmt = eslMSAFILE_UNKNOWN; |
| 95 |
ESL_MSAFILE *afp = NULL; |
| 96 |
ESL_MSAFILE2 *afp2 = NULL; |
| 97 |
FILE *ofp; |
| 98 |
char **alifile_list = NULL; |
| 99 |
int nalifile; |
| 100 |
int do_stall; |
| 101 |
int fi; |
| 102 |
int ai, ai2; |
| 103 |
int nali_tot; |
| 104 |
int *nali_per_file = NULL; |
| 105 |
int nseq_tot; |
| 106 |
int nseq_cur; |
| 107 |
int64_t alen_cur; |
| 108 |
int64_t *alenA = NULL; |
| 109 |
|
| 110 |
ESL_MSA **msaA = NULL; |
| 111 |
int *maxgap = NULL; |
| 112 |
|
| 113 |
int *maxmis = NULL; |
| 114 |
|
| 115 |
int nalloc = 0; |
| 116 |
int chunksize = 10; |
| 117 |
void *tmp; |
| 118 |
int clen; |
| 119 |
int cur_clen; |
| 120 |
int apos; |
| 121 |
ESL_MSA *mmsa = NULL; |
| 122 |
int alen_mmsa; |
| 123 |
char errbuf[eslERRBUFSIZE]; |
| 124 |
char *tmpstr; |
| 125 |
int **usemeA = NULL; |
| 126 |
ESL_STOPWATCH *w = NULL; |
| 127 |
int do_small; |
| 128 |
int do_rfonly; |
| 129 |
int *ngapA = NULL; |
| 130 |
int *nmisA = NULL; |
| 131 |
int *neitherA = NULL; |
| 132 |
|
| 133 |
|
| 134 |
char *namedashes = NULL; |
| 135 |
int ni; |
| 136 |
int namewidth; |
| 137 |
int tmp_len; |
| 138 |
|
| 139 |
|
| 140 |
int ngs_cur; |
| 141 |
int gs_exists = FALSE; |
| 142 |
int maxname, maxgf, maxgc, maxgr; |
| 143 |
int maxname_cur, maxgf_cur, maxgc_cur, maxgr_cur; |
| 144 |
int margin; |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
go = esl_getopts_Create(options); |
| 151 |
if (esl_opt_ProcessCmdline(go, argc, argv) != eslOK || |
| 152 |
esl_opt_VerifyConfig(go) != eslOK) |
| 153 |
{ |
| 154 |
printf("Failed to parse command line: %s\n", go->errbuf); |
| 155 |
esl_usage(stdout, argv[0], usage1); |
| 156 |
esl_usage(stdout, argv[0], usage2); |
| 157 |
printf("\nTo see more help on available options, do %s -h\n\n", argv[0]); |
| 158 |
exit(1); |
| 159 |
} |
| 160 |
|
| 161 |
if (esl_opt_GetBoolean(go, "-h") ) |
| 162 |
{ |
| 163 |
esl_banner(stdout, argv[0], banner); |
| 164 |
esl_usage (stdout, argv[0], usage1); |
| 165 |
esl_usage (stdout, argv[0], usage2); |
| 166 |
puts("\n where options are:"); |
| 167 |
esl_opt_DisplayHelp(stdout, go, 1, 2, 80); |
| 168 |
exit(0); |
| 169 |
} |
| 170 |
|
| 171 |
if(((! esl_opt_GetBoolean(go, "--list")) && (esl_opt_ArgNumber(go) != 2)) || |
| 172 |
(( esl_opt_GetBoolean(go, "--list")) && (esl_opt_ArgNumber(go) != 1))) |
| 173 |
{ |
| 174 |
printf("Incorrect number of command line arguments.\n"); |
| 175 |
esl_usage(stdout, argv[0], usage1); |
| 176 |
esl_usage(stdout, argv[0], usage2); |
| 177 |
printf("\nTo see more help on available options, do %s -h\n\n", argv[0]); |
| 178 |
exit(1); |
| 179 |
} |
| 180 |
|
| 181 |
if(esl_opt_GetBoolean(go, "--list")) { |
| 182 |
listfile = esl_opt_GetArg(go, 1); |
| 183 |
} |
| 184 |
else { |
| 185 |
msafile1 = esl_opt_GetArg(go, 1); |
| 186 |
msafile2 = esl_opt_GetArg(go, 2); |
| 187 |
} |
| 188 |
|
| 189 |
do_small = (esl_opt_IsOn(go, "--small")) ? TRUE : FALSE; |
| 190 |
do_rfonly = (esl_opt_IsOn(go, "--rfonly")) ? TRUE : FALSE; |
| 191 |
|
| 192 |
|
| 193 |
if (esl_opt_GetString(go, "-o") != NULL) { |
| 194 |
if ((ofp = fopen(esl_opt_GetString(go, "-o"), "w")) == NULL) |
| 195 |
esl_fatal("Failed to open -o output file %s\n", esl_opt_GetString(go, "-o")); |
| 196 |
} else ofp = stdout; |
| 197 |
|
| 198 |
if (esl_opt_IsOn(go, "--informat")) { |
| 199 |
infmt = esl_msafile_EncodeFormat(esl_opt_GetString(go, "--informat")); |
| 200 |
if (infmt == eslMSAFILE_UNKNOWN) esl_fatal("%s is not a valid input sequence file format for --informat", esl_opt_GetString(go, "--informat")); |
| 201 |
if (do_small && infmt != eslMSAFILE_PFAM) esl_fatal("small memory mode requires Pfam formatted alignments"); |
| 202 |
} |
| 203 |
if (esl_opt_IsOn(go, "--outformat")) { |
| 204 |
outfmt = esl_msafile_EncodeFormat(esl_opt_GetString(go, "--outformat")); |
| 205 |
if (outfmt == eslMSAFILE_UNKNOWN) esl_fatal("%s is not a valid input sequence file format for --outformat", esl_opt_GetString(go, "--outformat")); |
| 206 |
if (do_small && outfmt != eslMSAFILE_PFAM) esl_fatal("we can only output Pfam formatted alignments in small memory mode"); |
| 207 |
} |
| 208 |
else outfmt = eslMSAFILE_STOCKHOLM; |
| 209 |
|
| 210 |
if (do_small) { |
| 211 |
infmt = eslMSAFILE_PFAM; |
| 212 |
outfmt = eslMSAFILE_PFAM; |
| 213 |
} |
| 214 |
|
| 215 |
do_stall = esl_opt_GetBoolean(go, "--stall"); |
| 216 |
while (do_stall); |
| 217 |
|
| 218 |
|
| 219 |
if(listfile != NULL) { |
| 220 |
read_list_file(listfile, &alifile_list, &nalifile); |
| 221 |
if(nalifile == 0) esl_fatal("Failed to read a single alignment file name from %s\n", listfile); |
| 222 |
} |
| 223 |
else { |
| 224 |
nalifile = 2; |
| 225 |
ESL_ALLOC(alifile_list, sizeof(char *) * nalifile); |
| 226 |
if((status = esl_strdup(msafile1, -1, &(alifile_list[0]))) != eslOK) esl_fatal("Error storing alignment file name %s, error status: %d\n", msafile1, status); |
| 227 |
if((status = esl_strdup(msafile2, -1, &(alifile_list[1]))) != eslOK) esl_fatal("Error storing alignment file name %s, error status: %d\n", msafile2, status); |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
if(ofp != stdout) { |
| 232 |
w = esl_stopwatch_Create(); |
| 233 |
esl_stopwatch_Start(w); |
| 234 |
} |
| 235 |
|
| 236 |
if(esl_opt_GetBoolean(go, "-v")) { |
| 237 |
|
| 238 |
namewidth = 9; |
| 239 |
for(fi = 0; fi < nalifile; fi++) { |
| 240 |
if((status = esl_FileTail(alifile_list[fi], FALSE, &tmpstr)) != eslOK) esl_fatal("Memory allocation error."); |
| 241 |
namewidth = ESL_MAX(namewidth, strlen(tmpstr)); |
| 242 |
free(tmpstr); |
| 243 |
} |
| 244 |
|
| 245 |
ESL_ALLOC(namedashes, sizeof(char) * (namewidth+1)); |
| 246 |
namedashes[namewidth] = '\0'; |
| 247 |
for(ni = 0; ni < namewidth; ni++) namedashes[ni] = '-'; |
| 248 |
fprintf(stdout, "# Reading %d alignment files...\n", nalifile); |
| 249 |
fprintf(stdout, "#\n"); |
| 250 |
fprintf(stdout, "# %7s %-*s %7s %9s %9s %13s %8s\n", "", namewidth,"", "", "", "", "", "ncols"); |
| 251 |
fprintf(stdout, "# %7s %-*s %7s %9s %9s %13s %8s\n", "file #", namewidth,"file name", "ali #", "#seq/ali", "ncols/ali", "# seq total", "required"); |
| 252 |
fprintf(stdout, "# %7s %*s %7s %9s %9s %13s %8s\n", "-------", namewidth, namedashes, "-------", "---------", "---------", "-------------", "--------"); |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
nalloc = chunksize; |
| 257 |
ESL_ALLOC(msaA, sizeof(ESL_MSA *) * nalloc); |
| 258 |
ESL_ALLOC(alenA, sizeof(int64_t) * nalloc); |
| 259 |
if(do_rfonly) ESL_ALLOC(usemeA, sizeof(int *) * nalloc); |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
if (esl_opt_GetBoolean(go, "--amino")) abc = esl_alphabet_Create(eslAMINO); |
| 265 |
else if (esl_opt_GetBoolean(go, "--dna")) abc = esl_alphabet_Create(eslDNA); |
| 266 |
else if (esl_opt_GetBoolean(go, "--rna")) abc = esl_alphabet_Create(eslRNA); |
| 267 |
else if (do_small) abc = esl_alphabet_Create(eslRNA); |
| 268 |
else abc = esl_alphabet_Create(eslRNA); |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
ai = 0; |
| 275 |
nseq_tot = 0; |
| 276 |
maxname = maxgf = maxgc = maxgr = 0; |
| 277 |
ESL_ALLOC(nali_per_file, sizeof(int) * nalifile); |
| 278 |
esl_vec_ISet(nali_per_file, nalifile, 0); |
| 279 |
|
| 280 |
for (fi = 0; fi < nalifile; fi++) { |
| 281 |
|
| 282 |
if (do_small) |
| 283 |
{ |
| 284 |
status = esl_msafile2_Open(alifile_list[fi], NULL, &afp2); |
| 285 |
if (status == eslENOTFOUND) esl_fatal("Alignment file %s doesn't exist or is not readable\n", alifile_list[fi]); |
| 286 |
else if (status != eslOK) esl_fatal("Alignment file %s open failed with error %d\n", alifile_list[fi], status); |
| 287 |
} |
| 288 |
else |
| 289 |
{ |
| 290 |
status = esl_msafile_Open(NULL, alifile_list[fi], NULL, infmt, NULL, &afp); |
| 291 |
if (status != eslOK) esl_msafile_OpenFailure(afp, status); |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
while((status = (do_small) ? |
| 297 |
esl_msafile2_ReadInfoPfam(afp2, NULL, NULL, -1, NULL,NULL, &(msaA[ai]), &nseq_cur, &alen_cur, &ngs_cur, &maxname_cur, &maxgf_cur, &maxgc_cur, &maxgr_cur, NULL, NULL, NULL, NULL, NULL) : |
| 298 |
esl_msafile_Read (afp, &(msaA[ai]))) == eslOK) { |
| 299 |
|
| 300 |
if(msaA[ai]->rf == NULL) esl_fatal("Error, all alignments must have #=GC RF annotation; alignment %d of file %d does not (%s)\n", nali_per_file[fi], (fi+1), alifile_list[fi]); |
| 301 |
msaA[ai]->abc = abc; |
| 302 |
|
| 303 |
if (do_small) { |
| 304 |
maxname = ESL_MAX(maxname, maxname_cur); |
| 305 |
maxgf = ESL_MAX(maxgf, maxgf_cur); |
| 306 |
maxgc = ESL_MAX(maxgc, maxgc_cur); |
| 307 |
maxgr = ESL_MAX(maxgr, maxgr_cur); |
| 308 |
msaA[ai]->alen = alen_cur; |
| 309 |
if(ngs_cur > 0) gs_exists = TRUE; |
| 310 |
} |
| 311 |
else { |
| 312 |
nseq_cur = msaA[ai]->nseq; |
| 313 |
} |
| 314 |
alenA[ai] = msaA[ai]->alen; |
| 315 |
nali_per_file[fi]++; |
| 316 |
nseq_tot += nseq_cur; |
| 317 |
|
| 318 |
|
| 319 |
if((ai+1) == nalloc) { |
| 320 |
nalloc += chunksize; |
| 321 |
ESL_RALLOC(msaA, tmp, sizeof(ESL_MSA *) * nalloc); |
| 322 |
ESL_RALLOC(alenA, tmp, sizeof(int64_t) * nalloc); |
| 323 |
for(ai2 = ai+1; ai2 < nalloc; ai2++) { msaA[ai2] = NULL; } |
| 324 |
if(do_rfonly) { |
| 325 |
ESL_RALLOC(usemeA, tmp, sizeof(int *) * nalloc); |
| 326 |
for(ai2 = ai+1; ai2 < nalloc; ai2++) { usemeA[ai2] = NULL; } |
| 327 |
} |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
cur_clen = 0; |
| 332 |
for(apos = 0; apos < (int) msaA[ai]->alen; apos++) { |
| 333 |
if(rfchar_is_nongap_nonmissing(msaA[ai]->abc, msaA[ai]->rf[apos])) cur_clen++; |
| 334 |
} |
| 335 |
if(ai == 0) { |
| 336 |
clen = cur_clen; |
| 337 |
ESL_ALLOC(maxgap, sizeof(int) * (clen+1)); |
| 338 |
esl_vec_ISet(maxgap, (clen+1), 0); |
| 339 |
ESL_ALLOC(maxmis, sizeof(int) * (clen+1)); |
| 340 |
esl_vec_ISet(maxmis, (clen+1), 0); |
| 341 |
} |
| 342 |
else if(cur_clen != clen) { |
| 343 |
esl_fatal("Error, all alignments must have identical non-gap #=GC RF lengths; expected (RF length of first ali read): %d,\nalignment %d of file %d length is %d (%s))\n", clen, nali_per_file[fi], (fi+1), cur_clen, alifile_list[fi]); |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
if(do_rfonly) { |
| 348 |
|
| 349 |
|
| 350 |
ESL_ALLOC(usemeA[ai], sizeof(int) * (msaA[ai]->alen)); |
| 351 |
for(apos = 0; apos < msaA[ai]->alen; apos++) { usemeA[ai][apos] = (rfchar_is_nongap_nonmissing(abc, msaA[ai]->rf[apos])) ? TRUE : FALSE; } |
| 352 |
if((status = esl_msa_ColumnSubset(msaA[ai], errbuf, usemeA[ai])) != eslOK) { |
| 353 |
esl_fatal("status code: %d removing gap RF columns for msa %d from file %s:\n%s", status, (ai+1), alifile_list[fi], errbuf); |
| 354 |
} |
| 355 |
} |
| 356 |
else { |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
if((status = update_maxgap_and_maxmis(msaA[ai], errbuf, clen, msaA[ai]->alen, maxgap, maxmis)) != eslOK) esl_fatal(errbuf); |
| 362 |
} |
| 363 |
if(esl_opt_GetBoolean(go, "-v")) { |
| 364 |
if((status = esl_FileTail(alifile_list[fi], FALSE, &tmpstr)) != eslOK) esl_fatal("Memory allocation error."); |
| 365 |
tmp_len = clen + esl_vec_ISum(maxgap, clen+1) + esl_vec_ISum(maxmis, clen+1); |
| 366 |
fprintf(stdout, " %7d %-*s %7d %9d %9" PRId64 " %13d %8d\n", (fi+1), namewidth, tmpstr, (ai+1), nseq_cur, msaA[ai]->alen, nseq_tot, tmp_len); |
| 367 |
free(tmpstr); |
| 368 |
} |
| 369 |
ai++; |
| 370 |
} |
| 371 |
|
| 372 |
if (do_small) |
| 373 |
{ |
| 374 |
if (status == eslEFORMAT) esl_fatal("Alignment file %s, parse error:\n%s\n", alifile_list[fi], afp2->errbuf); |
| 375 |
else if (status == eslEINVAL) esl_fatal("Alignment file %s, parse error:\n%s\n", alifile_list[fi], afp2->errbuf); |
| 376 |
else if (status != eslEOF) esl_fatal("Alignment file %s, read failed with error code %d\n", alifile_list[fi], status); |
| 377 |
} |
| 378 |
else if (status != eslEOF) esl_msafile_ReadFailure(afp, status); |
| 379 |
|
| 380 |
if(nali_per_file[fi] == 0) esl_fatal("Failed to read any alignments from file %s\n", alifile_list[fi]); |
| 381 |
|
| 382 |
if (do_small) esl_msafile2_Close(afp2); |
| 383 |
else esl_msafile_Close(afp); |
| 384 |
} |
| 385 |
nali_tot = ai; |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
mmsa = esl_msa_Create(nseq_tot, -1); |
| 405 |
alen_mmsa = clen + esl_vec_ISum(maxgap, clen+1) + esl_vec_ISum(maxmis, clen+1); |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
if((status = validate_and_copy_msa_annotation(go, outfmt, mmsa, msaA, nali_tot, clen, alen_mmsa, maxgap, maxmis, errbuf)) != eslOK) |
| 413 |
esl_fatal("Error while checking and copying individual MSA annotation to merged MSA:%s\n", errbuf); |
| 414 |
|
| 415 |
if (do_small) { |
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
write_pfam_msa_top(ofp, mmsa); |
| 423 |
|
| 424 |
if(ofp != stdout) { |
| 425 |
if(esl_opt_GetBoolean(go, "-v")) { fprintf(stdout, "#\n"); } |
| 426 |
fprintf(stdout, "# Outputting merged alignment to file %s ... ", esl_opt_GetString(go, "-o")); |
| 427 |
fflush(stdout); |
| 428 |
} |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
if(gs_exists) { |
| 433 |
ai = 0; |
| 434 |
for(fi = 0; fi < nalifile; fi++) { |
| 435 |
|
| 436 |
status = esl_msafile2_Open(alifile_list[fi], NULL, &afp2); |
| 437 |
if (status == eslENOTFOUND) esl_fatal("Second pass, alignment file %s doesn't exist or is not readable\n", alifile_list[fi]); |
| 438 |
else if (status == eslEFORMAT) esl_fatal("Second pass, couldn't determine format of alignment %s\n", alifile_list[fi]); |
| 439 |
else if (status != eslOK) esl_fatal("Second pass, alignment file %s open failed with error %d\n", alifile_list[fi], status); |
| 440 |
|
| 441 |
for(ai2 = 0; ai2 < nali_per_file[fi]; ai2++) { |
| 442 |
status = esl_msafile2_RegurgitatePfam(afp2, ofp, |
| 443 |
maxname, maxgf, maxgc, maxgr, |
| 444 |
FALSE, |
| 445 |
FALSE, |
| 446 |
FALSE, |
| 447 |
FALSE, |
| 448 |
FALSE, |
| 449 |
TRUE, |
| 450 |
FALSE, |
| 451 |
FALSE, |
| 452 |
FALSE, |
| 453 |
NULL, |
| 454 |
NULL, |
| 455 |
NULL, |
| 456 |
NULL, |
| 457 |
alenA[ai], |
| 458 |
'.', |
| 459 |
NULL, |
| 460 |
NULL); |
| 461 |
if(status == eslEOF) esl_fatal("Second pass, error out of alignments too soon, when trying to read aln %d of file %s", ai2, alifile_list[fi]); |
| 462 |
if(status != eslOK) esl_fatal("Second pass, error reading alignment %d of file %s: %s", ai2, alifile_list[fi], afp2->errbuf); |
| 463 |
ai++; |
| 464 |
fflush(ofp); |
| 465 |
} |
| 466 |
esl_msafile2_Close(afp2); |
| 467 |
} |
| 468 |
fprintf(ofp, "\n"); |
| 469 |
} |
| 470 |
|
| 471 |
|
| 472 |
ai = 0; |
| 473 |
for(fi = 0; fi < nalifile; fi++) { |
| 474 |
status = esl_msafile2_Open(alifile_list[fi], NULL, &afp2); |
| 475 |
if (status == eslENOTFOUND) esl_fatal("Second pass, alignment file %s doesn't exist or is not readable\n", alifile_list[fi]); |
| 476 |
else if (status == eslEFORMAT) esl_fatal("Second pass, couldn't determine format of alignment %s\n", alifile_list[fi]); |
| 477 |
else if (status != eslOK) esl_fatal("Second pass, alignment file %s open failed with error %d\n", alifile_list[fi], status); |
| 478 |
|
| 479 |
for(ai2 = 0; ai2 < nali_per_file[fi]; ai2++) { |
| 480 |
|
| 481 |
|
| 482 |
if(! do_rfonly) { |
| 483 |
if((status = determine_gap_columns_to_add(msaA[ai], maxgap, maxmis, clen, &(ngapA), &(nmisA), &(neitherA), errbuf)) != eslOK) |
| 484 |
esl_fatal("error determining number of all gap columns to add to alignment %d of file %s", ai2, alifile_list[fi]); |
| 485 |
} |
| 486 |
status = esl_msafile2_RegurgitatePfam(afp2, ofp, |
| 487 |
maxname, maxgf, maxgc, maxgr, |
| 488 |
FALSE, |
| 489 |
FALSE, |
| 490 |
FALSE, |
| 491 |
FALSE, |
| 492 |
FALSE, |
| 493 |
FALSE, |
| 494 |
FALSE, |
| 495 |
TRUE, |
| 496 |
TRUE, |
| 497 |
NULL, |
| 498 |
NULL, |
| 499 |
(do_rfonly) ? usemeA[ai] : NULL, |
| 500 |
(do_rfonly) ? NULL : neitherA, |
| 501 |
alenA[ai], |
| 502 |
'.', |
| 503 |
NULL, |
| 504 |
NULL); |
| 505 |
|
| 506 |
if(status == eslEOF) esl_fatal("Second pass, error out of alignments too soon, when trying to read aln %d of file %s", ai2, alifile_list[fi]); |
| 507 |
if(status != eslOK) esl_fatal("Second pass, error reading alignment %d of file %s: %s", ai2, alifile_list[fi], afp2->errbuf); |
| 508 |
free(ngapA); |
| 509 |
free(nmisA); |
| 510 |
free(neitherA); |
| 511 |
esl_msa_Destroy(msaA[ai]); |
| 512 |
msaA[ai] = NULL; |
| 513 |
ai++; |
| 514 |
fflush(ofp); |
| 515 |
} |
| 516 |
esl_msafile2_Close(afp2); |
| 517 |
} |
| 518 |
|
| 519 |
margin = maxname + 1; |
| 520 |
if (maxgc > 0 && maxgc+6 > margin) margin = maxgc+6; |
| 521 |
if (maxgr > 0 && maxname+maxgr+7 > margin) margin = maxname+maxgr+7; |
| 522 |
write_pfam_msa_gc(ofp, mmsa, margin); |
| 523 |
} |
| 524 |
|
| 525 |
else { |
| 526 |
if(esl_opt_GetBoolean(go, "-v")) { fprintf(stdout, "#\n# Merging alignments ... "); fflush(stdout); } |
| 527 |
for(ai = 0; ai < nali_tot; ai++) { |
| 528 |
if((status = add_msa(mmsa, errbuf, msaA[ai], maxgap, maxmis, clen, alen_mmsa)) != eslOK) |
| 529 |
esl_fatal("Error, merging alignment %d of %d:\n%s.", (ai+1), nali_tot, errbuf); |
| 530 |
esl_msa_Destroy(msaA[ai]); |
| 531 |
msaA[ai] = NULL; |
| 532 |
} |
| 533 |
if(esl_opt_GetBoolean(go, "-v")) { fprintf(stdout, "done.\n#\n"); fflush(stdout); } |
| 534 |
mmsa->alen = alen_mmsa; |
| 535 |
if(ofp != stdout) { fprintf(stdout, "# Saving alignment to file %s ... ", esl_opt_GetString(go, "-o")); } |
| 536 |
status = esl_msafile_Write(ofp, mmsa, outfmt); |
| 537 |
if(status != eslOK) esl_fatal("Error, during alignment output; status code: %d\n", status); |
| 538 |
} |
| 539 |
if(ofp != stdout) { |
| 540 |
fflush(stdout); |
| 541 |
fclose(ofp); |
| 542 |
fprintf(stdout, "done\n#\n"); |
| 543 |
fflush(stdout); |
| 544 |
esl_stopwatch_Stop(w); |
| 545 |
esl_stopwatch_Display(stdout, w, "# CPU time: "); |
| 546 |
} |
| 547 |
|
| 548 |
|
| 549 |
if(alifile_list != NULL) { |
| 550 |
for(fi = 0; fi < nalifile; fi++) { |
| 551 |
if(alifile_list[fi] != NULL) free(alifile_list[fi]); |
| 552 |
} |
| 553 |
free(alifile_list); |
| 554 |
} |
| 555 |
if(usemeA != NULL) { |
| 556 |
for(ai = 0; ai < nali_tot; ai++) { |
| 557 |
free(usemeA[ai]); |
| 558 |
} |
| 559 |
free(usemeA); |
| 560 |
} |
| 561 |
|
| 562 |
if(nali_per_file != NULL) free(nali_per_file); |
| 563 |
if(alenA != NULL) free(alenA); |
| 564 |
if(namedashes != NULL) free(namedashes); |
| 565 |
if(msaA != NULL) free(msaA); |
| 566 |
if(maxgap != NULL) free(maxgap); |
| 567 |
if(maxmis != NULL) free(maxmis); |
| 568 |
if(mmsa != NULL) esl_msa_Destroy(mmsa); |
| 569 |
if(abc != NULL) esl_alphabet_Destroy(abc); |
| 570 |
if(w != NULL) esl_stopwatch_Destroy(w); |
| 571 |
esl_getopts_Destroy(go); |
| 572 |
return 0; |
| 573 |
|
| 574 |
ERROR: |
| 575 |
esl_fatal("Out of memory. Reformat to Pfam with esl-reformat and try esl-alimerge --small."); |
| 576 |
return eslEMEM; |
| 577 |
} |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
void |
| 593 |
read_list_file(char *listfile, char ***ret_alifile_list, int *ret_nalifile) |
| 594 |
{ |
| 595 |
int status; |
| 596 |
ESL_FILEPARSER *efp; |
| 597 |
char *tok; |
| 598 |
int nalloc = 10; |
| 599 |
int chunksize = 10; |
| 600 |
char **alifile_list = NULL; |
| 601 |
int n = 0; |
| 602 |
void *tmp; |
| 603 |
|
| 604 |
ESL_ALLOC(alifile_list, sizeof(char *) * nalloc); |
| 605 |
status = esl_fileparser_Open(listfile, NULL, &efp); |
| 606 |
if (status == eslENOTFOUND) esl_fatal("List file %s does not exist or is not readable\n", listfile); |
| 607 |
else if(status == eslEMEM) esl_fatal("Ran out of memory when opening list file %s\n", listfile); |
| 608 |
else if(status != eslOK) esl_fatal("Error opening list file %s\n", listfile); |
| 609 |
|
| 610 |
esl_fileparser_SetCommentChar(efp, '#'); |
| 611 |
while((status = esl_fileparser_GetToken(efp, &tok, NULL)) != eslEOF) { |
| 612 |
if(n == nalloc) { nalloc += chunksize; ESL_RALLOC(alifile_list, tmp, sizeof(char *) * nalloc); } |
| 613 |
if((status = esl_strdup(tok, -1, &(alifile_list[n++]))) != eslOK) { |
| 614 |
esl_fatal("Error storing alignment file name while reading list file %s, error status: %d\n", listfile, status); |
| 615 |
} |
| 616 |
} |
| 617 |
esl_fileparser_Close(efp); |
| 618 |
*ret_alifile_list = alifile_list; |
| 619 |
*ret_nalifile = n; |
| 620 |
|
| 621 |
return; |
| 622 |
|
| 623 |
ERROR: |
| 624 |
esl_fatal("Out of memory."); |
| 625 |
return; |
| 626 |
} |
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
int |
| 653 |
update_maxgap_and_maxmis(ESL_MSA *msa, char *errbuf, int clen, int64_t alen, int *maxgap, int *maxmis) |
| 654 |
{ |
| 655 |
int apos; |
| 656 |
int cpos = 0; |
| 657 |
int ngap = 0; |
| 658 |
int nmis = 0; |
| 659 |
|
| 660 |
for(apos = 0; apos < alen; apos++) { |
| 661 |
if(esl_abc_CIsGap(msa->abc, msa->rf[apos])) { |
| 662 |
ngap++; |
| 663 |
} |
| 664 |
else if (esl_abc_CIsMissing(msa->abc, msa->rf[apos])) { |
| 665 |
nmis++; |
| 666 |
if(ngap > 0) ESL_FAIL(eslEINVAL, errbuf, "after nongap RF pos %d, %d gap columns precede a missing data column (none should)", cpos, ngap); |
| 667 |
} |
| 668 |
else { |
| 669 |
maxgap[cpos] = ESL_MAX(maxgap[cpos], ngap); |
| 670 |
maxmis[cpos] = ESL_MAX(maxmis[cpos], nmis); |
| 671 |
cpos++; |
| 672 |
ngap = 0; |
| 673 |
nmis = 0; |
| 674 |
} |
| 675 |
} |
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
maxgap[cpos] = ESL_MAX(maxgap[cpos], ngap); |
| 680 |
maxmis[cpos] = ESL_MAX(maxmis[cpos], nmis); |
| 681 |
if(cpos != clen) ESL_FAIL(eslEINVAL, errbuf, "second pass expected clen (%d) not equal to actual clen (%d).\n", clen, cpos); |
| 682 |
|
| 683 |
return eslOK; |
| 684 |
} |
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
int |
| 719 |
validate_and_copy_msa_annotation(const ESL_GETOPTS *go, int outfmt, ESL_MSA *mmsa, ESL_MSA **msaA, int nmsa, int clen, int alen_merged, int *maxgap, int *maxmis, char *errbuf) |
| 720 |
{ |
| 721 |
int status; |
| 722 |
int j; |
| 723 |
int j2; |
| 724 |
int ai; |
| 725 |
char *dealigned = NULL; |
| 726 |
char *dealigned2 = NULL; |
| 727 |
char *gapped_out = NULL; |
| 728 |
int *ngapA = NULL; |
| 729 |
int *nmisA = NULL; |
| 730 |
int *neitherA = NULL; |
| 731 |
int do_add; |
| 732 |
int found_tag; |
| 733 |
int be_verbose = FALSE; |
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
if((esl_opt_GetBoolean(go, "-v")) && |
| 741 |
(outfmt == eslMSAFILE_STOCKHOLM || outfmt == eslMSAFILE_PFAM)) |
| 742 |
{ be_verbose = TRUE; } |
| 743 |
|
| 744 |
if(be_verbose) fprintf(stdout, "#\n"); |
| 745 |
|
| 746 |
if(nmsa == 0) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "in validate_and_copy_msa_annotation(): zero child alignments."); |
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
if((status = determine_gap_columns_to_add(msaA[0], maxgap, maxmis, clen, &(ngapA), &(nmisA), &(neitherA), errbuf)) != eslOK) |
| 752 |
return status; |
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
do_add = TRUE; |
| 759 |
if(msaA[0]->name != NULL) { |
| 760 |
for(ai = 1; ai < nmsa; ai++) { |
| 761 |
if(esl_strcmp(msaA[0]->name, msaA[ai]->name) != 0) { do_add = FALSE; break; } |
| 762 |
} |
| 763 |
if(do_add) { |
| 764 |
if(be_verbose) fprintf(stdout, "# Identical name annotation from all alignments transferred to merged alignment.\n"); |
| 765 |
if((status = esl_strdup(msaA[0]->name, -1, &(mmsa->name))) != eslOK) goto ERROR; |
| 766 |
} |
| 767 |
else if(be_verbose) fprintf(stdout, "# Name annotation is not identical in all alignments; not included in merged alignment.\n"); |
| 768 |
} |
| 769 |
else if(be_verbose) fprintf(stdout, "# Name annotation absent from (at least) first alignment; not included in merged alignment.\n"); |
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
do_add = TRUE; |
| 774 |
if(msaA[0]->desc != NULL) { |
| 775 |
for(ai = 1; ai < nmsa; ai++) { |
| 776 |
if(esl_strcmp(msaA[0]->desc, msaA[ai]->desc) != 0) { do_add = FALSE; break; } |
| 777 |
} |
| 778 |
if(do_add) { |
| 779 |
if(be_verbose) fprintf(stdout, "# Identical description annotation from all alignments transferred to merged alignment.\n"); |
| 780 |
if((status = esl_strdup(msaA[0]->desc, -1, &(mmsa->desc))) != eslOK) goto ERROR; |
| 781 |
} |
| 782 |
else if(be_verbose) fprintf(stdout, "# Description annotation is not identical in all alignments; not included in merged alignment.\n"); |
| 783 |
} |
| 784 |
else if(be_verbose) fprintf(stdout, "# Description annotation absent from (at least) first alignment; not included in merged alignment.\n"); |
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
do_add = TRUE; |
| 789 |
if(msaA[0]->acc != NULL) { |
| 790 |
for(ai = 1; ai < nmsa; ai++) { |
| 791 |
if(esl_strcmp(msaA[0]->acc, msaA[ai]->acc) != 0) { do_add = FALSE; break; } |
| 792 |
} |
| 793 |
if(do_add) { |
| 794 |
if(be_verbose) fprintf(stdout, "# Identical accession annotation from all alignments transferred to merged alignment.\n"); |
| 795 |
if((status = esl_strdup(msaA[0]->acc, -1, &(mmsa->acc))) != eslOK) goto ERROR; |
| 796 |
} |
| 797 |
else if(be_verbose) fprintf(stdout, "# Accession annotation is not identical in all alignments; not included in merged alignment.\n"); |
| 798 |
} |
| 799 |
else if(be_verbose) fprintf(stdout, "# Accession annotation absent from (at least) first alignment; not included in merged alignment.\n"); |
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
do_add = TRUE; |
| 804 |
if(msaA[0]->au != NULL) { |
| 805 |
for(ai = 1; ai < nmsa; ai++) { |
| 806 |
if(esl_strcmp(msaA[0]->au, msaA[ai]->au) != 0) { do_add = FALSE; break; } |
| 807 |
} |
| 808 |
if(do_add) { |
| 809 |
if(be_verbose) fprintf(stdout, "# Identical author annotation from all alignments transferred to merged alignment.\n"); |
| 810 |
if((status = esl_strdup(msaA[0]->au, -1, &(mmsa->au))) != eslOK) goto ERROR; |
| 811 |
} |
| 812 |
else if(be_verbose) fprintf(stdout, "# Author annotation is not identical in all alignments; not included in merged alignment.\n"); |
| 813 |
} |
| 814 |
else if(be_verbose) fprintf(stdout, "# Author annotation absent from (at least) first alignment; not included in merged alignment.\n"); |
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
if(msaA[0]->ngf > 0) { |
| 819 |
for(j = 0; j < msaA[0]->ngf; j++) { |
| 820 |
do_add = TRUE; |
| 821 |
|
| 822 |
if(msaA[0]->gf_tag[j] == NULL) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "unexpectedly, GF tag %d of msaA[0] is NULL, but msaA[0]->ngf is %d.\n", j, msaA[0]->ngf); |
| 823 |
if(msaA[0]->gf[j] == NULL) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "unexpectedly, GF annotation %d of msaA[0] is NULL, but msaA[0]->ngf is %d.\n", j, msaA[0]->ngf); |
| 824 |
for(ai = 1; ai < nmsa; ai++) { |
| 825 |
found_tag = FALSE; |
| 826 |
for(j2 = 0; j2 < msaA[ai]->ngf; j2++) { |
| 827 |
if(esl_strcmp(msaA[0]->gf_tag[j], msaA[ai]->gf_tag[j2]) == 0) { |
| 828 |
found_tag = TRUE; |
| 829 |
if(esl_strcmp(msaA[0]->gf[j], msaA[ai]->gf_tag[j2]) != 0) { |
| 830 |
do_add = FALSE; |
| 831 |
} |
| 832 |
break; |
| 833 |
} |
| 834 |
} |
| 835 |
if(found_tag && do_add) { |
| 836 |
if(be_verbose) fprintf(stdout, "# Identical GF tag %s annotation from all alignments transferred to merged alignment.\n", msaA[0]->gf_tag[j]); |
| 837 |
if((status = esl_msa_AddGF(mmsa, msaA[0]->gf_tag[j], -1, msaA[0]->gf[j], -1)) != eslOK) goto ERROR; |
| 838 |
} |
| 839 |
else { |
| 840 |
if(be_verbose) fprintf(stdout, "# GF tag %s annotation from first alignment absent from >= 1 other alignments; not included in merged alignment.\n", msaA[0]->gf_tag[j]); |
| 841 |
} |
| 842 |
} |
| 843 |
} |
| 844 |
} |
| 845 |
else if(be_verbose) fprintf(stdout, "# Unparsed GF annotation absent from (at least) first alignment; not included in merged alignment.\n"); |
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
if(msaA[0]->ncomment > 0) { |
| 850 |
do_add = TRUE; |
| 851 |
|
| 852 |
for(ai = 1; ai < nmsa; ai++) { |
| 853 |
if(msaA[ai]->ncomment != msaA[0]->ncomment) { |
| 854 |
do_add = FALSE; |
| 855 |
break; |
| 856 |
} |
| 857 |
} |
| 858 |
if(do_add) { |
| 859 |
|
| 860 |
for(j = 0; j < msaA[0]->ncomment; j++) { |
| 861 |
|
| 862 |
if(msaA[0]->comment[j] == NULL) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "unexpectedly, comment %d of msaA[0] is NULL, but msaA[0]->ncomment is %d.\n", j, msaA[0]->ncomment); |
| 863 |
for(ai = 1; ai < nmsa; ai++) { |
| 864 |
if(esl_strcmp(msaA[0]->comment[j], msaA[ai]->comment[j]) != 0) { |
| 865 |
do_add = FALSE; |
| 866 |
break; |
| 867 |
} |
| 868 |
} |
| 869 |
} |
| 870 |
} |
| 871 |
if(do_add) { |
| 872 |
for(j = 0; j < msaA[0]->ncomment; j++) { |
| 873 |
if((status = esl_msa_AddComment(mmsa, msaA[0]->comment[j], -1))!= eslOK) goto ERROR; |
| 874 |
} |
| 875 |
if(be_verbose) fprintf(stdout, "# All alignments have identical comments in the same order. These were transferred to merged alignment.\n"); |
| 876 |
} |
| 877 |
else { |
| 878 |
if(be_verbose) fprintf(stdout, "# Comments are not identical in all alignments; not included in merged alignment.\n"); |
| 879 |
} |
| 880 |
} |
| 881 |
else if(be_verbose) fprintf(stdout, "# No comments in (at least) first alignment; not included in merged alignment.\n"); |
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
if(msaA[0]->ngc > 0) { |
| 888 |
for(j = 0; j < msaA[0]->ngc; j++) { |
| 889 |
do_add = TRUE; |
| 890 |
|
| 891 |
if(msaA[0]->gc_tag[j] == NULL) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "unexpectedly, GC tag %d of msaA[0] is NULL, but msaA[0]->ngf is %d.\n", j, msaA[0]->ngc); |
| 892 |
if(msaA[0]->gc[j] == NULL) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "unexpectedly, GC annotation %d of msaA[0] is NULL, but msaA[0]->ngf is %d.\n", j, msaA[0]->ngc); |
| 893 |
|
| 894 |
|
| 895 |
if(validate_no_nongaps_in_rf_gaps(msaA[0]->abc, msaA[0]->rf, msaA[0]->gc[j], msaA[0]->alen)) { |
| 896 |
|
| 897 |
if((status = esl_strdup(msaA[0]->gc[j], msaA[0]->alen, &(dealigned))) != eslOK) goto ERROR; |
| 898 |
if((status = esl_strdealign(dealigned, msaA[0]->rf, "-_.~", NULL)) != eslOK) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "unexpected error dealigning GC tag %s of msaA[0]", msaA[0]->gc_tag[j]); |
| 899 |
|
| 900 |
for(ai = 1; ai < nmsa; ai++) { |
| 901 |
found_tag = FALSE; |
| 902 |
for(j2 = 0; j2 < msaA[ai]->ngc; j2++) { |
| 903 |
if(esl_strcmp(msaA[0]->gc_tag[j], msaA[ai]->gc_tag[j2]) == 0) { |
| 904 |
found_tag = TRUE; |
| 905 |
|
| 906 |
if(validate_no_nongaps_in_rf_gaps(msaA[ai]->abc, msaA[ai]->rf, msaA[ai]->gc[j2], msaA[ai]->alen)) { |
| 907 |
|
| 908 |
if((status = esl_strdup(msaA[ai]->gc[j2], msaA[ai]->alen, &(dealigned2))) != eslOK) goto ERROR; |
| 909 |
if((status = esl_strdealign(dealigned2, msaA[ai]->rf, "-_.~", NULL)) != eslOK) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "unexpected error dealigning GC tag %s of msaA[%d]", msaA[ai]->gc_tag[j2], ai); |
| 910 |
|
| 911 |
if(esl_strcmp(dealigned, dealigned2) != 0) { do_add = FALSE; } |
| 912 |
free(dealigned2); |
| 913 |
dealigned2 = NULL; |
| 914 |
break; |
| 915 |
} |
| 916 |
else { |
| 917 |
do_add = FALSE; |
| 918 |
} |
| 919 |
} |
| 920 |
} |
| 921 |
} |
| 922 |
if(dealigned != NULL) { free(dealigned); dealigned = NULL; } |
| 923 |
if(found_tag && do_add) { |
| 924 |
|
| 925 |
if((status = inflate_string_with_gaps_and_missing(msaA[0]->gc[j], msaA[0]->alen, alen_merged, neitherA, '.', NULL, '~', &(gapped_out))) != eslOK) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "Error adding gaps to create GC tag %s annotation for merged alignment.", msaA[0]->gc_tag[j]); |
| 926 |
if((status = esl_msa_AppendGC(mmsa, msaA[0]->gc_tag[j], gapped_out)) != eslOK) goto ERROR; |
| 927 |
free(gapped_out); |
| 928 |
gapped_out = NULL; |
| 929 |
if(be_verbose) fprintf(stdout, "# Identical GC tag %s annotation from all alignments transferred to merged alignment.\n", msaA[0]->gc_tag[j]); |
| 930 |
} |
| 931 |
else { |
| 932 |
if(be_verbose) fprintf(stdout, "# GC tag %s annotation from first alignment absent from or different in >= 1 other alignments; not included in merged alignment.\n", msaA[0]->gc_tag[j]); |
| 933 |
} |
| 934 |
} |
| 935 |
} |
| 936 |
} |
| 937 |
else if(be_verbose) fprintf(stdout, "# Unparsed GC annotation absent from (at least) first alignment; not included in merged alignment.\n"); |
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
if(msaA[0]->ss_cons != NULL) { |
| 943 |
do_add = TRUE; |
| 944 |
|
| 945 |
if(validate_no_nongaps_in_rf_gaps(msaA[0]->abc, msaA[0]->rf, msaA[0]->ss_cons, msaA[0]->alen)) { |
| 946 |
|
| 947 |
if((status = esl_strdup(msaA[0]->ss_cons, msaA[0]->alen, &(dealigned))) != eslOK) goto ERROR; |
| 948 |
if((status = esl_strdealign(dealigned, msaA[0]->rf, "-_.~", NULL)) != eslOK) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "unexpected error dealigning ss_cons of msaA[0]"); |
| 949 |
for(ai = 1; ai < nmsa; ai++) { |
| 950 |
if(msaA[ai]->ss_cons == NULL) { |
| 951 |
do_add = FALSE; |
| 952 |
break; |
| 953 |
} |
| 954 |
|
| 955 |
if(validate_no_nongaps_in_rf_gaps(msaA[ai]->abc, msaA[ai]->rf, msaA[ai]->ss_cons, msaA[ai]->alen)) { |
| 956 |
|
| 957 |
if((status = esl_strdup(msaA[ai]->ss_cons, msaA[ai]->alen, &(dealigned2))) != eslOK) goto ERROR; |
| 958 |
if((status = esl_strdealign(dealigned2, msaA[ai]->rf, "-_.~", NULL)) != eslOK) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "unexpected error dealigning ss_cons of msaA[%d]", ai); |
| 959 |
|
| 960 |
if(esl_strcmp(dealigned, dealigned2) != 0) { do_add = FALSE; } |
| 961 |
free(dealigned2); |
| 962 |
dealigned2 = NULL; |
| 963 |
break; |
| 964 |
} |
| 965 |
else { |
| 966 |
do_add = FALSE; |
| 967 |
} |
| 968 |
} |
| 969 |
if(dealigned != NULL) { free(dealigned); dealigned = NULL; } |
| 970 |
if(do_add) { |
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
if((status = inflate_string_with_gaps_and_missing(msaA[0]->ss_cons, msaA[0]->alen, alen_merged, ngapA, '.', nmisA, '~', &(gapped_out))) != eslOK) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "Error adding gaps to create SS_cons annotation for merged alignment."); |
| 975 |
if(mmsa->ss_cons != NULL) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "Error adding SS_cons to merged alignment, it is already non-NULL."); |
| 976 |
if((status = esl_strdup(gapped_out, alen_merged, &(mmsa->ss_cons))) != eslOK) goto ERROR; |
| 977 |
free(gapped_out); |
| 978 |
gapped_out = NULL; |
| 979 |
if(be_verbose) fprintf(stdout, "# Identical SS_cons annotation from all alignments transferred to merged alignment.\n"); |
| 980 |
} |
| 981 |
else { |
| 982 |
if(be_verbose) fprintf(stdout, "# SS_cons annotation from first alignment absent from or different in >= 1 other alignments; not included in merged alignment.\n"); |
| 983 |
} |
| 984 |
} |
| 985 |
} |
| 986 |
else if(be_verbose) fprintf(stdout, "# SS_cons annotation absent from (at least) first alignment; not included in merged alignment.\n"); |
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
if(msaA[0]->sa_cons != NULL) { |
| 992 |
do_add = TRUE; |
| 993 |
|
| 994 |
if(validate_no_nongaps_in_rf_gaps(msaA[0]->abc, msaA[0]->rf, msaA[0]->sa_cons, msaA[0]->alen)) { |
| 995 |
|
| 996 |
if((status = esl_strdup(msaA[0]->sa_cons, msaA[0]->alen, &(dealigned))) != eslOK) goto ERROR; |
| 997 |
if((status = esl_strdealign(dealigned, msaA[0]->rf, "-_.~", NULL)) != eslOK) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "unexpected error dealigning sa_cons of msaA[0]"); |
| 998 |
for(ai = 1; ai < nmsa; ai++) { |
| 999 |
if(msaA[ai]->sa_cons == NULL) { |
| 1000 |
do_add = FALSE; |
| 1001 |
break; |
| 1002 |
} |
| 1003 |
|
| 1004 |
if(validate_no_nongaps_in_rf_gaps(msaA[ai]->abc, msaA[ai]->rf, msaA[ai]->sa_cons, msaA[ai]->alen)) { |
| 1005 |
|
| 1006 |
if((status = esl_strdup(msaA[ai]->sa_cons, msaA[ai]->alen, &(dealigned2))) != eslOK) goto ERROR; |
| 1007 |
if((status = esl_strdealign(dealigned2, msaA[ai]->rf, "-_.~", NULL)) != eslOK) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "unexpected error dealigning sa_cons of msaA[%d]", ai); |
| 1008 |
|
| 1009 |
if(esl_strcmp(dealigned, dealigned2) != 0) { do_add = FALSE; } |
| 1010 |
free(dealigned2); |
| 1011 |
dealigned2 = NULL; |
| 1012 |
break; |
| 1013 |
} |
| 1014 |
else { |
| 1015 |
do_add = FALSE; |
| 1016 |
} |
| 1017 |
} |
| 1018 |
if(dealigned != NULL) { free(dealigned); dealigned = NULL; } |
| 1019 |
if(do_add) { |
| 1020 |
|
| 1021 |
if((status = inflate_string_with_gaps_and_missing(msaA[0]->sa_cons, msaA[0]->alen, alen_merged, neitherA, '.', NULL, '~', &(gapped_out))) != eslOK) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "Error adding gaps to create SA_cons annotation for merged alignment."); |
| 1022 |
if(mmsa->sa_cons != NULL) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "Error adding SA_cons to merged alignment, it is already non-NULL."); |
| 1023 |
if((status = esl_strdup(gapped_out, alen_merged, &(mmsa->sa_cons))) != eslOK) goto ERROR; |
| 1024 |
free(gapped_out); |
| 1025 |
gapped_out = NULL; |
| 1026 |
if(be_verbose) fprintf(stdout, "# Identical SA_cons annotation from all alignments transferred to merged alignment.\n"); |
| 1027 |
} |
| 1028 |
else { |
| 1029 |
if(be_verbose) fprintf(stdout, "# SA_cons annotation from first alignment absent from or different in >= 1 other alignments; not included in merged alignment.\n"); |
| 1030 |
} |
| 1031 |
} |
| 1032 |
} |
| 1033 |
else if(be_verbose) fprintf(stdout, "# SA_cons annotation absent from (at least) first alignment; not included in merged alignment.\n"); |
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
if(msaA[0]->pp_cons != NULL) { |
| 1039 |
do_add = TRUE; |
| 1040 |
|
| 1041 |
if(validate_no_nongaps_in_rf_gaps(msaA[0]->abc, msaA[0]->rf, msaA[0]->pp_cons, msaA[0]->alen)) { |
| 1042 |
|
| 1043 |
if((status = esl_strdup(msaA[0]->pp_cons, msaA[0]->alen, &(dealigned))) != eslOK) goto ERROR; |
| 1044 |
if((status = esl_strdealign(dealigned, msaA[0]->rf, "-_.~", NULL)) != eslOK) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "unexpected error dealigning pp_cons of msaA[0]"); |
| 1045 |
for(ai = 1; ai < nmsa; ai++) { |
| 1046 |
if(msaA[ai]->pp_cons == NULL) { |
| 1047 |
do_add = FALSE; |
| 1048 |
break; |
| 1049 |
} |
| 1050 |
|
| 1051 |
if(validate_no_nongaps_in_rf_gaps(msaA[ai]->abc, msaA[ai]->rf, msaA[ai]->pp_cons, msaA[ai]->alen)) { |
| 1052 |
|
| 1053 |
if((status = esl_strdup(msaA[ai]->pp_cons, msaA[ai]->alen, &(dealigned2))) != eslOK) goto ERROR; |
| 1054 |
if((status = esl_strdealign(dealigned2, msaA[ai]->rf, "-_.~", NULL)) != eslOK) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "unexpected error dealigning pp_cons of msaA[%d]", ai); |
| 1055 |
|
| 1056 |
if(esl_strcmp(dealigned, dealigned2) != 0) { do_add = FALSE; } |
| 1057 |
free(dealigned2); |
| 1058 |
dealigned2 = NULL; |
| 1059 |
break; |
| 1060 |
} |
| 1061 |
else { |
| 1062 |
do_add = FALSE; |
| 1063 |
} |
| 1064 |
} |
| 1065 |
if(dealigned != NULL) { free(dealigned); dealigned = NULL; } |
| 1066 |
if(do_add) { |
| 1067 |
|
| 1068 |
if((status = inflate_string_with_gaps_and_missing(msaA[0]->pp_cons, msaA[0]->alen, alen_merged, neitherA, '.', NULL, '~', &(gapped_out))) != eslOK) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "Error adding gaps to create PP_cons annotation for merged alignment."); |
| 1069 |
if(mmsa->pp_cons != NULL) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "Error adding PP_cons to merged alignment, it is already non-NULL."); |
| 1070 |
if((status = esl_strdup(gapped_out, alen_merged, &(mmsa->pp_cons))) != eslOK) goto ERROR; |
| 1071 |
free(gapped_out); |
| 1072 |
gapped_out = NULL; |
| 1073 |
if(be_verbose) fprintf(stdout, "# Identical PP_cons annotation from all alignments transferred to merged alignment.\n"); |
| 1074 |
} |
| 1075 |
else { |
| 1076 |
if(be_verbose) fprintf(stdout, "# PP_cons annotation from first alignment absent from or different in >= 1 other alignments; not included in merged alignment.\n"); |
| 1077 |
} |
| 1078 |
} |
| 1079 |
} |
| 1080 |
else if(be_verbose) fprintf(stdout, "# PP_cons annotation absent from (at least) first alignment; not included in merged alignment.\n"); |
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
if(msaA[0]->rf == NULL) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "All alignments must have #= GC RF annotation."); |
| 1086 |
|
| 1087 |
if((status = esl_strdup(msaA[0]->rf, msaA[0]->alen, &(dealigned))) != eslOK) goto ERROR; |
| 1088 |
if((status = esl_strdealign(dealigned, dealigned, "-_.~", NULL)) != eslOK) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "unexpected error dealigning RF of msaA[0]"); |
| 1089 |
for(ai = 1; ai < nmsa; ai++) { |
| 1090 |
if(msaA[ai]->rf == NULL) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "All alignments must have #= GC RF annotation."); |
| 1091 |
|
| 1092 |
if((status = esl_strdup(msaA[ai]->rf, msaA[ai]->alen, &(dealigned2))) != eslOK) goto ERROR; |
| 1093 |
if((status = esl_strdealign(dealigned2, dealigned2, "-_.~", NULL)) != eslOK) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "unexpected error dealigning RF of msaA[%d]", ai); |
| 1094 |
|
| 1095 |
if(esl_strcmp(dealigned, dealigned2) != 0) { |
| 1096 |
printf("%s\n%s\n", dealigned, dealigned2); |
| 1097 |
ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "All alignments must have identical #=GC RF annotation, once gaps (\".\",\"-\",\"_\") are removed.\nAlignment %d de-gapped RF annotation differs from that of alignment 1.\n%s\n%s", ai+1, dealigned, dealigned2); |
| 1098 |
} |
| 1099 |
if(dealigned2 != NULL) { free(dealigned2); dealigned2 = NULL; } |
| 1100 |
} |
| 1101 |
if(dealigned != NULL) { free(dealigned); dealigned = NULL; } |
| 1102 |
|
| 1103 |
if((status = inflate_string_with_gaps_and_missing(msaA[0]->rf, msaA[0]->alen, alen_merged, ngapA, '.', nmisA, '~', &(gapped_out))) != eslOK) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "Error adding gaps to create RF annotation for merged alignment."); |
| 1104 |
if(mmsa->rf != NULL) ESL_XFAIL(eslEINCONCEIVABLE, errbuf, "Error adding RF to merged alignment, it is already non-NULL."); |
| 1105 |
if((status = esl_strdup(gapped_out, alen_merged, &(mmsa->rf))) != eslOK) goto ERROR; |
| 1106 |
free(gapped_out); |
| 1107 |
gapped_out = NULL; |
| 1108 |
if(be_verbose) fprintf(stdout, "# Identical RF annotation from all alignments transferred to merged alignment.\n"); |
| 1109 |
|
| 1110 |
if(dealigned != NULL) free(dealigned); |
| 1111 |
if(dealigned2 != NULL) free(dealigned2); |
| 1112 |
if(gapped_out != NULL) free(gapped_out); |
| 1113 |
if(ngapA != NULL) free(ngapA); |
| 1114 |
if(nmisA != NULL) free(nmisA); |
| 1115 |
if(neitherA != NULL) free(neitherA); |
| 1116 |
return eslOK; |
| 1117 |
|
| 1118 |
ERROR: |
| 1119 |
if(dealigned != NULL) free(dealigned); |
| 1120 |
if(dealigned2 != NULL) free(dealigned2); |
| 1121 |
if(gapped_out != NULL) free(gapped_out); |
| 1122 |
if(ngapA != NULL) free(ngapA); |
| 1123 |
if(nmisA != NULL) free(nmisA); |
| 1124 |
if(neitherA != NULL) free(neitherA); |
| 1125 |
return status; |
| 1126 |
} |
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
int |
| 1156 |
add_msa(ESL_MSA *mmsa, char *errbuf, ESL_MSA *msa_to_add, int *maxgap, int *maxmis, int clen, int alen_merged) |
| 1157 |
{ |
| 1158 |
int status; |
| 1159 |
int i; |
| 1160 |
int j; |
| 1161 |
int mi; |
| 1162 |
void *tmp; |
| 1163 |
char *tmpstr; |
| 1164 |
int nseq_existing; |
| 1165 |
int *ngapA = NULL; |
| 1166 |
int *nmisA = NULL; |
| 1167 |
int *neitherA = NULL; |
| 1168 |
|
| 1169 |
nseq_existing = mmsa->nseq; |
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
if((status = determine_gap_columns_to_add(msa_to_add, maxgap, maxmis, clen, &(ngapA), &(nmisA), &(neitherA), errbuf)) != eslOK) |
| 1174 |
return status; |
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
for(i = 0, mi = nseq_existing; i < msa_to_add->nseq; i++, mi++) { |
| 1179 |
esl_strdup(msa_to_add->sqname[i], -1, &(mmsa->sqname[mi])); |
| 1180 |
|
| 1181 |
status = inflate_seq_with_gaps(msa_to_add->abc, msa_to_add->aseq[i], msa_to_add->alen, alen_merged, neitherA, '.', &(mmsa->aseq[mi])); |
| 1182 |
if (status == eslEMEM) ESL_XFAIL(status, errbuf, "Out of memory adding sequence %s", mmsa->sqname[mi]); |
| 1183 |
else if(status != eslOK) ESL_XFAIL(status, errbuf, "Found internal missing data symbols in seq: %s", mmsa->sqname[mi]); |
| 1184 |
free(msa_to_add->aseq[i]); |
| 1185 |
msa_to_add->aseq[i] = NULL; |
| 1186 |
} |
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
if(msa_to_add->sqacc != NULL) { |
| 1191 |
if(mmsa->sqacc == NULL) { |
| 1192 |
ESL_ALLOC(mmsa->sqacc, sizeof(char *) * (nseq_existing + msa_to_add->nseq)); |
| 1193 |
for(mi = 0; mi < nseq_existing; mi++) { mmsa->sqacc[mi] = NULL; } |
| 1194 |
} |
| 1195 |
else { |
| 1196 |
ESL_RALLOC(mmsa->sqacc, tmp, sizeof(char *) * (nseq_existing + msa_to_add->nseq)); |
| 1197 |
} |
| 1198 |
for(i = 0, mi = nseq_existing; i < msa_to_add->nseq; i++, mi++) { |
| 1199 |
if(msa_to_add->sqacc[i] != NULL) { |
| 1200 |
if((status = esl_strdup(msa_to_add->sqacc[i], -1, &(mmsa->sqacc[mi]))) != eslOK) |
| 1201 |
ESL_XFAIL(status, errbuf, "Memory allocation error when copying sequence accession number %d.\n", i+1); |
| 1202 |
free(msa_to_add->sqacc[i]); |
| 1203 |
msa_to_add->sqacc[i] = NULL; |
| 1204 |
} |
| 1205 |
else { |
| 1206 |
mmsa->sqacc[mi] = NULL; |
| 1207 |
} |
| 1208 |
} |
| 1209 |
} |
| 1210 |
else if(mmsa->sqacc != NULL) { |
| 1211 |
|
| 1212 |
ESL_RALLOC(mmsa->sqacc, tmp, sizeof(char *) * (nseq_existing + msa_to_add->nseq)); |
| 1213 |
for(mi = nseq_existing; mi < nseq_existing + msa_to_add->nseq; mi++) { |
| 1214 |
mmsa->sqacc[mi] = NULL; |
| 1215 |
} |
| 1216 |
} |
| 1217 |
|
| 1218 |
|
| 1219 |
if(msa_to_add->sqdesc != NULL) { |
| 1220 |
if(mmsa->sqdesc == NULL) { |
| 1221 |
ESL_ALLOC(mmsa->sqdesc, sizeof(char *) * (nseq_existing + msa_to_add->nseq)); |
| 1222 |
for(mi = 0; mi < nseq_existing; mi++) { mmsa->sqdesc[mi] = NULL; } |
| 1223 |
} |
| 1224 |
else { |
| 1225 |
ESL_RALLOC(mmsa->sqdesc, tmp, sizeof(char *) * (nseq_existing + msa_to_add->nseq)); |
| 1226 |
} |
| 1227 |
for(i = 0, mi = nseq_existing; i < msa_to_add->nseq; i++, mi++) { |
| 1228 |
if(msa_to_add->sqdesc[i] != NULL) { |
| 1229 |
if((status = esl_strdup(msa_to_add->sqdesc[i], -1, &(mmsa->sqdesc[mi]))) != eslOK) |
| 1230 |
ESL_XFAIL(status, errbuf, "Memory allocation error when copying sequence description number %d.\n", i+1); |
| 1231 |
free(msa_to_add->sqdesc[i]); |
| 1232 |
msa_to_add->sqdesc[i] = NULL; |
| 1233 |
} |
| 1234 |
else { |
| 1235 |
mmsa->sqdesc[mi] = NULL; |
| 1236 |
} |
| 1237 |
} |
| 1238 |
} |
| 1239 |
else if(mmsa->sqdesc != NULL) { |
| 1240 |
|
| 1241 |
ESL_RALLOC(mmsa->sqdesc, tmp, sizeof(char *) * (nseq_existing + msa_to_add->nseq)); |
| 1242 |
for(mi = nseq_existing; mi < nseq_existing + msa_to_add->nseq; mi++) { |
| 1243 |
mmsa->sqdesc[mi] = NULL; |
| 1244 |
} |
| 1245 |
} |
| 1246 |
|
| 1247 |
|
| 1248 |
if(msa_to_add->pp != NULL) { |
| 1249 |
if(mmsa->pp == NULL) { |
| 1250 |
ESL_ALLOC(mmsa->pp, sizeof(char *) * (nseq_existing + msa_to_add->nseq)); |
| 1251 |
for(mi = 0; mi < nseq_existing; mi++) { mmsa->pp[mi] = NULL; } |
| 1252 |
} |
| 1253 |
else { |
| 1254 |
ESL_RALLOC(mmsa->pp, tmp, sizeof(char *) * (nseq_existing + msa_to_add->nseq)); |
| 1255 |
} |
| 1256 |
for(i = 0, mi = nseq_existing; i < msa_to_add->nseq; i++, mi++) { |
| 1257 |
if(msa_to_add->pp[i] != NULL) { |
| 1258 |
if((status = inflate_string_with_gaps_and_missing(msa_to_add->pp[i], msa_to_add->alen, alen_merged, neitherA, '.', NULL, '~', &(mmsa->pp[mi]))) != eslOK) |
| 1259 |
ESL_XFAIL(status, errbuf, "Memory allocation error when copying sequence number %d posterior probabilities.\n", i+1); |
| 1260 |
free(msa_to_add->pp[i]); |
| 1261 |
msa_to_add->pp[i] = NULL; |
| 1262 |
} |
| 1263 |
else { |
| 1264 |
mmsa->pp[mi] = NULL; |
| 1265 |
} |
| 1266 |
} |
| 1267 |
} |
| 1268 |
else if(mmsa->pp != NULL) { |
| 1269 |
|
| 1270 |
ESL_RALLOC(mmsa->pp, tmp, sizeof(char *) * (nseq_existing + msa_to_add->nseq)); |
| 1271 |
for(mi = nseq_existing; mi < nseq_existing + msa_to_add->nseq; mi++) { |
| 1272 |
mmsa->pp[mi] = NULL; |
| 1273 |
} |
| 1274 |
} |
| 1275 |
|
| 1276 |
|
| 1277 |
if(msa_to_add->ss != NULL) { |
| 1278 |
if(mmsa->ss == NULL) { |
| 1279 |
ESL_ALLOC(mmsa->ss, sizeof(char *) * (nseq_existing + msa_to_add->nseq)); |
| 1280 |
for(mi = 0; mi < nseq_existing; mi++) { mmsa->ss[mi] = NULL; } |
| 1281 |
} |
| 1282 |
else { |
| 1283 |
ESL_RALLOC(mmsa->ss, tmp, sizeof(char *) * (nseq_existing + msa_to_add->nseq)); |
| 1284 |
} |
| 1285 |
for(i = 0, mi = nseq_existing; i < msa_to_add->nseq; i++, mi++) { |
| 1286 |
if(msa_to_add->ss[i] != NULL) { |
| 1287 |
if((status = inflate_string_with_gaps_and_missing(msa_to_add->ss[i], msa_to_add->alen, alen_merged, neitherA, '.', NULL, '~', &(mmsa->ss[mi]))) != eslOK) |
| 1288 |
ESL_XFAIL(status, errbuf, "Memory allocation error when copying sequence number %d secondary structure.\n", i+1); |
| 1289 |
free(msa_to_add->ss[i]); |
| 1290 |
msa_to_add->ss[i] = NULL; |
| 1291 |
} |
| 1292 |
else { |
| 1293 |
mmsa->ss[mi] = NULL; |
| 1294 |
} |
| 1295 |
} |
| 1296 |
} |
| 1297 |
else if(mmsa->ss != NULL) { |
| 1298 |
|
| 1299 |
ESL_RALLOC(mmsa->ss, tmp, sizeof(char *) * (nseq_existing + msa_to_add->nseq)); |
| 1300 |
for(mi = nseq_existing; mi < nseq_existing + msa_to_add->nseq; mi++) { |
| 1301 |
mmsa->ss[mi] = NULL; |
| 1302 |
} |
| 1303 |
} |
| 1304 |
|
| 1305 |
|
| 1306 |
if(msa_to_add->sa != NULL) { |
| 1307 |
if(mmsa->sa == NULL) { |
| 1308 |
ESL_ALLOC(mmsa->sa, sizeof(char *) * (nseq_existing + msa_to_add->nseq)); |
| 1309 |
for(mi = 0; mi < nseq_existing; mi++) { mmsa->sa[mi] = NULL; } |
| 1310 |
} |
| 1311 |
else { |
| 1312 |
ESL_RALLOC(mmsa->sa, tmp, sizeof(char *) * (nseq_existing + msa_to_add->nseq)); |
| 1313 |
} |
| 1314 |
for(i = 0, mi = nseq_existing; i < msa_to_add->nseq; i++, mi++) { |
| 1315 |
if(msa_to_add->sa[i] != NULL) { |
| 1316 |
if((status = inflate_string_with_gaps_and_missing(msa_to_add->sa[i], msa_to_add->alen, alen_merged, neitherA, '.', NULL, '~', &(mmsa->sa[mi]))) != eslOK) |
| 1317 |
ESL_XFAIL(status, errbuf, "Memory allocation error when copying sequence number %d surface accessibility.\n", i+1); |
| 1318 |
free(msa_to_add->sa[i]); |
| 1319 |
msa_to_add->sa[i] = NULL; |
| 1320 |
} |
| 1321 |
else { |
| 1322 |
mmsa->sa[mi] = NULL; |
| 1323 |
} |
| 1324 |
} |
| 1325 |
} |
| 1326 |
else if(mmsa->sa != NULL) { |
| 1327 |
|
| 1328 |
ESL_RALLOC(mmsa->sa, tmp, sizeof(char *) * (nseq_existing + msa_to_add->nseq)); |
| 1329 |
for(mi = nseq_existing; mi < nseq_existing + msa_to_add->nseq; mi++) { |
| 1330 |
mmsa->sa[mi] = NULL; |
| 1331 |
} |
| 1332 |
} |
| 1333 |
|
| 1334 |
|
| 1335 |
if(msa_to_add->ngs > 0) { |
| 1336 |
for(j = 0; j < msa_to_add->ngs; j++) { |
| 1337 |
for(i = 0, mi = nseq_existing; i < msa_to_add->nseq; i++, mi++) { |
| 1338 |
if(msa_to_add->gs[j][i] != NULL) |
| 1339 |
if((status =esl_msa_AddGS(mmsa, msa_to_add->gs_tag[j], -1, mi, msa_to_add->gs[j][i], -1)) != eslOK) |
| 1340 |
ESL_XFAIL(status, errbuf, "Memory allocation error when copying sequence number %d GS annotation.\n", i+1); |
| 1341 |
} |
| 1342 |
free(msa_to_add->gs[j][i]); |
| 1343 |
msa_to_add->gs[j][i] = NULL; |
| 1344 |
} |
| 1345 |
} |
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
if(msa_to_add->gr != NULL) { |
| 1350 |
for(j = 0; j < msa_to_add->ngr; j++) { |
| 1351 |
for(i = 0, mi = nseq_existing; i < msa_to_add->nseq; i++, mi++) { |
| 1352 |
if(msa_to_add->gr[j][i] != NULL) { |
| 1353 |
if((status = inflate_string_with_gaps_and_missing(msa_to_add->gr[j][i], msa_to_add->alen, alen_merged, neitherA, '.', NULL, '~', &(tmpstr))) != eslOK) |
| 1354 |
ESL_XFAIL(status, errbuf, "Memory allocation error when copying sequence number %d GR annotation.\n", i+1); |
| 1355 |
if((status = esl_msa_AppendGR(mmsa, msa_to_add->gr_tag[j], mi, tmpstr)) != eslOK) |
| 1356 |
ESL_XFAIL(status, errbuf, "Memory allocation error when copying sequence number %d GR annotation.\n", i+1); |
| 1357 |
free(tmpstr); |
| 1358 |
free(msa_to_add->gr[j][i]); |
| 1359 |
msa_to_add->gr[j][i] = NULL; |
| 1360 |
} |
| 1361 |
} |
| 1362 |
} |
| 1363 |
} |
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
mmsa->nseq += msa_to_add->nseq; |
| 1370 |
|
| 1371 |
if(ngapA != NULL) free(ngapA); |
| 1372 |
if(nmisA != NULL) free(nmisA); |
| 1373 |
if(neitherA != NULL) free(neitherA); |
| 1374 |
return eslOK; |
| 1375 |
|
| 1376 |
ERROR: |
| 1377 |
if(ngapA != NULL) free(ngapA); |
| 1378 |
if(nmisA != NULL) free(nmisA); |
| 1379 |
if(neitherA != NULL) free(neitherA); |
| 1380 |
return status; |
| 1381 |
} |
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
int |
| 1405 |
inflate_string_with_gaps_and_missing(char *src_str, int64_t src_len, int64_t dst_len, int *ngapA, char gapchar, int *nmisA, char mischar, char **ret_dst_str) |
| 1406 |
{ |
| 1407 |
int status; |
| 1408 |
int src_apos = 0; |
| 1409 |
int dst_apos = 0; |
| 1410 |
int i; |
| 1411 |
char *dst_str; |
| 1412 |
|
| 1413 |
ESL_ALLOC(dst_str, sizeof(char) * (dst_len+1)); |
| 1414 |
dst_str[dst_len] = '\0'; |
| 1415 |
|
| 1416 |
|
| 1417 |
if(nmisA) for(i = 0; i < nmisA[0]; i++) dst_str[dst_apos++] = mischar; |
| 1418 |
if(ngapA) for(i = 0; i < ngapA[0]; i++) dst_str[dst_apos++] = gapchar; |
| 1419 |
|
| 1420 |
|
| 1421 |
for(src_apos = 0; src_apos < src_len; src_apos++) { |
| 1422 |
dst_str[dst_apos++] = src_str[src_apos]; |
| 1423 |
if(nmisA) for(i = 0; i < nmisA[(src_apos+1)]; i++) dst_str[dst_apos++] = mischar; |
| 1424 |
if(ngapA) for(i = 0; i < ngapA[(src_apos+1)]; i++) dst_str[dst_apos++] = gapchar; |
| 1425 |
} |
| 1426 |
|
| 1427 |
*ret_dst_str = dst_str; |
| 1428 |
return eslOK; |
| 1429 |
|
| 1430 |
ERROR: |
| 1431 |
return eslEMEM; |
| 1432 |
} |
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
int |
| 1468 |
inflate_seq_with_gaps(const ESL_ALPHABET *abc, char *src_str, int64_t src_len, int64_t dst_len, int *ngapA, char gapchar, char **ret_dst_str) |
| 1469 |
{ |
| 1470 |
int status; |
| 1471 |
int src_apos = 0; |
| 1472 |
int dst_apos = 0; |
| 1473 |
int src_flpos = 0; |
| 1474 |
int src_frpos = 0; |
| 1475 |
int i; |
| 1476 |
char *dst_str; |
| 1477 |
char char2add; |
| 1478 |
int i_am_fragment = FALSE; |
| 1479 |
|
| 1480 |
ESL_ALLOC(dst_str, sizeof(char) * (dst_len+1)); |
| 1481 |
dst_str[dst_len] = '\0'; |
| 1482 |
|
| 1483 |
|
| 1484 |
src_flpos = 0; |
| 1485 |
while(src_flpos < src_len && esl_abc_CIsMissing(abc, src_str[src_flpos])) { src_flpos++; } |
| 1486 |
src_flpos--; |
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
src_frpos = src_len-1; |
| 1492 |
while(src_frpos > -1 && esl_abc_CIsMissing(abc, src_str[src_frpos])) { src_frpos--; } |
| 1493 |
src_frpos++; |
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
i_am_fragment = (src_flpos != -1 || src_frpos != src_len) ? TRUE : FALSE; |
| 1498 |
|
| 1499 |
|
| 1500 |
for(src_apos = src_flpos+1; src_apos <= src_frpos-1; src_apos++) { |
| 1501 |
if(esl_abc_CIsMissing(abc, src_str[src_apos])) return eslEINVAL; |
| 1502 |
} |
| 1503 |
|
| 1504 |
|
| 1505 |
src_apos = 0; |
| 1506 |
if(i_am_fragment) { |
| 1507 |
char2add = ((src_flpos >= src_apos) || (src_frpos <= src_apos)) ? esl_abc_CGetMissing(abc) : gapchar; |
| 1508 |
} |
| 1509 |
else { |
| 1510 |
char2add = gapchar; |
| 1511 |
} |
| 1512 |
if(ngapA) for(i = 0; i < ngapA[0]; i++) dst_str[dst_apos++] = char2add; |
| 1513 |
|
| 1514 |
|
| 1515 |
for(src_apos = 0; src_apos < src_len; src_apos++) { |
| 1516 |
dst_str[dst_apos++] = src_str[src_apos]; |
| 1517 |
if(i_am_fragment) { |
| 1518 |
char2add = ((src_flpos >= src_apos) || (src_frpos <= src_apos)) ? esl_abc_CGetMissing(abc) : gapchar; |
| 1519 |
} |
| 1520 |
else { |
| 1521 |
char2add = gapchar; |
| 1522 |
} |
| 1523 |
for(i = 0; i < ngapA[(src_apos+1)]; i++) dst_str[dst_apos++] = char2add; |
| 1524 |
} |
| 1525 |
|
| 1526 |
*ret_dst_str = dst_str; |
| 1527 |
return eslOK; |
| 1528 |
|
| 1529 |
ERROR: |
| 1530 |
return eslEMEM; |
| 1531 |
} |
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
int |
| 1546 |
validate_no_nongaps_in_rf_gaps(const ESL_ALPHABET *abc, char *rf_str, char *other_str, int64_t len) |
| 1547 |
{ |
| 1548 |
int64_t i; |
| 1549 |
for(i = 0; i < len; i++) { |
| 1550 |
if((! rfchar_is_nongap_nonmissing(abc, rf_str[i])) && (rfchar_is_nongap_nonmissing(abc, other_str[i]))) return FALSE; |
| 1551 |
} |
| 1552 |
return TRUE; |
| 1553 |
} |
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
int |
| 1590 |
determine_gap_columns_to_add(ESL_MSA *msa, int *maxgap, int *maxmis, int clen, int **ret_ngapA, int **ret_nmisA, int **ret_neitherA, char *errbuf) |
| 1591 |
{ |
| 1592 |
int status; |
| 1593 |
int apos; |
| 1594 |
int prv_cpos = 0; |
| 1595 |
int cpos = 0; |
| 1596 |
int ngap = 0; |
| 1597 |
int nmis = 0; |
| 1598 |
int *ngapA = NULL; |
| 1599 |
int *nmisA = NULL; |
| 1600 |
int *neitherA = NULL; |
| 1601 |
|
| 1602 |
|
| 1603 |
if(maxmis[0] != 0) ESL_FAIL(eslEINVAL, errbuf, "missing characters exist prior to first cpos, this shouldn't happen.\n"); |
| 1604 |
|
| 1605 |
ESL_ALLOC(ngapA, sizeof(int) * (msa->alen+1)); |
| 1606 |
ESL_ALLOC(nmisA, sizeof(int) * (msa->alen+1)); |
| 1607 |
ESL_ALLOC(neitherA, sizeof(int) * (msa->alen+1)); |
| 1608 |
esl_vec_ISet(ngapA, (msa->alen+1), 0); |
| 1609 |
esl_vec_ISet(nmisA, (msa->alen+1), 0); |
| 1610 |
esl_vec_ISet(neitherA, (msa->alen+1), 0); |
| 1611 |
|
| 1612 |
for(apos = 0; apos < msa->alen; apos++) { |
| 1613 |
if(esl_abc_CIsMissing(msa->abc, msa->rf[apos])) { |
| 1614 |
nmis++; |
| 1615 |
if(ngap > 0) ESL_FAIL(eslEINVAL, errbuf, "after nongap RF pos %d, %d gap columns precede a missing data column (none should)", cpos, ngap); |
| 1616 |
} |
| 1617 |
else if(esl_abc_CIsGap(msa->abc, msa->rf[apos])) { |
| 1618 |
ngap++; |
| 1619 |
} |
| 1620 |
else { |
| 1621 |
|
| 1622 |
if(ngap > maxgap[cpos]) ESL_FAIL(eslEINCONCEIVABLE, errbuf, "%d inserts before cpos %d greater than max expected (%d).\n", ngap, cpos, maxgap[cpos]); |
| 1623 |
if(nmis > maxmis[cpos]) ESL_FAIL(eslEINCONCEIVABLE, errbuf, "%d EL inserts before cpos %d greater than max expected (%d).\n", nmis, cpos, maxmis[cpos]); |
| 1624 |
|
| 1625 |
if (cpos == 0) { |
| 1626 |
|
| 1627 |
if(maxgap[cpos] > 0 && maxmis[cpos] == 0) { |
| 1628 |
ngapA[prv_cpos] = maxgap[cpos] - ngap; |
| 1629 |
} |
| 1630 |
else if(maxgap[cpos] == 0 && maxmis[cpos] > 0) { |
| 1631 |
nmisA[prv_cpos] = maxmis[cpos] - nmis; |
| 1632 |
} |
| 1633 |
else if(maxgap[cpos] > 0 && maxmis[cpos] > 0) { |
| 1634 |
|
| 1635 |
nmisA[prv_cpos] = maxmis[cpos] - nmis; |
| 1636 |
ngapA[prv_cpos+nmis] = maxgap[cpos] - ngap; |
| 1637 |
} |
| 1638 |
} |
| 1639 |
else { |
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
if(maxgap[cpos] > 0 && maxmis[cpos] == 0) { |
| 1646 |
ngapA[prv_cpos + 1 + (ngap/2)] = maxgap[cpos] - ngap; |
| 1647 |
} |
| 1648 |
else if(maxgap[cpos] == 0 && maxmis[cpos] > 0) { |
| 1649 |
nmisA[prv_cpos + 1 + (nmis/2)] = maxmis[cpos] - nmis; |
| 1650 |
} |
| 1651 |
else if(maxgap[cpos] > 0 && maxmis[cpos] > 0) { |
| 1652 |
|
| 1653 |
nmisA[prv_cpos + 1 + (nmis/2)] = maxmis[cpos] - nmis; |
| 1654 |
ngapA[prv_cpos + 1 + nmis + (ngap/2)] = maxgap[cpos] - ngap; |
| 1655 |
} |
| 1656 |
|
| 1657 |
|
| 1658 |
|
| 1659 |
} |
| 1660 |
cpos++; |
| 1661 |
prv_cpos = apos; |
| 1662 |
ngap = 0; |
| 1663 |
nmis = 0; |
| 1664 |
} |
| 1665 |
} |
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
if(cpos != clen) { |
| 1670 |
if(ngapA != NULL) free(ngapA); |
| 1671 |
if(nmisA != NULL) free(nmisA); |
| 1672 |
if(neitherA != NULL) free(neitherA); |
| 1673 |
ESL_FAIL(eslEINCONCEIVABLE, errbuf, "consensus length (%d) is not the expected length (%d).", cpos, clen); |
| 1674 |
} |
| 1675 |
|
| 1676 |
if(maxgap[cpos] > 0 && maxmis[cpos] == 0) { |
| 1677 |
ngapA[prv_cpos + 1 + ngap] = maxgap[cpos] - ngap; |
| 1678 |
} |
| 1679 |
else if(maxgap[cpos] == 0 && maxmis[cpos] > 0) { |
| 1680 |
nmisA[prv_cpos + 1 + nmis] = maxmis[cpos] - nmis; |
| 1681 |
} |
| 1682 |
else if(maxgap[cpos] > 0 && maxmis[cpos] > 0) { |
| 1683 |
|
| 1684 |
nmisA[prv_cpos + 1 + nmis] = maxmis[cpos] - nmis; |
| 1685 |
ngapA[prv_cpos + 1 + nmis + ngap] = maxgap[cpos] - ngap; |
| 1686 |
} |
| 1687 |
|
| 1688 |
|
| 1689 |
for(apos = 0; apos <= msa->alen; apos++) { |
| 1690 |
neitherA[apos] = ngapA[apos] + nmisA[apos]; |
| 1691 |
} |
| 1692 |
|
| 1693 |
*ret_ngapA = ngapA; |
| 1694 |
*ret_nmisA = nmisA; |
| 1695 |
*ret_neitherA = neitherA; |
| 1696 |
|
| 1697 |
return eslOK; |
| 1698 |
|
| 1699 |
ERROR: |
| 1700 |
if(ngapA != NULL) free(ngapA); |
| 1701 |
if(nmisA != NULL) free(nmisA); |
| 1702 |
if(neitherA != NULL) free(neitherA); |
| 1703 |
ESL_FAIL(status, errbuf, "Memory allocation error."); |
| 1704 |
return status; |
| 1705 |
} |
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
void |
| 1717 |
write_pfam_msa_top(FILE *fp, ESL_MSA *msa) |
| 1718 |
{ |
| 1719 |
int i, maxgf; |
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
|
| 1725 |
fprintf(fp, "# STOCKHOLM 1.0\n"); |
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
for (i = 0; i < msa->ncomment; i++) |
| 1730 |
fprintf(fp, "# %s\n", msa->comment[i]); |
| 1731 |
if (msa->ncomment > 0) fprintf(fp, "\n"); |
| 1732 |
|
| 1733 |
maxgf = maxwidth(msa->gf_tag, msa->ngf); |
| 1734 |
if (maxgf < 2) maxgf = 2; |
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
if (msa->name != NULL) fprintf(fp, "#=GF %-*s %s\n", maxgf, "ID", msa->name); |
| 1739 |
if (msa->acc != NULL) fprintf(fp, "#=GF %-*s %s\n", maxgf, "AC", msa->acc); |
| 1740 |
if (msa->desc != NULL) fprintf(fp, "#=GF %-*s %s\n", maxgf, "DE", msa->desc); |
| 1741 |
if (msa->au != NULL) fprintf(fp, "#=GF %-*s %s\n", maxgf, "AU", msa->au); |
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
if (msa->cutset[eslMSA_GA1] && msa->cutset[eslMSA_GA2]) |
| 1746 |
fprintf(fp, "#=GF %-*s %.1f %.1f\n", |
| 1747 |
maxgf, "GA", msa->cutoff[eslMSA_GA1], msa->cutoff[eslMSA_GA2]); |
| 1748 |
else if (msa->cutset[eslMSA_GA1]) |
| 1749 |
fprintf(fp, "#=GF %-*s %.1f\n", |
| 1750 |
maxgf, "GA", msa->cutoff[eslMSA_GA1]); |
| 1751 |
|
| 1752 |
if (msa->cutset[eslMSA_NC1] && msa->cutset[eslMSA_NC2]) |
| 1753 |
fprintf(fp, "#=GF %-*s %.1f %.1f\n", |
| 1754 |
maxgf, "NC", msa->cutoff[eslMSA_NC1], msa->cutoff[eslMSA_NC2]); |
| 1755 |
else if (msa->cutset[eslMSA_NC1]) |
| 1756 |
fprintf(fp, "#=GF %-*s %.1f\n", |
| 1757 |
maxgf, "NC", msa->cutoff[eslMSA_NC1]); |
| 1758 |
|
| 1759 |
if (msa->cutset[eslMSA_TC1] && msa->cutset[eslMSA_TC2]) |
| 1760 |
fprintf(fp, "#=GF %-*s %.1f %.1f\n", |
| 1761 |
maxgf, "TC", msa->cutoff[eslMSA_TC1], msa->cutoff[eslMSA_TC2]); |
| 1762 |
else if (msa->cutset[eslMSA_TC1]) |
| 1763 |
fprintf(fp, "#=GF %-*s %.1f\n", |
| 1764 |
maxgf, "TC", msa->cutoff[eslMSA_TC1]); |
| 1765 |
|
| 1766 |
for (i = 0; i < msa->ngf; i++) |
| 1767 |
fprintf(fp, "#=GF %-*s %s\n", maxgf, msa->gf_tag[i], msa->gf[i]); |
| 1768 |
fprintf(fp, "\n"); |
| 1769 |
|
| 1770 |
return; |
| 1771 |
} |
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 |
|
| 1780 |
|
| 1781 |
void |
| 1782 |
write_pfam_msa_gc(FILE *fp, ESL_MSA *msa, int margin) |
| 1783 |
{ |
| 1784 |
int i; |
| 1785 |
if (msa->ss_cons != NULL) { fprintf(fp, "#=GC %-*s %s\n", margin-6, "SS_cons", msa->ss_cons); } |
| 1786 |
if (msa->sa_cons != NULL) { fprintf(fp, "#=GC %-*s %s\n", margin-6, "SA_cons", msa->sa_cons); } |
| 1787 |
if (msa->pp_cons != NULL) { fprintf(fp, "#=GC %-*s %s\n", margin-6, "PP_cons", msa->pp_cons); } |
| 1788 |
if (msa->rf != NULL) { fprintf(fp, "#=GC %-*s %s\n", margin-6, "RF", msa->rf); } |
| 1789 |
for (i = 0; i < msa->ngc; i++) { fprintf(fp, "#=GC %-*s %s\n", margin-6, msa->gc_tag[i], msa->gc[i]); } |
| 1790 |
fprintf(fp, "//\n"); |
| 1791 |
} |
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
static int64_t |
| 1798 |
maxwidth(char **s, int n) |
| 1799 |
{ |
| 1800 |
int64_t max,len; |
| 1801 |
int i; |
| 1802 |
|
| 1803 |
max = 0; |
| 1804 |
for (i = 0; i < n; i++) |
| 1805 |
if (s[i] != NULL) |
| 1806 |
{ |
| 1807 |
len = strlen(s[i]); |
| 1808 |
if (len > max) max = len; |
| 1809 |
} |
| 1810 |
return max; |
| 1811 |
} |
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
static int |
| 1818 |
rfchar_is_nongap_nonmissing(const ESL_ALPHABET *abc, char rfchar) { |
| 1819 |
if(esl_abc_CIsGap (abc, rfchar)) return FALSE; |
| 1820 |
if(esl_abc_CIsMissing(abc, rfchar)) return FALSE; |
| 1821 |
return TRUE; |
| 1822 |
} |