| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#include <esl_config.h> |
| 8 |
|
| 9 |
#include <stdlib.h> |
| 10 |
#include <stdio.h> |
| 11 |
#include <string.h> |
| 12 |
#include <assert.h> |
| 13 |
#include <math.h> |
| 14 |
#include <time.h> |
| 15 |
|
| 16 |
#include "easel.h" |
| 17 |
#include "esl_arr2.h" |
| 18 |
#include "esl_arr3.h" |
| 19 |
#include "esl_distance.h" |
| 20 |
#include "esl_dmatrix.h" |
| 21 |
#include "esl_fileparser.h" |
| 22 |
#include "esl_getopts.h" |
| 23 |
#include "esl_keyhash.h" |
| 24 |
#include "esl_msa.h" |
| 25 |
#include "esl_msafile.h" |
| 26 |
#include "esl_msafile2.h" |
| 27 |
#include "esl_sq.h" |
| 28 |
#include "esl_sqio.h" |
| 29 |
#include "esl_stack.h" |
| 30 |
#include "esl_tree.h" |
| 31 |
#include "esl_vectorops.h" |
| 32 |
#include "esl_wuss.h" |
| 33 |
|
| 34 |
#define ERRBUFSIZE 1024 |
| 35 |
#define MAXMBWITHOUTFORCE 100 |
| 36 |
|
| 37 |
#define ALIMODE 0 |
| 38 |
#define INDIMODE 1 |
| 39 |
#define SIMPLEMASKMODE 2 |
| 40 |
#define INFILEMODE 3 |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
#define NCMYK 4 |
| 45 |
#define ICYAN 0 |
| 46 |
#define IMGTA 1 |
| 47 |
#define IYELW 2 |
| 48 |
#define IBLCK 3 |
| 49 |
|
| 50 |
|
| 51 |
#define NSCHEMES 7 |
| 52 |
|
| 53 |
#define RB_11_RH_SCHEME 0 |
| 54 |
#define RB_11_RL_SCHEME 1 |
| 55 |
#define RB_6_RH_SCHEME 2 |
| 56 |
#define RB_6_RL_SCHEME 3 |
| 57 |
#define RB_5_RH_SCHEME 4 |
| 58 |
#define RB_5_RL_SCHEME 5 |
| 59 |
#define RB_W5_OH_SCHEME 6 |
| 60 |
|
| 61 |
#define NRB_11_RH_SCHEME 11 |
| 62 |
#define NRB_11_RL_SCHEME 11 |
| 63 |
#define NRB_6_RH_SCHEME 6 |
| 64 |
#define NRB_6_RL_SCHEME 6 |
| 65 |
#define NRB_5_RH_SCHEME 5 |
| 66 |
#define NRB_5_RL_SCHEME 5 |
| 67 |
#define NRB_W5_OH_SCHEME 5 |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
#define RED2BLUE_1_OF_11_C 0.00 |
| 73 |
#define RED2BLUE_1_OF_11_M 0.94 |
| 74 |
#define RED2BLUE_1_OF_11_Y 1.00 |
| 75 |
#define RED2BLUE_1_OF_11_K 0.00 |
| 76 |
|
| 77 |
#define RED2BLUE_2_OF_11_C 0.00 |
| 78 |
#define RED2BLUE_2_OF_11_M 0.84 |
| 79 |
#define RED2BLUE_2_OF_11_Y 1.00 |
| 80 |
#define RED2BLUE_2_OF_11_K 0.00 |
| 81 |
|
| 82 |
#define RED2BLUE_3_OF_11_C 0.00 |
| 83 |
#define RED2BLUE_3_OF_11_M 0.63 |
| 84 |
#define RED2BLUE_3_OF_11_Y 1.00 |
| 85 |
#define RED2BLUE_3_OF_11_K 0.00 |
| 86 |
|
| 87 |
#define RED2BLUE_4_OF_11_C 0.00 |
| 88 |
#define RED2BLUE_4_OF_11_M 0.42 |
| 89 |
#define RED2BLUE_4_OF_11_Y 1.00 |
| 90 |
#define RED2BLUE_4_OF_11_K 0.00 |
| 91 |
|
| 92 |
#define RED2BLUE_5_OF_11_C 0.00 |
| 93 |
#define RED2BLUE_5_OF_11_M 0.21 |
| 94 |
#define RED2BLUE_5_OF_11_Y 1.00 |
| 95 |
#define RED2BLUE_5_OF_11_K 0.00 |
| 96 |
|
| 97 |
#define RED2BLUE_6_OF_11_C 0.00 |
| 98 |
#define RED2BLUE_6_OF_11_M 0.00 |
| 99 |
#define RED2BLUE_6_OF_11_Y 1.00 |
| 100 |
#define RED2BLUE_6_OF_11_K 0.00 |
| 101 |
|
| 102 |
#define RED2BLUE_7_OF_11_C 0.42 |
| 103 |
#define RED2BLUE_7_OF_11_M 0.00 |
| 104 |
#define RED2BLUE_7_OF_11_Y 1.00 |
| 105 |
#define RED2BLUE_7_OF_11_K 0.00 |
| 106 |
|
| 107 |
#define RED2BLUE_8_OF_11_C 0.61 |
| 108 |
#define RED2BLUE_8_OF_11_M 0.00 |
| 109 |
#define RED2BLUE_8_OF_11_Y 0.56 |
| 110 |
#define RED2BLUE_8_OF_11_K 0.22 |
| 111 |
|
| 112 |
#define RED2BLUE_9_OF_11_C 0.50 |
| 113 |
#define RED2BLUE_9_OF_11_M 0.00 |
| 114 |
#define RED2BLUE_9_OF_11_Y 0.00 |
| 115 |
#define RED2BLUE_9_OF_11_K 0.50 |
| 116 |
|
| 117 |
#define RED2BLUE_10_OF_11_C 0.78 |
| 118 |
#define RED2BLUE_10_OF_11_M 0.56 |
| 119 |
#define RED2BLUE_10_OF_11_Y 0.00 |
| 120 |
#define RED2BLUE_10_OF_11_K 0.22 |
| 121 |
|
| 122 |
#define RED2BLUE_11_OF_11_C 0.92 |
| 123 |
#define RED2BLUE_11_OF_11_M 0.84 |
| 124 |
#define RED2BLUE_11_OF_11_Y 0.00 |
| 125 |
#define RED2BLUE_11_OF_11_K 0.08 |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
#define RED2BLUE_1_OF_6_C 0.00 |
| 131 |
#define RED2BLUE_1_OF_6_M 0.94 |
| 132 |
#define RED2BLUE_1_OF_6_Y 1.00 |
| 133 |
#define RED2BLUE_1_OF_6_K 0.00 |
| 134 |
|
| 135 |
|
| 136 |
#define RED2BLUE_2_OF_6_C 0.00 |
| 137 |
#define RED2BLUE_2_OF_6_M 0.63 |
| 138 |
#define RED2BLUE_2_OF_6_Y 1.00 |
| 139 |
#define RED2BLUE_2_OF_6_K 0.00 |
| 140 |
|
| 141 |
|
| 142 |
#define RED2BLUE_3_OF_6_C 0.00 |
| 143 |
#define RED2BLUE_3_OF_6_M 0.21 |
| 144 |
#define RED2BLUE_3_OF_6_Y 1.00 |
| 145 |
#define RED2BLUE_3_OF_6_K 0.00 |
| 146 |
|
| 147 |
|
| 148 |
#define RED2BLUE_4_OF_6_C 0.42 |
| 149 |
#define RED2BLUE_4_OF_6_M 0.00 |
| 150 |
#define RED2BLUE_4_OF_6_Y 1.00 |
| 151 |
#define RED2BLUE_4_OF_6_K 0.00 |
| 152 |
|
| 153 |
|
| 154 |
#define RED2BLUE_5_OF_6_C 0.50 |
| 155 |
#define RED2BLUE_5_OF_6_M 0.00 |
| 156 |
#define RED2BLUE_5_OF_6_Y 0.00 |
| 157 |
#define RED2BLUE_5_OF_6_K 0.50 |
| 158 |
|
| 159 |
|
| 160 |
#define RED2BLUE_6_OF_6_C 0.92 |
| 161 |
#define RED2BLUE_6_OF_6_M 0.84 |
| 162 |
#define RED2BLUE_6_OF_6_Y 0.00 |
| 163 |
#define RED2BLUE_6_OF_6_K 0.08 |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
#define NOC 17 |
| 168 |
#define CYANOC 0 |
| 169 |
#define MAGENTAOC 1 |
| 170 |
#define YELLOWOC 2 |
| 171 |
#define BLACKOC 3 |
| 172 |
#define WHITEOC 4 |
| 173 |
#define LIGHTGREYOC 5 |
| 174 |
#define GREYOC 6 |
| 175 |
#define DARKGREYOC 7 |
| 176 |
#define REDOC 8 |
| 177 |
#define ORANGEOC 9 |
| 178 |
#define TEALOC 10 |
| 179 |
#define LIGHTGREENOC 11 |
| 180 |
#define GREENOC 12 |
| 181 |
#define DARKGREENOC 13 |
| 182 |
#define LIGHTPURPLEOC 14 |
| 183 |
#define PURPLEOC 15 |
| 184 |
#define DARKPURPLEOC 16 |
| 185 |
|
| 186 |
|
| 187 |
#define CYAN_C 1.0 |
| 188 |
#define CYAN_M 0.0 |
| 189 |
#define CYAN_Y 0.0 |
| 190 |
#define CYAN_K 0.0 |
| 191 |
|
| 192 |
#define MAGENTA_C 0.0 |
| 193 |
#define MAGENTA_M 1.0 |
| 194 |
#define MAGENTA_Y 0.0 |
| 195 |
#define MAGENTA_K 0.0 |
| 196 |
|
| 197 |
#define YELLOW_C 0.0 |
| 198 |
#define YELLOW_M 0.0 |
| 199 |
#define YELLOW_Y 1.0 |
| 200 |
#define YELLOW_K 0.0 |
| 201 |
|
| 202 |
#define BLACK_C 0.0 |
| 203 |
#define BLACK_M 0.0 |
| 204 |
#define BLACK_Y 0.0 |
| 205 |
#define BLACK_K 1.0 |
| 206 |
|
| 207 |
#define WHITE_C 0.0 |
| 208 |
#define WHITE_M 0.0 |
| 209 |
#define WHITE_Y 0.0 |
| 210 |
#define WHITE_K 0.0 |
| 211 |
|
| 212 |
#define LIGHTGREY_C 0.0 |
| 213 |
#define LIGHTGREY_M 0.0 |
| 214 |
#define LIGHTGREY_Y 0.0 |
| 215 |
#define LIGHTGREY_K 0.2 |
| 216 |
|
| 217 |
#define GREY_C 0.0 |
| 218 |
#define GREY_M 0.0 |
| 219 |
#define GREY_Y 0.0 |
| 220 |
#define GREY_K 0.5 |
| 221 |
|
| 222 |
#define DARKGREY_C 0.0 |
| 223 |
#define DARKGREY_M 0.0 |
| 224 |
#define DARKGREY_Y 0.0 |
| 225 |
#define DARKGREY_K 0.75 |
| 226 |
|
| 227 |
#define RED_C 0.0 |
| 228 |
#define RED_M 1.0 |
| 229 |
#define RED_Y 1.0 |
| 230 |
#define RED_K 0.0 |
| 231 |
|
| 232 |
#define ORANGE_C 0.0 |
| 233 |
#define ORANGE_M 0.5 |
| 234 |
#define ORANGE_Y 1.0 |
| 235 |
#define ORANGE_K 0.0 |
| 236 |
|
| 237 |
#define TEAL_C 0.5 |
| 238 |
#define TEAL_M 0.0 |
| 239 |
#define TEAL_Y 0.0 |
| 240 |
#define TEAL_K 0.5 |
| 241 |
|
| 242 |
#define LIGHTGREEN_C 0.5 |
| 243 |
#define LIGHTGREEN_M 0.0 |
| 244 |
#define LIGHTGREEN_Y 0.5 |
| 245 |
#define LIGHTGREEN_K 0.0 |
| 246 |
|
| 247 |
#define GREEN_C 1.0 |
| 248 |
#define GREEN_M 0.0 |
| 249 |
#define GREEN_Y 1.0 |
| 250 |
#define GREEN_K 0.0 |
| 251 |
|
| 252 |
#define DARKGREEN_C 1.0 |
| 253 |
#define DARKGREEN_M 0.5 |
| 254 |
#define DARKGREEN_Y 1.0 |
| 255 |
#define DARKGREEN_K 0.0 |
| 256 |
|
| 257 |
#define LIGHTPURPLE_C 0.3 |
| 258 |
#define LIGHTPURPLE_M 0.6 |
| 259 |
#define LIGHTPURPLE_Y 0.0 |
| 260 |
#define LIGHTPURPLE_K 0.0 |
| 261 |
|
| 262 |
#define PURPLE_C 0.5 |
| 263 |
#define PURPLE_M 1.0 |
| 264 |
#define PURPLE_Y 0.0 |
| 265 |
#define PURPLE_K 0.0 |
| 266 |
|
| 267 |
#define DARKPURPLE_C 1.0 |
| 268 |
#define DARKPURPLE_M 1.0 |
| 269 |
#define DARKPURPLE_Y 0.0 |
| 270 |
#define DARKPURPLE_K 0.0 |
| 271 |
|
| 272 |
|
| 273 |
#define LEG_NBOXES 11 |
| 274 |
#define LEG_MINFONTSIZE 10 |
| 275 |
#define SPECIAL_FONT "Courier-BoldOblique" |
| 276 |
#define LEG_FONT "Courier-Bold" |
| 277 |
#define LEG_EXTRA_COLUMNS 12 |
| 278 |
#define COURIER_HEIGHT_WIDTH_RATIO 1.65 |
| 279 |
#define LEG_EXTRA_TEXT_FONT "Helvetica" |
| 280 |
|
| 281 |
|
| 282 |
#define DEFAULT_FONT "Courier-Bold" |
| 283 |
#define FOOTER_FONT "Helvetica" |
| 284 |
#define NUCLEOTIDES_FONT "Courier-Bold" |
| 285 |
|
| 286 |
|
| 287 |
#define POSNTEXT_FONT "Helvetica" |
| 288 |
#define NUCLEOTIDES_FONTSIZE 8. |
| 289 |
#define POSNTEXT_FONTSIZE 8. |
| 290 |
#define LEG_FONTSIZE_UNSCALED 8 |
| 291 |
#define LEG_EXTRA_TEXT_FONTSIZE_UNSCALED 8 |
| 292 |
#define HEADER_FONTSIZE_UNSCALED 12 |
| 293 |
#define HEADER_MODELNAME_MAXCHARS 20 |
| 294 |
#define TICKS_LINEWIDTH 2. |
| 295 |
#define BP_LINEWIDTH 1. |
| 296 |
#define CELLSIZE 8. |
| 297 |
#define CELLSIZE_INT 8 |
| 298 |
|
| 299 |
#define CELL_XOFFSET_FRACTION 0.2 |
| 300 |
#define CELL_YOFFSET_FRACTION 0.2 |
| 301 |
#define LOWERCASE_LOW_HANGING_CHARS "gjpqy" |
| 302 |
#define NUCLEOTIDE_YOFFSET_FRACTION_LOWERCASE_LOW_HANGING_CHARS 0.1875 |
| 303 |
|
| 304 |
|
| 305 |
#define POSTSCRIPT_PAGEWIDTH 612. |
| 306 |
#define POSTSCRIPT_PAGEHEIGHT 792. |
| 307 |
#define PAGE_TOPBUF 30. |
| 308 |
#define PAGE_SIDEBUF 32. |
| 309 |
#define PAGE_BOTBUF 30. |
| 310 |
|
| 311 |
|
| 312 |
#define OUTLINE_LINEWIDTH_CELL_FRACTION_MIN 0.04 |
| 313 |
#define OUTLINE_LINEWIDTH_CELL_FRACTION_MAX 0.16 |
| 314 |
#define NOUTLINETYPES 2 |
| 315 |
#define OUTLINE_NONE_IDX 0 |
| 316 |
#define OUTLINE_MIN_IDX 1 |
| 317 |
#define OUTLINE_MAX_IDX 2 |
| 318 |
#define OUTLINE_PROCEDURE "box" |
| 319 |
|
| 320 |
|
| 321 |
#define OCCL_BLANK_COUNT -1 |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
typedef struct scheme_color_legend_s { |
| 330 |
int scheme; |
| 331 |
int nbins; |
| 332 |
char *text1; |
| 333 |
char *text2; |
| 334 |
float *limits; |
| 335 |
int *counts; |
| 336 |
int *counts_masked; |
| 337 |
int ints_only_flag; |
| 338 |
int low_inclusive; |
| 339 |
int high_inclusive; |
| 340 |
int use_mask; |
| 341 |
} SchemeColorLegend_t; |
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
typedef struct onecell_color_legend_s { |
| 350 |
float col[NCMYK]; |
| 351 |
char *text; |
| 352 |
char *celltext; |
| 353 |
char *procname; |
| 354 |
|
| 355 |
float *procstack; |
| 356 |
int nprocstack; |
| 357 |
int nres; |
| 358 |
int nres_masked; |
| 359 |
int do_separator; |
| 360 |
int do_no_vspace; |
| 361 |
} OneCellColorLegend_t; |
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
typedef struct text_legend_s { |
| 370 |
char **text_per_line; |
| 371 |
int nlines; |
| 372 |
int do_separator; |
| 373 |
} TextLegend_t; |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
typedef struct ss_postscript_s { |
| 384 |
int npage; |
| 385 |
char *modelname; |
| 386 |
int *modeA; |
| 387 |
char **descA; |
| 388 |
int desc_max_chars; |
| 389 |
float headerx; |
| 390 |
float headery; |
| 391 |
float headerx_charsize; |
| 392 |
float headery_charsize; |
| 393 |
float headerx_desc; |
| 394 |
int leg_posn; |
| 395 |
int leg_cellsize; |
| 396 |
float leg_rhs_space; |
| 397 |
float legx_offset; |
| 398 |
float legy_offset; |
| 399 |
float legx; |
| 400 |
float legy; |
| 401 |
float cur_legy; |
| 402 |
float legx_charsize; |
| 403 |
float legy_charsize; |
| 404 |
int legx_max_chars; |
| 405 |
int legy_max_chars; |
| 406 |
int legx_stats; |
| 407 |
float pagex_max; |
| 408 |
float pagey_max; |
| 409 |
float scale; |
| 410 |
char **regurgA; |
| 411 |
int nregurg; |
| 412 |
char **posntextA; |
| 413 |
float *posntextxA; |
| 414 |
float *posntextyA; |
| 415 |
int nposntext; |
| 416 |
float *ticksx1A; |
| 417 |
float *ticksx2A; |
| 418 |
float *ticksy1A; |
| 419 |
float *ticksy2A; |
| 420 |
int nticks; |
| 421 |
float *bpx1A; |
| 422 |
float *bpx2A; |
| 423 |
float *bpy1A; |
| 424 |
float *bpy2A; |
| 425 |
int nbp; |
| 426 |
float *rxA; |
| 427 |
float *ryA; |
| 428 |
int rflen; |
| 429 |
char **rAA; |
| 430 |
float ***rcolAAA; |
| 431 |
float ***bcolAAA; |
| 432 |
char **otypeAA; |
| 433 |
|
| 434 |
OneCellColorLegend_t ***occlAAA; |
| 435 |
int *nocclA; |
| 436 |
SchemeColorLegend_t **sclAA; |
| 437 |
TextLegend_t ***tlAAA; |
| 438 |
int *ntlA; |
| 439 |
char *mask; |
| 440 |
int nalloc; |
| 441 |
int msa_nseq; |
| 442 |
char *msa_cseq_maj; |
| 443 |
char *msa_cseq_amb; |
| 444 |
|
| 445 |
|
| 446 |
int *msa_ct; |
| 447 |
|
| 448 |
int msa_nbp; |
| 449 |
int *msa_rf2a_map; |
| 450 |
int *msa_a2rf_map; |
| 451 |
int *uaseqlenA; |
| 452 |
int *seqidxA; |
| 453 |
ESL_MSA *msa; |
| 454 |
const ESL_ALPHABET *abc; |
| 455 |
} SSPostscript_t; |
| 456 |
|
| 457 |
static SSPostscript_t *create_sspostscript(const ESL_GETOPTS *go); |
| 458 |
static int setup_sspostscript(SSPostscript_t *ps, char *errbuf); |
| 459 |
static OneCellColorLegend_t *create_onecell_colorlegend(float *cmykA, int nres, int nres_masked, int do_separator, int do_no_vspace); |
| 460 |
static SchemeColorLegend_t *create_scheme_colorlegend(int scheme, int ncols, float *limits, int ints_only_flag, int low_inclusive, int high_inclusive, int use_mask); |
| 461 |
static TextLegend_t *create_text_legend(int nlines, char **text_per_line, int do_separator); |
| 462 |
static TextLegend_t *create_text_legend_for_consensus_sequence(const ESL_GETOPTS *go, int do_separator); |
| 463 |
static int add_text_to_scheme_colorlegend(SSPostscript_t *ps, SchemeColorLegend_t *scl, char *text, int legx_max_chars, char *errbuf); |
| 464 |
static int add_text_to_onecell_colorlegend(SSPostscript_t *ps, OneCellColorLegend_t *occl, char *text, int legx_max_chars, char *errbuf); |
| 465 |
static int add_celltext_to_onecell_colorlegend(SSPostscript_t *ps, OneCellColorLegend_t *occl, char *celltext, char *errbuf); |
| 466 |
static int add_procedure_to_onecell_colorlegend(SSPostscript_t *ps, OneCellColorLegend_t *occl, char *procname, float *procstack, int nprocstack, char *errbuf); |
| 467 |
static int add_page_desc_to_sspostscript(SSPostscript_t *ps, int page, char *text, char *errbuf); |
| 468 |
static int add_diffmask_page_desc_to_sspostscript(SSPostscript_t *ps, int page, char *mask_file, char *maskdiff_file, char *errbuf); |
| 469 |
static int draw_sspostscript(FILE *fp, const ESL_GETOPTS *go, char *errbuf, char *command, char *date, float ***hc_scheme, SSPostscript_t *ps); |
| 470 |
static int draw_legend_column_headers(FILE *fp, SSPostscript_t *ps, int pagenum, char *errbuf); |
| 471 |
static int draw_onecell_colorlegend(FILE *fp, OneCellColorLegend_t *occl, SSPostscript_t *ps, int occl_idx, int pagenum); |
| 472 |
static int draw_scheme_colorlegend(const ESL_GETOPTS *go, FILE *fp, SchemeColorLegend_t *scl, float **hc_scheme, SSPostscript_t *ps, int pagenum); |
| 473 |
static void free_sspostscript(SSPostscript_t *ps); |
| 474 |
static int add_pages_sspostscript(SSPostscript_t *ps, int ntoadd, int page_mode); |
| 475 |
static int parse_template_file(char *filename, const ESL_GETOPTS *go, char *errbuf, int msa_rflen, SSPostscript_t **ret_ps); |
| 476 |
static int parse_template_page(ESL_FILEPARSER *efp, const ESL_GETOPTS *go, char *errbuf, SSPostscript_t **ret_ps); |
| 477 |
static int parse_modelname_section(ESL_FILEPARSER *efp, char *errbuf, SSPostscript_t *ps); |
| 478 |
static int parse_legend_section(ESL_FILEPARSER *efp, char *errbuf, SSPostscript_t *ps); |
| 479 |
static int parse_scale_section(ESL_FILEPARSER *efp, char *errbuf, SSPostscript_t *ps); |
| 480 |
static int parse_ignore_section(ESL_FILEPARSER *efp, char *errbuf, int *ret_read_showpage); |
| 481 |
static int parse_regurgitate_section(ESL_FILEPARSER *efp, char *errbuf, SSPostscript_t *ps); |
| 482 |
static int parse_text_section(ESL_FILEPARSER *efp, char *errbuf, SSPostscript_t *ps); |
| 483 |
static int parse_lines_section(ESL_FILEPARSER *efp, char *errbuf, SSPostscript_t *ps); |
| 484 |
static int validate_justread_sspostscript(SSPostscript_t *ps, char *errbuf); |
| 485 |
static int validate_and_update_sspostscript_given_msa(const ESL_GETOPTS *go, const ESL_ALPHABET *abc, SSPostscript_t *ps, ESL_MSA *msa, int msa_nseq, char *errbuf); |
| 486 |
static int read_mask_file(char *filename, char *errbuf, char **ret_mask, int *ret_masklen, int *ret_mask_has_internal_zeroes); |
| 487 |
static void PairCount(const ESL_ALPHABET *abc, double *counters, ESL_DSQ syml, ESL_DSQ symr, double wt); |
| 488 |
static int get_command(const ESL_GETOPTS *go, char *errbuf, char **ret_command); |
| 489 |
static int get_date(char *errbuf, char **ret_date); |
| 490 |
static int set_scheme_values(char *errbuf, float *vec, int ncolvals, float **scheme, float val, SchemeColorLegend_t *scl, int within_mask, int *ret_bi); |
| 491 |
static int set_onecell_values(char *errbuf, float *vec, int ncolvals, float *onecolor); |
| 492 |
static int add_mask_to_ss_postscript(SSPostscript_t *ps, char *mask); |
| 493 |
static int draw_masked_block(FILE *fp, float x, float y, float *colvec, int do_circle_mask, int do_square_mask, int do_x_mask, int do_border, float cellsize); |
| 494 |
static int draw_header_and_footer(FILE *fp, const ESL_GETOPTS *go, char *errbuf, SSPostscript_t *ps, int page, int pageidx2print); |
| 495 |
static void get_insert_info_from_msa(const ESL_ALPHABET *abc, ESL_MSA *msa, int rflen, int **ret_nseq_with_ins_ct, int **ret_nins_ct, int ***ret_per_seq_ins_ct); |
| 496 |
static void get_insert_info_from_abc_ct(double **abc_ct, ESL_ALPHABET *abc, char *msa_rf, int64_t msa_alen, int rflen, int **ret_nseq_with_ins_ct, int **ret_nins_ct); |
| 497 |
static void get_insert_info_from_ifile(char *ifile, int rflen, int msa_nseq, ESL_KEYHASH *useme_keyhash, int **ret_nseq_with_ins_ct, int **ret_nins_ct, int ***ret_per_seq_ins_ct, int **ret_soff_ct, int **ret_eoff_ct); |
| 498 |
static int count_msa(const ESL_ALPHABET *abc, ESL_MSA *msa, char *errbuf, double ***ret_abc_ct, double ****ret_bp_ct, double ***ret_pp_ct, int **ret_spos_ct, int **ret_epos_ct); |
| 499 |
static int get_consensus_seqs_from_abc_ct(const ESL_GETOPTS *go,SSPostscript_t *ps, char *errbuf, double **abc_ct, ESL_ALPHABET *abc, int64_t msa_alen); |
| 500 |
static int infocontent_sspostscript(const ESL_GETOPTS *go, ESL_ALPHABET *abc, char *errbuf, SSPostscript_t *ps, double **abc_ct, int msa_nseq, float ***hc_scheme, int hc_scheme_idx, int hc_nbins, float **hc_onecell, int hc_onecell_idx, FILE *tabfp); |
| 501 |
static int mutual_information_sspostscript(const ESL_GETOPTS *go, ESL_ALPHABET *abc, char *errbuf, SSPostscript_t *ps, double ***bp_ct, int msa_nseq, float ***hc_scheme, int hc_scheme_idx, int hc_nbins, float **hc_onecell, int ss_idx, int zerores_idx, FILE *tabfp); |
| 502 |
static int delete_sspostscript(const ESL_GETOPTS *go, ESL_ALPHABET *abc, char *errbuf, SSPostscript_t *ps, double **abc_ct, int *span_ct, int msa_nseq, int do_all, float ***hc_scheme, int hc_scheme_idx, int hc_nbins, float **hc_onecell, int hc_zerodel_idx, int hc_fewdel_idx, FILE *tabfp); |
| 503 |
static int avg_posteriors_sspostscript(const ESL_GETOPTS *go, ESL_ALPHABET *abc, char *errbuf, SSPostscript_t *ps, double **pp_ct, int msa_nseq, float ***hc_scheme, int hc_scheme_idx, int hc_nbins, float **hc_onecell, int hc_onecell_idx, FILE *tabfp); |
| 504 |
static int insertfreq_sspostscript(const ESL_GETOPTS *go, char *errbuf, SSPostscript_t *ps, int *nseq_with_ins_ct, int *span_ct, int msa_nseq, float ***hc_scheme, int hc_scheme_idx, int hc_nbins, float **hc_onecell, int hc_zeroins_idx, int hc_fewins_idx, FILE *tabfp); |
| 505 |
static int insertavglen_sspostscript(const ESL_GETOPTS *go, char *errbuf, SSPostscript_t *ps, int *nseq_with_ins_ct, int *nins_ct, int *span_ct, int msa_nseq, float ***hc_scheme, int hc_scheme_idx, int hc_nbins, float **hc_onecell, int hc_zeroins_idx, FILE *tabfp); |
| 506 |
static int span_sspostscript(const ESL_GETOPTS *go, char *errbuf, SSPostscript_t *ps, int *span_ct, int msa_nseq, float ***hc_scheme, int hc_scheme_idx, int hc_nbins, float **hc_onecell, int zercov_idx, int maxcov_idx, FILE *tabfp); |
| 507 |
static int individuals_sspostscript(const ESL_GETOPTS *go, ESL_ALPHABET *abc, char *errbuf, SSPostscript_t *ps, double **abc_ct, ESL_MSA *msa, int **per_seq_ins_ct, int do_prob, int do_rescol, float ***hc_scheme, int hc_scheme_idx_s, int hc_scheme_idx_p, int hc_nbins_s, int hc_nbins_p, float **hc_onecell, int extdel_idx_s, int wcbp_idx_s, int gubp_idx_s, int ncbp_idx_s, int dgbp_idx_s, int hgbp_idx_s, int gap_idx_p, FILE *tabfp); |
| 508 |
static int cons_seq_sspostscript(const ESL_GETOPTS *go, char *errbuf, SSPostscript_t *ps, float **hc_onecell, int wcbp_idx_s, int gubp_idx_s, int ncbp_idx_s, int dgbp_idx_s, int hgbp_idx_s); |
| 509 |
static int rf_seq_sspostscript(const ESL_GETOPTS *go, char *errbuf, SSPostscript_t *ps, ESL_MSA *msa, int do_rescol, float **hc_onecell, int wcbp_idx_s, int gubp_idx_s, int ncbp_idx_s); |
| 510 |
static int colormask_sspostscript(const ESL_GETOPTS *go, char *errbuf, SSPostscript_t *ps, ESL_MSA *msa, float **hc_onecell, int incmask_idx, int excmask_idx); |
| 511 |
static int diffmask_sspostscript(const ESL_GETOPTS *go, char *errbuf, SSPostscript_t *ps, ESL_MSA *msa, char *mask2, float **hc_onecell, int incboth_idx, int inc1_idx, int inc2_idx, int excboth_idx); |
| 512 |
static int drawfile2sspostscript(const ESL_GETOPTS *go, char *errbuf, SSPostscript_t *ps, float ***hc_scheme, int hc_scheme_idx, int hc_nbins); |
| 513 |
static int expertfile2sspostscript(const ESL_GETOPTS *go, char *errbuf, SSPostscript_t *ps); |
| 514 |
static int get_pp_idx(const ESL_ALPHABET *abc, char ppchar); |
| 515 |
static int get_span_ct(int *msa_rf2a_map, int64_t alen, int rflen, int nseq, int *spos_ct, int *epos_ct, int *srfoff_ct, int *erfoff_ct, int **ret_span_ct); |
| 516 |
static int is_watson_crick_bp(char i, char j); |
| 517 |
static int is_gu_or_ug_bp(char i, char j); |
| 518 |
static int compare_two_cmyk_colors(float acol_C, float acol_M, float acol_Y, float acol_K, float bcol_C, float bcol_M, float bcol_Y, float bcol_K); |
| 519 |
static void define_outline_procedure(FILE *fp); |
| 520 |
|
| 521 |
static char banner[] = "draw postscript secondary structure diagrams"; |
| 522 |
static char usage[] = "[options] <msafile> <SS postscript template> <output postscript file name>\n\ |
| 523 |
The <msafile> must be in Stockholm format."; |
| 524 |
|
| 525 |
static ESL_OPTIONS options[] = { |
| 526 |
|
| 527 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, NULL, "help; show brief info on version and usage", 1 }, |
| 528 |
{ "-d", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, NULL, "draw default set of alignment summary diagrams", 1 }, |
| 529 |
{ "--mask", eslARG_INFILE, NULL, NULL, NULL, NULL,NULL, NULL, "for all diagrams, mark masked ('0') columns from mask in <f>", 1 }, |
| 530 |
{ "--small", eslARG_NONE, NULL, NULL, NULL, NULL,NULL, NULL, "operate in small memory mode (aln must be 1 line/seq Pfam format)", 1 }, |
| 531 |
|
| 532 |
{ "--cons", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, NULL, "draw diagram showing the alignment's consensus sequence", 2 }, |
| 533 |
{ "--info", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, NULL, "draw information content diagram", 2 }, |
| 534 |
{ "--mutinfo",eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, NULL, "draw base pair mutual information diagram", 2 }, |
| 535 |
{ "--ifreq", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, NULL, "draw insert frequency diagram", 2 }, |
| 536 |
{ "--iavglen",eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, NULL, "draw average insert length diagram", 2 }, |
| 537 |
{ "--dall", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, NULL, "draw delete diagram w/all deletions (incl. terminal deletes)", 2 }, |
| 538 |
{ "--prob", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, NULL, "draw average posterior probability diagram", 2 }, |
| 539 |
{ "--span", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, NULL, "draw diagram showing fraction of seqs that span each posn", 2 }, |
| 540 |
{ "--rf", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, NULL, "draw diagram showing reference (#=GC RF) sequence", 2 }, |
| 541 |
{ "--dint", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, NULL, "draw delete diagram w/only internal (non-terminal) deletions", 2 }, |
| 542 |
{ "--tabfile",eslARG_OUTFILE,NULL, NULL, NULL, NULL,NULL, NULL, "output per position data in tabular format to file <f>", 2 }, |
| 543 |
|
| 544 |
{ "--indi", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, "--small", "draw diagrams for individual sequences in the alignment", 3 }, |
| 545 |
{ "-f", eslARG_NONE, FALSE, NULL, NULL, NULL,"--indi", NULL, "force; w/--indi draw all seqs, even if predicted output >100 Mb", 3 }, |
| 546 |
|
| 547 |
{ "--no-pp", eslARG_NONE, FALSE, NULL, NULL, NULL,"--indi", NULL, "with --indi, do not draw indi posterior probability diagrams", 9 }, |
| 548 |
{ "--no-bp", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, NULL, "do not color nucleotides based on basepair type", 9 }, |
| 549 |
{ "--no-ol", eslARG_NONE, FALSE, NULL, NULL, NULL,"--indi", NULL, "w/--indi, do not outline nts that are not most common nt", 9 }, |
| 550 |
{ "--no-ntpp", eslARG_NONE, FALSE, NULL, NULL, NULL,"--indi", "--no-pp", "w/--indi, do not draw nts on individual post prob diagrams", 9 }, |
| 551 |
|
| 552 |
{ "--no-cnt", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, NULL, "do not draw consensus nts on alignment summary diagrams", 7 }, |
| 553 |
{ "--cthresh",eslARG_REAL, "0.75", NULL,"0<x<=1.0", NULL,NULL, "--no-cnt", "capitalize cons nts occuring in >= <x> fraction of seqs", 7 }, |
| 554 |
{ "--cambig", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, "--no-cnt", "allow ambiguous nts in consensus sequence", 7 }, |
| 555 |
{ "--athresh",eslARG_REAL, "0.9", NULL,"0<x<=1.0", NULL,"--cambig",NULL, "w/--cambig, cons nt must represent >= <x> fraction of seqs", 7 }, |
| 556 |
|
| 557 |
{ "--mask-u", eslARG_NONE, FALSE, NULL, NULL, NULL,"--mask", "--mask-x","with --mask, mark masked columns as squares", 4 }, |
| 558 |
{ "--mask-x", eslARG_NONE, FALSE, NULL, NULL, NULL,"--mask", "--mask-u","with --mask, mark masked columns as x's", 4 }, |
| 559 |
{ "--mask-a", eslARG_NONE, FALSE, NULL, NULL, NULL,"--mask", NULL, "with --mask-u or --mask-x, draw alternative mask style", 4 }, |
| 560 |
|
| 561 |
{ "--mask-col", eslARG_NONE, NULL,NULL, NULL, NULL,"--mask", NULL, "w/--mask draw two color diagram denoting masked columns", 5 }, |
| 562 |
{ "--mask-diff",eslARG_INFILE,NULL,NULL, NULL, NULL,"--mask", NULL, "with --mask <f1>, compare mask in <f1> to mask in <f>", 5 }, |
| 563 |
|
| 564 |
{ "--dfile", eslARG_INFILE, NULL,NULL, NULL, NULL,NULL, NULL, "read 'draw file' specifying >=1 diagrams", 6 }, |
| 565 |
{ "--efile", eslARG_INFILE, NULL,NULL, NULL, NULL,NULL, NULL, "read 'expert draw file' specifying >=1 diagrams", 6 }, |
| 566 |
{ "--ifile", eslARG_INFILE, NULL,NULL, NULL, NULL,NULL, NULL, "read insert information from cmalign insert file <f>", 6 }, |
| 567 |
|
| 568 |
{ "--no-leg", eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, NULL, "do not draw legend", 8 }, |
| 569 |
{ "--no-head",eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, NULL, "do not draw header", 8 }, |
| 570 |
{ "--no-foot",eslARG_NONE, FALSE, NULL, NULL, NULL,NULL, NULL, "do not draw footer", 8 }, |
| 571 |
{ 0,0,0,0,0,0,0,0,0,0 }, |
| 572 |
}; |
| 573 |
|
| 574 |
int |
| 575 |
main(int argc, char **argv) |
| 576 |
{ |
| 577 |
ESL_GETOPTS *go = NULL; |
| 578 |
ESL_ALPHABET *abc = NULL; |
| 579 |
char *alifile = NULL; |
| 580 |
char *outfile = NULL; |
| 581 |
char *templatefile = NULL; |
| 582 |
|
| 583 |
int fmt; |
| 584 |
ESL_MSAFILE *afp = NULL; |
| 585 |
ESL_MSAFILE2 *afp2 = NULL; |
| 586 |
ESL_MSA *msa = NULL; |
| 587 |
int status; |
| 588 |
int rflen; |
| 589 |
int apos; |
| 590 |
char errbuf[ERRBUFSIZE]; |
| 591 |
FILE *ofp = NULL; |
| 592 |
FILE *tabfp = NULL; |
| 593 |
SSPostscript_t *ps = NULL; |
| 594 |
int *hc_nbins = NULL; |
| 595 |
float ***hc_scheme = NULL; |
| 596 |
float **hc_onecell = NULL; |
| 597 |
int z; |
| 598 |
char *command = NULL; |
| 599 |
char *date = NULL; |
| 600 |
char *mask = NULL; |
| 601 |
int masklen; |
| 602 |
char *mask2 = NULL; |
| 603 |
int mask2len; |
| 604 |
int mask_has_internal_zeroes = FALSE; |
| 605 |
int mask2_has_internal_zeroes = FALSE; |
| 606 |
|
| 607 |
int *nseq_with_ins_ct = NULL; |
| 608 |
int *nins_ct = NULL; |
| 609 |
int **per_seq_ins_ct = NULL; |
| 610 |
double **abc_ct = NULL; |
| 611 |
double ***bp_ct = NULL; |
| 612 |
|
| 613 |
double **pp_ct = NULL; |
| 614 |
int *spos_ct = NULL; |
| 615 |
int *epos_ct = NULL; |
| 616 |
int *srfoff_ct = NULL; |
| 617 |
int *erfoff_ct = NULL; |
| 618 |
int *span_ct = NULL; |
| 619 |
int64_t msa_alen; |
| 620 |
int msa_nseq; |
| 621 |
|
| 622 |
int do_small = TRUE; |
| 623 |
|
| 624 |
int do_default_set = TRUE; |
| 625 |
int do_cons = FALSE; |
| 626 |
int do_rf = FALSE; |
| 627 |
int do_info = FALSE; |
| 628 |
int do_mutinfo = FALSE; |
| 629 |
int do_ifreq = FALSE; |
| 630 |
int do_iavglen = FALSE; |
| 631 |
int do_dall = FALSE; |
| 632 |
int do_dint = FALSE; |
| 633 |
int do_prob = FALSE; |
| 634 |
int do_span = FALSE; |
| 635 |
int do_indi = FALSE; |
| 636 |
int do_maskcol = FALSE; |
| 637 |
int do_maskdiff = FALSE; |
| 638 |
int do_dfile = FALSE; |
| 639 |
int do_efile = FALSE; |
| 640 |
int need_span_ct = FALSE; |
| 641 |
int tmp_Mb = 0; |
| 642 |
int predicted_Mb = 0; |
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
go = esl_getopts_Create(options); |
| 648 |
if (esl_opt_ProcessCmdline(go, argc, argv) != eslOK || |
| 649 |
esl_opt_VerifyConfig(go) != eslOK) |
| 650 |
{ |
| 651 |
printf("Failed to parse command line: %s\n", go->errbuf); |
| 652 |
esl_usage(stdout, argv[0], usage); |
| 653 |
printf("\nTo see more help on available options, do %s -h\n\n", argv[0]); |
| 654 |
exit(1); |
| 655 |
} |
| 656 |
|
| 657 |
if (esl_opt_GetBoolean(go, "-h") ) |
| 658 |
{ |
| 659 |
esl_banner(stdout, argv[0], banner); |
| 660 |
esl_usage (stdout, argv[0], usage); |
| 661 |
puts("\n where basic options are:"); |
| 662 |
esl_opt_DisplayHelp(stdout, go, 1, 2, 80); |
| 663 |
puts("\noptions for alignment summary diagrams (incompatible with --indi):"); |
| 664 |
esl_opt_DisplayHelp(stdout, go, 2, 2, 80); |
| 665 |
puts("\noptions for drawing individual sequences (require --indi):"); |
| 666 |
esl_opt_DisplayHelp(stdout, go, 3, 2, 80); |
| 667 |
puts("\noptions for omitting parts of the diagram:"); |
| 668 |
esl_opt_DisplayHelp(stdout, go, 8, 2, 80); |
| 669 |
puts("\noptions for drawing simple two color diagrams of masks:"); |
| 670 |
esl_opt_DisplayHelp(stdout, go, 5, 2, 80); |
| 671 |
puts("\nexpert options for controlling individual seq diagrams (require --indi):"); |
| 672 |
esl_opt_DisplayHelp(stdout, go, 9, 2, 80); |
| 673 |
puts("\nexpert options related to consensus sequence definition:"); |
| 674 |
esl_opt_DisplayHelp(stdout, go, 7, 2, 80); |
| 675 |
puts("\nexpert options controlling style of masked positions:"); |
| 676 |
esl_opt_DisplayHelp(stdout, go, 4, 2, 80); |
| 677 |
puts("\nexpert options related to input files:"); |
| 678 |
esl_opt_DisplayHelp(stdout, go, 6, 2, 80); |
| 679 |
exit(0); |
| 680 |
} |
| 681 |
|
| 682 |
if (esl_opt_ArgNumber(go) != 3) |
| 683 |
{ |
| 684 |
printf("Incorrect number of command line arguments.\n"); |
| 685 |
esl_usage(stdout, argv[0], usage); |
| 686 |
printf("\nTo see more help on available options, do %s -h\n\n", argv[0]); |
| 687 |
exit(1); |
| 688 |
} |
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
if (esl_opt_IsOn(go, "--mask-a") && (! esl_opt_IsOn(go, "--mask-u")) && (! esl_opt_IsOn(go, "--mask-x"))) { |
| 693 |
esl_fatal("--mask-a requires either --mask-u or mask-x"); |
| 694 |
} |
| 695 |
|
| 696 |
alifile = esl_opt_GetArg(go, 1); |
| 697 |
templatefile = esl_opt_GetArg(go, 2); |
| 698 |
outfile = esl_opt_GetArg(go, 3); |
| 699 |
|
| 700 |
if((status = get_command(go, errbuf, &command)) != eslOK) esl_fatal(errbuf); |
| 701 |
if((status = get_date(errbuf, &date)) != eslOK) esl_fatal(errbuf); |
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
ESL_ALLOC(hc_onecell, sizeof(float *) * NOC); |
| 708 |
for(z = 0; z < NOC; z++) hc_onecell[z] = NULL; |
| 709 |
for(z = 0; z < NOC; z++) { ESL_ALLOC(hc_onecell[z], sizeof(float) * NCMYK); } |
| 710 |
|
| 711 |
hc_onecell[CYANOC][ICYAN] = CYAN_C; |
| 712 |
hc_onecell[CYANOC][IMGTA] = CYAN_M; |
| 713 |
hc_onecell[CYANOC][IYELW] = CYAN_Y; |
| 714 |
hc_onecell[CYANOC][IBLCK] = CYAN_K; |
| 715 |
|
| 716 |
hc_onecell[MAGENTAOC][ICYAN] = MAGENTA_C; |
| 717 |
hc_onecell[MAGENTAOC][IMGTA] = MAGENTA_M; |
| 718 |
hc_onecell[MAGENTAOC][IYELW] = MAGENTA_Y; |
| 719 |
hc_onecell[MAGENTAOC][IBLCK] = MAGENTA_K; |
| 720 |
|
| 721 |
hc_onecell[YELLOWOC][ICYAN] = YELLOW_C; |
| 722 |
hc_onecell[YELLOWOC][IMGTA] = YELLOW_M; |
| 723 |
hc_onecell[YELLOWOC][IYELW] = YELLOW_Y; |
| 724 |
hc_onecell[YELLOWOC][IBLCK] = YELLOW_K; |
| 725 |
|
| 726 |
hc_onecell[BLACKOC][ICYAN] = BLACK_C; |
| 727 |
hc_onecell[BLACKOC][IMGTA] = BLACK_M; |
| 728 |
hc_onecell[BLACKOC][IYELW] = BLACK_Y; |
| 729 |
hc_onecell[BLACKOC][IBLCK] = BLACK_K; |
| 730 |
|
| 731 |
hc_onecell[WHITEOC][ICYAN] = WHITE_C; |
| 732 |
hc_onecell[WHITEOC][IMGTA] = WHITE_M; |
| 733 |
hc_onecell[WHITEOC][IYELW] = WHITE_Y; |
| 734 |
hc_onecell[WHITEOC][IBLCK] = WHITE_K; |
| 735 |
|
| 736 |
hc_onecell[LIGHTGREYOC][ICYAN] = LIGHTGREY_C; |
| 737 |
hc_onecell[LIGHTGREYOC][IMGTA] = LIGHTGREY_M; |
| 738 |
hc_onecell[LIGHTGREYOC][IYELW] = LIGHTGREY_Y; |
| 739 |
hc_onecell[LIGHTGREYOC][IBLCK] = LIGHTGREY_K; |
| 740 |
|
| 741 |
hc_onecell[GREYOC][ICYAN] = GREY_C; |
| 742 |
hc_onecell[GREYOC][IMGTA] = GREY_M; |
| 743 |
hc_onecell[GREYOC][IYELW] = GREY_Y; |
| 744 |
hc_onecell[GREYOC][IBLCK] = GREY_K; |
| 745 |
|
| 746 |
hc_onecell[DARKGREYOC][ICYAN] = DARKGREY_C; |
| 747 |
hc_onecell[DARKGREYOC][IMGTA] = DARKGREY_M; |
| 748 |
hc_onecell[DARKGREYOC][IYELW] = DARKGREY_Y; |
| 749 |
hc_onecell[DARKGREYOC][IBLCK] = DARKGREY_K; |
| 750 |
|
| 751 |
hc_onecell[REDOC][ICYAN] = RED_C; |
| 752 |
hc_onecell[REDOC][IMGTA] = RED_M; |
| 753 |
hc_onecell[REDOC][IYELW] = RED_Y; |
| 754 |
hc_onecell[REDOC][IBLCK] = RED_K; |
| 755 |
|
| 756 |
hc_onecell[ORANGEOC][ICYAN] = ORANGE_C; |
| 757 |
hc_onecell[ORANGEOC][IMGTA] = ORANGE_M; |
| 758 |
hc_onecell[ORANGEOC][IYELW] = ORANGE_Y; |
| 759 |
hc_onecell[ORANGEOC][IBLCK] = ORANGE_K; |
| 760 |
|
| 761 |
hc_onecell[TEALOC][ICYAN] = TEAL_C; |
| 762 |
hc_onecell[TEALOC][IMGTA] = TEAL_M; |
| 763 |
hc_onecell[TEALOC][IYELW] = TEAL_Y; |
| 764 |
hc_onecell[TEALOC][IBLCK] = TEAL_K; |
| 765 |
|
| 766 |
hc_onecell[LIGHTGREENOC][ICYAN] = LIGHTGREEN_C; |
| 767 |
hc_onecell[LIGHTGREENOC][IMGTA] = LIGHTGREEN_M; |
| 768 |
hc_onecell[LIGHTGREENOC][IYELW] = LIGHTGREEN_Y; |
| 769 |
hc_onecell[LIGHTGREENOC][IBLCK] = LIGHTGREEN_K; |
| 770 |
|
| 771 |
hc_onecell[GREENOC][ICYAN] = GREEN_C; |
| 772 |
hc_onecell[GREENOC][IMGTA] = GREEN_M; |
| 773 |
hc_onecell[GREENOC][IYELW] = GREEN_Y; |
| 774 |
hc_onecell[GREENOC][IBLCK] = GREEN_K; |
| 775 |
|
| 776 |
hc_onecell[DARKGREENOC][ICYAN] = DARKGREEN_C; |
| 777 |
hc_onecell[DARKGREENOC][IMGTA] = DARKGREEN_M; |
| 778 |
hc_onecell[DARKGREENOC][IYELW] = DARKGREEN_Y; |
| 779 |
hc_onecell[DARKGREENOC][IBLCK] = DARKGREEN_K; |
| 780 |
|
| 781 |
hc_onecell[LIGHTPURPLEOC][ICYAN] = LIGHTPURPLE_C; |
| 782 |
hc_onecell[LIGHTPURPLEOC][IMGTA] = LIGHTPURPLE_M; |
| 783 |
hc_onecell[LIGHTPURPLEOC][IYELW] = LIGHTPURPLE_Y; |
| 784 |
hc_onecell[LIGHTPURPLEOC][IBLCK] = LIGHTPURPLE_K; |
| 785 |
|
| 786 |
hc_onecell[PURPLEOC][ICYAN] = PURPLE_C; |
| 787 |
hc_onecell[PURPLEOC][IMGTA] = PURPLE_M; |
| 788 |
hc_onecell[PURPLEOC][IYELW] = PURPLE_Y; |
| 789 |
hc_onecell[PURPLEOC][IBLCK] = PURPLE_K; |
| 790 |
|
| 791 |
hc_onecell[DARKPURPLEOC][ICYAN] = DARKPURPLE_C; |
| 792 |
hc_onecell[DARKPURPLEOC][IMGTA] = DARKPURPLE_M; |
| 793 |
hc_onecell[DARKPURPLEOC][IYELW] = DARKPURPLE_Y; |
| 794 |
hc_onecell[DARKPURPLEOC][IBLCK] = DARKPURPLE_K; |
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
ESL_ALLOC(hc_scheme, sizeof(float **) * NSCHEMES); |
| 799 |
for (z = 0; z < NSCHEMES; z++) hc_scheme[z] = NULL; |
| 800 |
|
| 801 |
ESL_ALLOC(hc_nbins, sizeof(int) * NSCHEMES); |
| 802 |
hc_nbins[RB_11_RH_SCHEME] = NRB_11_RH_SCHEME; |
| 803 |
hc_nbins[RB_11_RL_SCHEME] = NRB_11_RL_SCHEME; |
| 804 |
hc_nbins[RB_6_RH_SCHEME] = NRB_6_RH_SCHEME; |
| 805 |
hc_nbins[RB_6_RL_SCHEME] = NRB_6_RL_SCHEME; |
| 806 |
hc_nbins[RB_5_RH_SCHEME] = NRB_5_RH_SCHEME; |
| 807 |
hc_nbins[RB_5_RL_SCHEME] = NRB_5_RL_SCHEME; |
| 808 |
hc_nbins[RB_W5_OH_SCHEME] = NRB_W5_OH_SCHEME; |
| 809 |
|
| 810 |
|
| 811 |
ESL_ALLOC(hc_scheme[RB_11_RH_SCHEME], sizeof(float *) * NRB_11_RH_SCHEME); |
| 812 |
for(z = 0; z < NRB_11_RH_SCHEME; z++) hc_scheme[RB_11_RH_SCHEME][z] = NULL; |
| 813 |
for(z = 0; z < NRB_11_RH_SCHEME; z++) { ESL_ALLOC(hc_scheme[RB_11_RH_SCHEME][z], sizeof(float) * NCMYK); } |
| 814 |
|
| 815 |
|
| 816 |
ESL_ALLOC(hc_scheme[RB_11_RL_SCHEME], sizeof(float *) * NRB_11_RL_SCHEME); |
| 817 |
for(z = 0; z < NRB_11_RL_SCHEME; z++) hc_scheme[RB_11_RL_SCHEME][z] = NULL; |
| 818 |
for(z = 0; z < NRB_11_RL_SCHEME; z++) { ESL_ALLOC(hc_scheme[RB_11_RL_SCHEME][z], sizeof(float) * NCMYK); } |
| 819 |
|
| 820 |
|
| 821 |
ESL_ALLOC(hc_scheme[RB_6_RH_SCHEME], sizeof(float *) * NRB_6_RH_SCHEME); |
| 822 |
for(z = 0; z < NRB_6_RH_SCHEME; z++) hc_scheme[RB_6_RH_SCHEME][z] = NULL; |
| 823 |
for(z = 0; z < NRB_6_RH_SCHEME; z++) { ESL_ALLOC(hc_scheme[RB_6_RH_SCHEME][z], sizeof(float) * NCMYK); } |
| 824 |
|
| 825 |
|
| 826 |
ESL_ALLOC(hc_scheme[RB_6_RL_SCHEME], sizeof(float *) * NRB_6_RL_SCHEME); |
| 827 |
for(z = 0; z < NRB_6_RL_SCHEME; z++) hc_scheme[RB_6_RL_SCHEME][z] = NULL; |
| 828 |
for(z = 0; z < NRB_6_RL_SCHEME; z++) { ESL_ALLOC(hc_scheme[RB_6_RL_SCHEME][z], sizeof(float) * NCMYK); } |
| 829 |
|
| 830 |
|
| 831 |
ESL_ALLOC(hc_scheme[RB_5_RH_SCHEME], sizeof(float *) * NRB_5_RH_SCHEME); |
| 832 |
for(z = 0; z < NRB_5_RH_SCHEME; z++) hc_scheme[RB_5_RH_SCHEME][z] = NULL; |
| 833 |
for(z = 0; z < NRB_5_RH_SCHEME; z++) { ESL_ALLOC(hc_scheme[RB_5_RH_SCHEME][z], sizeof(float) * NCMYK); } |
| 834 |
|
| 835 |
|
| 836 |
ESL_ALLOC(hc_scheme[RB_5_RL_SCHEME], sizeof(float *) * NRB_5_RL_SCHEME); |
| 837 |
for(z = 0; z < NRB_5_RL_SCHEME; z++) hc_scheme[RB_5_RL_SCHEME][z] = NULL; |
| 838 |
for(z = 0; z < NRB_5_RL_SCHEME; z++) { ESL_ALLOC(hc_scheme[RB_5_RL_SCHEME][z], sizeof(float) * NCMYK); } |
| 839 |
|
| 840 |
|
| 841 |
ESL_ALLOC(hc_scheme[RB_W5_OH_SCHEME], sizeof(float *) * NRB_W5_OH_SCHEME); |
| 842 |
for(z = 0; z < NRB_W5_OH_SCHEME; z++) hc_scheme[RB_W5_OH_SCHEME][z] = NULL; |
| 843 |
for(z = 0; z < NRB_W5_OH_SCHEME; z++) { ESL_ALLOC(hc_scheme[RB_W5_OH_SCHEME][z], sizeof(float) * NCMYK); } |
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
hc_scheme[RB_6_RL_SCHEME][0][ICYAN] = hc_scheme[RB_6_RH_SCHEME][5][ICYAN] = hc_scheme[RB_5_RL_SCHEME][0][ICYAN] = hc_scheme[RB_5_RL_SCHEME][4][ICYAN] = RED2BLUE_1_OF_6_C; |
| 850 |
hc_scheme[RB_6_RL_SCHEME][0][IMGTA] = hc_scheme[RB_6_RH_SCHEME][5][IMGTA] = hc_scheme[RB_5_RL_SCHEME][0][IMGTA] = hc_scheme[RB_5_RL_SCHEME][4][IMGTA] = RED2BLUE_1_OF_6_M; |
| 851 |
hc_scheme[RB_6_RL_SCHEME][0][IYELW] = hc_scheme[RB_6_RH_SCHEME][5][IYELW] = hc_scheme[RB_5_RL_SCHEME][0][IYELW] = hc_scheme[RB_5_RL_SCHEME][4][IYELW] = RED2BLUE_1_OF_6_Y; |
| 852 |
hc_scheme[RB_6_RL_SCHEME][0][IBLCK] = hc_scheme[RB_6_RH_SCHEME][5][IBLCK] = hc_scheme[RB_5_RL_SCHEME][0][IBLCK] = hc_scheme[RB_5_RL_SCHEME][4][IBLCK] = RED2BLUE_1_OF_6_K; |
| 853 |
|
| 854 |
hc_scheme[RB_6_RL_SCHEME][1][ICYAN] = hc_scheme[RB_6_RH_SCHEME][4][ICYAN] = hc_scheme[RB_5_RL_SCHEME][1][ICYAN] = hc_scheme[RB_5_RL_SCHEME][3][ICYAN] = RED2BLUE_2_OF_6_C; |
| 855 |
hc_scheme[RB_6_RL_SCHEME][1][IMGTA] = hc_scheme[RB_6_RH_SCHEME][4][IMGTA] = hc_scheme[RB_5_RL_SCHEME][1][IMGTA] = hc_scheme[RB_5_RL_SCHEME][3][IMGTA] = RED2BLUE_2_OF_6_M; |
| 856 |
hc_scheme[RB_6_RL_SCHEME][1][IYELW] = hc_scheme[RB_6_RH_SCHEME][4][IYELW] = hc_scheme[RB_5_RL_SCHEME][1][IYELW] = hc_scheme[RB_5_RL_SCHEME][3][IYELW] = RED2BLUE_2_OF_6_Y; |
| 857 |
hc_scheme[RB_6_RL_SCHEME][1][IBLCK] = hc_scheme[RB_6_RH_SCHEME][4][IBLCK] = hc_scheme[RB_5_RL_SCHEME][1][IBLCK] = hc_scheme[RB_5_RL_SCHEME][3][IBLCK] = RED2BLUE_2_OF_6_K; |
| 858 |
|
| 859 |
hc_scheme[RB_6_RL_SCHEME][2][ICYAN] = hc_scheme[RB_6_RH_SCHEME][3][ICYAN] = hc_scheme[RB_5_RL_SCHEME][2][ICYAN] = RED2BLUE_3_OF_6_C; |
| 860 |
hc_scheme[RB_6_RL_SCHEME][2][IMGTA] = hc_scheme[RB_6_RH_SCHEME][3][IMGTA] = hc_scheme[RB_5_RL_SCHEME][2][IMGTA] = RED2BLUE_3_OF_6_M; |
| 861 |
hc_scheme[RB_6_RL_SCHEME][2][IYELW] = hc_scheme[RB_6_RH_SCHEME][3][IYELW] = hc_scheme[RB_5_RL_SCHEME][2][IYELW] = RED2BLUE_3_OF_6_Y; |
| 862 |
hc_scheme[RB_6_RL_SCHEME][2][IBLCK] = hc_scheme[RB_6_RH_SCHEME][3][IBLCK] = hc_scheme[RB_5_RL_SCHEME][2][IBLCK] = RED2BLUE_3_OF_6_K; |
| 863 |
|
| 864 |
hc_scheme[RB_6_RL_SCHEME][3][ICYAN] = hc_scheme[RB_6_RH_SCHEME][2][ICYAN] = hc_scheme[RB_5_RL_SCHEME][3][ICYAN] = hc_scheme[RB_5_RL_SCHEME][1][ICYAN] = RED2BLUE_4_OF_6_C; |
| 865 |
hc_scheme[RB_6_RL_SCHEME][3][IMGTA] = hc_scheme[RB_6_RH_SCHEME][2][IMGTA] = hc_scheme[RB_5_RL_SCHEME][3][IMGTA] = hc_scheme[RB_5_RL_SCHEME][1][IMGTA] = RED2BLUE_4_OF_6_M; |
| 866 |
hc_scheme[RB_6_RL_SCHEME][3][IYELW] = hc_scheme[RB_6_RH_SCHEME][2][IYELW] = hc_scheme[RB_5_RL_SCHEME][3][IYELW] = hc_scheme[RB_5_RL_SCHEME][1][IYELW] = RED2BLUE_4_OF_6_Y; |
| 867 |
hc_scheme[RB_6_RL_SCHEME][3][IBLCK] = hc_scheme[RB_6_RH_SCHEME][2][IBLCK] = hc_scheme[RB_5_RL_SCHEME][3][IBLCK] = hc_scheme[RB_5_RL_SCHEME][1][IBLCK] = RED2BLUE_4_OF_6_K; |
| 868 |
|
| 869 |
hc_scheme[RB_6_RL_SCHEME][4][ICYAN] = hc_scheme[RB_6_RH_SCHEME][1][ICYAN] = hc_scheme[RB_5_RL_SCHEME][4][ICYAN] = hc_scheme[RB_5_RL_SCHEME][0][ICYAN] = RED2BLUE_5_OF_6_C; |
| 870 |
hc_scheme[RB_6_RL_SCHEME][4][IMGTA] = hc_scheme[RB_6_RH_SCHEME][1][IMGTA] = hc_scheme[RB_5_RL_SCHEME][4][IMGTA] = hc_scheme[RB_5_RL_SCHEME][0][IMGTA] = RED2BLUE_5_OF_6_M; |
| 871 |
hc_scheme[RB_6_RL_SCHEME][4][IYELW] = hc_scheme[RB_6_RH_SCHEME][1][IYELW] = hc_scheme[RB_5_RL_SCHEME][4][IYELW] = hc_scheme[RB_5_RL_SCHEME][0][IYELW] = RED2BLUE_5_OF_6_Y; |
| 872 |
hc_scheme[RB_6_RL_SCHEME][4][IBLCK] = hc_scheme[RB_6_RH_SCHEME][1][IBLCK] = hc_scheme[RB_5_RL_SCHEME][4][IBLCK] = hc_scheme[RB_5_RL_SCHEME][0][IBLCK] = RED2BLUE_5_OF_6_K; |
| 873 |
|
| 874 |
hc_scheme[RB_6_RL_SCHEME][5][ICYAN] = hc_scheme[RB_6_RH_SCHEME][0][ICYAN] = RED2BLUE_6_OF_6_C; |
| 875 |
hc_scheme[RB_6_RL_SCHEME][5][IMGTA] = hc_scheme[RB_6_RH_SCHEME][0][IMGTA] = RED2BLUE_6_OF_6_M; |
| 876 |
hc_scheme[RB_6_RL_SCHEME][5][IYELW] = hc_scheme[RB_6_RH_SCHEME][0][IYELW] = RED2BLUE_6_OF_6_Y; |
| 877 |
hc_scheme[RB_6_RL_SCHEME][5][IBLCK] = hc_scheme[RB_6_RH_SCHEME][0][IBLCK] = RED2BLUE_6_OF_6_K; |
| 878 |
|
| 879 |
|
| 880 |
hc_scheme[RB_W5_OH_SCHEME][0][ICYAN] = WHITE_C; |
| 881 |
hc_scheme[RB_W5_OH_SCHEME][0][IMGTA] = WHITE_M; |
| 882 |
hc_scheme[RB_W5_OH_SCHEME][0][IYELW] = WHITE_Y; |
| 883 |
hc_scheme[RB_W5_OH_SCHEME][0][IBLCK] = WHITE_K; |
| 884 |
|
| 885 |
hc_scheme[RB_W5_OH_SCHEME][1][ICYAN] = RED2BLUE_5_OF_6_C; |
| 886 |
hc_scheme[RB_W5_OH_SCHEME][1][IMGTA] = RED2BLUE_5_OF_6_M; |
| 887 |
hc_scheme[RB_W5_OH_SCHEME][1][IYELW] = RED2BLUE_5_OF_6_Y; |
| 888 |
hc_scheme[RB_W5_OH_SCHEME][1][IBLCK] = RED2BLUE_5_OF_6_K; |
| 889 |
|
| 890 |
hc_scheme[RB_W5_OH_SCHEME][2][ICYAN] = RED2BLUE_4_OF_6_C; |
| 891 |
hc_scheme[RB_W5_OH_SCHEME][2][IMGTA] = RED2BLUE_4_OF_6_M; |
| 892 |
hc_scheme[RB_W5_OH_SCHEME][2][IYELW] = RED2BLUE_4_OF_6_Y; |
| 893 |
hc_scheme[RB_W5_OH_SCHEME][2][IBLCK] = RED2BLUE_4_OF_6_K; |
| 894 |
|
| 895 |
hc_scheme[RB_W5_OH_SCHEME][3][ICYAN] = RED2BLUE_3_OF_6_C; |
| 896 |
hc_scheme[RB_W5_OH_SCHEME][3][IMGTA] = RED2BLUE_3_OF_6_M; |
| 897 |
hc_scheme[RB_W5_OH_SCHEME][3][IYELW] = RED2BLUE_3_OF_6_Y; |
| 898 |
hc_scheme[RB_W5_OH_SCHEME][3][IBLCK] = RED2BLUE_3_OF_6_K; |
| 899 |
|
| 900 |
hc_scheme[RB_W5_OH_SCHEME][4][ICYAN] = RED2BLUE_2_OF_6_C; |
| 901 |
hc_scheme[RB_W5_OH_SCHEME][4][IMGTA] = RED2BLUE_2_OF_6_M; |
| 902 |
hc_scheme[RB_W5_OH_SCHEME][4][IYELW] = RED2BLUE_2_OF_6_Y; |
| 903 |
hc_scheme[RB_W5_OH_SCHEME][4][IBLCK] = RED2BLUE_2_OF_6_K; |
| 904 |
|
| 905 |
|
| 906 |
hc_scheme[RB_11_RL_SCHEME][0][ICYAN] = hc_scheme[RB_11_RH_SCHEME][10][ICYAN] = RED2BLUE_1_OF_11_C; |
| 907 |
hc_scheme[RB_11_RL_SCHEME][0][IMGTA] = hc_scheme[RB_11_RH_SCHEME][10][IMGTA] = RED2BLUE_1_OF_11_M; |
| 908 |
hc_scheme[RB_11_RL_SCHEME][0][IYELW] = hc_scheme[RB_11_RH_SCHEME][10][IYELW] = RED2BLUE_1_OF_11_Y; |
| 909 |
hc_scheme[RB_11_RL_SCHEME][0][IBLCK] = hc_scheme[RB_11_RH_SCHEME][10][IBLCK] = RED2BLUE_1_OF_11_K; |
| 910 |
|
| 911 |
hc_scheme[RB_11_RL_SCHEME][1][ICYAN] = hc_scheme[RB_11_RH_SCHEME][9][ICYAN] = RED2BLUE_2_OF_11_C; |
| 912 |
hc_scheme[RB_11_RL_SCHEME][1][IMGTA] = hc_scheme[RB_11_RH_SCHEME][9][IMGTA] = RED2BLUE_2_OF_11_M; |
| 913 |
hc_scheme[RB_11_RL_SCHEME][1][IYELW] = hc_scheme[RB_11_RH_SCHEME][9][IYELW] = RED2BLUE_2_OF_11_Y; |
| 914 |
hc_scheme[RB_11_RL_SCHEME][1][IBLCK] = hc_scheme[RB_11_RH_SCHEME][9][IBLCK] = RED2BLUE_2_OF_11_K; |
| 915 |
|
| 916 |
hc_scheme[RB_11_RL_SCHEME][2][ICYAN] = hc_scheme[RB_11_RH_SCHEME][8][ICYAN] = RED2BLUE_3_OF_11_C; |
| 917 |
hc_scheme[RB_11_RL_SCHEME][2][IMGTA] = hc_scheme[RB_11_RH_SCHEME][8][IMGTA] = RED2BLUE_3_OF_11_M; |
| 918 |
hc_scheme[RB_11_RL_SCHEME][2][IYELW] = hc_scheme[RB_11_RH_SCHEME][8][IYELW] = RED2BLUE_3_OF_11_Y; |
| 919 |
hc_scheme[RB_11_RL_SCHEME][2][IBLCK] = hc_scheme[RB_11_RH_SCHEME][8][IBLCK] = RED2BLUE_3_OF_11_K; |
| 920 |
|
| 921 |
hc_scheme[RB_11_RL_SCHEME][3][ICYAN] = hc_scheme[RB_11_RH_SCHEME][7][ICYAN] = RED2BLUE_4_OF_11_C; |
| 922 |
hc_scheme[RB_11_RL_SCHEME][3][IMGTA] = hc_scheme[RB_11_RH_SCHEME][7][IMGTA] = RED2BLUE_4_OF_11_M; |
| 923 |
hc_scheme[RB_11_RL_SCHEME][3][IYELW] = hc_scheme[RB_11_RH_SCHEME][7][IYELW] = RED2BLUE_4_OF_11_Y; |
| 924 |
hc_scheme[RB_11_RL_SCHEME][3][IBLCK] = hc_scheme[RB_11_RH_SCHEME][7][IBLCK] = RED2BLUE_4_OF_11_K; |
| 925 |
|
| 926 |
hc_scheme[RB_11_RL_SCHEME][4][ICYAN] = hc_scheme[RB_11_RH_SCHEME][6][ICYAN] = RED2BLUE_5_OF_11_C; |
| 927 |
hc_scheme[RB_11_RL_SCHEME][4][IMGTA] = hc_scheme[RB_11_RH_SCHEME][6][IMGTA] = RED2BLUE_5_OF_11_M; |
| 928 |
hc_scheme[RB_11_RL_SCHEME][4][IYELW] = hc_scheme[RB_11_RH_SCHEME][6][IYELW] = RED2BLUE_5_OF_11_Y; |
| 929 |
hc_scheme[RB_11_RL_SCHEME][4][IBLCK] = hc_scheme[RB_11_RH_SCHEME][6][IBLCK] = RED2BLUE_5_OF_11_K; |
| 930 |
|
| 931 |
hc_scheme[RB_11_RL_SCHEME][5][ICYAN] = hc_scheme[RB_11_RH_SCHEME][5][ICYAN] = RED2BLUE_6_OF_11_C; |
| 932 |
hc_scheme[RB_11_RL_SCHEME][5][IMGTA] = hc_scheme[RB_11_RH_SCHEME][5][IMGTA] = RED2BLUE_6_OF_11_M; |
| 933 |
hc_scheme[RB_11_RL_SCHEME][5][IYELW] = hc_scheme[RB_11_RH_SCHEME][5][IYELW] = RED2BLUE_6_OF_11_Y; |
| 934 |
hc_scheme[RB_11_RL_SCHEME][5][IBLCK] = hc_scheme[RB_11_RH_SCHEME][5][IBLCK] = RED2BLUE_6_OF_11_K; |
| 935 |
|
| 936 |
hc_scheme[RB_11_RL_SCHEME][6][ICYAN] = hc_scheme[RB_11_RH_SCHEME][4][ICYAN] = RED2BLUE_7_OF_11_C; |
| 937 |
hc_scheme[RB_11_RL_SCHEME][6][IMGTA] = hc_scheme[RB_11_RH_SCHEME][4][IMGTA] = RED2BLUE_7_OF_11_M; |
| 938 |
hc_scheme[RB_11_RL_SCHEME][6][IYELW] = hc_scheme[RB_11_RH_SCHEME][4][IYELW] = RED2BLUE_7_OF_11_Y; |
| 939 |
hc_scheme[RB_11_RL_SCHEME][6][IBLCK] = hc_scheme[RB_11_RH_SCHEME][4][IBLCK] = RED2BLUE_7_OF_11_K; |
| 940 |
|
| 941 |
hc_scheme[RB_11_RL_SCHEME][7][ICYAN] = hc_scheme[RB_11_RH_SCHEME][3][ICYAN] = RED2BLUE_8_OF_11_C; |
| 942 |
hc_scheme[RB_11_RL_SCHEME][7][IMGTA] = hc_scheme[RB_11_RH_SCHEME][3][IMGTA] = RED2BLUE_8_OF_11_M; |
| 943 |
hc_scheme[RB_11_RL_SCHEME][7][IYELW] = hc_scheme[RB_11_RH_SCHEME][3][IYELW] = RED2BLUE_8_OF_11_Y; |
| 944 |
hc_scheme[RB_11_RL_SCHEME][7][IBLCK] = hc_scheme[RB_11_RH_SCHEME][3][IBLCK] = RED2BLUE_8_OF_11_K; |
| 945 |
|
| 946 |
hc_scheme[RB_11_RL_SCHEME][8][ICYAN] = hc_scheme[RB_11_RH_SCHEME][2][ICYAN] = RED2BLUE_9_OF_11_C; |
| 947 |
hc_scheme[RB_11_RL_SCHEME][8][IMGTA] = hc_scheme[RB_11_RH_SCHEME][2][IMGTA] = RED2BLUE_9_OF_11_M; |
| 948 |
hc_scheme[RB_11_RL_SCHEME][8][IYELW] = hc_scheme[RB_11_RH_SCHEME][2][IYELW] = RED2BLUE_9_OF_11_Y; |
| 949 |
hc_scheme[RB_11_RL_SCHEME][8][IBLCK] = hc_scheme[RB_11_RH_SCHEME][2][IBLCK] = RED2BLUE_9_OF_11_K; |
| 950 |
|
| 951 |
hc_scheme[RB_11_RL_SCHEME][9][ICYAN] = hc_scheme[RB_11_RH_SCHEME][1][ICYAN] = RED2BLUE_10_OF_11_C; |
| 952 |
hc_scheme[RB_11_RL_SCHEME][9][IMGTA] = hc_scheme[RB_11_RH_SCHEME][1][IMGTA] = RED2BLUE_10_OF_11_M; |
| 953 |
hc_scheme[RB_11_RL_SCHEME][9][IYELW] = hc_scheme[RB_11_RH_SCHEME][1][IYELW] = RED2BLUE_10_OF_11_Y; |
| 954 |
hc_scheme[RB_11_RL_SCHEME][9][IBLCK] = hc_scheme[RB_11_RH_SCHEME][1][IBLCK] = RED2BLUE_10_OF_11_K; |
| 955 |
|
| 956 |
hc_scheme[RB_11_RL_SCHEME][10][ICYAN] = hc_scheme[RB_11_RH_SCHEME][0][ICYAN] = RED2BLUE_11_OF_11_C; |
| 957 |
hc_scheme[RB_11_RL_SCHEME][10][IMGTA] = hc_scheme[RB_11_RH_SCHEME][0][IMGTA] = RED2BLUE_11_OF_11_M; |
| 958 |
hc_scheme[RB_11_RL_SCHEME][10][IYELW] = hc_scheme[RB_11_RH_SCHEME][0][IYELW] = RED2BLUE_11_OF_11_Y; |
| 959 |
hc_scheme[RB_11_RL_SCHEME][10][IBLCK] = hc_scheme[RB_11_RH_SCHEME][0][IBLCK] = RED2BLUE_11_OF_11_K; |
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
do_small = esl_opt_GetBoolean(go, "--small") ? TRUE : FALSE; |
| 966 |
fmt = do_small ? eslMSAFILE_PFAM : eslMSAFILE_STOCKHOLM; |
| 967 |
abc = esl_alphabet_Create(eslRNA); |
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
if (do_small) |
| 974 |
{ |
| 975 |
status = esl_msafile2_Open(alifile, NULL, &afp2); |
| 976 |
if (status == eslENOTFOUND) esl_fatal("Alignment file %s doesn't exist or is not readable\n", alifile); |
| 977 |
else if (status != eslOK) esl_fatal("Alignment file open failed with error %d\n", status); |
| 978 |
} |
| 979 |
else |
| 980 |
{ |
| 981 |
status = esl_msafile_Open(NULL, alifile, NULL, fmt, NULL, &afp); |
| 982 |
if (status != eslOK) esl_msafile_OpenFailure(afp, status); |
| 983 |
} |
| 984 |
|
| 985 |
|
| 986 |
if(esl_opt_IsOn(go, "--mask")) { |
| 987 |
if((status = read_mask_file(esl_opt_GetString(go, "--mask"), errbuf, &mask, &masklen, &mask_has_internal_zeroes)) != eslOK) esl_fatal(errbuf); |
| 988 |
} |
| 989 |
if(esl_opt_IsOn(go, "--mask-diff")) { |
| 990 |
if((status = read_mask_file(esl_opt_GetString(go, "--mask-diff"), errbuf, &mask2, &mask2len, &mask2_has_internal_zeroes)) != eslOK) esl_fatal(errbuf); |
| 991 |
if(masklen != mask2len) esl_fatal("Mask in %f length (%d) differs from mask in %f (%d)!", esl_opt_GetString(go, "--mask"), masklen, esl_opt_GetString(go, "--mask-diff"), mask2len); |
| 992 |
} |
| 993 |
|
| 994 |
|
| 995 |
if (esl_opt_IsOn(go, "--tabfile")) { |
| 996 |
if((tabfp = fopen(esl_opt_GetString(go, "--tabfile"), "w")) == NULL) esl_fatal("Failed to open output file %s\n", esl_opt_GetString(go, "--tabfile")); |
| 997 |
} |
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
if (do_small) |
| 1003 |
{ |
| 1004 |
status = esl_msafile2_ReadInfoPfam(afp2, NULL, abc, -1, NULL, NULL, &msa, &msa_nseq, &msa_alen, NULL, NULL, NULL, NULL, NULL, &abc_ct, &pp_ct, NULL, NULL, NULL); |
| 1005 |
if (status == eslEFORMAT) esl_fatal("Alignment file parse error:\n%s\n", afp2->errbuf); |
| 1006 |
else if (status == eslEINVAL) esl_fatal("Alignment file parse error:\n%s\n", afp2->errbuf); |
| 1007 |
else if (status == eslEOF) esl_fatal("No alignments found in file %s\n", alifile); |
| 1008 |
else if (status != eslOK) esl_fatal("Alignment file read failed with error code %d\n%s", status, afp2); |
| 1009 |
|
| 1010 |
msa->alen = msa_alen; |
| 1011 |
} |
| 1012 |
else |
| 1013 |
{ |
| 1014 |
status = esl_msafile_Read(afp, &msa); |
| 1015 |
if (status != eslOK) esl_msafile_ReadFailure(afp, status); |
| 1016 |
|
| 1017 |
msa_nseq = msa->nseq; |
| 1018 |
msa_alen = msa->alen; |
| 1019 |
} |
| 1020 |
|
| 1021 |
if(msa->rf == NULL) esl_fatal("First MSA in %s does not have RF annotation.", alifile); |
| 1022 |
|
| 1023 |
|
| 1024 |
rflen = 0; |
| 1025 |
for(apos = 0; apos < msa->alen; apos++) { |
| 1026 |
if(esl_abc_CIsResidue(abc, msa->rf[apos])) { |
| 1027 |
rflen++; |
| 1028 |
} |
| 1029 |
} |
| 1030 |
|
| 1031 |
if((status = parse_template_file(templatefile, go, errbuf, rflen, &ps) != eslOK)) esl_fatal(errbuf); |
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
do_default_set = TRUE; |
| 1045 |
if(esl_opt_GetBoolean(go, "--info")) { do_info = TRUE; do_default_set = FALSE; } |
| 1046 |
if(esl_opt_GetBoolean(go, "--mutinfo")) { do_mutinfo = TRUE; do_default_set = FALSE; } |
| 1047 |
if(esl_opt_GetBoolean(go, "--ifreq")) { do_ifreq = TRUE; do_default_set = FALSE; } |
| 1048 |
if(esl_opt_GetBoolean(go, "--iavglen")) { do_iavglen = TRUE; do_default_set = FALSE; } |
| 1049 |
if(esl_opt_GetBoolean(go, "--dall")) { do_dall = TRUE; do_default_set = FALSE; } |
| 1050 |
if(esl_opt_GetBoolean(go, "--dint")) { do_dint = TRUE; do_default_set = FALSE; } |
| 1051 |
if(esl_opt_GetBoolean(go, "--prob")) { do_prob = TRUE; do_default_set = FALSE; } |
| 1052 |
if(esl_opt_GetBoolean(go, "--span")) { do_span = TRUE; do_default_set = FALSE; } |
| 1053 |
if(esl_opt_GetBoolean(go, "--mask-col")) { do_maskcol = TRUE; do_default_set = FALSE; } |
| 1054 |
if(esl_opt_IsOn (go, "--mask-diff")) { do_maskdiff = TRUE; do_default_set = FALSE; } |
| 1055 |
if(esl_opt_IsOn (go, "--dfile")) { do_dfile = TRUE; do_default_set = FALSE; } |
| 1056 |
if(esl_opt_IsOn (go, "--efile")) { do_efile = TRUE; do_default_set = FALSE; } |
| 1057 |
if(esl_opt_GetBoolean(go, "--cons")) { do_cons = TRUE; do_default_set = FALSE; } |
| 1058 |
if(esl_opt_GetBoolean(go, "--rf")) { |
| 1059 |
if(msa->rf == NULL) esl_fatal("--rf selected by msa does not have #=GC RF annotation"); |
| 1060 |
do_rf = TRUE; |
| 1061 |
do_default_set = FALSE; |
| 1062 |
} |
| 1063 |
if(esl_opt_GetBoolean(go, "--indi")) { |
| 1064 |
do_indi = TRUE; |
| 1065 |
do_default_set = FALSE; |
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
predicted_Mb = (int) (ps->rflen * 0.0002 * msa_nseq); |
| 1070 |
if(! esl_opt_GetBoolean(go, "--no-pp")) predicted_Mb *= 2; |
| 1071 |
|
| 1072 |
tmp_Mb = 10; while(tmp_Mb < predicted_Mb) tmp_Mb += 10; |
| 1073 |
predicted_Mb = tmp_Mb; |
| 1074 |
if(predicted_Mb > MAXMBWITHOUTFORCE && (! esl_opt_GetBoolean(go, "-f"))) { |
| 1075 |
esl_fatal("WARNING: drawing individual seqs and msa has %d seqs in it,\noutput postcript file will be large (~%d Mb).\nUse -f to override this warning and do it anyway.", msa_nseq, predicted_Mb); |
| 1076 |
} |
| 1077 |
} |
| 1078 |
|
| 1079 |
if(esl_opt_GetBoolean(go, "-d")) do_default_set = TRUE; |
| 1080 |
if(do_default_set) { |
| 1081 |
do_cons = do_info = do_mutinfo = do_ifreq = do_iavglen = do_dall = TRUE; |
| 1082 |
if((do_small && pp_ct != NULL) || (msa->pp != NULL)) do_prob = TRUE; |
| 1083 |
} |
| 1084 |
|
| 1085 |
if(tabfp != NULL && |
| 1086 |
do_info == FALSE && do_mutinfo == FALSE && do_ifreq == FALSE && do_prob == FALSE && |
| 1087 |
do_iavglen == FALSE && do_dall == FALSE && do_dint == FALSE && do_span == FALSE && do_indi == FALSE) { |
| 1088 |
esl_fatal("--tabfile only makes sense w/0 other options, or with >= 1 of --info,--mutinfo,--ifreq,--iavglen,--prob,--dall,--dint,--span,--indi"); |
| 1089 |
} |
| 1090 |
need_span_ct = (do_dint || do_span || do_ifreq || do_iavglen) ? TRUE : FALSE; |
| 1091 |
|
| 1092 |
if(do_small && (do_dint || do_span || do_ifreq || do_iavglen || do_mutinfo)) { |
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
esl_msafile2_Close(afp2); |
| 1100 |
status = esl_msafile2_Open(alifile, NULL, &afp2); |
| 1101 |
if (status == eslENOTFOUND) esl_fatal("2nd pass, alignment file %s doesn't exist or is not readable\n", alifile); |
| 1102 |
else if (status == eslEFORMAT) esl_fatal("2nd pass, couldn't determine format of alignment %s\n", alifile); |
| 1103 |
else if (status != eslOK) esl_fatal("2nd pass, alignment file open failed with error %d\n", status); |
| 1104 |
|
| 1105 |
status = esl_msafile2_ReadInfoPfam(afp2, NULL, abc, msa_alen, msa->rf, msa->ss_cons, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &bp_ct, &spos_ct, &epos_ct); |
| 1106 |
if (status == eslEFORMAT) esl_fatal("2nd pass, Alignment file parse error:\n%s\n", afp2->errbuf); |
| 1107 |
else if (status == eslEINVAL) esl_fatal("2nd pass, Alignment file parse error:\n%s\n", afp2->errbuf); |
| 1108 |
else if (status == eslEOF) esl_fatal("2nd pass, No alignments found in file %s\n", alifile); |
| 1109 |
else if (status != eslOK) esl_fatal("2nd pass, Alignment file read failed with error code %d\n", status); |
| 1110 |
} |
| 1111 |
|
| 1112 |
|
| 1113 |
if(ofp == NULL) { |
| 1114 |
|
| 1115 |
if ((ofp = fopen(outfile, "w")) == NULL) |
| 1116 |
esl_fatal("Failed to open output postscript file %s\n", esl_opt_GetArg(go, 2)); |
| 1117 |
} |
| 1118 |
|
| 1119 |
|
| 1120 |
if((status = setup_sspostscript(ps, errbuf) != eslOK)) esl_fatal(errbuf); |
| 1121 |
if(ps->rflen == 0) esl_fatal("MSA has consensus (non-gap RF) length of %d which != template file consensus length of %d.", rflen, ps->rflen); |
| 1122 |
if(rflen != ps->rflen) esl_fatal("MSA has consensus (non-gap RF) length of %d which != template file consensus length of %d.", rflen, ps->rflen); |
| 1123 |
|
| 1124 |
|
| 1125 |
if(mask != NULL) add_mask_to_ss_postscript(ps, mask); |
| 1126 |
if(mask != NULL && ps->rflen != masklen) esl_fatal("MSA has consensus (non-gap RF) length of %d which != lane mask length of %d from mask file %s.", rflen, masklen, esl_opt_GetString(go, "--mask")); |
| 1127 |
|
| 1128 |
if ((status = validate_and_update_sspostscript_given_msa(go, abc, ps, msa, msa_nseq, errbuf)) != eslOK) esl_fatal(errbuf); |
| 1129 |
|
| 1130 |
|
| 1131 |
if(! do_small) { |
| 1132 |
if((status = count_msa(abc, msa, errbuf, &(abc_ct), &(bp_ct), (do_prob ? &(pp_ct) : NULL), &(spos_ct), &(epos_ct))) != eslOK) esl_fatal(errbuf); |
| 1133 |
} |
| 1134 |
if (esl_opt_GetBoolean(go, "--prob") && pp_ct == NULL) esl_fatal("--prob requires all sequences have PP annotation"); |
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
if(esl_opt_IsOn(go, "--ifile")) { |
| 1140 |
get_insert_info_from_ifile((esl_opt_GetString(go, "--ifile")), ps->rflen, msa_nseq, NULL, &(nseq_with_ins_ct), &(nins_ct), NULL, &srfoff_ct, &erfoff_ct); |
| 1141 |
} |
| 1142 |
|
| 1143 |
if(need_span_ct) { |
| 1144 |
if((status = get_span_ct(ps->msa_rf2a_map, msa_alen, ps->rflen, msa_nseq, spos_ct, epos_ct, srfoff_ct, erfoff_ct, &span_ct)) != eslOK) esl_fatal("Out of memory, getting span_ct array."); |
| 1145 |
} |
| 1146 |
|
| 1147 |
if((status = get_consensus_seqs_from_abc_ct(go, ps, errbuf, abc_ct, abc, msa_alen)) != eslOK) esl_fatal(errbuf); |
| 1148 |
|
| 1149 |
|
| 1150 |
if(do_cons) { |
| 1151 |
|
| 1152 |
if((status = cons_seq_sspostscript(go, errbuf, ps, hc_onecell, |
| 1153 |
BLACKOC, |
| 1154 |
GREENOC, |
| 1155 |
REDOC, |
| 1156 |
LIGHTPURPLEOC, |
| 1157 |
LIGHTPURPLEOC)) != eslOK) |
| 1158 |
esl_fatal(errbuf); |
| 1159 |
} |
| 1160 |
|
| 1161 |
if(do_rf) { |
| 1162 |
|
| 1163 |
if((status = rf_seq_sspostscript(go, errbuf, ps, msa, (! esl_opt_GetBoolean(go, "--no-bp")), hc_onecell, |
| 1164 |
BLACKOC, |
| 1165 |
GREENOC, |
| 1166 |
REDOC)) != eslOK) |
| 1167 |
esl_fatal(errbuf); |
| 1168 |
} |
| 1169 |
|
| 1170 |
if(do_info) { |
| 1171 |
if((status = infocontent_sspostscript(go, abc, errbuf, ps, abc_ct, msa_nseq, hc_scheme, RB_6_RL_SCHEME, hc_nbins[RB_6_RL_SCHEME], hc_onecell, LIGHTGREYOC, tabfp)) != eslOK) esl_fatal(errbuf); |
| 1172 |
} |
| 1173 |
|
| 1174 |
if(do_mutinfo) { |
| 1175 |
if((status = mutual_information_sspostscript(go, abc, errbuf, ps, bp_ct, msa_nseq, hc_scheme, RB_6_RH_SCHEME, hc_nbins[RB_6_RH_SCHEME], hc_onecell, GREYOC, LIGHTGREYOC, tabfp)) != eslOK) esl_fatal(errbuf); |
| 1176 |
} |
| 1177 |
|
| 1178 |
if(do_ifreq || do_iavglen) { |
| 1179 |
|
| 1180 |
if(esl_opt_IsOn(go, "--ifile")) { |
| 1181 |
|
| 1182 |
if(nseq_with_ins_ct == NULL) esl_fatal("Internal error, --ifile selected, but not read"); |
| 1183 |
} |
| 1184 |
else if (do_small) { |
| 1185 |
get_insert_info_from_abc_ct(abc_ct, abc, msa->rf, msa_alen, ps->rflen, &(nseq_with_ins_ct), &(nins_ct)); |
| 1186 |
} |
| 1187 |
else { |
| 1188 |
get_insert_info_from_msa(abc, msa, ps->rflen, &(nseq_with_ins_ct), &(nins_ct), NULL); |
| 1189 |
} |
| 1190 |
|
| 1191 |
if(do_ifreq) { |
| 1192 |
if((status = insertfreq_sspostscript(go, errbuf, ps, nseq_with_ins_ct, span_ct, msa_nseq, hc_scheme, RB_6_RH_SCHEME, hc_nbins[RB_6_RH_SCHEME], hc_onecell, LIGHTGREYOC, GREYOC, tabfp)) != eslOK) esl_fatal(errbuf); |
| 1193 |
} |
| 1194 |
if(do_iavglen) { |
| 1195 |
if((status = insertavglen_sspostscript(go, errbuf, ps, nseq_with_ins_ct, nins_ct, span_ct, msa_nseq, hc_scheme, RB_6_RH_SCHEME, hc_nbins[RB_6_RH_SCHEME], hc_onecell, LIGHTGREYOC, tabfp)) != eslOK) esl_fatal(errbuf); |
| 1196 |
} |
| 1197 |
} |
| 1198 |
|
| 1199 |
if(do_dall) { |
| 1200 |
if((status = delete_sspostscript(go, abc, errbuf, ps, abc_ct, span_ct, msa_nseq, TRUE, hc_scheme, RB_6_RH_SCHEME, hc_nbins[RB_6_RH_SCHEME], hc_onecell, LIGHTGREYOC, DARKGREYOC, tabfp)) != eslOK) esl_fatal(errbuf); |
| 1201 |
} |
| 1202 |
|
| 1203 |
if(do_dint) { |
| 1204 |
if((status = delete_sspostscript(go, abc, errbuf, ps, abc_ct, span_ct, msa_nseq, FALSE, hc_scheme, RB_6_RH_SCHEME, hc_nbins[RB_6_RH_SCHEME], hc_onecell, LIGHTGREYOC, DARKGREYOC, tabfp)) != eslOK) esl_fatal(errbuf); |
| 1205 |
} |
| 1206 |
|
| 1207 |
if(do_prob && pp_ct != NULL) { |
| 1208 |
if((status = avg_posteriors_sspostscript(go, abc, errbuf, ps, pp_ct, msa_nseq, hc_scheme, RB_6_RL_SCHEME, hc_nbins[RB_6_RL_SCHEME], hc_onecell, LIGHTGREYOC, tabfp)) != eslOK) esl_fatal(errbuf); |
| 1209 |
} |
| 1210 |
|
| 1211 |
if(do_span) { |
| 1212 |
if((status = span_sspostscript(go, errbuf, ps, span_ct, msa_nseq, hc_scheme, RB_6_RL_SCHEME, hc_nbins[RB_6_RL_SCHEME], hc_onecell, LIGHTGREYOC, BLACKOC, tabfp)) != eslOK) esl_fatal(errbuf); |
| 1213 |
} |
| 1214 |
|
| 1215 |
if(do_maskcol) { |
| 1216 |
|
| 1217 |
|
| 1218 |
if((status = colormask_sspostscript(go, errbuf, ps, msa, hc_onecell, BLACKOC, (mask_has_internal_zeroes ? MAGENTAOC : LIGHTGREYOC))) != eslOK) esl_fatal(errbuf); |
| 1219 |
} |
| 1220 |
|
| 1221 |
if(do_maskdiff) { |
| 1222 |
if((status = diffmask_sspostscript(go, errbuf, ps, msa, mask2, hc_onecell, BLACKOC, CYANOC, MAGENTAOC, LIGHTGREYOC)) != eslOK) esl_fatal(errbuf); |
| 1223 |
} |
| 1224 |
|
| 1225 |
if(do_dfile) { |
| 1226 |
if((status = drawfile2sspostscript(go, errbuf, ps, hc_scheme, RB_6_RH_SCHEME, hc_nbins[RB_6_RH_SCHEME])) != eslOK) esl_fatal(errbuf); |
| 1227 |
} |
| 1228 |
|
| 1229 |
if(do_efile) { |
| 1230 |
if((status = expertfile2sspostscript(go, errbuf, ps)) != eslOK) esl_fatal(errbuf); |
| 1231 |
} |
| 1232 |
|
| 1233 |
if(do_indi) { |
| 1234 |
|
| 1235 |
if(esl_opt_IsOn(go, "--ifile")) { |
| 1236 |
get_insert_info_from_ifile((esl_opt_GetString(go, "--ifile")), ps->rflen, msa_nseq, NULL, NULL, NULL, &(per_seq_ins_ct), NULL, NULL); |
| 1237 |
} |
| 1238 |
else { |
| 1239 |
get_insert_info_from_msa(abc, msa, ps->rflen, NULL, NULL, &per_seq_ins_ct); |
| 1240 |
} |
| 1241 |
|
| 1242 |
|
| 1243 |
if((status = individuals_sspostscript(go, abc, errbuf, ps, abc_ct, |
| 1244 |
msa, per_seq_ins_ct, |
| 1245 |
((! esl_opt_GetBoolean(go, "--no-pp")) && (msa->pp != NULL)), |
| 1246 |
(! esl_opt_GetBoolean(go, "--no-bp")), |
| 1247 |
hc_scheme, RB_W5_OH_SCHEME, RB_6_RL_SCHEME, hc_nbins[RB_W5_OH_SCHEME], hc_nbins[RB_6_RL_SCHEME], hc_onecell, |
| 1248 |
LIGHTGREYOC, |
| 1249 |
BLACKOC, |
| 1250 |
GREENOC, |
| 1251 |
REDOC, |
| 1252 |
LIGHTPURPLEOC, |
| 1253 |
LIGHTPURPLEOC, |
| 1254 |
LIGHTGREYOC, |
| 1255 |
tabfp)) != eslOK) |
| 1256 |
esl_fatal(errbuf); |
| 1257 |
} |
| 1258 |
if((status = draw_sspostscript(ofp, go, errbuf, command, date, hc_scheme, ps)) != eslOK) esl_fatal(errbuf); |
| 1259 |
free(command); |
| 1260 |
fclose(ofp); |
| 1261 |
printf("# %d page postscript saved to file %s.\n", ps->npage, outfile); |
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
if(tabfp != NULL) { |
| 1266 |
fclose(tabfp); |
| 1267 |
if(do_indi && (do_info || do_mutinfo || do_ifreq || do_iavglen || do_dall || do_dint || do_prob || do_span)) { |
| 1268 |
printf("# Per-position and per-sequence data saved to tab-delimited text file %s.\n", esl_opt_GetString(go, "--tabfile")); |
| 1269 |
} |
| 1270 |
else if (do_indi) { |
| 1271 |
printf("# Per-sequence data saved to tab-delimited text file %s.\n", esl_opt_GetString(go, "--tabfile")); |
| 1272 |
} |
| 1273 |
else { |
| 1274 |
printf("# Per-position data saved to tab-delimited text file %s.\n", esl_opt_GetString(go, "--tabfile")); |
| 1275 |
} |
| 1276 |
} |
| 1277 |
|
| 1278 |
esl_arr2_Destroy((void **) abc_ct, msa? msa->alen:0); |
| 1279 |
esl_arr2_Destroy((void **) pp_ct, msa? msa->alen:0); |
| 1280 |
esl_arr3_Destroy((void ***) bp_ct, msa? msa->alen:0, abc? abc->Kp: 0); |
| 1281 |
esl_arr2_Destroy((void **) per_seq_ins_ct, msa_nseq); |
| 1282 |
|
| 1283 |
if(nins_ct){ |
| 1284 |
free(nins_ct); |
| 1285 |
} |
| 1286 |
esl_free(spos_ct); |
| 1287 |
esl_free(epos_ct); |
| 1288 |
esl_free(srfoff_ct); |
| 1289 |
esl_free(erfoff_ct); |
| 1290 |
esl_free(span_ct); |
| 1291 |
esl_free(nseq_with_ins_ct); |
| 1292 |
esl_free(mask); |
| 1293 |
if(mask2 !=0){ |
| 1294 |
free(mask2); |
| 1295 |
} |
| 1296 |
esl_free(date); |
| 1297 |
esl_free(hc_nbins); |
| 1298 |
|
| 1299 |
free_sspostscript(ps); |
| 1300 |
esl_alphabet_Destroy(abc); |
| 1301 |
esl_msafile_Close(afp); |
| 1302 |
esl_msafile2_Close(afp2); |
| 1303 |
esl_getopts_Destroy(go); |
| 1304 |
|
| 1305 |
for(z = 0; z < NOC; z++) esl_free(hc_onecell[z]); |
| 1306 |
esl_free(hc_onecell); |
| 1307 |
for(z = 0; z < NRB_11_RH_SCHEME; z++) esl_free(hc_scheme[RB_11_RH_SCHEME][z]); |
| 1308 |
for(z = 0; z < NRB_11_RL_SCHEME; z++) esl_free(hc_scheme[RB_11_RL_SCHEME][z]); |
| 1309 |
for(z = 0; z < NRB_6_RH_SCHEME; z++) esl_free(hc_scheme[RB_6_RH_SCHEME][z]); |
| 1310 |
for(z = 0; z < NRB_6_RL_SCHEME; z++) esl_free(hc_scheme[RB_6_RL_SCHEME][z]); |
| 1311 |
for(z = 0; z < NRB_5_RH_SCHEME; z++) esl_free(hc_scheme[RB_5_RH_SCHEME][z]); |
| 1312 |
for(z = 0; z < NRB_5_RL_SCHEME; z++) esl_free(hc_scheme[RB_5_RL_SCHEME][z]); |
| 1313 |
for(z = 0; z < NRB_W5_OH_SCHEME; z++) esl_free(hc_scheme[RB_W5_OH_SCHEME][z]); |
| 1314 |
for(z = 0; z < NSCHEMES; z++) { esl_free(hc_scheme[z]); } |
| 1315 |
free(hc_scheme); |
| 1316 |
esl_msa_Destroy(msa); |
| 1317 |
return 0; |
| 1318 |
|
| 1319 |
ERROR: |
| 1320 |
esl_fatal("Memory allocation error in main()."); |
| 1321 |
return eslFAIL; |
| 1322 |
} |
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
static SSPostscript_t * |
| 1330 |
create_sspostscript(const ESL_GETOPTS *go) |
| 1331 |
{ |
| 1332 |
int status; |
| 1333 |
SSPostscript_t *ps; |
| 1334 |
|
| 1335 |
ESL_ALLOC(ps, sizeof(SSPostscript_t)); |
| 1336 |
|
| 1337 |
ps->npage = 0; |
| 1338 |
ps->modelname = NULL; |
| 1339 |
ps->modeA = NULL; |
| 1340 |
ps->descA = NULL; |
| 1341 |
ps->headerx = 0.; |
| 1342 |
ps->headery = 0.; |
| 1343 |
ps->headerx_desc = 0.; |
| 1344 |
ps->headerx_charsize = 0.; |
| 1345 |
ps->headery_charsize = 0.; |
| 1346 |
ps->desc_max_chars = 0; |
| 1347 |
ps->leg_posn = -1; |
| 1348 |
ps->leg_cellsize = -1; |
| 1349 |
ps->leg_rhs_space = 0.; |
| 1350 |
ps->legx_offset = 0.; |
| 1351 |
ps->legy_offset = 0.; |
| 1352 |
ps->legx = 0.; |
| 1353 |
ps->legy = 0.; |
| 1354 |
ps->cur_legy = 0.; |
| 1355 |
ps->legx_charsize = 0.; |
| 1356 |
ps->legy_charsize = 0.; |
| 1357 |
ps->legx_max_chars = 0; |
| 1358 |
ps->legx_stats = 0.; |
| 1359 |
ps->pagex_max = 0.; |
| 1360 |
ps->pagey_max = 0.; |
| 1361 |
ps->scale = -1.; |
| 1362 |
ps->regurgA = NULL; |
| 1363 |
ps->nregurg = 0; |
| 1364 |
ps->posntextA = NULL; |
| 1365 |
ps->posntextxA = ps->posntextyA = NULL; |
| 1366 |
ps->nposntext = 0; |
| 1367 |
ps->ticksx1A = ps->ticksx2A = ps->ticksy1A = ps->ticksy2A = NULL; |
| 1368 |
ps->nticks = 0; |
| 1369 |
ps->bpx1A = ps->bpx2A = ps->bpy1A = ps->bpy2A = NULL; |
| 1370 |
ps->nbp = 0; |
| 1371 |
ps->rxA = ps->ryA = NULL; |
| 1372 |
ps->rflen = 0; |
| 1373 |
ps->rAA = NULL; |
| 1374 |
ps->rcolAAA = NULL; |
| 1375 |
ps->bcolAAA = NULL; |
| 1376 |
ps->otypeAA = NULL; |
| 1377 |
ps->occlAAA = NULL; |
| 1378 |
ps->nocclA = NULL; |
| 1379 |
ps->sclAA = NULL; |
| 1380 |
ps->tlAAA = NULL; |
| 1381 |
ps->ntlA = NULL; |
| 1382 |
ps->mask = NULL; |
| 1383 |
ps->nalloc = 50; |
| 1384 |
ps->msa_cseq_maj = NULL; |
| 1385 |
ps->msa_cseq_amb = NULL; |
| 1386 |
ps->msa_ct = NULL; |
| 1387 |
ps->msa_nbp = 0; |
| 1388 |
ps->msa_rf2a_map = NULL; |
| 1389 |
ps->msa_a2rf_map = NULL; |
| 1390 |
ps->uaseqlenA = NULL; |
| 1391 |
ps->seqidxA = NULL; |
| 1392 |
ps->msa = NULL; |
| 1393 |
ps->abc = NULL; |
| 1394 |
return ps; |
| 1395 |
|
| 1396 |
ERROR: esl_fatal("create_sspostscript(): memory allocation error."); |
| 1397 |
return NULL; |
| 1398 |
} |
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
static int |
| 1406 |
setup_sspostscript(SSPostscript_t *ps, char *errbuf) |
| 1407 |
{ |
| 1408 |
float xroom, yroom; |
| 1409 |
float header_max_chars; |
| 1410 |
|
| 1411 |
if(ps->rflen == 0) ESL_FAIL(eslEINVAL, errbuf, "Failed to ready any nucleotides in template file."); |
| 1412 |
|
| 1413 |
|
| 1414 |
ps->legx = ps->rxA[ps->leg_posn-1] + ps->legx_offset; |
| 1415 |
ps->legy = ps->ryA[ps->leg_posn-1] + ps->legy_offset; |
| 1416 |
ps->cur_legy = ps->legy; |
| 1417 |
|
| 1418 |
ps->pagex_max = POSTSCRIPT_PAGEWIDTH / ps->scale; |
| 1419 |
ps->pagey_max = POSTSCRIPT_PAGEHEIGHT / ps->scale; |
| 1420 |
|
| 1421 |
ps->headerx = 0. + PAGE_SIDEBUF; |
| 1422 |
ps->headery = ps->pagey_max - PAGE_TOPBUF - ((HEADER_FONTSIZE_UNSCALED) / ps->scale); |
| 1423 |
|
| 1424 |
|
| 1425 |
ps->legx_charsize = (LEG_FONTSIZE_UNSCALED / COURIER_HEIGHT_WIDTH_RATIO) / ps->scale; |
| 1426 |
ps->legy_charsize = (LEG_FONTSIZE_UNSCALED) / ps->scale; |
| 1427 |
xroom = ps->pagex_max - ps->legx - (ps->leg_cellsize - ps->legx_charsize); |
| 1428 |
yroom = ps->pagey_max - ps->legy - (ps->leg_cellsize - ps->legy_charsize); |
| 1429 |
ps->legx_max_chars = (int) (xroom / ps->legx_charsize); |
| 1430 |
ps->legy_max_chars = (int) (yroom / ps->legy_charsize); |
| 1431 |
ps->legx_stats = ps->pagex_max - PAGE_SIDEBUF - ps->leg_rhs_space - (LEG_EXTRA_COLUMNS * ps->legx_charsize); |
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
ps->headerx_charsize = (HEADER_FONTSIZE_UNSCALED / COURIER_HEIGHT_WIDTH_RATIO) / ps->scale; |
| 1436 |
header_max_chars = (int) ((ps->pagex_max - 2*PAGE_SIDEBUF) / ps->headerx_charsize); |
| 1437 |
ps->headery_charsize = (HEADER_FONTSIZE_UNSCALED) / ps->scale; |
| 1438 |
ps->desc_max_chars = header_max_chars - (HEADER_MODELNAME_MAXCHARS + 6 + 6 + 8 +2); |
| 1439 |
ps->headerx_desc = ps->pagex_max - PAGE_SIDEBUF - (ps->desc_max_chars * ps->headerx_charsize); |
| 1440 |
|
| 1441 |
return eslOK; |
| 1442 |
} |
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
static void |
| 1450 |
free_sspostscript(SSPostscript_t *ps) |
| 1451 |
{ |
| 1452 |
int i, p, c, l, l2; |
| 1453 |
|
| 1454 |
if(ps->modelname != NULL) free(ps->modelname); |
| 1455 |
|
| 1456 |
if(ps->modeA != NULL) free(ps->modeA); |
| 1457 |
|
| 1458 |
if(ps->descA != NULL) { |
| 1459 |
for(i = 0; i < ps->npage; i++) { |
| 1460 |
if(ps->descA[i] != NULL) { |
| 1461 |
free(ps->descA[i]); |
| 1462 |
} |
| 1463 |
} |
| 1464 |
free(ps->descA); |
| 1465 |
} |
| 1466 |
|
| 1467 |
if(ps->regurgA != NULL) { |
| 1468 |
for(i = 0; i < ps->nregurg; i++) { |
| 1469 |
if(ps->regurgA[i] != NULL) { |
| 1470 |
free(ps->regurgA[i]); |
| 1471 |
} |
| 1472 |
} |
| 1473 |
free(ps->regurgA); |
| 1474 |
} |
| 1475 |
|
| 1476 |
if(ps->posntextA != NULL) { |
| 1477 |
for(i = 0; i < ps->nposntext; i++) free(ps->posntextA[i]); |
| 1478 |
free(ps->posntextA); |
| 1479 |
} |
| 1480 |
if(ps->posntextxA != NULL) free(ps->posntextxA); |
| 1481 |
if(ps->posntextyA != NULL) free(ps->posntextyA); |
| 1482 |
if(ps->ticksx1A != NULL) free(ps->ticksx1A); |
| 1483 |
if(ps->ticksy1A != NULL) free(ps->ticksy1A); |
| 1484 |
if(ps->ticksx2A != NULL) free(ps->ticksx2A); |
| 1485 |
if(ps->ticksy2A != NULL) free(ps->ticksy2A); |
| 1486 |
if(ps->bpx1A != NULL) free(ps->bpx1A); |
| 1487 |
if(ps->bpy1A != NULL) free(ps->bpy1A); |
| 1488 |
if(ps->bpx2A != NULL) free(ps->bpx2A); |
| 1489 |
if(ps->bpy2A != NULL) free(ps->bpy2A); |
| 1490 |
if(ps->rxA != NULL) free(ps->rxA); |
| 1491 |
if(ps->ryA != NULL) free(ps->ryA); |
| 1492 |
|
| 1493 |
if(ps->rAA != NULL) { |
| 1494 |
for(p = 0; p < ps->npage; p++) |
| 1495 |
if(ps->rAA[p] != NULL) free(ps->rAA[p]); |
| 1496 |
free(ps->rAA); |
| 1497 |
} |
| 1498 |
|
| 1499 |
if(ps->rcolAAA != NULL) { |
| 1500 |
for(p = 0; p < ps->npage; p++) { |
| 1501 |
if(ps->rcolAAA[p] != NULL) { |
| 1502 |
for(c = 0; c < ps->rflen; c++) free(ps->rcolAAA[p][c]); |
| 1503 |
free(ps->rcolAAA[p]); |
| 1504 |
} |
| 1505 |
} |
| 1506 |
free(ps->rcolAAA); |
| 1507 |
} |
| 1508 |
|
| 1509 |
if(ps->bcolAAA != NULL) { |
| 1510 |
for(p = 0; p < ps->npage; p++) { |
| 1511 |
if(ps->bcolAAA[p] != NULL) { |
| 1512 |
for(c = 0; c < ps->rflen; c++) free(ps->bcolAAA[p][c]); |
| 1513 |
free(ps->bcolAAA[p]); |
| 1514 |
} |
| 1515 |
} |
| 1516 |
free(ps->bcolAAA); |
| 1517 |
} |
| 1518 |
|
| 1519 |
if(ps->otypeAA != NULL) { |
| 1520 |
for(p = 0; p < ps->npage; p++) { |
| 1521 |
if(ps->otypeAA[p] != NULL) { |
| 1522 |
free(ps->otypeAA[p]); |
| 1523 |
} |
| 1524 |
} |
| 1525 |
free(ps->otypeAA); |
| 1526 |
} |
| 1527 |
|
| 1528 |
if(ps->occlAAA != NULL) { |
| 1529 |
for(p = 0; p < ps->npage; p++) { |
| 1530 |
if(ps->occlAAA[p] != NULL) { |
| 1531 |
for(l = 0; l < ps->nocclA[p]; l++) { |
| 1532 |
if(ps->occlAAA[p][l]->text != NULL) free(ps->occlAAA[p][l]->text); |
| 1533 |
if(ps->occlAAA[p][l]->celltext != NULL) free(ps->occlAAA[p][l]->celltext); |
| 1534 |
if(ps->occlAAA[p][l]->procname != NULL) free(ps->occlAAA[p][l]->procname); |
| 1535 |
if(ps->occlAAA[p][l]->procstack != NULL) free(ps->occlAAA[p][l]->procstack); |
| 1536 |
free(ps->occlAAA[p][l]); |
| 1537 |
} |
| 1538 |
free(ps->occlAAA[p]); |
| 1539 |
} |
| 1540 |
} |
| 1541 |
free(ps->occlAAA); |
| 1542 |
} |
| 1543 |
|
| 1544 |
if(ps->sclAA != NULL) { |
| 1545 |
for(p = 0; p < ps->npage; p++) { |
| 1546 |
if(ps->sclAA[p] != NULL) { |
| 1547 |
if(ps->sclAA[p]->limits != NULL) free(ps->sclAA[p]->limits); |
| 1548 |
if(ps->sclAA[p]->counts != NULL) free(ps->sclAA[p]->counts); |
| 1549 |
if(ps->sclAA[p]->counts_masked != NULL) free(ps->sclAA[p]->counts_masked); |
| 1550 |
if(ps->sclAA[p]->text1 != NULL) free(ps->sclAA[p]->text1); |
| 1551 |
if(ps->sclAA[p]->text2 != NULL) free(ps->sclAA[p]->text2); |
| 1552 |
free(ps->sclAA[p]); |
| 1553 |
} |
| 1554 |
} |
| 1555 |
free(ps->sclAA); |
| 1556 |
} |
| 1557 |
|
| 1558 |
if(ps->tlAAA != NULL) { |
| 1559 |
for(p = 0; p < ps->npage; p++) { |
| 1560 |
if(ps->tlAAA[p] != NULL) { |
| 1561 |
for(l = 0; l < ps->ntlA[p]; l++) { |
| 1562 |
for(l2 = 0; l2 < ps->tlAAA[p][l]->nlines; l2++) { |
| 1563 |
free(ps->tlAAA[p][l]->text_per_line[l2]); |
| 1564 |
} |
| 1565 |
free(ps->tlAAA[p][l]->text_per_line); |
| 1566 |
free(ps->tlAAA[p][l]); |
| 1567 |
} |
| 1568 |
free(ps->tlAAA[p]); |
| 1569 |
} |
| 1570 |
} |
| 1571 |
free(ps->tlAAA); |
| 1572 |
} |
| 1573 |
|
| 1574 |
if(ps->ntlA != NULL) free(ps->ntlA); |
| 1575 |
if(ps->nocclA != NULL) free(ps->nocclA); |
| 1576 |
if(ps->msa_cseq_maj != NULL) free(ps->msa_cseq_maj); |
| 1577 |
if(ps->msa_cseq_amb != NULL) free(ps->msa_cseq_amb); |
| 1578 |
if(ps->msa_ct != NULL) free(ps->msa_ct); |
| 1579 |
if(ps->msa_rf2a_map != NULL) free(ps->msa_rf2a_map); |
| 1580 |
if(ps->msa_a2rf_map != NULL) free(ps->msa_a2rf_map); |
| 1581 |
if(ps->mask != NULL) free(ps->mask); |
| 1582 |
if(ps->seqidxA != NULL) free(ps->seqidxA); |
| 1583 |
if(ps->uaseqlenA != NULL) free(ps->uaseqlenA); |
| 1584 |
|
| 1585 |
free(ps); |
| 1586 |
return; |
| 1587 |
} |
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
static OneCellColorLegend_t * |
| 1597 |
create_onecell_colorlegend(float *col, int nres, int nres_masked, int do_separator, int do_no_vspace) |
| 1598 |
{ |
| 1599 |
int status; |
| 1600 |
OneCellColorLegend_t *occl; |
| 1601 |
|
| 1602 |
ESL_ALLOC(occl, sizeof(OneCellColorLegend_t)); |
| 1603 |
|
| 1604 |
|
| 1605 |
esl_vec_FSet(occl->col, NCMYK, 0.); |
| 1606 |
occl->text = NULL; |
| 1607 |
occl->celltext = NULL; |
| 1608 |
occl->procname = NULL; |
| 1609 |
occl->procstack = NULL; |
| 1610 |
occl->nprocstack = 0; |
| 1611 |
|
| 1612 |
|
| 1613 |
esl_vec_FCopy(col, NCMYK, occl->col); |
| 1614 |
|
| 1615 |
occl->nres = nres; |
| 1616 |
occl->nres_masked = nres_masked; |
| 1617 |
occl->do_separator = do_separator; |
| 1618 |
occl->do_no_vspace = do_no_vspace; |
| 1619 |
|
| 1620 |
return occl; |
| 1621 |
|
| 1622 |
ERROR: esl_fatal("create_onecell_colorlegend(): memory allocation error."); |
| 1623 |
return NULL; |
| 1624 |
} |
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
static TextLegend_t * |
| 1634 |
create_text_legend(int nlines, char **text_per_line, int do_separator) |
| 1635 |
{ |
| 1636 |
int status; |
| 1637 |
TextLegend_t *tl; |
| 1638 |
int i; |
| 1639 |
|
| 1640 |
ESL_ALLOC(tl, sizeof(TextLegend_t)); |
| 1641 |
|
| 1642 |
|
| 1643 |
tl->text_per_line = NULL; |
| 1644 |
|
| 1645 |
|
| 1646 |
tl->nlines = nlines; |
| 1647 |
tl->do_separator = do_separator; |
| 1648 |
ESL_ALLOC(tl->text_per_line, sizeof(char *) * nlines); |
| 1649 |
for(i = 0; i < nlines; i++) { |
| 1650 |
if((status = esl_strdup(text_per_line[i], -1, &(tl->text_per_line[i]))) != eslOK) esl_fatal("create_text_legend(), error copying text"); |
| 1651 |
} |
| 1652 |
|
| 1653 |
return tl; |
| 1654 |
|
| 1655 |
ERROR: esl_fatal("create_text_legend(): memory allocation error."); |
| 1656 |
return NULL; |
| 1657 |
} |
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
static TextLegend_t * |
| 1669 |
create_text_legend_for_consensus_sequence(const ESL_GETOPTS *go, int do_separator) |
| 1670 |
{ |
| 1671 |
int status; |
| 1672 |
TextLegend_t *tl; |
| 1673 |
int i; |
| 1674 |
int nlines; |
| 1675 |
char **text; |
| 1676 |
|
| 1677 |
if(esl_opt_GetBoolean(go, "--cambig")) { |
| 1678 |
nlines = 5; |
| 1679 |
ESL_ALLOC(text, sizeof(char *) * nlines); |
| 1680 |
for (i = 0; i < nlines; i++) text[i] = NULL; |
| 1681 |
if ((status = esl_strcat(&(text[0]), -1, "Consensus nucleotides (nt) are displayed, calculated", -1)) != eslOK) esl_fatal("create_text_legend_for_consensus_sequence(), error copying text"); |
| 1682 |
esl_sprintf(&(text[1]), "as the least ambiguous nt that represents >= %0.2f", esl_opt_GetReal(go, "--athresh")); |
| 1683 |
if((status = esl_strcat(&(text[2]), -1, "of all non-gap nts at each position.", -1)) != eslOK) esl_fatal("create_text_legend_for_consensus_sequence(), error copying text"); |
| 1684 |
if((status = esl_strcat(&(text[3]), -1, "K=G|U, M=A|C, R=A|G, S=C|G, Y=C|U, W=A|U", -1)) != eslOK) esl_fatal("create_text_legend_for_consensus_sequence(), error copying text"); |
| 1685 |
if((status = esl_strcat(&(text[4]), -1, "B=C|G|U, D=A|G|U, H=A|C|U, V=A|C|G, N=A|C|G|U", -1)) != eslOK) esl_fatal("create_text_legend_for_consensus_sequence(), error copying text"); |
| 1686 |
} |
| 1687 |
else { |
| 1688 |
nlines = 4; |
| 1689 |
ESL_ALLOC(text, sizeof(char *) * nlines); |
| 1690 |
for(i = 0; i < nlines; i++) { text[i] = NULL; } |
| 1691 |
if((status = esl_strcat(&(text[0]), -1, "Consensus nucleotides (nt) are displayed, defined", -1)) != eslOK) esl_fatal("create_text_legend_for_consensus_sequence(), error copying text"); |
| 1692 |
if((status = esl_strcat(&(text[1]), -1, "as the most frequent nt at each position.", -1)) != eslOK) esl_fatal("create_text_legend_for_consensus_sequence(), error copying text"); |
| 1693 |
esl_sprintf(&(text[2]), "Capitalized nts occur in >= %0.2f fraction of sequences", esl_opt_GetReal(go, "--cthresh")); |
| 1694 |
if((status = esl_strcat(&(text[3]), -1, "that do not have a gap at the position.", -1)) != eslOK) esl_fatal("create_text_legend_for_consensus_sequence(), error copying text"); |
| 1695 |
} |
| 1696 |
|
| 1697 |
tl = create_text_legend(nlines, text, do_separator); |
| 1698 |
for(i = 0; i < nlines; i++) { |
| 1699 |
free(text[i]); |
| 1700 |
} |
| 1701 |
free(text); |
| 1702 |
return tl; |
| 1703 |
|
| 1704 |
ERROR: esl_fatal("create_text_legend(): memory allocation error."); |
| 1705 |
return NULL; |
| 1706 |
} |
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
static SchemeColorLegend_t * |
| 1715 |
create_scheme_colorlegend(int scheme, int nbins, float *limits, int ints_only_flag, int low_inclusive, int high_inclusive, int use_mask) |
| 1716 |
{ |
| 1717 |
int status; |
| 1718 |
SchemeColorLegend_t *scl; |
| 1719 |
int i; |
| 1720 |
int *counts; |
| 1721 |
int *counts_masked; |
| 1722 |
ESL_ALLOC(scl, sizeof(SchemeColorLegend_t)); |
| 1723 |
|
| 1724 |
|
| 1725 |
scl->text1 = NULL; |
| 1726 |
scl->text2 = NULL; |
| 1727 |
|
| 1728 |
|
| 1729 |
scl->scheme = scheme; |
| 1730 |
scl->nbins = nbins; |
| 1731 |
ESL_ALLOC(scl->limits, sizeof(float) * (nbins+1)); |
| 1732 |
for(i = 0; i <= nbins; i++) { scl->limits[i] = limits[i]; } |
| 1733 |
|
| 1734 |
ESL_ALLOC(counts, sizeof(int) * nbins); |
| 1735 |
ESL_ALLOC(counts_masked, sizeof(int) * nbins); |
| 1736 |
esl_vec_ISet(counts, nbins, 0); |
| 1737 |
esl_vec_ISet(counts_masked, nbins, 0); |
| 1738 |
scl->counts = counts; |
| 1739 |
scl->counts_masked = counts_masked; |
| 1740 |
scl->ints_only_flag = ints_only_flag; |
| 1741 |
scl->low_inclusive = low_inclusive; |
| 1742 |
scl->high_inclusive = high_inclusive; |
| 1743 |
scl->use_mask = use_mask; |
| 1744 |
return scl; |
| 1745 |
|
| 1746 |
ERROR: esl_fatal("create_scheme_colorlegend(): memory allocation error."); |
| 1747 |
return NULL; |
| 1748 |
} |
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
int |
| 1756 |
add_text_to_scheme_colorlegend(SSPostscript_t *ps, SchemeColorLegend_t *scl, char *text, int legx_max_chars, char *errbuf) |
| 1757 |
{ |
| 1758 |
int status; |
| 1759 |
int i, idx; |
| 1760 |
int max_chars_per_line; |
| 1761 |
|
| 1762 |
if(scl->text1 != NULL) esl_fatal("add_text_to_scheme_colorlegend(), text already exists!\n"); |
| 1763 |
if(scl->text2 != NULL) esl_fatal("add_text_to_scheme_colorlegend(), text already exists!\n"); |
| 1764 |
if(text == NULL) esl_fatal("add_text_to_scheme_colorlegend(), passed in text is NULL!\n"); |
| 1765 |
|
| 1766 |
max_chars_per_line = ps->legx_max_chars - |
| 1767 |
((int) ps->leg_rhs_space / ps->legx_charsize) - |
| 1768 |
((int) (PAGE_SIDEBUF / ps->legx_charsize)) - |
| 1769 |
LEG_EXTRA_COLUMNS - 2; |
| 1770 |
if(((int) strlen(text)) <= max_chars_per_line) { |
| 1771 |
|
| 1772 |
if((status = esl_strdup(text, -1, &(scl->text1))) != eslOK) esl_fatal("add_text_to_scheme_colorlegend(), error copying text"); |
| 1773 |
return eslOK; |
| 1774 |
} |
| 1775 |
else if(((int) strlen(text)) > ((2 * max_chars_per_line) - 6)) { |
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 |
|
| 1780 |
ESL_FAIL(eslEINVAL, errbuf, "add_text_to_scheme_colorlegend(), text is %d chars, max allowed is %d (%s)\n", (int) strlen(text), ((2 * max_chars_per_line) - 6), text); |
| 1781 |
} |
| 1782 |
else { |
| 1783 |
idx = max_chars_per_line - 1; |
| 1784 |
while(text[idx] != ' ') { |
| 1785 |
idx--; |
| 1786 |
if(idx < 0) ESL_FAIL(eslEINVAL, errbuf, "add_text_to_scheme_colorlegend(), couldn't find a breakpoint for splitting the string (%s)\n", text); |
| 1787 |
} |
| 1788 |
|
| 1789 |
ESL_ALLOC(scl->text1, sizeof(char) * (idx+1)); |
| 1790 |
for(i = 0; i < idx; i++) scl->text1[i] = text[i]; |
| 1791 |
scl->text1[idx] = '\0'; |
| 1792 |
|
| 1793 |
|
| 1794 |
int len = (int) strlen(text); |
| 1795 |
idx++; |
| 1796 |
ESL_ALLOC(scl->text2, sizeof(char) * (len - idx+1)); |
| 1797 |
for(i = idx; i < len; i++) scl->text2[i-idx] = text[i]; |
| 1798 |
scl->text2[len-idx] = '\0'; |
| 1799 |
} |
| 1800 |
return eslOK; |
| 1801 |
|
| 1802 |
ERROR: ESL_FAIL(status, errbuf, "Error adding text to scheme_colorlegend probably out of memory"); |
| 1803 |
} |
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
int |
| 1812 |
add_text_to_onecell_colorlegend(SSPostscript_t *ps, OneCellColorLegend_t *occl, char *text, int legx_max_chars, char *errbuf) |
| 1813 |
{ |
| 1814 |
int status; |
| 1815 |
int max_chars_per_line; |
| 1816 |
if(occl->text != NULL) esl_fatal("add_text_to_onecell_colorlegend(), text description already exists!\n"); |
| 1817 |
if(text == NULL) esl_fatal("add_text_to_onecell_colorlegend(), passed in text is NULL!\n"); |
| 1818 |
|
| 1819 |
max_chars_per_line = legx_max_chars - LEG_EXTRA_COLUMNS - 2 - ((int) (((float) ps->leg_cellsize * 1.5) / ps->legx_charsize)); |
| 1820 |
|
| 1821 |
if(((int) strlen(text)) > (max_chars_per_line)) { |
| 1822 |
ESL_FAIL(eslEINVAL, errbuf, "add_text_to_onecell_colorlegend(), text is %d chars, max allowed is %d (%s)\n", (int) strlen(text), max_chars_per_line, text); |
| 1823 |
} |
| 1824 |
if((status = esl_strdup(text, -1, &(occl->text))) != eslOK) esl_fatal("add_text_to_onecell_colorlegend(), error copying text"); |
| 1825 |
return eslOK; |
| 1826 |
} |
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
int |
| 1833 |
add_celltext_to_onecell_colorlegend(SSPostscript_t *ps, OneCellColorLegend_t *occl, char *celltext, char *errbuf) |
| 1834 |
{ |
| 1835 |
int status; |
| 1836 |
if(occl->celltext != NULL) esl_fatal("add_celltext_to_onecell_colorlegend(), cell text already exists!\n"); |
| 1837 |
if(celltext == NULL) esl_fatal("add_celltext_to_onecell_colorlegend(), passed in celltext is NULL!\n"); |
| 1838 |
|
| 1839 |
if((status = esl_strdup(celltext, -1, &(occl->celltext))) != eslOK) esl_fatal("add_celltext_to_onecell_colorlegend(), error copying text"); |
| 1840 |
|
| 1841 |
return eslOK; |
| 1842 |
} |
| 1843 |
|
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
int |
| 1849 |
add_procedure_to_onecell_colorlegend(SSPostscript_t *ps, OneCellColorLegend_t *occl, char *procname, float *procstack, int nprocstack, char *errbuf) |
| 1850 |
{ |
| 1851 |
int status; |
| 1852 |
int i; |
| 1853 |
|
| 1854 |
if(occl->celltext != NULL) esl_fatal("add_procedure_to_onecell_colorlegend(), cell text already exists!\n"); |
| 1855 |
if(occl->procname != NULL) esl_fatal("add_procedure_to_onecell_colorlegend(), procedure text already exists!\n"); |
| 1856 |
if(occl->procstack != NULL) esl_fatal("add_procedure_to_onecell_colorlegend(), procedure stack already exists!\n"); |
| 1857 |
if(procname == NULL) esl_fatal("add_procedure_to_onecell_colorlegend(), passed in procname is NULL!\n"); |
| 1858 |
if(procstack == NULL) esl_fatal("add_procedure_to_onecell_colorlegend(), passed in procstack is NULL!\n"); |
| 1859 |
|
| 1860 |
if((status = esl_strdup(procname, -1, &(occl->procname))) != eslOK) esl_fatal("add_procedure_to_onecell_colorlegend(), error copying text"); |
| 1861 |
ESL_ALLOC(occl->procstack, sizeof(float) * nprocstack); |
| 1862 |
for(i = 0; i < nprocstack; i++) occl->procstack[i] = procstack[i]; |
| 1863 |
occl->nprocstack = nprocstack; |
| 1864 |
|
| 1865 |
return eslOK; |
| 1866 |
|
| 1867 |
ERROR: |
| 1868 |
return eslEMEM; |
| 1869 |
} |
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
int |
| 1877 |
add_page_desc_to_sspostscript(SSPostscript_t *ps, int page, char *text, char *errbuf) |
| 1878 |
{ |
| 1879 |
int status; |
| 1880 |
int i, j; |
| 1881 |
int max_both_lines; |
| 1882 |
|
| 1883 |
if(ps->descA[page] != NULL) ESL_FAIL(eslEINVAL, errbuf, "add_page_desc_to_sspostscript(), description for page %d already exists!\n", page); |
| 1884 |
if(text == NULL) ESL_FAIL(eslEINVAL, errbuf, "add_page_desc_to_sspostscript(), passed in text is NULL!\n"); |
| 1885 |
|
| 1886 |
max_both_lines =(2. * ps->desc_max_chars); |
| 1887 |
if(ps->modeA[page] == INDIMODE || ps->modeA[page] == SIMPLEMASKMODE) |
| 1888 |
max_both_lines--; |
| 1889 |
|
| 1890 |
|
| 1891 |
int textlen = (int) strlen(text); |
| 1892 |
if(textlen <= ps->desc_max_chars) { |
| 1893 |
if((status = esl_strdup(text, -1, &(ps->descA[page]))) != eslOK) ESL_FAIL(eslEINVAL, errbuf, "add_page_desc_to_sspostscript(), error copying text"); |
| 1894 |
} |
| 1895 |
else if (textlen <= max_both_lines) { |
| 1896 |
if(ps->modeA[page] == ALIMODE) { |
| 1897 |
|
| 1898 |
i = ps->desc_max_chars; |
| 1899 |
while(text[i] != ' ' && text[i] != '-') { |
| 1900 |
i--; |
| 1901 |
if(i < 0) ESL_FAIL(eslEINVAL, errbuf, "add_page_desc_to_sspostscript(), first word of text (%s) is more than max allowed of %d chars", text, ps->desc_max_chars); |
| 1902 |
} |
| 1903 |
|
| 1904 |
if((textlen - (i+1)) <= ps->desc_max_chars) { |
| 1905 |
if((status = esl_strdup(text, -1, &(ps->descA[page]))) != eslOK) ESL_FAIL(eslEINVAL, errbuf, "add_page_desc_to_sspostscript(), error copying text"); |
| 1906 |
ps->descA[page][i] = '\n'; |
| 1907 |
} |
| 1908 |
else ESL_FAIL(eslEINVAL, errbuf, "add_page_desc_to_sspostscript(), couldn't find (' ') for splitting text into two chunks (%s)", text); |
| 1909 |
} |
| 1910 |
else { |
| 1911 |
ESL_ALLOC(ps->descA[page], sizeof(char) * (textlen + 3)); |
| 1912 |
for(i = 0; i < ps->desc_max_chars; i++) ps->descA[page][i] = text[i]; |
| 1913 |
i = ps->desc_max_chars; |
| 1914 |
ps->descA[page][i] = '-'; |
| 1915 |
i++; |
| 1916 |
ps->descA[page][i] = '\n'; |
| 1917 |
for(i = ps->desc_max_chars; i < textlen; i++) ps->descA[page][i+2] = text[i]; |
| 1918 |
ps->descA[page][textlen+2] = '\0'; |
| 1919 |
} |
| 1920 |
} |
| 1921 |
else |
| 1922 |
if(ps->modeA[page] != INDIMODE) { |
| 1923 |
ESL_FAIL(eslEINVAL, errbuf, "add_page_desc_to_sspostscript(), text is %d chars, max allowed is %d (%s)\n", textlen, max_both_lines, text); |
| 1924 |
} |
| 1925 |
else { |
| 1926 |
ESL_ALLOC(ps->descA[page], sizeof(char) * (max_both_lines + 2)); |
| 1927 |
|
| 1928 |
j = ps->desc_max_chars; |
| 1929 |
while(text[j] != ' ' && j > 0) { |
| 1930 |
j--; |
| 1931 |
} |
| 1932 |
if(j == 0) { j = ps->desc_max_chars; } |
| 1933 |
for(i = 0; i < j; i++) ps->descA[page][i] = text[i]; |
| 1934 |
i = j; |
| 1935 |
if(j == ps->desc_max_chars && text[j] != ' ') { |
| 1936 |
ps->descA[page][i] = '-'; |
| 1937 |
} |
| 1938 |
i++; |
| 1939 |
ps->descA[page][i] = '\n'; |
| 1940 |
for(i = j; i < j + ps->desc_max_chars; i++) ps->descA[page][i+2] = text[i]; |
| 1941 |
ps->descA[page][i+2] = '\0'; |
| 1942 |
} |
| 1943 |
return eslOK; |
| 1944 |
|
| 1945 |
ERROR: ESL_FAIL(status, errbuf, "add_page_desc_to_sspostscript() error, probably out of memory."); |
| 1946 |
} |
| 1947 |
|
| 1948 |
|
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
int |
| 1955 |
add_diffmask_page_desc_to_sspostscript(SSPostscript_t *ps, int page, char *mask_file, char *maskdiff_file, char *errbuf) |
| 1956 |
{ |
| 1957 |
int status; |
| 1958 |
int i; |
| 1959 |
char *mask1desc = NULL; |
| 1960 |
char *mask2desc = NULL; |
| 1961 |
int len2copy; |
| 1962 |
int mask_file_len; |
| 1963 |
int maskdiff_file_len; |
| 1964 |
void *tmp; |
| 1965 |
|
| 1966 |
if(ps->mask == NULL) ESL_FAIL(eslEINVAL, errbuf, "add_diffmask_page_desc_to_sspostscript(), ps->mask is NULL\n"); |
| 1967 |
if(ps->descA[page] != NULL) ESL_FAIL(eslEINVAL, errbuf, "add_diffmask_page_desc_to_sspostscript(), description for page %d already exists!\n", page); |
| 1968 |
if(maskdiff_file == NULL) ESL_FAIL(eslEINVAL, errbuf, "add_diffmask_page_desc_to_sspostscript(), passed in maskdiff_file is NULL!\n"); |
| 1969 |
|
| 1970 |
|
| 1971 |
mask_file_len = (int) strlen(ps->mask); |
| 1972 |
maskdiff_file_len = (int) strlen(maskdiff_file); |
| 1973 |
if((status = esl_strcat(&(mask1desc), -1, "mask 1: ", -1)) != eslOK) ESL_FAIL(eslEINVAL, errbuf, "add_diffmask_page_desc_to_sspostscript(), error copying text"); |
| 1974 |
if((mask_file_len + 8) <= ps->desc_max_chars) { |
| 1975 |
if((status = esl_strcat(&(mask1desc), -1, mask_file, -1)) != eslOK) ESL_FAIL(eslEINVAL, errbuf, "add_diffmask_page_desc_to_sspostscript(), error copying text"); |
| 1976 |
} |
| 1977 |
else { |
| 1978 |
len2copy = ps->desc_max_chars - 8 - 3; |
| 1979 |
ESL_RALLOC(mask1desc, tmp, sizeof(char) * ps->desc_max_chars+1); |
| 1980 |
for(i = 0; i < len2copy; i++) { |
| 1981 |
mask1desc[8+i] = mask_file[i]; |
| 1982 |
} |
| 1983 |
mask1desc[8+len2copy] = '.'; |
| 1984 |
mask1desc[8+len2copy+1] = '.'; |
| 1985 |
mask1desc[8+len2copy+2] = '.'; |
| 1986 |
mask1desc[8+len2copy+3] = '\0'; |
| 1987 |
} |
| 1988 |
|
| 1989 |
|
| 1990 |
if((status = esl_strcat(&(mask2desc), -1, "mask 2: ", -1)) != eslOK) ESL_FAIL(eslEINVAL, errbuf, "add_diffmask_page_desc_to_sspostscript(), error copying text"); |
| 1991 |
if((maskdiff_file_len + 8) <= ps->desc_max_chars) { |
| 1992 |
if((status = esl_strcat(&(mask2desc), -1, maskdiff_file, -1)) != eslOK) ESL_FAIL(eslEINVAL, errbuf, "add_diffmask_page_desc_to_sspostscript(), error copying text"); |
| 1993 |
} |
| 1994 |
else { |
| 1995 |
len2copy = ps->desc_max_chars - 8 - 3; |
| 1996 |
ESL_RALLOC(mask2desc, tmp, sizeof(char) * ps->desc_max_chars+1); |
| 1997 |
for(i = 0; i < len2copy; i++) { |
| 1998 |
mask2desc[8+i] = maskdiff_file[i]; |
| 1999 |
} |
| 2000 |
mask2desc[8+len2copy] = '.'; |
| 2001 |
mask2desc[8+len2copy+1] = '.'; |
| 2002 |
mask2desc[8+len2copy+2] = '.'; |
| 2003 |
mask2desc[8+len2copy+3] = '\0'; |
| 2004 |
} |
| 2005 |
|
| 2006 |
|
| 2007 |
if((status = esl_strcat(&(ps->descA[page]), -1, mask1desc, -1)) != eslOK) ESL_FAIL(eslEINVAL, errbuf, "add_diffmask_page_desc_to_sspostscript(), error copying text"); |
| 2008 |
if((status = esl_strcat(&(ps->descA[page]), -1, "\n", -1)) != eslOK) ESL_FAIL(eslEINVAL, errbuf, "add_diffmask_page_desc_to_sspostscript(), error copying text"); |
| 2009 |
if((status = esl_strcat(&(ps->descA[page]), -1, mask2desc, -1)) != eslOK) ESL_FAIL(eslEINVAL, errbuf, "add_diffmask_page_desc_to_sspostscript(), error copying text"); |
| 2010 |
|
| 2011 |
free(mask1desc); |
| 2012 |
free(mask2desc); |
| 2013 |
return eslOK; |
| 2014 |
|
| 2015 |
ERROR: ESL_FAIL(status, errbuf, "add_page_desc_to_sspostscript() error, probably out of memory."); |
| 2016 |
} |
| 2017 |
|
| 2018 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
int |
| 2023 |
add_mask_to_ss_postscript(SSPostscript_t *ps, char *mask) |
| 2024 |
{ |
| 2025 |
int status; |
| 2026 |
if(ps->mask != NULL) { esl_fatal("add_mask_to_ss_postscript(), mask is non-null!\n"); } |
| 2027 |
if(mask == NULL) esl_fatal("add_mask_to_ss_postscript(), passed in mask is NULL!\n"); |
| 2028 |
if((status = esl_strdup(mask, -1, &(ps->mask))) != eslOK) esl_fatal("add_mask_to_ss_postscript(), error copying mask"); |
| 2029 |
return eslOK; |
| 2030 |
} |
| 2031 |
|
| 2032 |
|
| 2033 |
|
| 2034 |
|
| 2035 |
|
| 2036 |
|
| 2037 |
|
| 2038 |
static int |
| 2039 |
draw_legend_column_headers(FILE *fp, SSPostscript_t *ps, int pagenum, char *errbuf) |
| 2040 |
{ |
| 2041 |
int status; |
| 2042 |
int i; |
| 2043 |
float x, y; |
| 2044 |
|
| 2045 |
char *cur_string; |
| 2046 |
int cur_width = 0; |
| 2047 |
|
| 2048 |
|
| 2049 |
|
| 2050 |
x = ps->legx; |
| 2051 |
y = ps->cur_legy; |
| 2052 |
if(ps->mask != NULL && ps->modeA[pagenum] == ALIMODE) { |
| 2053 |
y -= 1.25 * (float) ps->leg_cellsize; |
| 2054 |
} |
| 2055 |
|
| 2056 |
fprintf(fp, "%% begin legend column headers\n"); |
| 2057 |
fprintf(fp, "(%s) %.2f %.2f moveto show\n", "LEGEND", x, (y + ((float) ps->leg_cellsize * .25))); |
| 2058 |
|
| 2059 |
|
| 2060 |
x = ps->legx_stats; |
| 2061 |
y = ps->cur_legy; |
| 2062 |
cur_width = ps->legx_max_chars - |
| 2063 |
((int) ps->leg_rhs_space / ps->legx_charsize) - |
| 2064 |
((int) (PAGE_SIDEBUF / ps->legx_charsize)) - |
| 2065 |
LEG_EXTRA_COLUMNS - 2; |
| 2066 |
|
| 2067 |
ESL_ALLOC(cur_string, sizeof(char) * (cur_width+1)); |
| 2068 |
for(i = 0; i < cur_width; i++) cur_string[i] = '-'; |
| 2069 |
cur_string[cur_width] = '\0'; |
| 2070 |
|
| 2071 |
if(ps->mask != NULL && ps->modeA[pagenum] == ALIMODE) { |
| 2072 |
fprintf(fp, "(%4s %4s) %.2f %.2f moveto show\n", "", "incl", x, (y + ((float) ps->leg_cellsize * .25))); |
| 2073 |
y -= 0.625 * (float) ps->leg_cellsize; |
| 2074 |
fprintf(fp, "(%4s %4s) %.2f %.2f moveto show\n", "", " by ", x, (y + ((float) ps->leg_cellsize * .25))); |
| 2075 |
y -= 0.625 * (float) ps->leg_cellsize; |
| 2076 |
fprintf(fp, "(%4s %4s) %.2f %.2f moveto show\n", "all", "mask", x, (y + ((float) ps->leg_cellsize * .25))); |
| 2077 |
y -= 0.625 * (float) ps->leg_cellsize; |
| 2078 |
fprintf(fp, "(%s) %.2f %.2f moveto show\n", cur_string, ps->legx, (y + ((float) ps->leg_cellsize * .25))); |
| 2079 |
fprintf(fp, "(---- ----) %.2f %.2f moveto show\n", x, (y + ((float) ps->leg_cellsize * .25))); |
| 2080 |
} |
| 2081 |
else { |
| 2082 |
fprintf(fp, "(%5s) %.2f %.2f moveto show\n", "count", x, (y + ((float) ps->leg_cellsize * .25))); |
| 2083 |
y -= 0.625 * (float) ps->leg_cellsize; |
| 2084 |
fprintf(fp, "(%s) %.2f %.2f moveto show\n", cur_string, ps->legx, (y + ((float) ps->leg_cellsize * .25))); |
| 2085 |
fprintf(fp, "(-----) %.2f %.2f moveto show\n", x, (y + ((float) ps->leg_cellsize * .25))); |
| 2086 |
} |
| 2087 |
ps->cur_legy = y - (1.0 * (float) ps->leg_cellsize); |
| 2088 |
|
| 2089 |
fprintf(fp, "%% end legend column headers\n\n"); |
| 2090 |
free(cur_string); |
| 2091 |
|
| 2092 |
return eslOK; |
| 2093 |
|
| 2094 |
ERROR: ESL_FAIL(status, errbuf, "ERROR drawing legend column headers, probably out of memory."); |
| 2095 |
} |
| 2096 |
|
| 2097 |
|
| 2098 |
|
| 2099 |
|
| 2100 |
|
| 2101 |
|
| 2102 |
static int |
| 2103 |
draw_onecell_colorlegend(FILE *fp, OneCellColorLegend_t *occl, SSPostscript_t *ps, int occl_idx, int pagenum) |
| 2104 |
{ |
| 2105 |
int status; |
| 2106 |
float x, y; |
| 2107 |
int cp, i; |
| 2108 |
float fontsize; |
| 2109 |
char *cur_string; |
| 2110 |
int cur_width = 0; |
| 2111 |
|
| 2112 |
|
| 2113 |
x = ps->legx; |
| 2114 |
y = ps->cur_legy; |
| 2115 |
|
| 2116 |
|
| 2117 |
fprintf(fp, "%% begin one cell color legend\n"); |
| 2118 |
if(occl->celltext == NULL && occl->procname == NULL) { |
| 2119 |
fprintf(fp, "newpath\n"); |
| 2120 |
fprintf(fp, " %.2f %.2f moveto", x, y); |
| 2121 |
fprintf(fp, " 0 %.3f rlineto %.3f 0 rlineto 0 %.3f rlineto closepath\n", (float) ps->leg_cellsize, (float) ps->leg_cellsize, (-1 * (float) ps->leg_cellsize)); |
| 2122 |
fprintf(fp, " "); |
| 2123 |
for(cp = 0; cp < NCMYK; cp++) fprintf(fp, "%.2f ", occl->col[cp]); |
| 2124 |
fprintf(fp, "setcmykcolor\n"); |
| 2125 |
fprintf(fp, " fill\n"); |
| 2126 |
|
| 2127 |
|
| 2128 |
|
| 2129 |
|
| 2130 |
|
| 2131 |
|
| 2132 |
|
| 2133 |
|
| 2134 |
|
| 2135 |
} |
| 2136 |
else if (occl->procname != NULL) { |
| 2137 |
fprintf(fp, "%.2f %.2f ", x, y); |
| 2138 |
for(i = 0; i < occl->nprocstack; i++) { fprintf(fp, "%.2f ", occl->procstack[i]); } |
| 2139 |
fprintf(fp, "%s\n", occl->procname); |
| 2140 |
} |
| 2141 |
else if (occl->celltext != NULL){ |
| 2142 |
|
| 2143 |
fontsize = (float) ps->leg_cellsize / 2; |
| 2144 |
fprintf(fp, "/%s findfont %f scalefont setfont\n", NUCLEOTIDES_FONT, fontsize); |
| 2145 |
for(cp = 0; cp < NCMYK; cp++) fprintf(fp, "%.2f ", occl->col[cp]); |
| 2146 |
fprintf(fp, "setcmykcolor\n"); |
| 2147 |
fprintf(fp, "(%s) %.2f %.2f moveto show\n", occl->celltext, x, y + ((float) ps->leg_cellsize * 0.25)); |
| 2148 |
} |
| 2149 |
if(occl->celltext == NULL || (strlen(occl->celltext) > 0)) { |
| 2150 |
|
| 2151 |
x += (float) ps->leg_cellsize * 1.5; |
| 2152 |
} |
| 2153 |
fontsize = LEG_FONTSIZE_UNSCALED / ps->scale; |
| 2154 |
|
| 2155 |
|
| 2156 |
if(occl->text != NULL) { |
| 2157 |
|
| 2158 |
fprintf(fp, " 0.00 0.00 0.00 1.00 setcmykcolor\n"); |
| 2159 |
fprintf(fp, "/%s findfont %f scalefont setfont\n", LEG_FONT, fontsize); |
| 2160 |
fprintf(fp, "(%s) %.2f %.2f moveto show\n", occl->text, x, y + ((float) ps->leg_cellsize * 0.25)); |
| 2161 |
|
| 2162 |
|
| 2163 |
if(occl->nres != OCCL_BLANK_COUNT) { |
| 2164 |
x = ps->legx_stats; |
| 2165 |
if(ps->mask != NULL && ps->modeA[pagenum] == ALIMODE) { |
| 2166 |
fprintf(fp, "(%4d %4d) %.2f %.2f moveto show\n", occl->nres, occl->nres_masked, x, y + ((float) ps->leg_cellsize * 0.25)); |
| 2167 |
} |
| 2168 |
else { |
| 2169 |
fprintf(fp, "(%5d) %.2f %.2f moveto show\n", occl->nres, x, y + ((float) ps->leg_cellsize * 0.25)); |
| 2170 |
} |
| 2171 |
} |
| 2172 |
} |
| 2173 |
|
| 2174 |
|
| 2175 |
fprintf(fp, " %.4f %.4f %.4f %.4f setcmykcolor\n", 0., 0., 0., 1.); |
| 2176 |
|
| 2177 |
if(occl->do_separator) { |
| 2178 |
cur_width = ps->legx_max_chars - |
| 2179 |
((int) ps->leg_rhs_space / ps->legx_charsize) - |
| 2180 |
((int) (PAGE_SIDEBUF / ps->legx_charsize)) - |
| 2181 |
LEG_EXTRA_COLUMNS - 2; |
| 2182 |
ESL_ALLOC(cur_string, sizeof(char) * (cur_width+1)); |
| 2183 |
for(i = 0; i < cur_width; i++) cur_string[i] = '-'; |
| 2184 |
cur_string[cur_width] = '\0'; |
| 2185 |
fprintf(fp, "(%s) %.2f %.2f moveto show\n", cur_string, ps->legx, (y - ((float) ps->leg_cellsize * 0.5))); |
| 2186 |
fprintf(fp, "(-----) %.2f %.2f moveto show\n", (float) ps->legx_stats, (y - ((float) ps->leg_cellsize * 0.5))); |
| 2187 |
y -= (float) ps->leg_cellsize * 0.5; |
| 2188 |
free(cur_string); |
| 2189 |
} |
| 2190 |
|
| 2191 |
|
| 2192 |
if(occl->do_no_vspace) { y -= (float) (ps->leg_cellsize / COURIER_HEIGHT_WIDTH_RATIO) * 1.25; } |
| 2193 |
else { y -= (float) ps->leg_cellsize * 1.25; } |
| 2194 |
ps->cur_legy = y; |
| 2195 |
|
| 2196 |
|
| 2197 |
fprintf(fp, "%% end one cell color legend\n\n"); |
| 2198 |
return eslOK; |
| 2199 |
|
| 2200 |
ERROR: esl_fatal("ERROR drawing one cell legend, probably out of memory."); |
| 2201 |
return eslEMEM; |
| 2202 |
} |
| 2203 |
|
| 2204 |
|
| 2205 |
|
| 2206 |
|
| 2207 |
|
| 2208 |
|
| 2209 |
|
| 2210 |
static int |
| 2211 |
draw_scheme_colorlegend(const ESL_GETOPTS *go, FILE *fp, SchemeColorLegend_t *scl, float **hc_scheme, SSPostscript_t *ps, int pagenum) |
| 2212 |
{ |
| 2213 |
float x, y; |
| 2214 |
int cp; |
| 2215 |
int c,i,n1s; |
| 2216 |
float fontsize; |
| 2217 |
int do_circle_mask, do_square_mask, do_x_mask, do_border; |
| 2218 |
int do_mask; |
| 2219 |
float old_x; |
| 2220 |
|
| 2221 |
do_mask = ((ps->mask != NULL) && (scl->use_mask)) ? TRUE : FALSE; |
| 2222 |
do_border = (!esl_opt_GetBoolean(go, "--mask-a")); |
| 2223 |
do_circle_mask = do_square_mask = do_x_mask = FALSE; |
| 2224 |
if(esl_opt_GetBoolean(go, "--mask-u")) { do_square_mask = TRUE; } |
| 2225 |
else if(esl_opt_GetBoolean(go, "--mask-x")) { do_x_mask = TRUE; } |
| 2226 |
else do_circle_mask = TRUE; |
| 2227 |
|
| 2228 |
x = ps->legx; |
| 2229 |
y = ps->cur_legy; |
| 2230 |
|
| 2231 |
fontsize = LEG_FONTSIZE_UNSCALED / ps->scale; |
| 2232 |
fprintf(fp, "%% begin color scheme legend\n"); |
| 2233 |
fprintf(fp, "/%s findfont %f scalefont setfont\n", LEG_FONT, fontsize); |
| 2234 |
fprintf(fp, " 0.00 0.00 0.00 1.00 setcmykcolor\n"); |
| 2235 |
|
| 2236 |
float colvec[NCMYK]; |
| 2237 |
colvec[0] = colvec[1] = colvec[2] = 0.; |
| 2238 |
colvec[3] = 1.0; |
| 2239 |
if(do_mask) { |
| 2240 |
|
| 2241 |
|
| 2242 |
fprintf(fp, "%.1f setlinewidth\n", (float) ps->leg_cellsize/4.); |
| 2243 |
fprintf(fp, "newpath\n"); |
| 2244 |
fprintf(fp, " %.2f %.2f moveto", x, y); |
| 2245 |
fprintf(fp, " 0 %.3f rlineto %.3f 0 rlineto 0 %.3f rlineto closepath\n", (float) ps->leg_cellsize, (float) ps->leg_cellsize, (-1 * (float) ps->leg_cellsize)); |
| 2246 |
fprintf(fp, " "); |
| 2247 |
for(cp = 0; cp < NCMYK; cp++) { |
| 2248 |
fprintf(fp, "%.2f ", colvec[cp]); |
| 2249 |
} |
| 2250 |
fprintf(fp, "setcmykcolor\n"); |
| 2251 |
fprintf(fp, " fill\n"); |
| 2252 |
|
| 2253 |
|
| 2254 |
x += (float) ps->leg_cellsize * 1.5; |
| 2255 |
y += (float) ps->leg_cellsize * 0.625; |
| 2256 |
fprintf(fp, "(included by mask) %.2f %.2f moveto show\n", x, y); |
| 2257 |
y -= (float) ps->leg_cellsize * 0.625; |
| 2258 |
fprintf(fp, "((all colors)) %.2f %.2f moveto show\n", x, y); |
| 2259 |
x -= (float) ps->leg_cellsize * 1.5; |
| 2260 |
|
| 2261 |
|
| 2262 |
old_x = x; |
| 2263 |
n1s = 0; |
| 2264 |
for(i = 0; i < ps->rflen; i++) if(ps->mask[i] == '1') n1s++; |
| 2265 |
x = ps->legx_stats; |
| 2266 |
y += (float) ps->leg_cellsize * 0.3125; |
| 2267 |
fprintf(fp, "(%4d %4d) %.2f %.2f moveto show\n", n1s, n1s, x, y); |
| 2268 |
y -= (float) ps->leg_cellsize * 0.3125; |
| 2269 |
|
| 2270 |
x = old_x; |
| 2271 |
y -= (float) ps->leg_cellsize * 1.5; |
| 2272 |
draw_masked_block(fp, x, y, colvec, do_circle_mask, do_square_mask, do_x_mask, do_border, (float) ps->leg_cellsize); |
| 2273 |
|
| 2274 |
x += (float) ps->leg_cellsize * 1.5; |
| 2275 |
y += (float) ps->leg_cellsize * 0.625; |
| 2276 |
fprintf(fp, "(excluded by mask) %.2f %.2f moveto show\n", x, y); |
| 2277 |
y -= (float) ps->leg_cellsize * 0.625; |
| 2278 |
fprintf(fp, "((all colors)) %.2f %.2f moveto show\n", x, y); |
| 2279 |
|
| 2280 |
|
| 2281 |
x = ps->legx_stats; |
| 2282 |
y += (float) ps->leg_cellsize * 0.3125; |
| 2283 |
fprintf(fp, "(%4d %4d) %.2f %.2f moveto show\n", ps->rflen-n1s, 0, x, y); |
| 2284 |
|
| 2285 |
y -= (float) ps->leg_cellsize * 1.8125; |
| 2286 |
x = ps->legx; |
| 2287 |
} |
| 2288 |
|
| 2289 |
|
| 2290 |
if(scl->text1 != NULL) { |
| 2291 |
if(scl->text2 == NULL) { |
| 2292 |
fprintf(fp, "(%s:) %.2f %.2f moveto show\n", scl->text1, x, (y + ((float) ps->leg_cellsize * .25))); |
| 2293 |
} |
| 2294 |
else { |
| 2295 |
fprintf(fp, "(%s) %.2f %.2f moveto show\n", scl->text1, x, (y + ((float) ps->leg_cellsize * .25))); |
| 2296 |
y -= (float) ps->leg_cellsize * 0.625; |
| 2297 |
fprintf(fp, "(%s:) %.2f %.2f moveto show\n", scl->text2, x, (y + ((float) ps->leg_cellsize * .25))); |
| 2298 |
} |
| 2299 |
} |
| 2300 |
y -= (float) ps->leg_cellsize; |
| 2301 |
|
| 2302 |
|
| 2303 |
for(c = 0; c < scl->nbins; c++) { |
| 2304 |
fprintf(fp, "newpath\n"); |
| 2305 |
fprintf(fp, " %.2f %.2f moveto", x, y); |
| 2306 |
fprintf(fp, " 0 %.3f rlineto %.3f 0 rlineto 0 %.3f rlineto closepath\n", (float) ps->leg_cellsize, (float) ps->leg_cellsize, (-1 * (float) ps->leg_cellsize)); |
| 2307 |
fprintf(fp, " "); |
| 2308 |
for(cp = 0; cp < NCMYK; cp++) { |
| 2309 |
fprintf(fp, "%.2f ", hc_scheme[c][cp]); |
| 2310 |
} |
| 2311 |
fprintf(fp, "setcmykcolor\n"); |
| 2312 |
fprintf(fp, " fill\n"); |
| 2313 |
|
| 2314 |
|
| 2315 |
|
| 2316 |
|
| 2317 |
|
| 2318 |
|
| 2319 |
|
| 2320 |
|
| 2321 |
|
| 2322 |
|
| 2323 |
|
| 2324 |
x += (float) ps->leg_cellsize * 1.5; |
| 2325 |
y += (float) ps->leg_cellsize * 0.25; |
| 2326 |
fprintf(fp, " 0.00 0.00 0.00 1.00 setcmykcolor\n"); |
| 2327 |
if(esl_FCompare_old(scl->limits[c+1], eslINFINITY, eslSMALLX1) == eslOK) { |
| 2328 |
if(c != scl->nbins-1) esl_fatal("ERROR when drawing color legend, limits[%d] is INFINITY, but this is reserved only for the max limit", c+1); |
| 2329 |
if(scl->ints_only_flag) fprintf(fp, "(>=%d) %.2f %.2f moveto show\n", (int) scl->limits[c], x, y); |
| 2330 |
else fprintf(fp, "(>=%3.f) %.2f %.2f moveto show\n", scl->limits[c], x, y); |
| 2331 |
} |
| 2332 |
else if(scl->ints_only_flag) { |
| 2333 |
if(c == scl->nbins-1) { |
| 2334 |
fprintf(fp, "(\\[%d-%d\\]) %.2f %.2f moveto show\n", (int) scl->limits[c], (int) scl->limits[c+1], x, y); |
| 2335 |
} |
| 2336 |
else if(esl_FCompare_old(scl->limits[c], scl->limits[c+1]-1, eslSMALLX1) == eslOK) { |
| 2337 |
if(compare_two_cmyk_colors(hc_scheme[c][ICYAN], hc_scheme[c][IMGTA], hc_scheme[c][IYELW], hc_scheme[c][IBLCK], WHITE_C, WHITE_M, WHITE_Y, WHITE_K)) { |
| 2338 |
|
| 2339 |
fprintf(fp, "(\\(blank\\) %d) %.2f %.2f moveto show\n", (int) scl->limits[c], x, y); |
| 2340 |
} |
| 2341 |
else { |
| 2342 |
fprintf(fp, "(%d) %.2f %.2f moveto show\n", (int) scl->limits[c], x, y); |
| 2343 |
} |
| 2344 |
} |
| 2345 |
else { |
| 2346 |
fprintf(fp, "(\\[%d-%d\\]) %.2f %.2f moveto show\n", (int) scl->limits[c], (int) scl->limits[c+1]-1, x, y); |
| 2347 |
} |
| 2348 |
} |
| 2349 |
else { |
| 2350 |
if(c == scl->nbins-1) fprintf(fp, "(\\[%.3f-%.3f\\%c) %.2f %.2f moveto show\n", scl->limits[c], scl->limits[c+1], (scl->high_inclusive ? ']' : ')'), x, y); |
| 2351 |
else if(c == 0) fprintf(fp, "(\\%c%.3f-%.3f\\)) %.2f %.2f moveto show\n", (scl->low_inclusive ? '[' : '('), scl->limits[c], scl->limits[c+1], x, y); |
| 2352 |
else fprintf(fp, "(\\[%.3f-%.3f\\)) %.2f %.2f moveto show\n", scl->limits[c], scl->limits[c+1], x, y); |
| 2353 |
} |
| 2354 |
|
| 2355 |
old_x = x; |
| 2356 |
x = ps->legx_stats; |
| 2357 |
if(do_mask) { |
| 2358 |
fprintf(fp, "(%4d %4d) %.2f %.2f moveto show\n", scl->counts[c], scl->counts_masked[c], x, y); |
| 2359 |
} |
| 2360 |
else { |
| 2361 |
fprintf(fp, "(%5d) %.2f %.2f moveto show\n", scl->counts[c], x, y); |
| 2362 |
} |
| 2363 |
|
| 2364 |
x = old_x - (float) ps->leg_cellsize * 1.5; |
| 2365 |
y -= (float) ps->leg_cellsize * 0.25; |
| 2366 |
y -= (float) ps->leg_cellsize; |
| 2367 |
} |
| 2368 |
|
| 2369 |
|
| 2370 |
fprintf(fp, " %.4f %.4f %.4f %.4f setcmykcolor\n", 0., 0., 0., 1.); |
| 2371 |
fprintf(fp, "%% end color scheme legend\n\n"); |
| 2372 |
|
| 2373 |
ps->cur_legy = y; |
| 2374 |
return eslOK; |
| 2375 |
} |
| 2376 |
|
| 2377 |
|
| 2378 |
|
| 2379 |
|
| 2380 |
|
| 2381 |
|
| 2382 |
|
| 2383 |
static int |
| 2384 |
draw_text_section_in_legend(FILE *fp, TextLegend_t *tl, SSPostscript_t *ps, int tl_idx, int pagenum) |
| 2385 |
{ |
| 2386 |
int status; |
| 2387 |
float x, y; |
| 2388 |
int i; |
| 2389 |
float fontsize; |
| 2390 |
char *cur_string; |
| 2391 |
int cur_width = 0; |
| 2392 |
|
| 2393 |
x = ps->legx; |
| 2394 |
y = ps->cur_legy; |
| 2395 |
|
| 2396 |
|
| 2397 |
fprintf(fp, "%% begin text legend\n"); |
| 2398 |
fontsize = LEG_EXTRA_TEXT_FONTSIZE_UNSCALED / ps->scale; |
| 2399 |
|
| 2400 |
|
| 2401 |
|
| 2402 |
fprintf(fp, " 0.00 0.00 0.00 1.00 setcmykcolor\n"); |
| 2403 |
fprintf(fp, "/%s findfont %f scalefont setfont\n", LEG_EXTRA_TEXT_FONT, fontsize); |
| 2404 |
for(i = 0; i < tl->nlines; i++) { |
| 2405 |
fprintf(fp, "(%s) %.2f %.2f moveto show\n", tl->text_per_line[i], x, y); |
| 2406 |
y -= (float) fontsize * 1.25; |
| 2407 |
} |
| 2408 |
if(tl->do_separator) { |
| 2409 |
cur_width = ps->legx_max_chars - ((int) (PAGE_SIDEBUF / ps->legx_charsize)) - LEG_EXTRA_COLUMNS - 2; |
| 2410 |
ESL_ALLOC(cur_string, sizeof(char) * (cur_width+1)); |
| 2411 |
for(i = 0; i < cur_width; i++) cur_string[i] = '-'; |
| 2412 |
cur_string[cur_width] = '\0'; |
| 2413 |
fprintf(fp, "(%s) %.2f %.2f moveto show\n", cur_string, ps->legx, (y - ((float) ps->leg_cellsize * 0.5))); |
| 2414 |
fprintf(fp, "(-----) %.2f %.2f moveto show\n", (float) ps->legx_stats, (y - ((float) ps->leg_cellsize * 0.5))); |
| 2415 |
y -= (float) ps->leg_cellsize * 0.5; |
| 2416 |
free(cur_string); |
| 2417 |
} |
| 2418 |
ps->cur_legy = y - (1.0 * (float) ps->leg_cellsize); |
| 2419 |
|
| 2420 |
fprintf(fp, "%% end text legend\n\n"); |
| 2421 |
return eslOK; |
| 2422 |
|
| 2423 |
ERROR: esl_fatal("ERROR drawing text legend, probably out of memory."); |
| 2424 |
return eslEMEM; |
| 2425 |
} |
| 2426 |
|
| 2427 |
|
| 2428 |
|
| 2429 |
|
| 2430 |
|
| 2431 |
|
| 2432 |
|
| 2433 |
static int |
| 2434 |
draw_sspostscript(FILE *fp, const ESL_GETOPTS *go, char *errbuf, char *command, char *date, float ***hc_scheme, SSPostscript_t *ps) |
| 2435 |
{ |
| 2436 |
int status; |
| 2437 |
int p, pi, i, c, l; |
| 2438 |
int do_circle_mask, do_square_mask, do_x_mask, do_border; |
| 2439 |
int *page_orderA; |
| 2440 |
|
| 2441 |
if(ps->modelname == NULL) ESL_FAIL(eslEINVAL, errbuf, "Error, failed to read modelname from template file."); |
| 2442 |
|
| 2443 |
do_border = (!esl_opt_GetBoolean(go, "--mask-a")); |
| 2444 |
do_circle_mask = do_square_mask = do_x_mask = FALSE; |
| 2445 |
if(esl_opt_GetBoolean(go, "--mask-u")) { do_square_mask = TRUE; } |
| 2446 |
else if(esl_opt_GetBoolean(go, "--mask-x")) { do_x_mask = TRUE; } |
| 2447 |
else do_circle_mask = TRUE; |
| 2448 |
|
| 2449 |
if(ps->npage == 0) ESL_FAIL(eslEINCOMPAT, errbuf, "draw_sspostscript, ps->npage == 0\n"); |
| 2450 |
|
| 2451 |
|
| 2452 |
ESL_ALLOC(page_orderA, sizeof(int) * ps->npage); |
| 2453 |
for(pi = 0; pi < ps->npage; pi++) page_orderA[pi] = pi; |
| 2454 |
|
| 2455 |
|
| 2456 |
fprintf(fp, "%% ------------------------------------------------------------\n"); |
| 2457 |
fprintf(fp, "%% Procedure definitions\n"); |
| 2458 |
define_outline_procedure(fp); |
| 2459 |
fprintf(fp, "%% ------------------------------------------------------------\n"); |
| 2460 |
|
| 2461 |
|
| 2462 |
for(pi = 0; pi < ps->npage; pi++) { |
| 2463 |
p = page_orderA[pi]; |
| 2464 |
ps->cur_legy = ps->legy; |
| 2465 |
|
| 2466 |
|
| 2467 |
fprintf(fp, "%% ------------------------------------------------------------\n"); |
| 2468 |
fprintf(fp, "%% Postscript file created by esl-ssdraw (page %d of %d)\n", pi+1, ps->npage); |
| 2469 |
fprintf(fp, "%% ------------------------------------------------------------\n"); |
| 2470 |
fprintf(fp, "%% msafile: %s (%d seqs)\n", esl_opt_GetArg(go, 1), ps->msa_nseq); |
| 2471 |
fprintf(fp, "%% templatefile: %s\n", esl_opt_GetArg(go, 2)); |
| 2472 |
fprintf(fp, "%% modelname: %s\n", ps->modelname); |
| 2473 |
fprintf(fp, "%% consensus-len: %d\n", ps->rflen); |
| 2474 |
if(esl_opt_IsOn(go, "--mask")) { |
| 2475 |
fprintf(fp, "%% maskfile: %s\n", esl_opt_GetString(go, "--mask")); |
| 2476 |
} |
| 2477 |
if(esl_opt_IsOn(go, "--mask-diff")) { |
| 2478 |
fprintf(fp, "%% difffile: %s\n", esl_opt_GetString(go, "--mask-diff")); |
| 2479 |
} |
| 2480 |
if(esl_opt_IsOn(go, "--dfile")) { |
| 2481 |
fprintf(fp, "%% dfile: %s\n", esl_opt_GetString(go, "--dfile")); |
| 2482 |
} |
| 2483 |
if(esl_opt_IsOn(go, "--efile")) { |
| 2484 |
fprintf(fp, "%% efile: %s\n", esl_opt_GetString(go, "--efile")); |
| 2485 |
} |
| 2486 |
if(esl_opt_IsOn(go, "--ifile")) { |
| 2487 |
fprintf(fp, "%% ifile: %s\n", esl_opt_GetString(go, "--ifile")); |
| 2488 |
} |
| 2489 |
fprintf(fp, "%%\n"); |
| 2490 |
|
| 2491 |
|
| 2492 |
fprintf(fp, "%.2f %.2f scale\n\n", ps->scale, ps->scale); |
| 2493 |
|
| 2494 |
|
| 2495 |
if((status = draw_header_and_footer(fp, go, errbuf, ps, p, pi+1)) != eslOK) return status; |
| 2496 |
|
| 2497 |
|
| 2498 |
if(ps->regurgA != NULL) { |
| 2499 |
fprintf(fp, "%% begin regurgitate\n"); |
| 2500 |
for(i = 0; i < ps->nregurg; i++) |
| 2501 |
fprintf(fp, "%s", ps->regurgA[i]); |
| 2502 |
fprintf(fp, "%% end regurgitate\n\n"); |
| 2503 |
} |
| 2504 |
|
| 2505 |
|
| 2506 |
for(i = 0; i < ps->nposntext; i++) { |
| 2507 |
if(i == 0) { |
| 2508 |
fprintf(fp, "%% begin text positiontext\n"); |
| 2509 |
fprintf(fp, "/%s findfont %.2f scalefont setfont\n", POSNTEXT_FONT, POSNTEXT_FONTSIZE); |
| 2510 |
fprintf(fp, "0.00 0.00 0.00 1.00 setcmykcolor\n"); |
| 2511 |
} |
| 2512 |
fprintf(fp, "%s %.2f %.2f moveto show\n", ps->posntextA[i], ps->posntextxA[i], ps->posntextyA[i]); |
| 2513 |
if(i == (ps->nposntext-1)) { |
| 2514 |
fprintf(fp, "%% end text positiontext\n\n"); |
| 2515 |
} |
| 2516 |
} |
| 2517 |
|
| 2518 |
|
| 2519 |
for(i = 0; i < ps->nbp; i++) { |
| 2520 |
if(i == 0) { |
| 2521 |
fprintf(fp, "%% begin lines bpconnects\n"); |
| 2522 |
fprintf(fp, "%.2f setlinewidth\n", BP_LINEWIDTH); |
| 2523 |
fprintf(fp, "0.00 0.00 0.00 1.00 setcmykcolor\n"); |
| 2524 |
} |
| 2525 |
fprintf(fp, "%.2f %.2f %.2f %.2f newpath moveto lineto stroke\n", ps->bpx1A[i], ps->bpy1A[i], ps->bpx2A[i], ps->bpy2A[i]); |
| 2526 |
if(i == (ps->nbp-1)) { |
| 2527 |
fprintf(fp, "%% end lines bpconnects\n\n"); |
| 2528 |
} |
| 2529 |
} |
| 2530 |
|
| 2531 |
|
| 2532 |
|
| 2533 |
fprintf(fp, "0.00 0.00 0.00 1.00 setcmykcolor\n"); |
| 2534 |
fprintf(fp, "/%s findfont %f scalefont setfont\n\n", LEG_FONT, LEG_FONTSIZE_UNSCALED / ps->scale); |
| 2535 |
|
| 2536 |
|
| 2537 |
if((ps->nocclA[p] > 0) || (ps->sclAA != NULL && ps->sclAA[p] != NULL)) { |
| 2538 |
if(! (esl_opt_GetBoolean(go, "--no-leg"))) { |
| 2539 |
if((status = draw_legend_column_headers(fp, ps, p, errbuf)) != eslOK) return status; |
| 2540 |
} |
| 2541 |
} |
| 2542 |
|
| 2543 |
|
| 2544 |
if(ps->occlAAA != NULL && ps->occlAAA[p] != NULL) { |
| 2545 |
for(l = 0; l < ps->nocclA[p]; l++) { |
| 2546 |
if(! (esl_opt_GetBoolean(go, "--no-leg"))) { |
| 2547 |
draw_onecell_colorlegend(fp, ps->occlAAA[p][l], ps, l, p); |
| 2548 |
} |
| 2549 |
} |
| 2550 |
} |
| 2551 |
|
| 2552 |
if(ps->sclAA != NULL && ps->sclAA[p] != NULL) { |
| 2553 |
if(! (esl_opt_GetBoolean(go, "--no-leg"))) { |
| 2554 |
draw_scheme_colorlegend(go, fp, ps->sclAA[p], hc_scheme[ps->sclAA[p]->scheme], ps, p); |
| 2555 |
} |
| 2556 |
} |
| 2557 |
|
| 2558 |
if(ps->tlAAA != NULL && ps->tlAAA[p] != NULL) { |
| 2559 |
for(l = 0; l < ps->ntlA[p]; l++) { |
| 2560 |
if(! (esl_opt_GetBoolean(go, "--no-leg"))) { |
| 2561 |
draw_text_section_in_legend(fp, ps->tlAAA[p][l], ps, l, p); |
| 2562 |
} |
| 2563 |
} |
| 2564 |
} |
| 2565 |
|
| 2566 |
if(ps->bcolAAA != NULL && ps->bcolAAA[p] != NULL) { |
| 2567 |
fprintf(fp, "%% begin colored positions\n"); |
| 2568 |
if(ps->mask != NULL && ps->modeA[p] != SIMPLEMASKMODE && ps->modeA[p] != INDIMODE) { |
| 2569 |
fprintf(fp, "2.0 setlinewidth\n"); |
| 2570 |
if(do_border && do_x_mask) { fprintf(fp, "1.0 setlinewidth\n"); } |
| 2571 |
if(do_border && do_square_mask) { fprintf(fp, "2.0 setlinewidth\n"); } |
| 2572 |
if(do_border && do_circle_mask) { fprintf(fp, "2.5 setlinewidth\n"); } |
| 2573 |
for(c = 0; c < ps->rflen; c++) { |
| 2574 |
fprintf(fp, "%snucleotide %d\n", "%", c+1); |
| 2575 |
if(ps->mask[c] == '0') { |
| 2576 |
draw_masked_block(fp, ps->rxA[c]-1., ps->ryA[c]-1., ps->bcolAAA[p][c], do_circle_mask, do_square_mask, do_x_mask, do_border, CELLSIZE); |
| 2577 |
} |
| 2578 |
else { |
| 2579 |
fprintf(fp, "newpath\n"); |
| 2580 |
fprintf(fp, " %.2f %.2f moveto", ps->rxA[c] - (CELLSIZE * CELL_XOFFSET_FRACTION), ps->ryA[c] - (CELLSIZE * CELL_YOFFSET_FRACTION)); |
| 2581 |
fprintf(fp, " 0 %d rlineto %d 0 rlineto 0 %d rlineto closepath\n", CELLSIZE_INT, CELLSIZE_INT, -1 * CELLSIZE_INT); |
| 2582 |
fprintf(fp, " %.2f %.2f %.2f %.2f setcmykcolor\n", ps->bcolAAA[p][c][0], ps->bcolAAA[p][c][1], ps->bcolAAA[p][c][2], ps->bcolAAA[p][c][3]); |
| 2583 |
fprintf(fp, " fill\n"); |
| 2584 |
} |
| 2585 |
} |
| 2586 |
fprintf(fp, "1.00 setlinewidth\n"); |
| 2587 |
} |
| 2588 |
else { |
| 2589 |
for(c = 0; c < ps->rflen; c++) { |
| 2590 |
fprintf(fp, "%snucleotide %d\n", "%", c+1); |
| 2591 |
fprintf(fp, "newpath\n"); |
| 2592 |
fprintf(fp, " %.2f %.2f moveto", ps->rxA[c] - (CELLSIZE * CELL_XOFFSET_FRACTION), ps->ryA[c] - (CELLSIZE * CELL_YOFFSET_FRACTION)); |
| 2593 |
fprintf(fp, " 0 %d rlineto %d 0 rlineto 0 %d rlineto closepath\n", CELLSIZE_INT, CELLSIZE_INT, -1 * CELLSIZE_INT); |
| 2594 |
fprintf(fp, " %.2f %.2f %.2f %.2f setcmykcolor\n", ps->bcolAAA[p][c][0], ps->bcolAAA[p][c][1], ps->bcolAAA[p][c][2], ps->bcolAAA[p][c][3]); |
| 2595 |
fprintf(fp, " fill\n"); |
| 2596 |
} |
| 2597 |
} |
| 2598 |
|
| 2599 |
fprintf(fp, " 0.00 0.00 0.00 1.00 setcmykcolor\n"); |
| 2600 |
fprintf(fp, "%% end colored positions\n\n"); |
| 2601 |
} |
| 2602 |
|
| 2603 |
if(ps->rAA[p] != NULL) { |
| 2604 |
fprintf(fp, "/%s findfont %f scalefont setfont\n", NUCLEOTIDES_FONT, NUCLEOTIDES_FONTSIZE); |
| 2605 |
fprintf(fp, " 0.00 0.00 0.00 1.00 setcmykcolor\n"); |
| 2606 |
fprintf(fp, "%% begin text nucleotides\n"); |
| 2607 |
if(ps->rcolAAA[p] != NULL) { |
| 2608 |
for(c = 0; c < ps->rflen; c++) { |
| 2609 |
fprintf(fp, " %.2f %.2f %.2f %.2f setcmykcolor ", ps->rcolAAA[p][c][0], ps->rcolAAA[p][c][1], ps->rcolAAA[p][c][2], ps->rcolAAA[p][c][3]); |
| 2610 |
if(strchr(LOWERCASE_LOW_HANGING_CHARS, ps->rAA[p][c]) != NULL) { |
| 2611 |
fprintf(fp, "(%c) %.2f %.2f moveto show", ps->rAA[p][c], ps->rxA[c], ps->ryA[c] + (CELLSIZE * NUCLEOTIDE_YOFFSET_FRACTION_LOWERCASE_LOW_HANGING_CHARS)); |
| 2612 |
|
| 2613 |
} |
| 2614 |
else if(ps->rAA[p][c] != ' ') { |
| 2615 |
fprintf(fp, "(%c) %.2f %.2f moveto show", ps->rAA[p][c], ps->rxA[c], ps->ryA[c]); |
| 2616 |
} |
| 2617 |
fprintf(fp, "\n"); |
| 2618 |
} |
| 2619 |
} |
| 2620 |
else { |
| 2621 |
for(c = 0; c < ps->rflen; c++) { |
| 2622 |
if(strchr(LOWERCASE_LOW_HANGING_CHARS, ps->rAA[p][c]) != NULL) { |
| 2623 |
fprintf(fp, "(%c) %.2f %.2f moveto show", ps->rAA[p][c], ps->rxA[c], ps->ryA[c] + (CELLSIZE * NUCLEOTIDE_YOFFSET_FRACTION_LOWERCASE_LOW_HANGING_CHARS)); |
| 2624 |
|
| 2625 |
} |
| 2626 |
else if(ps->rAA[p][c] != ' ') { |
| 2627 |
fprintf(fp, "(%c) %.2f %.2f moveto show", ps->rAA[p][c], ps->rxA[c], ps->ryA[c]); |
| 2628 |
} |
| 2629 |
fprintf(fp, "\n"); |
| 2630 |
} |
| 2631 |
} |
| 2632 |
fprintf(fp, "%% end text nucleotides\n"); |
| 2633 |
fprintf(fp, " 0.000 0.000 0.000 1.000 setcmykcolor\n"); |
| 2634 |
} |
| 2635 |
|
| 2636 |
if(ps->otypeAA != NULL && ps->otypeAA[p] != NULL) { |
| 2637 |
fprintf(fp, "%% begin outlines\n"); |
| 2638 |
for(c = 0; c < ps->rflen; c++) { |
| 2639 |
if(ps->otypeAA[p][c] != OUTLINE_NONE_IDX) { |
| 2640 |
|
| 2641 |
fprintf(fp, "%.2f %.2f %.2f", |
| 2642 |
ps->rxA[c] - (CELLSIZE * CELL_XOFFSET_FRACTION), |
| 2643 |
ps->ryA[c] - (CELLSIZE * CELL_YOFFSET_FRACTION), |
| 2644 |
CELLSIZE); |
| 2645 |
if(ps->otypeAA[p][c] == OUTLINE_MIN_IDX) { |
| 2646 |
fprintf(fp, " %.2f %s\n", |
| 2647 |
OUTLINE_LINEWIDTH_CELL_FRACTION_MIN * CELLSIZE, |
| 2648 |
OUTLINE_PROCEDURE); |
| 2649 |
} |
| 2650 |
else if(ps->otypeAA[p][c] == OUTLINE_MAX_IDX) { |
| 2651 |
fprintf(fp, " %.2f %s\n", |
| 2652 |
OUTLINE_LINEWIDTH_CELL_FRACTION_MAX * CELLSIZE, |
| 2653 |
OUTLINE_PROCEDURE); |
| 2654 |
} |
| 2655 |
} |
| 2656 |
} |
| 2657 |
fprintf(fp, "%% end outlines\n"); |
| 2658 |
fprintf(fp, " 0.000 0.000 0.000 1.000 setcmykcolor\n"); |
| 2659 |
} |
| 2660 |
|
| 2661 |
|
| 2662 |
for(i = 0; i < ps->nticks; i++) { |
| 2663 |
if(i == 0) { |
| 2664 |
fprintf(fp, "%% begin lines positionticks\n"); |
| 2665 |
fprintf(fp, "%.2f setlinewidth\n", TICKS_LINEWIDTH); |
| 2666 |
fprintf(fp, "0.00 0.00 0.00 1.00 setcmykcolor\n"); |
| 2667 |
} |
| 2668 |
fprintf(fp, "%.2f %.2f %.2f %.2f newpath moveto lineto stroke\n", ps->ticksx1A[i], ps->ticksy1A[i], ps->ticksx2A[i], ps->ticksy2A[i]); |
| 2669 |
if(i == (ps->nticks-1)) { |
| 2670 |
fprintf(fp, "%% end lines positionticks\n\n"); |
| 2671 |
} |
| 2672 |
} |
| 2673 |
|
| 2674 |
fprintf(fp, "showpage\n\n"); |
| 2675 |
|
| 2676 |
} |
| 2677 |
free(page_orderA); |
| 2678 |
return eslOK; |
| 2679 |
|
| 2680 |
ERROR: ESL_FAIL(eslEINVAL, errbuf, "draw_sspostscript() error, probably out of memory."); |
| 2681 |
} |
| 2682 |
|
| 2683 |
|
| 2684 |
|
| 2685 |
|
| 2686 |
|
| 2687 |
|
| 2688 |
|
| 2689 |
|
| 2690 |
|
| 2691 |
|
| 2692 |
|
| 2693 |
|
| 2694 |
|
| 2695 |
|
| 2696 |
|
| 2697 |
|
| 2698 |
|
| 2699 |
|
| 2700 |
|
| 2701 |
|
| 2702 |
int |
| 2703 |
parse_template_file(char *filename, const ESL_GETOPTS *go, char *errbuf, int msa_rflen, SSPostscript_t **ret_ps) |
| 2704 |
{ |
| 2705 |
int status; |
| 2706 |
ESL_FILEPARSER *efp; |
| 2707 |
SSPostscript_t *ps; |
| 2708 |
int found_match = FALSE; |
| 2709 |
|
| 2710 |
if (esl_fileparser_Open(filename, NULL, &efp) != eslOK) esl_fatal("ERROR, failed to open template file %s in parse_template_file\n", filename); |
| 2711 |
esl_fileparser_SetCommentChar(efp, '#'); |
| 2712 |
|
| 2713 |
status = eslOK; |
| 2714 |
while((found_match == FALSE) && (status == eslOK)) { |
| 2715 |
status = parse_template_page(efp, go, errbuf, &ps); |
| 2716 |
if((status != eslOK) && (status != eslEOF)) { |
| 2717 |
esl_fileparser_Close(efp); |
| 2718 |
return status; |
| 2719 |
} |
| 2720 |
if(ps->rflen == msa_rflen) { found_match = TRUE; } |
| 2721 |
else { free_sspostscript(ps); } |
| 2722 |
} |
| 2723 |
if(found_match == FALSE) { |
| 2724 |
esl_fileparser_Close(efp); |
| 2725 |
esl_fatal("ERROR, did not find template structure to match alignment consensus length of %d in:\n%s\n", msa_rflen, filename); |
| 2726 |
} |
| 2727 |
|
| 2728 |
|
| 2729 |
|
| 2730 |
|
| 2731 |
if((status = validate_justread_sspostscript(ps, errbuf)) != eslOK) return status; |
| 2732 |
|
| 2733 |
esl_fileparser_Close(efp); |
| 2734 |
*ret_ps = ps; |
| 2735 |
|
| 2736 |
return eslOK; |
| 2737 |
} |
| 2738 |
|
| 2739 |
|
| 2740 |
|
| 2741 |
|
| 2742 |
|
| 2743 |
|
| 2744 |
|
| 2745 |
|
| 2746 |
|
| 2747 |
|
| 2748 |
|
| 2749 |
|
| 2750 |
|
| 2751 |
|
| 2752 |
|
| 2753 |
|
| 2754 |
|
| 2755 |
|
| 2756 |
|
| 2757 |
|
| 2758 |
|
| 2759 |
|
| 2760 |
|
| 2761 |
|
| 2762 |
|
| 2763 |
|
| 2764 |
|
| 2765 |
|
| 2766 |
|
| 2767 |
|
| 2768 |
|
| 2769 |
|
| 2770 |
|
| 2771 |
|
| 2772 |
|
| 2773 |
|
| 2774 |
|
| 2775 |
|
| 2776 |
|
| 2777 |
|
| 2778 |
|
| 2779 |
|
| 2780 |
|
| 2781 |
int |
| 2782 |
parse_template_page(ESL_FILEPARSER *efp, const ESL_GETOPTS *go, char *errbuf, SSPostscript_t **ret_ps) |
| 2783 |
{ |
| 2784 |
int status; |
| 2785 |
char *tok; |
| 2786 |
int toklen; |
| 2787 |
SSPostscript_t *ps = NULL; |
| 2788 |
int read_showpage = FALSE; |
| 2789 |
int reached_eof = FALSE; |
| 2790 |
|
| 2791 |
|
| 2792 |
ps = create_sspostscript(go); |
| 2793 |
|
| 2794 |
while ((read_showpage == FALSE) && ((status = esl_fileparser_GetToken(efp, &tok, &toklen)) == eslOK)) { |
| 2795 |
if(strcmp(tok, "%") == 0) { |
| 2796 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) == eslOK) { |
| 2797 |
if(strcmp(tok, "begin") == 0) { |
| 2798 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) == eslOK) { |
| 2799 |
if(strcmp(tok, "modelname") == 0) { |
| 2800 |
if((status = parse_modelname_section(efp, errbuf, ps)) != eslOK) return status; |
| 2801 |
} |
| 2802 |
else if(strcmp(tok, "legend") == 0) { |
| 2803 |
|
| 2804 |
if((status = parse_legend_section(efp, errbuf, ps)) != eslOK) return status; |
| 2805 |
} |
| 2806 |
else if(strcmp(tok, "scale") == 0) { |
| 2807 |
|
| 2808 |
if((status = parse_scale_section(efp, errbuf, ps)) != eslOK) return status; |
| 2809 |
} |
| 2810 |
else if(strcmp(tok, "ignore") == 0) { |
| 2811 |
|
| 2812 |
if((status = parse_ignore_section(efp, errbuf, &read_showpage)) != eslOK) return status; |
| 2813 |
} |
| 2814 |
else if(strcmp(tok, "regurgitate") == 0) { |
| 2815 |
|
| 2816 |
if((status = parse_regurgitate_section(efp, errbuf, ps)) != eslOK) return status; |
| 2817 |
} |
| 2818 |
else if(strcmp(tok, "text") == 0) { |
| 2819 |
|
| 2820 |
if((status = parse_text_section(efp, errbuf, ps)) != eslOK) return status; |
| 2821 |
} |
| 2822 |
else if(strcmp(tok, "lines") == 0) { |
| 2823 |
|
| 2824 |
if((status = parse_lines_section(efp, errbuf, ps)) != eslOK) return status; |
| 2825 |
} |
| 2826 |
else { |
| 2827 |
ESL_FAIL(eslEINVAL, errbuf, "parse_template_page(), error, unknown section type %s.", tok); |
| 2828 |
} |
| 2829 |
} |
| 2830 |
else { |
| 2831 |
ESL_FAIL(eslEINVAL, errbuf, "parse_template_page(), error last read line number %d.", efp->linenumber); |
| 2832 |
} |
| 2833 |
} |
| 2834 |
else { |
| 2835 |
ESL_FAIL(eslEINVAL, errbuf, "parse_template_page(), expected line beginning with %%%% begin, but read tok: %s instead of begin, last read line number %d.", tok, efp->linenumber); |
| 2836 |
} |
| 2837 |
} |
| 2838 |
else { |
| 2839 |
ESL_FAIL(eslEINVAL, errbuf, "parse_template_page(), ran out of tokens early, error last read line number %d.", efp->linenumber); |
| 2840 |
} |
| 2841 |
} |
| 2842 |
else { |
| 2843 |
ESL_FAIL(eslEINVAL, errbuf, "parse_template_page(), expected line beginning with %%%%, read tok: %s, last read line number %d.", tok, efp->linenumber); |
| 2844 |
} |
| 2845 |
} |
| 2846 |
if(read_showpage == FALSE && status != eslEOF) { |
| 2847 |
ESL_FAIL(status, errbuf, "parse_template_page(), error, ran out of tokens, but not at end of file?, last read line number %d.", efp->linenumber); |
| 2848 |
} |
| 2849 |
if(status == eslEOF) reached_eof = TRUE; |
| 2850 |
|
| 2851 |
*ret_ps = ps; |
| 2852 |
|
| 2853 |
if(reached_eof) return eslEOF; |
| 2854 |
else return eslOK; |
| 2855 |
} |
| 2856 |
|
| 2857 |
|
| 2858 |
|
| 2859 |
|
| 2860 |
|
| 2861 |
|
| 2862 |
|
| 2863 |
|
| 2864 |
|
| 2865 |
int |
| 2866 |
parse_modelname_section(ESL_FILEPARSER *efp, char *errbuf, SSPostscript_t *ps) |
| 2867 |
{ |
| 2868 |
int status; |
| 2869 |
char *tok; |
| 2870 |
int toklen; |
| 2871 |
char *curstr = NULL; |
| 2872 |
int curlen = 0; |
| 2873 |
int ntok = 0; |
| 2874 |
|
| 2875 |
|
| 2876 |
|
| 2877 |
|
| 2878 |
|
| 2879 |
|
| 2880 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing modelname section, reading token 1 of 3"); |
| 2881 |
if (strcmp(tok, "%") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing modelname section, middle line token 1 should be a percent sign but it's %s", tok); |
| 2882 |
|
| 2883 |
while ((status = esl_fileparser_GetTokenOnLine(efp, &tok, &toklen)) == eslOK) { |
| 2884 |
if(ntok > 0) { |
| 2885 |
if((status = esl_strcat(&curstr, curlen, " ", 1)) != eslOK) ESL_FAIL(status, errbuf, "parse_modelname_section(), error parsing model name."); |
| 2886 |
curlen += 1; |
| 2887 |
} |
| 2888 |
if((status = esl_strcat(&curstr, curlen, tok, toklen)) != eslOK) ESL_FAIL(status, errbuf, "parse_modelname_section(), error parsing model name."); |
| 2889 |
curlen += toklen; |
| 2890 |
ntok++; |
| 2891 |
} |
| 2892 |
ESL_ALLOC(ps->modelname, sizeof(char) * (curlen+1)); |
| 2893 |
strcpy(ps->modelname, curstr); |
| 2894 |
|
| 2895 |
|
| 2896 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing modelname section, reading end line token 1 of 3"); |
| 2897 |
if (strcmp(tok, "%") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing modelname section, end line token 1 of 3 should be a percent sign but it's %s", tok); |
| 2898 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing modelname section, reading end line token 2 of 3"); |
| 2899 |
if (strcmp(tok, "end") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing modelname section, end line token 2 of 3 should be 'end' but it's %s", tok); |
| 2900 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing modelname section, reading end line token 3 of 3"); |
| 2901 |
if (strcmp(tok, "modelname") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing modelname section, end line token 3 of 3 should be 'modelname' but it's %s", tok); |
| 2902 |
|
| 2903 |
if(curstr != NULL) free(curstr); |
| 2904 |
return eslOK; |
| 2905 |
|
| 2906 |
ERROR: ESL_FAIL(status, errbuf, "Error, parsing modelname section, memory error?"); |
| 2907 |
} |
| 2908 |
|
| 2909 |
|
| 2910 |
|
| 2911 |
|
| 2912 |
|
| 2913 |
|
| 2914 |
|
| 2915 |
|
| 2916 |
|
| 2917 |
int |
| 2918 |
parse_legend_section(ESL_FILEPARSER *efp, char *errbuf, SSPostscript_t *ps) |
| 2919 |
{ |
| 2920 |
int status; |
| 2921 |
char *tok; |
| 2922 |
int toklen; |
| 2923 |
|
| 2924 |
|
| 2925 |
|
| 2926 |
|
| 2927 |
|
| 2928 |
|
| 2929 |
|
| 2930 |
|
| 2931 |
|
| 2932 |
|
| 2933 |
|
| 2934 |
|
| 2935 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing legend section, reading token 1 of 6"); |
| 2936 |
if (strcmp(tok, "%") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing legend section, middle line token 1 should be a percent sign but it's %s", tok); |
| 2937 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing legend section, reading token 2 of 6"); |
| 2938 |
ps->leg_posn = atoi(tok); |
| 2939 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing legend section, reading token 3 of 6"); |
| 2940 |
ps->legx_offset = atof(tok); |
| 2941 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing legend section, reading token 4 of 6"); |
| 2942 |
ps->legy_offset = atof(tok); |
| 2943 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing legend section, reading token 5 of 6"); |
| 2944 |
ps->leg_cellsize = atoi(tok); |
| 2945 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing legend section, reading token 6 of 6"); |
| 2946 |
ps->leg_rhs_space = atof(tok); |
| 2947 |
|
| 2948 |
|
| 2949 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing legend section, reading token 3 of 3"); |
| 2950 |
if (strcmp(tok, "%") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing legend section, end line token 1 of 3 should be a percent sign but it's %s", tok); |
| 2951 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing legend section, reading end line token 2 of 3"); |
| 2952 |
if (strcmp(tok, "end") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing legend section, end line token 2 of 3 should be 'end' but it's %s", tok); |
| 2953 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing legend section, reading end line token 3 of 3"); |
| 2954 |
if (strcmp(tok, "legend") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing legend section, end line token 3 of 3 should be 'legend' but it's %s", tok); |
| 2955 |
|
| 2956 |
return eslOK; |
| 2957 |
} |
| 2958 |
|
| 2959 |
|
| 2960 |
|
| 2961 |
|
| 2962 |
|
| 2963 |
|
| 2964 |
|
| 2965 |
|
| 2966 |
|
| 2967 |
int |
| 2968 |
parse_scale_section(ESL_FILEPARSER *efp, char *errbuf, SSPostscript_t *ps) |
| 2969 |
{ |
| 2970 |
int status; |
| 2971 |
char *tok; |
| 2972 |
int toklen; |
| 2973 |
|
| 2974 |
|
| 2975 |
|
| 2976 |
|
| 2977 |
|
| 2978 |
|
| 2979 |
|
| 2980 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing scale section, reading token 1 of 3"); |
| 2981 |
ps->scale = atof(tok); |
| 2982 |
if(ps->scale < 0.) ESL_FAIL(status, errbuf, "Error, parsing scale section, scale must be positive real number, read %s\n", tok); |
| 2983 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing scale section, reading token 2 of 3"); |
| 2984 |
if(esl_FCompare_old(ps->scale, atof(tok), eslSMALLX1) != eslOK) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing scale section, x and y scales are not equal %.2f != %.2f", ps->scale, atof(tok)); |
| 2985 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing scale section, reading token 3 of 3"); |
| 2986 |
if (strcmp(tok, "scale") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing scale section, token 3 of 3 should be 'scale' but it's %s", tok); |
| 2987 |
|
| 2988 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing scale section, reading end line token 1 of 3"); |
| 2989 |
if (strcmp(tok, "%") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing scale section, end line token 1 of 3 should be a percent sign but it's %s", tok); |
| 2990 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing scale section, reading end line token 2 of 3"); |
| 2991 |
if (strcmp(tok, "end") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing scale section, end line token 2 of 3 should be 'end' but it's %s", tok); |
| 2992 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing scale section, reading end line token 3 of 3"); |
| 2993 |
if (strcmp(tok, "scale") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing scale section, end line token 3 of 3 should be 'scale' but it's %s", tok); |
| 2994 |
|
| 2995 |
return eslOK; |
| 2996 |
} |
| 2997 |
|
| 2998 |
|
| 2999 |
|
| 3000 |
|
| 3001 |
|
| 3002 |
|
| 3003 |
|
| 3004 |
|
| 3005 |
|
| 3006 |
|
| 3007 |
|
| 3008 |
|
| 3009 |
|
| 3010 |
|
| 3011 |
|
| 3012 |
int |
| 3013 |
parse_ignore_section(ESL_FILEPARSER *efp, char *errbuf, int *ret_read_showpage) |
| 3014 |
{ |
| 3015 |
int status; |
| 3016 |
char *tok; |
| 3017 |
int keep_reading = TRUE; |
| 3018 |
int read_showpage = FALSE; |
| 3019 |
|
| 3020 |
while((keep_reading) && (status = esl_fileparser_NextLine(efp) == eslOK)) { |
| 3021 |
|
| 3022 |
if(((status = esl_fileparser_GetToken(efp, &tok, NULL)) == eslOK) && (strcmp(tok, "%") == 0)) { |
| 3023 |
if(((status = esl_fileparser_GetToken(efp, &tok, NULL)) == eslOK) && (strcmp(tok, "end") == 0)) { |
| 3024 |
if(((status = esl_fileparser_GetToken(efp, &tok, NULL)) == eslOK) && (strcmp(tok, "ignore") == 0)) { |
| 3025 |
keep_reading = FALSE; |
| 3026 |
status = eslOK; |
| 3027 |
} |
| 3028 |
} |
| 3029 |
} |
| 3030 |
else if(strcmp(tok, "showpage") == 0) { |
| 3031 |
read_showpage = TRUE; |
| 3032 |
} |
| 3033 |
} |
| 3034 |
if(status == eslEOF) ESL_FAIL(status, errbuf, "Error, parsing ignore section, finished file looking for '%%%% end ignore' line"); |
| 3035 |
if(status != eslOK) ESL_FAIL(status, errbuf, "Error, parsing ignore section, last line number read %d", efp->linenumber); |
| 3036 |
|
| 3037 |
*ret_read_showpage = read_showpage; |
| 3038 |
return eslOK; |
| 3039 |
} |
| 3040 |
|
| 3041 |
|
| 3042 |
|
| 3043 |
|
| 3044 |
|
| 3045 |
|
| 3046 |
|
| 3047 |
|
| 3048 |
|
| 3049 |
|
| 3050 |
int |
| 3051 |
parse_regurgitate_section(ESL_FILEPARSER *efp, char *errbuf, SSPostscript_t *ps) |
| 3052 |
{ |
| 3053 |
int status; |
| 3054 |
char *tok; |
| 3055 |
int toklen; |
| 3056 |
int seen_end = FALSE; |
| 3057 |
char *curstr = NULL; |
| 3058 |
char *newstr; |
| 3059 |
int nalloc = ps->nregurg; |
| 3060 |
int curlen; |
| 3061 |
void *tmp; |
| 3062 |
int ntok = 0; |
| 3063 |
|
| 3064 |
while (((status = esl_fileparser_NextLine(efp)) == eslOK) && (!seen_end)) |
| 3065 |
{ |
| 3066 |
curlen = ntok = 0; |
| 3067 |
while ((status = esl_fileparser_GetTokenOnLine(efp, &tok, &toklen)) == eslOK) { |
| 3068 |
if (strcmp(tok, "%") == 0) { |
| 3069 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing regurgitate section, read %%%% prefixed line without ' end regurgitate' after it"); |
| 3070 |
if (strcmp(tok, "end") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing regurgitate section, read %%%% prefixed line without ' end regurgitate' after it"); |
| 3071 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing regurgitate section, read %%%% prefixed line without ' end regurgitate' after it"); |
| 3072 |
if (strcmp(tok, "regurgitate") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing regurgitate section, read %%%% prefixed line without ' end regurgitate' after it"); |
| 3073 |
seen_end = TRUE; |
| 3074 |
break; |
| 3075 |
} |
| 3076 |
else { |
| 3077 |
if(ntok > 0) { |
| 3078 |
if((status = esl_strcat(&curstr, curlen, " ", 1)) != eslOK) ESL_FAIL(status, errbuf, "parse_regurgitate_section(), error (2)."); |
| 3079 |
curlen += 1; |
| 3080 |
} |
| 3081 |
if((status = esl_strcat(&curstr, curlen, tok, toklen)) != eslOK) ESL_FAIL(status, errbuf, "parse_regurgitate_section(), error (1)."); |
| 3082 |
curlen += toklen; |
| 3083 |
ntok++; |
| 3084 |
} |
| 3085 |
} |
| 3086 |
if(seen_end) break; |
| 3087 |
if((status = esl_strcat(&curstr, curlen, "\n", 1)) != eslOK) ESL_FAIL(status, errbuf, "parse_regurgitate_section(), error (3)."); |
| 3088 |
curlen += 1; |
| 3089 |
ESL_ALLOC(newstr, sizeof(char) * (curlen+1)); |
| 3090 |
strcpy(newstr, curstr); |
| 3091 |
if(ps->nregurg == nalloc) { |
| 3092 |
nalloc += ps->nalloc; ESL_RALLOC(ps->regurgA, tmp, sizeof(char *) * nalloc); |
| 3093 |
} |
| 3094 |
ps->regurgA[ps->nregurg++] = newstr; |
| 3095 |
free(curstr); |
| 3096 |
curstr = NULL; |
| 3097 |
} |
| 3098 |
if(status == eslEOF) ESL_FAIL(status, errbuf, "Error, parsing regurgitate section, finished file looking for '%%%% end regurgitate' line"); |
| 3099 |
if(status != eslOK) ESL_FAIL(status, errbuf, "Error, parsing regurgitate section, last line number read %d", efp->linenumber); |
| 3100 |
|
| 3101 |
return eslOK; |
| 3102 |
|
| 3103 |
ERROR: ESL_FAIL(status, errbuf, "Memory error parsing regurgitate section"); |
| 3104 |
} |
| 3105 |
|
| 3106 |
|
| 3107 |
|
| 3108 |
|
| 3109 |
|
| 3110 |
|
| 3111 |
|
| 3112 |
|
| 3113 |
|
| 3114 |
|
| 3115 |
int |
| 3116 |
parse_text_section(ESL_FILEPARSER *efp, char *errbuf, SSPostscript_t *ps) |
| 3117 |
{ |
| 3118 |
int status; |
| 3119 |
char *tok; |
| 3120 |
int toklen; |
| 3121 |
int seen_end = FALSE; |
| 3122 |
int nalloc; |
| 3123 |
void *tmp; |
| 3124 |
int do_posntext = FALSE; |
| 3125 |
int do_nucleotides = FALSE; |
| 3126 |
int i; |
| 3127 |
|
| 3128 |
|
| 3129 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing text section, last line %d\n", efp->linenumber); |
| 3130 |
if (strcmp(tok, "positiontext") == 0) { do_posntext = TRUE; nalloc = ps->nposntext; } |
| 3131 |
else if (strcmp(tok, "nucleotides") == 0) { do_nucleotides = TRUE; nalloc = ps->rflen; } |
| 3132 |
|
| 3133 |
|
| 3134 |
|
| 3135 |
|
| 3136 |
while (((status = esl_fileparser_NextLine(efp)) == eslOK) && (!seen_end)) |
| 3137 |
{ |
| 3138 |
if((status = esl_fileparser_GetTokenOnLine(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing text section, each non-comment line should be 5-tokens ending with 'show'"); |
| 3139 |
if (tok[0] == '%') { |
| 3140 |
if(strcmp(tok, "%") == 0) { |
| 3141 |
if(((status = esl_fileparser_GetToken(efp, &tok, &toklen)) == eslOK) && (strcmp(tok, "end") == 0)) { |
| 3142 |
if(((status = esl_fileparser_GetToken(efp, &tok, &toklen)) == eslOK) && (strcmp(tok, "text") == 0)) { |
| 3143 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) == eslOK) { |
| 3144 |
if(do_posntext && strcmp(tok, "positiontext") == 0) seen_end = TRUE; |
| 3145 |
if(do_nucleotides && strcmp(tok, "nucleotides") == 0) seen_end = TRUE; |
| 3146 |
} |
| 3147 |
} |
| 3148 |
} |
| 3149 |
} |
| 3150 |
} |
| 3151 |
else { |
| 3152 |
|
| 3153 |
if(do_posntext) { |
| 3154 |
if(ps->nposntext == nalloc) { |
| 3155 |
ESL_RALLOC(ps->posntextA, tmp, sizeof(char *) * (nalloc + ps->nalloc)); |
| 3156 |
ESL_RALLOC(ps->posntextxA, tmp, sizeof(float) * (nalloc + ps->nalloc)); |
| 3157 |
ESL_RALLOC(ps->posntextyA, tmp, sizeof(float) * (nalloc + ps->nalloc)); |
| 3158 |
for(i = nalloc; i < nalloc + ps->nalloc; i++) ps->posntextA[i] = NULL; |
| 3159 |
nalloc += ps->nalloc; |
| 3160 |
} |
| 3161 |
if((status = esl_strdup(tok, -1, &(ps->posntextA[ps->nposntext]))) != eslOK) goto ERROR; |
| 3162 |
} |
| 3163 |
if(do_nucleotides && ps->rflen == nalloc) { |
| 3164 |
ESL_RALLOC(ps->rxA, tmp, sizeof(float) * (nalloc + ps->nalloc)); |
| 3165 |
ESL_RALLOC(ps->ryA, tmp, sizeof(float) * (nalloc + ps->nalloc)); |
| 3166 |
nalloc += ps->nalloc; |
| 3167 |
} |
| 3168 |
|
| 3169 |
|
| 3170 |
if((status = esl_fileparser_GetTokenOnLine(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing text section, each non-comment line should be 5 tokens ending with 'show'"); |
| 3171 |
if(do_posntext) ps->posntextxA[ps->nposntext] = atof(tok); |
| 3172 |
if(do_nucleotides) ps->rxA[ps->rflen] = atof(tok); |
| 3173 |
|
| 3174 |
if((status = esl_fileparser_GetTokenOnLine(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing text section, each non-comment line should be 5 tokens ending with 'show'"); |
| 3175 |
if(do_posntext) ps->posntextyA[ps->nposntext] = atof(tok); |
| 3176 |
if(do_nucleotides) ps->ryA[ps->rflen] = atof(tok); |
| 3177 |
|
| 3178 |
|
| 3179 |
if((status = esl_fileparser_GetTokenOnLine(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing text section, each non-comment line should be 5 tokens ending with 'show'"); |
| 3180 |
if (strcmp(tok, "moveto") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing text main section, fourth token should be 'moveto', line %d", efp->linenumber); |
| 3181 |
|
| 3182 |
if((status = esl_fileparser_GetTokenOnLine(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing text section, each non-comment line should be 5 tokens ending with 'show'"); |
| 3183 |
if (strcmp(tok, "show") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing text main section, fifth token should be 'show', line %d", efp->linenumber); |
| 3184 |
|
| 3185 |
if(do_posntext) ps->nposntext++; |
| 3186 |
if(do_nucleotides) ps->rflen++; |
| 3187 |
} |
| 3188 |
} |
| 3189 |
if(!seen_end) { |
| 3190 |
if(do_posntext) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing text positiontext section, didn't see '%%%% end text positiontext' line: %d\n", efp->linenumber); |
| 3191 |
if(do_nucleotides) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing text positiontext section, didn't see '%%%% end text nucleotides' line: %d\n", efp->linenumber); |
| 3192 |
} |
| 3193 |
if(status == eslEOF && do_posntext) |
| 3194 |
ESL_FAIL(status, errbuf, "Error, parsing text section, finished file looking for '%%%% end text positiontext' line"); |
| 3195 |
if(status == eslEOF && do_nucleotides) |
| 3196 |
ESL_FAIL(status, errbuf, "Error, parsing text section, finished file looking for '%%%% end text nucleotides' line"); |
| 3197 |
if(status != eslOK) ESL_FAIL(status, errbuf, "Error, parsing text section, last line number read %d", efp->linenumber); |
| 3198 |
|
| 3199 |
return eslOK; |
| 3200 |
|
| 3201 |
ERROR: ESL_FAIL(status, errbuf, "Memory error parsing text section"); |
| 3202 |
} |
| 3203 |
|
| 3204 |
|
| 3205 |
|
| 3206 |
|
| 3207 |
|
| 3208 |
|
| 3209 |
|
| 3210 |
|
| 3211 |
|
| 3212 |
int |
| 3213 |
parse_lines_section(ESL_FILEPARSER *efp, char *errbuf, SSPostscript_t *ps) |
| 3214 |
{ |
| 3215 |
int status; |
| 3216 |
char *tok; |
| 3217 |
int toklen; |
| 3218 |
int seen_end = FALSE; |
| 3219 |
int nalloc; |
| 3220 |
void *tmp; |
| 3221 |
int do_ticks = FALSE; |
| 3222 |
int do_bpconnects = FALSE; |
| 3223 |
|
| 3224 |
|
| 3225 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing lines section, last line %d\n", efp->linenumber); |
| 3226 |
if (strcmp(tok, "positionticks") == 0) { do_ticks = TRUE; nalloc = ps->nticks; } |
| 3227 |
else if (strcmp(tok, "bpconnects") == 0) { do_bpconnects = TRUE; nalloc = ps->nbp; } |
| 3228 |
else ESL_FAIL(status, errbuf, "Error, parsing lines section unrecognized type: %s ('bpconnects' or 'positionticks' expected)\n", tok); |
| 3229 |
|
| 3230 |
|
| 3231 |
|
| 3232 |
|
| 3233 |
while (((status = esl_fileparser_NextLine(efp)) == eslOK) && (!seen_end)) |
| 3234 |
{ |
| 3235 |
if((status = esl_fileparser_GetTokenOnLine(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing lines main section should include 5-tokens ending with 'show'"); |
| 3236 |
if (strcmp(tok, "%") == 0) { |
| 3237 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing lines section, read %%%% prefixed line without ' end lines' after it"); |
| 3238 |
if (strcmp(tok, "end") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing lines section, read %%%% prefixed line without ' end lines' after it"); |
| 3239 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing lines section, read %%%% prefixed line without ' end lines' after it"); |
| 3240 |
if (strcmp(tok, "lines") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing lines section, read %%%% prefixed line without ' end lines' after it"); |
| 3241 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing lines section, read %%%% prefixed line without ' end lines' after it"); |
| 3242 |
if(do_ticks) { |
| 3243 |
if (strcmp(tok, "positionticks") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing lines section, read %%%% prefixed line without ' end lines positionticks' after it"); |
| 3244 |
} |
| 3245 |
if(do_bpconnects) { |
| 3246 |
if (strcmp(tok, "bpconnects") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing lines section, read %%%% prefixed line without ' end lines bpconnects' after it"); |
| 3247 |
} |
| 3248 |
seen_end = TRUE; |
| 3249 |
break; |
| 3250 |
} |
| 3251 |
|
| 3252 |
|
| 3253 |
if(do_ticks && ps->nticks == nalloc) { |
| 3254 |
nalloc += ps->nalloc; |
| 3255 |
ESL_RALLOC(ps->ticksx1A, tmp, sizeof(float) * nalloc); |
| 3256 |
ESL_RALLOC(ps->ticksy1A, tmp, sizeof(float) * nalloc); |
| 3257 |
ESL_RALLOC(ps->ticksx2A, tmp, sizeof(float) * nalloc); |
| 3258 |
ESL_RALLOC(ps->ticksy2A, tmp, sizeof(float) * nalloc); |
| 3259 |
} |
| 3260 |
if(do_bpconnects && ps->nbp == nalloc) { |
| 3261 |
nalloc += ps->nalloc; |
| 3262 |
ESL_RALLOC(ps->bpx1A, tmp, sizeof(float) * nalloc); |
| 3263 |
ESL_RALLOC(ps->bpy1A, tmp, sizeof(float) * nalloc); |
| 3264 |
ESL_RALLOC(ps->bpx2A, tmp, sizeof(float) * nalloc); |
| 3265 |
ESL_RALLOC(ps->bpy2A, tmp, sizeof(float) * nalloc); |
| 3266 |
} |
| 3267 |
|
| 3268 |
if(do_ticks) ps->ticksx1A[ps->nticks] = atof(tok); |
| 3269 |
if(do_bpconnects) ps->bpx1A[ps->nbp] = atof(tok); |
| 3270 |
|
| 3271 |
if((status = esl_fileparser_GetTokenOnLine(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing lines main section should include 8-tokens ending with 'stroke'"); |
| 3272 |
if(do_ticks) ps->ticksy1A[ps->nticks] = atof(tok); |
| 3273 |
if(do_bpconnects) ps->bpy1A[ps->nbp] = atof(tok); |
| 3274 |
|
| 3275 |
if((status = esl_fileparser_GetTokenOnLine(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing lines main section should include 8-tokens ending with 'stroke'"); |
| 3276 |
if(do_ticks) ps->ticksx2A[ps->nticks] = atof(tok); |
| 3277 |
if(do_bpconnects) ps->bpx2A[ps->nbp] = atof(tok); |
| 3278 |
|
| 3279 |
if((status = esl_fileparser_GetTokenOnLine(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing lines main section should include 8-tokens ending with 'stroke'"); |
| 3280 |
if(do_ticks) ps->ticksy2A[ps->nticks] = atof(tok); |
| 3281 |
if(do_bpconnects) ps->bpy2A[ps->nbp] = atof(tok); |
| 3282 |
|
| 3283 |
|
| 3284 |
if((status = esl_fileparser_GetTokenOnLine(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing lines main section should include 8-tokens ending with 'stroke'"); |
| 3285 |
if (strcmp(tok, "newpath") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing lines main section, fifth token should be 'newpath', line %d", efp->linenumber); |
| 3286 |
|
| 3287 |
if((status = esl_fileparser_GetTokenOnLine(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing lines main section should include 8-tokens ending with 'stroke'"); |
| 3288 |
if (strcmp(tok, "moveto") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing lines main section, sixth token should be 'moveto', line %d", efp->linenumber); |
| 3289 |
|
| 3290 |
if((status = esl_fileparser_GetTokenOnLine(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing lines main section should include 8-tokens ending with 'stroke'"); |
| 3291 |
if (strcmp(tok, "lineto") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing lines main section, seventh token should be 'lineto', line %d", efp->linenumber); |
| 3292 |
|
| 3293 |
if((status = esl_fileparser_GetTokenOnLine(efp, &tok, &toklen)) != eslOK) ESL_FAIL(status, errbuf, "Error, parsing lines main section should include 8-tokens ending with 'stroke'"); |
| 3294 |
if (strcmp(tok, "stroke") != 0) ESL_FAIL(eslEINVAL, errbuf, "Error, parsing lines main section, eigth token should be 'stroke', line %d", efp->linenumber); |
| 3295 |
|
| 3296 |
if(do_ticks) ps->nticks++; |
| 3297 |
if(do_bpconnects) ps->nbp++; |
| 3298 |
} |
| 3299 |
if(!seen_end) ESL_FAIL(status, errbuf, "Error, parsing lines section, didn't see end! line: %d\n", efp->linenumber); |
| 3300 |
if(status == eslEOF && do_ticks) |
| 3301 |
ESL_FAIL(status, errbuf, "Error, parsing lines section, finished file looking for '%%%% end lines positionticks' line"); |
| 3302 |
if(status == eslEOF && do_bpconnects) |
| 3303 |
ESL_FAIL(status, errbuf, "Error, parsing lines section, finished file looking for '%%%% end lines bpconnects' line"); |
| 3304 |
|
| 3305 |
if(status != eslOK) ESL_FAIL(status, errbuf, "Error, parsing lines section, last line number read %d", efp->linenumber); |
| 3306 |
|
| 3307 |
return eslOK; |
| 3308 |
ERROR: ESL_FAIL(status, errbuf, "Memory error parsing lines section"); |
| 3309 |
} |
| 3310 |
|
| 3311 |
|
| 3312 |
|
| 3313 |
|
| 3314 |
|
| 3315 |
|
| 3316 |
|
| 3317 |
|
| 3318 |
|
| 3319 |
|
| 3320 |
|
| 3321 |
|
| 3322 |
|
| 3323 |
|
| 3324 |
static int |
| 3325 |
individuals_sspostscript(const ESL_GETOPTS *go, ESL_ALPHABET *abc, char *errbuf, SSPostscript_t *ps, double **abc_ct, ESL_MSA *msa, int **per_seq_ins_ct, |
| 3326 |
int do_prob, int do_rescol, float ***hc_scheme, int hc_scheme_idx_s, int hc_scheme_idx_p, |
| 3327 |
int hc_nbins_s, int hc_nbins_p, float **hc_onecell, int extdel_idx_s, int wcbp_idx_s, int gubp_idx_s, |
| 3328 |
int ncbp_idx_s, int dgbp_idx_s, int hgbp_idx_s, int gap_idx_p, FILE *tabfp) |
| 3329 |
{ |
| 3330 |
int status; |
| 3331 |
int p, i, pp; |
| 3332 |
int rfpos, apos, lpos, rpos, lrfpos, rrfpos; |
| 3333 |
int orig_npage = ps->npage; |
| 3334 |
int new_npage; |
| 3335 |
|
| 3336 |
|
| 3337 |
int nextdel_s = 0; |
| 3338 |
int nwc_s = 0; |
| 3339 |
int ngu_s = 0; |
| 3340 |
int nnc_s = 0; |
| 3341 |
int ndgi_s = 0; |
| 3342 |
int nhgi_s = 0; |
| 3343 |
int ndge_s = 0; |
| 3344 |
int nhge_s = 0; |
| 3345 |
float *limits_s; |
| 3346 |
int nins_s; |
| 3347 |
int spos, epos; |
| 3348 |
int apos_is_internal; |
| 3349 |
int lpos_is_internal; |
| 3350 |
int rpos_is_internal; |
| 3351 |
int namewidth; |
| 3352 |
char *namedashes = NULL; |
| 3353 |
int ni; |
| 3354 |
double cur_cfreq; |
| 3355 |
int noutline_min = 0; |
| 3356 |
int noutline_max = 0; |
| 3357 |
int noutline_bp_good = 0; |
| 3358 |
int noutline_bp_bad = 0; |
| 3359 |
int maj_bp_is_wc_or_gu; |
| 3360 |
float *stack; |
| 3361 |
|
| 3362 |
|
| 3363 |
int ngap_p = 0; |
| 3364 |
int ngap_masked_p = 0; |
| 3365 |
float *limits_p; |
| 3366 |
int within_mask; |
| 3367 |
float ppavgA[11]; |
| 3368 |
int ppidx; |
| 3369 |
int do_prob_res = FALSE; |
| 3370 |
int do_outline = FALSE; |
| 3371 |
int noccl; |
| 3372 |
|
| 3373 |
|
| 3374 |
if(do_prob) { |
| 3375 |
if(msa->pp == NULL) ESL_FAIL(eslEINVAL, errbuf, "internal error, individuals_sspostscript() do_prob == TRUE, msa->pp == FALSE"); |
| 3376 |
for(i = 0; i < msa->nseq; i++) { |
| 3377 |
if(msa->pp[i] == NULL) |
| 3378 |
ESL_FAIL(eslEINVAL, errbuf, "with --indi, either all or none of the selected sequences must have PP annotation, seq %d does not", i); |
| 3379 |
} |
| 3380 |
do_prob_res = (! esl_opt_GetBoolean(go, "--no-ntpp")); |
| 3381 |
} |
| 3382 |
do_outline = (! esl_opt_GetBoolean(go, "--no-ol")); |
| 3383 |
|
| 3384 |
|
| 3385 |
ppavgA[0] = 0.025; |
| 3386 |
ppavgA[1] = 0.10; |
| 3387 |
ppavgA[2] = 0.20; |
| 3388 |
ppavgA[3] = 0.30; |
| 3389 |
ppavgA[4] = 0.40; |
| 3390 |
ppavgA[5] = 0.50; |
| 3391 |
ppavgA[6] = 0.60; |
| 3392 |
ppavgA[7] = 0.70; |
| 3393 |
ppavgA[8] = 0.80; |
| 3394 |
ppavgA[9] = 0.90; |
| 3395 |
ppavgA[10] = 0.975; |
| 3396 |
|
| 3397 |
|
| 3398 |
new_npage = do_prob ? msa->nseq*2 : msa->nseq; |
| 3399 |
if((status = add_pages_sspostscript(ps, new_npage, INDIMODE)) != eslOK) ESL_FAIL(status, errbuf, "memory error adding pages to the postscript object."); |
| 3400 |
|
| 3401 |
|
| 3402 |
for(p = orig_npage; p < ps->npage; p++) { |
| 3403 |
|
| 3404 |
ESL_ALLOC(ps->rAA[p], sizeof(char) * (ps->rflen+1)); |
| 3405 |
if(do_rescol) ESL_ALLOC(ps->rcolAAA[p], sizeof(float *) * ps->rflen); |
| 3406 |
if(do_outline) { |
| 3407 |
ESL_ALLOC(ps->otypeAA[p], sizeof(char) * ps->rflen); |
| 3408 |
for(rfpos = 0; rfpos < ps->rflen; rfpos++) ps->otypeAA[p][rfpos] = OUTLINE_NONE_IDX; |
| 3409 |
} |
| 3410 |
ESL_ALLOC(ps->bcolAAA[p], sizeof(float *) * ps->rflen); |
| 3411 |
ESL_ALLOC(ps->sclAA[p], sizeof(SchemeColorLegend_t) * 1); |
| 3412 |
noccl = 2; |
| 3413 |
if (do_rescol) noccl += 5; |
| 3414 |
if (do_outline) noccl += 7; |
| 3415 |
ESL_ALLOC(ps->occlAAA[p], sizeof(OneCellColorLegend_t *) * noccl); |
| 3416 |
for(rfpos = 0; rfpos < ps->rflen; rfpos++) { |
| 3417 |
if(do_rescol) ESL_ALLOC(ps->rcolAAA[p][rfpos], sizeof(float) * NCMYK); |
| 3418 |
ESL_ALLOC(ps->bcolAAA[p][rfpos], sizeof(float) * NCMYK); |
| 3419 |
} |
| 3420 |
|
| 3421 |
if(do_prob) { |
| 3422 |
|
| 3423 |
p++; |
| 3424 |
ESL_ALLOC(ps->rAA[p], sizeof(char) * (ps->rflen+1)); |
| 3425 |
ESL_ALLOC(ps->bcolAAA[p], sizeof(float *) * ps->rflen); |
| 3426 |
ESL_ALLOC(ps->sclAA[p], sizeof(SchemeColorLegend_t) * 1); |
| 3427 |
ESL_ALLOC(ps->occlAAA[p], sizeof(OneCellColorLegend_t *) * 1); |
| 3428 |
if(do_prob_res) ESL_ALLOC(ps->rcolAAA[p], sizeof(float *) * ps->rflen); |
| 3429 |
for(rfpos = 0; rfpos < ps->rflen; rfpos++) { |
| 3430 |
ESL_ALLOC(ps->bcolAAA[p][rfpos], sizeof(float) * NCMYK); |
| 3431 |
if(do_prob_res) ESL_ALLOC(ps->rcolAAA[p][rfpos], sizeof(float) * NCMYK); |
| 3432 |
} |
| 3433 |
} |
| 3434 |
} |
| 3435 |
|
| 3436 |
|
| 3437 |
ESL_ALLOC(limits_s, sizeof(float) * (hc_nbins_s+1)); |
| 3438 |
limits_s[0] = 0; |
| 3439 |
limits_s[1] = 1; |
| 3440 |
limits_s[2] = 2; |
| 3441 |
limits_s[3] = 5; |
| 3442 |
limits_s[4] = 10; |
| 3443 |
limits_s[5] = eslINFINITY; |
| 3444 |
|
| 3445 |
|
| 3446 |
ESL_ALLOC(limits_p, sizeof(float) * (hc_nbins_p+1)); |
| 3447 |
limits_p[0] = 0.0; |
| 3448 |
limits_p[1] = 0.35; |
| 3449 |
limits_p[2] = 0.55; |
| 3450 |
limits_p[3] = 0.75; |
| 3451 |
limits_p[4] = 0.85; |
| 3452 |
limits_p[5] = 0.95; |
| 3453 |
limits_p[6] = 1.00; |
| 3454 |
|
| 3455 |
|
| 3456 |
if(ps->uaseqlenA != NULL) { free(ps->uaseqlenA); ps->uaseqlenA = NULL; } |
| 3457 |
ESL_ALLOC(ps->uaseqlenA, sizeof(int) * msa->nseq); |
| 3458 |
esl_vec_ISet(ps->uaseqlenA, msa->nseq, 0); |
| 3459 |
|
| 3460 |
if(tabfp != NULL) { |
| 3461 |
|
| 3462 |
namewidth = 8; |
| 3463 |
for(i = 0; i < msa->nseq; i++) { |
| 3464 |
namewidth = ESL_MAX(namewidth, strlen(msa->sqname[i])); |
| 3465 |
} |
| 3466 |
ESL_ALLOC(namedashes, sizeof(char) * namewidth+1); |
| 3467 |
namedashes[namewidth] = '\0'; |
| 3468 |
for(ni = 0; ni < namewidth; ni++) namedashes[ni] = '-'; |
| 3469 |
fprintf(tabfp, "# -----------------------\n"); |
| 3470 |
fprintf(tabfp, "# Per-sequence statistics\n"); |
| 3471 |
fprintf(tabfp, "# -----------------------\n"); |
| 3472 |
fprintf(tabfp, "# This section includes %d non #-prefixed lines, one for each sequence\n", ps->rflen); |
| 3473 |
fprintf(tabfp, "# printed to the output postscript file.\n"); |
| 3474 |
fprintf(tabfp, "# Each line includes %d tokens, separated by whitespace:\n", do_outline ? 15 : 11); |
| 3475 |
fprintf(tabfp, "# \ttoken 1: 'perseq' (tag defining line type to ease parsing)\n"); |
| 3476 |
fprintf(tabfp, "# \ttoken 2: sequence name\n"); |
| 3477 |
fprintf(tabfp, "# \ttoken 3: spos: aligned position of first (5'-most) nongap nucleotide in sequence\n"); |
| 3478 |
fprintf(tabfp, "# \ttoken 4: epos: aligned position of final (3'-most) nongap nucleotide in sequence\n"); |
| 3479 |
fprintf(tabfp, "# \ttoken 5: number of Watson-Crick basepairs (A-U, C-G, G-C, or U-A) in the sequence\n"); |
| 3480 |
fprintf(tabfp, "# \ttoken 6: number of G-U or U-G basepairs in the sequence\n"); |
| 3481 |
fprintf(tabfp, "# \ttoken 7: number of non-canonical basepairs (A-A, A-C, A-G, C-A, C-C, C-U, G-A, G-G, U-C, U-U) in the sequence\n"); |
| 3482 |
fprintf(tabfp, "# \ttoken 8: number of internal half-gap basepairs in the sequence\n"); |
| 3483 |
fprintf(tabfp, "# \ttoken 9: number of internal double-gap basepairs in the sequence\n"); |
| 3484 |
fprintf(tabfp, "# \ttoken 10: number of external half-gap basepairs in the sequence\n"); |
| 3485 |
fprintf(tabfp, "# \ttoken 11: number of external double-gap basepairs in the sequence\n"); |
| 3486 |
if(do_outline) { |
| 3487 |
fprintf(tabfp, "# \ttoken 12: number of nt changes relative to majority rule consensus sequence\n"); |
| 3488 |
fprintf(tabfp, "# \ttoken 13: subset of token 12 for which consensus nt occurs in > 0.75 of nongap sequences\n"); |
| 3489 |
fprintf(tabfp, "# \ttoken 14: number of internal basepairs in seq that differ from majority rule consensus basepair\n"); |
| 3490 |
fprintf(tabfp, "# \t *and* consensus bp is Watson-Crick, G-U or U-G\n"); |
| 3491 |
fprintf(tabfp, "# \ttoken 15: subset of token 14 which are Watson-Crick, G-U or U-G in seq\n"); |
| 3492 |
} |
| 3493 |
fprintf(tabfp, "#\n"); |
| 3494 |
fprintf(tabfp, "# Alignment length: %" PRId64 " (this is max possible value for tokens 3 and 4)\n", msa->alen); |
| 3495 |
fprintf(tabfp, "# Number of consensus basepairs: %d (this is max possible value for tokens 5-11)\n", ps->nbp); |
| 3496 |
fprintf(tabfp, "# A basepair between positions i and j for sequence s is a half-gap basepair if s has\n"); |
| 3497 |
fprintf(tabfp, "# a gap at either position i or j, but not both. It is a double-gap basepair if it has\n"); |
| 3498 |
fprintf(tabfp, "# a gap at both positions i and j.\n"); |
| 3499 |
fprintf(tabfp, "# A basepair between i:j is 'internal' for sequence s if if spos <= i and epos >= j.\n"); |
| 3500 |
fprintf(tabfp, "# Otherwise, basepair i:j is 'external' for sequence s.\n"); |
| 3501 |
fprintf(tabfp, "# All basepairs that are nongaps in both i and j are necessarily internal.\n"); |
| 3502 |
fprintf(tabfp, "#\n"); |
| 3503 |
fprintf(tabfp, "# %6s %-*s %4s %4s %4s %4s %4s %4s %4s %4s %4s", "type", namewidth, "seq name", "spos", "epos", "nwc", "ngu", "nnc", "nhgi", "ndgi", "nhge", "ndge"); |
| 3504 |
if(do_outline) { fprintf(tabfp, " %4s %4s %5s %5s", "ndf", "nrdf", "nbpdf", "nbpcp"); } |
| 3505 |
fprintf(tabfp, "\n"); |
| 3506 |
fprintf(tabfp, "# %6s %-*s %4s %4s %4s %4s %4s %4s %4s %4s %4s", "------", namewidth, namedashes, "----", "----", "----", "----", "----", "----", "----", "----", "----"); |
| 3507 |
if(do_outline) { fprintf(tabfp, " %4s %4s %5s %5s", "----", "----", "-----", "-----"); } |
| 3508 |
fprintf(tabfp, "\n"); |
| 3509 |
} |
| 3510 |
|
| 3511 |
|
| 3512 |
pp = orig_npage-1; |
| 3513 |
for(i = 0; i < msa->nseq; i++) { |
| 3514 |
|
| 3515 |
|
| 3516 |
|
| 3517 |
pp++; |
| 3518 |
spos = epos = -1; |
| 3519 |
|
| 3520 |
for(apos = 0; apos < msa->alen; apos++) { |
| 3521 |
if((! esl_abc_CIsGap(abc, msa->aseq[i][apos]))) { |
| 3522 |
spos = apos; |
| 3523 |
break; |
| 3524 |
} |
| 3525 |
} |
| 3526 |
for(apos = msa->alen-1; apos >= 0; apos--) { |
| 3527 |
if((! esl_abc_CIsGap(abc, msa->aseq[i][apos]))) { |
| 3528 |
epos = apos; |
| 3529 |
break; |
| 3530 |
} |
| 3531 |
} |
| 3532 |
if(ps->sclAA[pp] != NULL){ |
| 3533 |
free(ps->sclAA[pp]); |
| 3534 |
} |
| 3535 |
ps->sclAA[pp] = create_scheme_colorlegend(hc_scheme_idx_s, hc_nbins_s, limits_s, TRUE, TRUE, TRUE, FALSE); |
| 3536 |
|
| 3537 |
nextdel_s = nwc_s = ngu_s = nnc_s = ndgi_s = nhgi_s = ndge_s = nhge_s = noutline_min = noutline_max = noutline_bp_good = noutline_bp_bad = 0; |
| 3538 |
for(rfpos = 0; rfpos < ps->rflen; rfpos++) { |
| 3539 |
apos = ps->msa_rf2a_map[rfpos]; |
| 3540 |
nins_s = per_seq_ins_ct[i][rfpos+1]; |
| 3541 |
apos_is_internal = TRUE; |
| 3542 |
|
| 3543 |
if(! esl_abc_CIsGap(abc, msa->aseq[i][apos])) ps->uaseqlenA[i]++; |
| 3544 |
ps->uaseqlenA[i] += nins_s; |
| 3545 |
ps->rAA[pp][rfpos] = msa->aseq[i][apos]; |
| 3546 |
if(do_outline) { |
| 3547 |
if((! esl_abc_CIsGap(abc, msa->aseq[i][apos])) && |
| 3548 |
(esl_abc_CIsCanonical(abc, ps->msa_cseq_maj[rfpos])) && |
| 3549 |
(toupper(msa->aseq[i][apos]) != toupper(ps->msa_cseq_maj[rfpos]))) { |
| 3550 |
cur_cfreq = abc_ct[apos][esl_abc_DigitizeSymbol(abc, toupper(ps->msa_cseq_maj[rfpos]))] / |
| 3551 |
esl_vec_DSum(abc_ct[apos], abc->K); |
| 3552 |
if(cur_cfreq > 0.75) { ps->otypeAA[pp][rfpos] = OUTLINE_MAX_IDX; noutline_max++; } |
| 3553 |
else { ps->otypeAA[pp][rfpos] = OUTLINE_MIN_IDX; noutline_min++; } |
| 3554 |
} |
| 3555 |
} |
| 3556 |
|
| 3557 |
if((spos != -1 && epos != -1) && |
| 3558 |
(apos < spos || apos > epos)) { |
| 3559 |
if((status = set_onecell_values(errbuf, ps->bcolAAA[pp][rfpos], NCMYK, hc_onecell[extdel_idx_s])) != eslOK) return status; |
| 3560 |
nextdel_s++; |
| 3561 |
apos_is_internal = FALSE; |
| 3562 |
} |
| 3563 |
else { |
| 3564 |
if((status = set_scheme_values(errbuf, ps->bcolAAA[pp][rfpos], NCMYK, hc_scheme[hc_scheme_idx_s], nins_s, ps->sclAA[pp], TRUE, NULL)) != eslOK) return status; |
| 3565 |
} |
| 3566 |
if(do_rescol || tabfp != NULL) { |
| 3567 |
if(ps->msa_ct[(rfpos+1)] == 0) { |
| 3568 |
if(do_rescol) { |
| 3569 |
|
| 3570 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[wcbp_idx_s])) != eslOK) return status; |
| 3571 |
} |
| 3572 |
} |
| 3573 |
else { |
| 3574 |
lpos = apos; |
| 3575 |
rpos = ps->msa_rf2a_map[ps->msa_ct[rfpos+1]-1]; |
| 3576 |
lrfpos = rfpos; |
| 3577 |
rrfpos = ps->msa_ct[rfpos+1]-1; |
| 3578 |
maj_bp_is_wc_or_gu = ((is_watson_crick_bp(ps->msa_cseq_maj[lrfpos], ps->msa_cseq_maj[rrfpos])) |
| 3579 |
|| (is_gu_or_ug_bp(ps->msa_cseq_maj[lrfpos], ps->msa_cseq_maj[rrfpos]))) ? TRUE : FALSE; |
| 3580 |
lpos_is_internal = apos_is_internal; |
| 3581 |
rpos_is_internal = TRUE; |
| 3582 |
if((spos != -1 && epos != -1) && |
| 3583 |
(rpos < spos || rpos > epos)) { |
| 3584 |
rpos_is_internal = FALSE; |
| 3585 |
} |
| 3586 |
if(lpos_is_internal && rpos_is_internal) { |
| 3587 |
if(is_watson_crick_bp(msa->aseq[i][lpos], msa->aseq[i][rpos])) { |
| 3588 |
if(do_rescol) { |
| 3589 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[wcbp_idx_s])) != eslOK) return status; |
| 3590 |
} |
| 3591 |
if(lpos < rpos) nwc_s++; |
| 3592 |
if(do_outline && (lpos > rpos) && maj_bp_is_wc_or_gu) { |
| 3593 |
|
| 3594 |
if((ps->otypeAA[pp][lrfpos] != OUTLINE_NONE_IDX) || |
| 3595 |
(ps->otypeAA[pp][rrfpos] != OUTLINE_NONE_IDX)) { |
| 3596 |
noutline_bp_good++; |
| 3597 |
} |
| 3598 |
} |
| 3599 |
} |
| 3600 |
else if(is_gu_or_ug_bp(msa->aseq[i][lpos], msa->aseq[i][rpos])) { |
| 3601 |
if(do_rescol) { |
| 3602 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[gubp_idx_s])) != eslOK) return status; |
| 3603 |
} |
| 3604 |
if(lpos < rpos) ngu_s++; |
| 3605 |
if(do_outline && (lpos > rpos) && maj_bp_is_wc_or_gu) { |
| 3606 |
if((ps->otypeAA[pp][lrfpos] != OUTLINE_NONE_IDX) || |
| 3607 |
(ps->otypeAA[pp][rrfpos] != OUTLINE_NONE_IDX)) { |
| 3608 |
noutline_bp_good++; |
| 3609 |
} |
| 3610 |
} |
| 3611 |
} |
| 3612 |
else if ((! esl_abc_CIsResidue(abc, msa->aseq[i][lpos])) && (! esl_abc_CIsResidue(abc, msa->aseq[i][rpos]))) { |
| 3613 |
if(do_rescol) { |
| 3614 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[dgbp_idx_s])) != eslOK) return status; |
| 3615 |
} |
| 3616 |
if(lpos < rpos) ndgi_s++; |
| 3617 |
if(do_outline && (lpos > rpos) && maj_bp_is_wc_or_gu) { |
| 3618 |
if((ps->otypeAA[pp][lrfpos] != OUTLINE_NONE_IDX) || |
| 3619 |
(ps->otypeAA[pp][rrfpos] != OUTLINE_NONE_IDX)) { |
| 3620 |
noutline_bp_bad++; |
| 3621 |
} |
| 3622 |
} |
| 3623 |
} |
| 3624 |
else if ((! esl_abc_CIsResidue(abc, msa->aseq[i][lpos])) || (! esl_abc_CIsResidue(abc, msa->aseq[i][rpos]))) { |
| 3625 |
if(do_rescol) { |
| 3626 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[hgbp_idx_s])) != eslOK) return status; |
| 3627 |
} |
| 3628 |
if(lpos < rpos) nhgi_s++; |
| 3629 |
if(do_outline && (lpos > rpos) && maj_bp_is_wc_or_gu) { |
| 3630 |
if((ps->otypeAA[pp][lrfpos] != OUTLINE_NONE_IDX) || |
| 3631 |
(ps->otypeAA[pp][rrfpos] != OUTLINE_NONE_IDX)) { |
| 3632 |
noutline_bp_bad++; |
| 3633 |
} |
| 3634 |
} |
| 3635 |
} |
| 3636 |
else { |
| 3637 |
if(do_rescol) { |
| 3638 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[ncbp_idx_s])) != eslOK) return status; |
| 3639 |
} |
| 3640 |
if(lpos < rpos) nnc_s++; |
| 3641 |
if(do_outline && (lpos > rpos) && maj_bp_is_wc_or_gu) { |
| 3642 |
if((ps->otypeAA[pp][lrfpos] != OUTLINE_NONE_IDX) || |
| 3643 |
(ps->otypeAA[pp][rrfpos] != OUTLINE_NONE_IDX)) { |
| 3644 |
noutline_bp_bad++; |
| 3645 |
} |
| 3646 |
} |
| 3647 |
} |
| 3648 |
} |
| 3649 |
else { |
| 3650 |
if ((! esl_abc_CIsResidue(abc, msa->aseq[i][lpos])) && (! esl_abc_CIsResidue(abc, msa->aseq[i][rpos]))) { |
| 3651 |
ndge_s++; |
| 3652 |
} |
| 3653 |
if ((! esl_abc_CIsResidue(abc, msa->aseq[i][lpos])) || (! esl_abc_CIsResidue(abc, msa->aseq[i][rpos]))) { |
| 3654 |
nhge_s++; |
| 3655 |
} |
| 3656 |
if(do_rescol) { |
| 3657 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[BLACKOC])) != eslOK) return status; |
| 3658 |
} |
| 3659 |
} |
| 3660 |
} |
| 3661 |
} |
| 3662 |
} |
| 3663 |
ps->rAA[pp][ps->rflen] = '\0'; |
| 3664 |
ps->seqidxA[pp] = i; |
| 3665 |
ps->nocclA[pp] = 0; |
| 3666 |
|
| 3667 |
if(tabfp != NULL) { |
| 3668 |
fprintf(tabfp, " perseq %-*s %4d %4d %4d %4d %4d %4d %4d %4d %4d", namewidth, msa->sqname[i], spos+1, epos+1, nwc_s, ngu_s, nnc_s, nhgi_s, ndgi_s, nhge_s, ndge_s); |
| 3669 |
if(do_outline) { |
| 3670 |
fprintf(tabfp, " %4d %4d %5d %5d", noutline_min + noutline_max, noutline_max, noutline_bp_good + noutline_bp_bad, noutline_bp_good); |
| 3671 |
} |
| 3672 |
fprintf(tabfp, "\n"); |
| 3673 |
} |
| 3674 |
|
| 3675 |
|
| 3676 |
if(do_rescol) { |
| 3677 |
|
| 3678 |
ps->occlAAA[pp][ps->nocclA[pp]] = create_onecell_colorlegend(hc_onecell[wcbp_idx_s], nwc_s, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 3679 |
if((status = add_text_to_onecell_colorlegend (ps, ps->occlAAA[pp][ps->nocclA[pp]], "Watson-Crick basepair (WC bp)", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 3680 |
if((status = add_celltext_to_onecell_colorlegend(ps, ps->occlAAA[pp][ps->nocclA[pp]], "C-G", errbuf)) != eslOK) return status; |
| 3681 |
ps->nocclA[pp]++; |
| 3682 |
|
| 3683 |
|
| 3684 |
ps->occlAAA[pp][ps->nocclA[pp]] = create_onecell_colorlegend(hc_onecell[gubp_idx_s], ngu_s, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 3685 |
if((status = add_text_to_onecell_colorlegend (ps, ps->occlAAA[pp][ps->nocclA[pp]], "G-U or U-G bp", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 3686 |
if((status = add_celltext_to_onecell_colorlegend(ps, ps->occlAAA[pp][ps->nocclA[pp]], "G-U", errbuf)) != eslOK) return status; |
| 3687 |
ps->nocclA[pp]++; |
| 3688 |
|
| 3689 |
|
| 3690 |
ps->occlAAA[pp][ps->nocclA[pp]] = create_onecell_colorlegend(hc_onecell[ncbp_idx_s], nnc_s, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 3691 |
if((status = add_text_to_onecell_colorlegend (ps, ps->occlAAA[pp][ps->nocclA[pp]], "non-canonical bp", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 3692 |
if((status = add_celltext_to_onecell_colorlegend(ps, ps->occlAAA[pp][ps->nocclA[pp]], "A-A", errbuf)) != eslOK) return status; |
| 3693 |
ps->nocclA[pp]++; |
| 3694 |
|
| 3695 |
|
| 3696 |
ps->occlAAA[pp][ps->nocclA[pp]] = create_onecell_colorlegend(hc_onecell[hgbp_idx_s], nhgi_s, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 3697 |
if((status = add_text_to_onecell_colorlegend (ps, ps->occlAAA[pp][ps->nocclA[pp]], "internal half-gap bp", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 3698 |
if((status = add_celltext_to_onecell_colorlegend(ps, ps->occlAAA[pp][ps->nocclA[pp]], "A--", errbuf)) != eslOK) return status; |
| 3699 |
ps->nocclA[pp]++; |
| 3700 |
|
| 3701 |
|
| 3702 |
ps->occlAAA[pp][ps->nocclA[pp]] = create_onecell_colorlegend(hc_onecell[dgbp_idx_s], ndgi_s, OCCL_BLANK_COUNT, TRUE, FALSE); |
| 3703 |
if((status = add_text_to_onecell_colorlegend (ps, ps->occlAAA[pp][ps->nocclA[pp]], "internal double-gap bp", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 3704 |
if((status = add_celltext_to_onecell_colorlegend(ps, ps->occlAAA[pp][ps->nocclA[pp]], "---", errbuf)) != eslOK) return status; |
| 3705 |
ps->nocclA[pp]++; |
| 3706 |
} |
| 3707 |
|
| 3708 |
|
| 3709 |
if(do_outline) { |
| 3710 |
|
| 3711 |
ps->occlAAA[pp][ps->nocclA[pp]] = create_onecell_colorlegend(hc_onecell[BLACKOC], OCCL_BLANK_COUNT, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 3712 |
if((status = add_text_to_onecell_colorlegend (ps, ps->occlAAA[pp][ps->nocclA[pp]], "Positions != to most common nt x:", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 3713 |
if((status = add_celltext_to_onecell_colorlegend(ps, ps->occlAAA[pp][ps->nocclA[pp]], "", errbuf)) != eslOK) return status; |
| 3714 |
ps->nocclA[pp]++; |
| 3715 |
|
| 3716 |
|
| 3717 |
ESL_ALLOC(stack, sizeof(float) * 2); |
| 3718 |
stack[0] = ps->leg_cellsize; |
| 3719 |
stack[1] = ps->leg_cellsize * OUTLINE_LINEWIDTH_CELL_FRACTION_MIN; |
| 3720 |
|
| 3721 |
ps->occlAAA[pp][ps->nocclA[pp]] = create_onecell_colorlegend(hc_onecell[BLACKOC], noutline_min, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 3722 |
if((status = add_text_to_onecell_colorlegend (ps, ps->occlAAA[pp][ps->nocclA[pp]], "!= x and freq(x) < 0.75", ps->legx_max_chars, errbuf)) != eslOK) { |
| 3723 |
free(stack); |
| 3724 |
return status; |
| 3725 |
} |
| 3726 |
if((status = add_procedure_to_onecell_colorlegend(ps, ps->occlAAA[pp][ps->nocclA[pp]], OUTLINE_PROCEDURE, stack, 2, errbuf)) != eslOK) return status; |
| 3727 |
ps->nocclA[pp]++; |
| 3728 |
|
| 3729 |
stack[1] = ps->leg_cellsize * OUTLINE_LINEWIDTH_CELL_FRACTION_MAX; |
| 3730 |
|
| 3731 |
ps->occlAAA[pp][ps->nocclA[pp]] = create_onecell_colorlegend(hc_onecell[BLACKOC], noutline_max, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 3732 |
if((status = add_text_to_onecell_colorlegend (ps, ps->occlAAA[pp][ps->nocclA[pp]], "!= x and freq(x) >= 0.75", ps->legx_max_chars, errbuf)) != eslOK){ |
| 3733 |
free(stack); |
| 3734 |
return status; |
| 3735 |
} |
| 3736 |
if((status = add_procedure_to_onecell_colorlegend(ps, ps->occlAAA[pp][ps->nocclA[pp]], OUTLINE_PROCEDURE, stack, 2, errbuf)) != eslOK){ |
| 3737 |
free(stack); |
| 3738 |
return status; |
| 3739 |
} |
| 3740 |
ps->nocclA[pp]++; |
| 3741 |
|
| 3742 |
|
| 3743 |
ps->occlAAA[pp][ps->nocclA[pp]] = create_onecell_colorlegend(hc_onecell[BLACKOC], OCCL_BLANK_COUNT, OCCL_BLANK_COUNT, FALSE, TRUE); |
| 3744 |
if((status = add_text_to_onecell_colorlegend (ps, ps->occlAAA[pp][ps->nocclA[pp]], "Number of bps != most common bp a:b", ps->legx_max_chars, errbuf)) != eslOK){ |
| 3745 |
free(stack); |
| 3746 |
return status; |
| 3747 |
} |
| 3748 |
if((status = add_celltext_to_onecell_colorlegend(ps, ps->occlAAA[pp][ps->nocclA[pp]], "", errbuf)) != eslOK){ |
| 3749 |
free(stack); |
| 3750 |
return status; |
| 3751 |
} |
| 3752 |
ps->nocclA[pp]++; |
| 3753 |
|
| 3754 |
|
| 3755 |
ps->occlAAA[pp][ps->nocclA[pp]] = create_onecell_colorlegend(hc_onecell[BLACKOC], OCCL_BLANK_COUNT, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 3756 |
if((status = add_text_to_onecell_colorlegend (ps, ps->occlAAA[pp][ps->nocclA[pp]], "and a:b is Watson-Crick, GU or UG:", ps->legx_max_chars, errbuf)) != eslOK){ |
| 3757 |
free(stack); |
| 3758 |
return status; |
| 3759 |
} |
| 3760 |
if((status = add_celltext_to_onecell_colorlegend(ps, ps->occlAAA[pp][ps->nocclA[pp]], "", errbuf)) != eslOK){ |
| 3761 |
free(stack); |
| 3762 |
return status; |
| 3763 |
} |
| 3764 |
ps->nocclA[pp]++; |
| 3765 |
|
| 3766 |
ps->occlAAA[pp][ps->nocclA[pp]] = create_onecell_colorlegend(hc_onecell[BLACKOC], noutline_bp_good, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 3767 |
if((status = add_text_to_onecell_colorlegend (ps, ps->occlAAA[pp][ps->nocclA[pp]], " Watson-Crick, GU or UG but != a:b", ps->legx_max_chars, errbuf)) != eslOK){ |
| 3768 |
free(stack); |
| 3769 |
return status; |
| 3770 |
} |
| 3771 |
if((status = add_celltext_to_onecell_colorlegend(ps, ps->occlAAA[pp][ps->nocclA[pp]], "", errbuf)) != eslOK){ |
| 3772 |
free(stack); |
| 3773 |
return status; |
| 3774 |
} |
| 3775 |
ps->nocclA[pp]++; |
| 3776 |
|
| 3777 |
ps->occlAAA[pp][ps->nocclA[pp]] = create_onecell_colorlegend(hc_onecell[BLACKOC], noutline_bp_bad, OCCL_BLANK_COUNT, TRUE, FALSE); |
| 3778 |
if((status = add_text_to_onecell_colorlegend (ps, ps->occlAAA[pp][ps->nocclA[pp]], " non-canonical or w/gap and != a:b", ps->legx_max_chars, errbuf)) != eslOK){ |
| 3779 |
free(stack); |
| 3780 |
return status; |
| 3781 |
} |
| 3782 |
if((status = add_celltext_to_onecell_colorlegend(ps, ps->occlAAA[pp][ps->nocclA[pp]], "", errbuf)) != eslOK){ |
| 3783 |
free(stack); |
| 3784 |
return status; |
| 3785 |
} |
| 3786 |
ps->nocclA[pp]++; |
| 3787 |
free(stack); |
| 3788 |
} |
| 3789 |
|
| 3790 |
|
| 3791 |
if((status = add_text_to_scheme_colorlegend(ps, ps->sclAA[pp], "# inserted nucleotides after each consensus position", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 3792 |
if((status = add_page_desc_to_sspostscript(ps, pp, msa->sqname[i], errbuf)) != eslOK) return status; |
| 3793 |
|
| 3794 |
|
| 3795 |
|
| 3796 |
ps->occlAAA[pp][ps->nocclA[pp]] = create_onecell_colorlegend(hc_onecell[extdel_idx_s], nextdel_s, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 3797 |
if((status = add_text_to_onecell_colorlegend(ps, ps->occlAAA[pp][ps->nocclA[pp]], "5'/3'-flush gaps", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 3798 |
ps->nocclA[pp]++; |
| 3799 |
|
| 3800 |
|
| 3801 |
|
| 3802 |
|
| 3803 |
if(do_prob) { |
| 3804 |
pp++; |
| 3805 |
if(ps->sclAA[pp] != NULL){ |
| 3806 |
free(ps->sclAA[pp]); |
| 3807 |
} |
| 3808 |
ps->sclAA[pp] = create_scheme_colorlegend(hc_scheme_idx_p, hc_nbins_p, limits_p, FALSE, TRUE, TRUE, FALSE); |
| 3809 |
ngap_p = 0; |
| 3810 |
ngap_masked_p = (ps->mask == NULL) ? -1 : 0; |
| 3811 |
|
| 3812 |
for(rfpos = 0; rfpos < ps->rflen; rfpos++) { |
| 3813 |
apos = ps->msa_rf2a_map[rfpos]; |
| 3814 |
if(do_prob_res) { |
| 3815 |
ps->rAA[pp][rfpos] = msa->aseq[i][apos]; |
| 3816 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[WHITEOC])) != eslOK) return status; |
| 3817 |
} |
| 3818 |
else { |
| 3819 |
ps->rAA[pp][rfpos] = ' '; |
| 3820 |
} |
| 3821 |
if(! esl_abc_CIsGap(abc, msa->aseq[i][apos])) { |
| 3822 |
if((ppidx = get_pp_idx(abc, msa->pp[i][apos])) == -1) ESL_FAIL(eslEFORMAT, errbuf, "bad #=GR PP char: %c", msa->pp[i][apos]); |
| 3823 |
if(ppidx == 11) ESL_FAIL(eslEFORMAT, errbuf, "nongap nucleotide: %c, annotated with gap #=GR PP char: %c", msa->aseq[i][apos], msa->pp[i][apos]); |
| 3824 |
within_mask = (ps->mask != NULL && ps->mask[rfpos] == '1') ? TRUE : FALSE; |
| 3825 |
if((status = set_scheme_values(errbuf, ps->bcolAAA[pp][rfpos], NCMYK, hc_scheme[hc_scheme_idx_p], ppavgA[ppidx], ps->sclAA[pp], within_mask, NULL)) != eslOK) return status; |
| 3826 |
} |
| 3827 |
else { |
| 3828 |
if((status = set_onecell_values(errbuf, ps->bcolAAA[pp][rfpos], NCMYK, hc_onecell[gap_idx_p])) != eslOK) return status; |
| 3829 |
ngap_p++; |
| 3830 |
if(ps->mask != NULL && ps->mask[rfpos] == '1') ngap_masked_p++; |
| 3831 |
} |
| 3832 |
} |
| 3833 |
|
| 3834 |
|
| 3835 |
ps->occlAAA[pp][0] = create_onecell_colorlegend(hc_onecell[gap_idx_p], ngap_p, ngap_masked_p, FALSE, FALSE); |
| 3836 |
if((status = add_text_to_onecell_colorlegend(ps, ps->occlAAA[pp][0], "gap", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 3837 |
ps->nocclA[pp] = 1; |
| 3838 |
|
| 3839 |
if((status = add_text_to_scheme_colorlegend(ps, ps->sclAA[pp], "posterior probability \\(alignment confidence\\)", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 3840 |
ps->seqidxA[pp] = i; |
| 3841 |
if((status = add_page_desc_to_sspostscript(ps, pp, msa->sqname[i], errbuf)) != eslOK) return status; |
| 3842 |
|
| 3843 |
ps->rAA[pp][ps->rflen] = '\0'; |
| 3844 |
} |
| 3845 |
} |
| 3846 |
free(limits_s); |
| 3847 |
free(limits_p); |
| 3848 |
return eslOK; |
| 3849 |
|
| 3850 |
ERROR: ESL_FAIL(status, errbuf, "individuals_sspostscript(): memory allocation error."); |
| 3851 |
return status; |
| 3852 |
} |
| 3853 |
|
| 3854 |
|
| 3855 |
|
| 3856 |
|
| 3857 |
|
| 3858 |
|
| 3859 |
|
| 3860 |
static int |
| 3861 |
cons_seq_sspostscript(const ESL_GETOPTS *go, char *errbuf, SSPostscript_t *ps, |
| 3862 |
float **hc_onecell, int wcbp_idx_s, int gubp_idx_s, int ncbp_idx_s, int dgbp_idx_s, int hgbp_idx_s) |
| 3863 |
{ |
| 3864 |
int status; |
| 3865 |
int p, pp; |
| 3866 |
int rfpos, lpos, rpos; |
| 3867 |
int orig_npage = ps->npage; |
| 3868 |
int nwc_s; |
| 3869 |
int ngu_s; |
| 3870 |
int nnc_s; |
| 3871 |
int ndgi_s = 0; |
| 3872 |
int nhgi_s = 0; |
| 3873 |
int spos, epos; |
| 3874 |
int lpos_is_internal; |
| 3875 |
int rpos_is_internal; |
| 3876 |
int lpos_is_gap; |
| 3877 |
int rpos_is_gap; |
| 3878 |
|
| 3879 |
nwc_s = ngu_s = nnc_s = ndgi_s = nhgi_s = 0; |
| 3880 |
|
| 3881 |
if((status = add_pages_sspostscript(ps, 1, INDIMODE)) != eslOK) ESL_FAIL(status, errbuf, "memory error adding pages to the postscript object."); |
| 3882 |
|
| 3883 |
for(p = orig_npage; p < ps->npage; p++) { |
| 3884 |
ESL_ALLOC(ps->rAA[p], sizeof(char) * ps->rflen); |
| 3885 |
ESL_ALLOC(ps->tlAAA[p], sizeof(TextLegend_t *) * 1); |
| 3886 |
} |
| 3887 |
|
| 3888 |
|
| 3889 |
pp = orig_npage; |
| 3890 |
for(rfpos = 0; rfpos < ps->rflen; rfpos++) { |
| 3891 |
ps->rAA[pp][rfpos] = esl_opt_GetBoolean(go, "--cambig") ? ps->msa_cseq_amb[rfpos] : ps->msa_cseq_maj[rfpos]; |
| 3892 |
} |
| 3893 |
|
| 3894 |
if((! esl_opt_GetBoolean(go, "--cambig")) && (! esl_opt_GetBoolean(go, "--no-bp"))) { |
| 3895 |
spos = epos = -1; |
| 3896 |
|
| 3897 |
for(rfpos = 0; rfpos < ps->rflen; rfpos++) { |
| 3898 |
if(! esl_abc_CIsGap(ps->abc, ps->msa_cseq_maj[rfpos])) { |
| 3899 |
spos = rfpos; |
| 3900 |
break; |
| 3901 |
} |
| 3902 |
} |
| 3903 |
for(rfpos = ps->rflen-1; rfpos >= 0; rfpos--) { |
| 3904 |
if(! esl_abc_CIsGap(ps->abc, ps->msa_cseq_maj[rfpos])) { |
| 3905 |
epos = rfpos; |
| 3906 |
break; |
| 3907 |
} |
| 3908 |
} |
| 3909 |
|
| 3910 |
ESL_ALLOC(ps->rcolAAA[pp], sizeof(float *) * ps->rflen); |
| 3911 |
ESL_ALLOC(ps->occlAAA[pp], sizeof(OneCellColorLegend_t *) * 5); |
| 3912 |
for(rfpos = 0; rfpos < ps->rflen; rfpos++) { |
| 3913 |
ESL_ALLOC(ps->rcolAAA[pp][rfpos], sizeof(float) * NCMYK); |
| 3914 |
if(ps->msa_ct[(rfpos+1)] == 0) { |
| 3915 |
|
| 3916 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[wcbp_idx_s])) != eslOK) return status; |
| 3917 |
} |
| 3918 |
else { |
| 3919 |
lpos = rfpos; |
| 3920 |
rpos = ps->msa_ct[rfpos+1]-1; |
| 3921 |
lpos_is_internal = ((lpos < spos) || (lpos > epos)) ? FALSE : TRUE; |
| 3922 |
rpos_is_internal = ((rpos < spos) || (rpos > epos)) ? FALSE : TRUE; |
| 3923 |
lpos_is_gap = esl_abc_CIsGap(ps->abc, ps->msa_cseq_maj[lpos]) ? TRUE : FALSE; |
| 3924 |
rpos_is_gap = esl_abc_CIsGap(ps->abc, ps->msa_cseq_maj[rpos]) ? TRUE : FALSE; |
| 3925 |
if(lpos_is_internal && rpos_is_internal) { |
| 3926 |
if(is_watson_crick_bp(ps->msa_cseq_maj[lpos], ps->msa_cseq_maj[rpos])) { |
| 3927 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[wcbp_idx_s])) != eslOK) return status; |
| 3928 |
if(lpos < rpos) nwc_s++; |
| 3929 |
} |
| 3930 |
else if(is_gu_or_ug_bp(ps->msa_cseq_maj[lpos], ps->msa_cseq_maj[rpos])) { |
| 3931 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[gubp_idx_s])) != eslOK) return status; |
| 3932 |
if(lpos < rpos) ngu_s++; |
| 3933 |
} |
| 3934 |
else if (lpos_is_gap && rpos_is_gap) { |
| 3935 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[dgbp_idx_s])) != eslOK) return status; |
| 3936 |
if(lpos < rpos) ndgi_s++; |
| 3937 |
} |
| 3938 |
else if (lpos_is_gap || rpos_is_gap) { |
| 3939 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[hgbp_idx_s])) != eslOK) return status; |
| 3940 |
if(lpos < rpos) nhgi_s++; |
| 3941 |
} |
| 3942 |
else { |
| 3943 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[ncbp_idx_s])) != eslOK) return status; |
| 3944 |
if(lpos < rpos) nnc_s++; |
| 3945 |
} |
| 3946 |
} |
| 3947 |
else { |
| 3948 |
|
| 3949 |
|
| 3950 |
|
| 3951 |
|
| 3952 |
|
| 3953 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[BLACKOC])) != eslOK) return status; |
| 3954 |
} |
| 3955 |
} |
| 3956 |
} |
| 3957 |
|
| 3958 |
|
| 3959 |
ps->occlAAA[pp][ps->nocclA[pp]] = create_onecell_colorlegend(hc_onecell[wcbp_idx_s], nwc_s, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 3960 |
if((status = add_text_to_onecell_colorlegend (ps, ps->occlAAA[pp][ps->nocclA[pp]], "Watson-Crick basepair (bp)", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 3961 |
if((status = add_celltext_to_onecell_colorlegend(ps, ps->occlAAA[pp][ps->nocclA[pp]], "C-G", errbuf)) != eslOK) return status; |
| 3962 |
ps->nocclA[pp]++; |
| 3963 |
|
| 3964 |
|
| 3965 |
ps->occlAAA[pp][ps->nocclA[pp]] = create_onecell_colorlegend(hc_onecell[gubp_idx_s], ngu_s, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 3966 |
if((status = add_text_to_onecell_colorlegend (ps, ps->occlAAA[pp][ps->nocclA[pp]], "G-U or U-G bp", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 3967 |
if((status = add_celltext_to_onecell_colorlegend(ps, ps->occlAAA[pp][ps->nocclA[pp]], "G-U", errbuf)) != eslOK) return status; |
| 3968 |
ps->nocclA[pp]++; |
| 3969 |
|
| 3970 |
|
| 3971 |
ps->occlAAA[pp][ps->nocclA[pp]] = create_onecell_colorlegend(hc_onecell[ncbp_idx_s], nnc_s, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 3972 |
if((status = add_text_to_onecell_colorlegend (ps, ps->occlAAA[pp][ps->nocclA[pp]], "non-canonical bp", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 3973 |
if((status = add_celltext_to_onecell_colorlegend(ps, ps->occlAAA[pp][ps->nocclA[pp]], "A-A", errbuf)) != eslOK) return status; |
| 3974 |
ps->nocclA[pp]++; |
| 3975 |
|
| 3976 |
|
| 3977 |
ps->occlAAA[pp][ps->nocclA[pp]] = create_onecell_colorlegend(hc_onecell[hgbp_idx_s], nhgi_s, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 3978 |
if((status = add_text_to_onecell_colorlegend (ps, ps->occlAAA[pp][ps->nocclA[pp]], "internal half-gap bp", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 3979 |
if((status = add_celltext_to_onecell_colorlegend(ps, ps->occlAAA[pp][ps->nocclA[pp]], "A--", errbuf)) != eslOK) return status; |
| 3980 |
ps->nocclA[pp]++; |
| 3981 |
|
| 3982 |
|
| 3983 |
ps->occlAAA[pp][ps->nocclA[pp]] = create_onecell_colorlegend(hc_onecell[dgbp_idx_s], ndgi_s, OCCL_BLANK_COUNT, TRUE, FALSE); |
| 3984 |
if((status = add_text_to_onecell_colorlegend (ps, ps->occlAAA[pp][ps->nocclA[pp]], "internal double-gap bp", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 3985 |
if((status = add_celltext_to_onecell_colorlegend(ps, ps->occlAAA[pp][ps->nocclA[pp]], "---", errbuf)) != eslOK) return status; |
| 3986 |
ps->nocclA[pp]++; |
| 3987 |
} |
| 3988 |
|
| 3989 |
|
| 3990 |
if((status = add_page_desc_to_sspostscript(ps, pp, "alignment consensus sequence", errbuf)) != eslOK) return status; |
| 3991 |
|
| 3992 |
|
| 3993 |
ps->tlAAA[pp][0] = create_text_legend_for_consensus_sequence(go, FALSE); |
| 3994 |
ps->ntlA[pp] = 1; |
| 3995 |
|
| 3996 |
return eslOK; |
| 3997 |
|
| 3998 |
ERROR: ESL_FAIL(status, errbuf, "cons_seq_sspostscript(): memory allocation error."); |
| 3999 |
return status; |
| 4000 |
} |
| 4001 |
|
| 4002 |
|
| 4003 |
|
| 4004 |
|
| 4005 |
|
| 4006 |
|
| 4007 |
|
| 4008 |
static int |
| 4009 |
rf_seq_sspostscript(const ESL_GETOPTS *go, char *errbuf, SSPostscript_t *ps, ESL_MSA *msa, int do_rescol, |
| 4010 |
float **hc_onecell, int wcbp_idx_s, int gubp_idx_s, int ncbp_idx_s) |
| 4011 |
{ |
| 4012 |
int status; |
| 4013 |
int p, pp; |
| 4014 |
int rfpos, apos, lpos, rpos; |
| 4015 |
int orig_npage = ps->npage; |
| 4016 |
int seen_canonical = FALSE; |
| 4017 |
int nwc_s; |
| 4018 |
int ngu_s; |
| 4019 |
int nnc_s; |
| 4020 |
|
| 4021 |
nwc_s = ngu_s = nnc_s = 0; |
| 4022 |
|
| 4023 |
if((status = add_pages_sspostscript(ps, 1, INDIMODE)) != eslOK) ESL_FAIL(status, errbuf, "memory error adding pages to the postscript object."); |
| 4024 |
|
| 4025 |
for(p = orig_npage; p < ps->npage; p++) { |
| 4026 |
ESL_ALLOC(ps->rAA[p], sizeof(char) * ps->rflen); |
| 4027 |
} |
| 4028 |
|
| 4029 |
|
| 4030 |
pp = orig_npage; |
| 4031 |
for(rfpos = 0; rfpos < ps->rflen; rfpos++) { |
| 4032 |
apos = ps->msa_rf2a_map[rfpos]; |
| 4033 |
if(esl_abc_CIsCanonical(ps->abc, msa->rf[apos])) seen_canonical = TRUE; |
| 4034 |
ps->rAA[pp][rfpos] = msa->rf[apos]; |
| 4035 |
} |
| 4036 |
|
| 4037 |
|
| 4038 |
if(do_rescol && seen_canonical) { |
| 4039 |
ESL_ALLOC(ps->rcolAAA[pp], sizeof(float *) * ps->rflen); |
| 4040 |
ESL_ALLOC(ps->occlAAA[pp], sizeof(OneCellColorLegend_t *) * 3); |
| 4041 |
for(rfpos = 0; rfpos < ps->rflen; rfpos++) { |
| 4042 |
ESL_ALLOC(ps->rcolAAA[pp][rfpos], sizeof(float) * NCMYK); |
| 4043 |
apos = ps->msa_rf2a_map[rfpos]; |
| 4044 |
if(ps->msa_ct[(rfpos+1)] == 0) { |
| 4045 |
|
| 4046 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[wcbp_idx_s])) != eslOK) return status; |
| 4047 |
} |
| 4048 |
else { |
| 4049 |
lpos = apos; |
| 4050 |
rpos = ps->msa_rf2a_map[ps->msa_ct[rfpos+1]-1]; |
| 4051 |
if(is_watson_crick_bp(msa->rf[lpos], msa->rf[rpos])) { |
| 4052 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[wcbp_idx_s])) != eslOK) return status; |
| 4053 |
if(lpos < rpos) nwc_s++; |
| 4054 |
} |
| 4055 |
else if(is_gu_or_ug_bp(msa->rf[lpos], msa->rf[rpos])) { |
| 4056 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[gubp_idx_s])) != eslOK) return status; |
| 4057 |
if(lpos < rpos) ngu_s++; |
| 4058 |
} |
| 4059 |
else { |
| 4060 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[ncbp_idx_s])) != eslOK) return status; |
| 4061 |
if(lpos < rpos) nnc_s++; |
| 4062 |
} |
| 4063 |
} |
| 4064 |
} |
| 4065 |
|
| 4066 |
|
| 4067 |
ps->occlAAA[pp][ps->nocclA[pp]] = create_onecell_colorlegend(hc_onecell[wcbp_idx_s], nwc_s, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 4068 |
if((status = add_text_to_onecell_colorlegend (ps, ps->occlAAA[pp][ps->nocclA[pp]], "Watson-Crick basepair (bp)", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 4069 |
if((status = add_celltext_to_onecell_colorlegend(ps, ps->occlAAA[pp][ps->nocclA[pp]], "C-G", errbuf)) != eslOK) return status; |
| 4070 |
ps->nocclA[pp]++; |
| 4071 |
|
| 4072 |
|
| 4073 |
ps->occlAAA[pp][ps->nocclA[pp]] = create_onecell_colorlegend(hc_onecell[gubp_idx_s], ngu_s, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 4074 |
if((status = add_text_to_onecell_colorlegend (ps, ps->occlAAA[pp][ps->nocclA[pp]], "G-U or U-G bp", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 4075 |
if((status = add_celltext_to_onecell_colorlegend(ps, ps->occlAAA[pp][ps->nocclA[pp]], "G-U", errbuf)) != eslOK) return status; |
| 4076 |
ps->nocclA[pp]++; |
| 4077 |
|
| 4078 |
|
| 4079 |
ps->occlAAA[pp][ps->nocclA[pp]] = create_onecell_colorlegend(hc_onecell[ncbp_idx_s], nnc_s, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 4080 |
if((status = add_text_to_onecell_colorlegend (ps, ps->occlAAA[pp][ps->nocclA[pp]], "non-canonical bp", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 4081 |
if((status = add_celltext_to_onecell_colorlegend(ps, ps->occlAAA[pp][ps->nocclA[pp]], "A-A", errbuf)) != eslOK) return status; |
| 4082 |
ps->nocclA[pp]++; |
| 4083 |
} |
| 4084 |
|
| 4085 |
|
| 4086 |
if((status = add_page_desc_to_sspostscript(ps, pp, "*REFERENCE* (\"#=GC RF\")", errbuf)) != eslOK) return status; |
| 4087 |
|
| 4088 |
return eslOK; |
| 4089 |
|
| 4090 |
ERROR: ESL_FAIL(status, errbuf, "rf_seq_sspostscript(): memory allocation error."); |
| 4091 |
return status; |
| 4092 |
} |
| 4093 |
|
| 4094 |
|
| 4095 |
|
| 4096 |
|
| 4097 |
|
| 4098 |
|
| 4099 |
|
| 4100 |
|
| 4101 |
|
| 4102 |
|
| 4103 |
|
| 4104 |
|
| 4105 |
|
| 4106 |
|
| 4107 |
|
| 4108 |
|
| 4109 |
|
| 4110 |
|
| 4111 |
|
| 4112 |
|
| 4113 |
|
| 4114 |
|
| 4115 |
|
| 4116 |
|
| 4117 |
|
| 4118 |
|
| 4119 |
|
| 4120 |
|
| 4121 |
|
| 4122 |
|
| 4123 |
|
| 4124 |
|
| 4125 |
|
| 4126 |
int count_msa(const ESL_ALPHABET *abc, ESL_MSA *msa, char *errbuf, double ***ret_abc_ct, double ****ret_bp_ct, double ***ret_pp_ct, int **ret_spos_ct, int **ret_epos_ct) |
| 4127 |
{ |
| 4128 |
int status; |
| 4129 |
double **abc_ct = NULL; |
| 4130 |
double ***bp_ct = NULL; |
| 4131 |
int *spos_ct = NULL; |
| 4132 |
int *epos_ct = NULL; |
| 4133 |
int apos, i, j, x, epos; |
| 4134 |
ESL_DSQ *tmp_dsq = NULL; |
| 4135 |
int seen_start = FALSE; |
| 4136 |
|
| 4137 |
int *ct = NULL; |
| 4138 |
char *ss_nopseudo = NULL; |
| 4139 |
int nppvals = 12; |
| 4140 |
double **pp_ct = NULL; |
| 4141 |
int ppidx; |
| 4142 |
|
| 4143 |
|
| 4144 |
if(msa->flags & eslMSA_DIGITAL) ESL_FAIL(eslEINVAL, errbuf, "count_msa() contract violation, MSA is digitized"); |
| 4145 |
if(msa->ss_cons == NULL) ESL_FAIL(eslEINVAL, errbuf, "the alignment lacks SS_cons annotation"); |
| 4146 |
|
| 4147 |
|
| 4148 |
if(ret_pp_ct != NULL && msa->pp != NULL) { |
| 4149 |
ESL_ALLOC(pp_ct, sizeof(double *) * msa->alen); |
| 4150 |
for(apos = 0; apos < msa->alen; apos++) { |
| 4151 |
ESL_ALLOC(pp_ct[apos], sizeof(double) * nppvals); |
| 4152 |
esl_vec_DSet(pp_ct[apos], nppvals, 0.); |
| 4153 |
} |
| 4154 |
} |
| 4155 |
|
| 4156 |
|
| 4157 |
ESL_ALLOC(ct, sizeof(int) * (msa->alen+1)); |
| 4158 |
ESL_ALLOC(ss_nopseudo, sizeof(char) * (msa->alen+1)); |
| 4159 |
esl_wuss_nopseudo(msa->ss_cons, ss_nopseudo); |
| 4160 |
if ((status = esl_wuss2ct(ss_nopseudo, msa->alen, ct)) != eslOK) ESL_FAIL(status, errbuf, "Consensus structure string is inconsistent."); |
| 4161 |
|
| 4162 |
ESL_ALLOC(tmp_dsq, (msa->alen+2) * sizeof(ESL_DSQ)); |
| 4163 |
ESL_ALLOC(abc_ct, sizeof(double *) * msa->alen); |
| 4164 |
ESL_ALLOC(bp_ct, sizeof(double **) * msa->alen); |
| 4165 |
for(apos = 0; apos < msa->alen; apos++) { |
| 4166 |
ESL_ALLOC(abc_ct[apos], sizeof(double) * (abc->K+1)); |
| 4167 |
esl_vec_DSet(abc_ct[apos], (abc->K+1), 0.); |
| 4168 |
|
| 4169 |
if(ct[(apos+1)] > (apos+1)) { |
| 4170 |
ESL_ALLOC(bp_ct[apos], sizeof(double *) * (abc->Kp)); |
| 4171 |
for(x = 0; x < abc->Kp; x++) { |
| 4172 |
ESL_ALLOC(bp_ct[apos][x], sizeof(double) * (abc->Kp)); |
| 4173 |
esl_vec_DSet(bp_ct[apos][x], abc->Kp, 0.); |
| 4174 |
} |
| 4175 |
} |
| 4176 |
else { |
| 4177 |
bp_ct[apos] = NULL; |
| 4178 |
} |
| 4179 |
} |
| 4180 |
ESL_ALLOC(spos_ct, sizeof(int) * msa->alen); |
| 4181 |
ESL_ALLOC(epos_ct, sizeof(int) * msa->alen); |
| 4182 |
esl_vec_ISet(spos_ct, msa->alen, 0); |
| 4183 |
esl_vec_ISet(epos_ct, msa->alen, 0); |
| 4184 |
|
| 4185 |
for(i = 0; i < msa->nseq; i++) { |
| 4186 |
seen_start = FALSE; |
| 4187 |
epos = 0; |
| 4188 |
if((status = esl_abc_Digitize(abc, msa->aseq[i], tmp_dsq)) != eslOK) ESL_FAIL(status, errbuf, "problem digitizing sequence %d", i); |
| 4189 |
for(apos = 0; apos < msa->alen; apos++) { |
| 4190 |
if((status = esl_abc_DCount(abc, abc_ct[apos], tmp_dsq[apos+1], 1.0)) != eslOK) ESL_FAIL(status, errbuf, "problem counting nucleotide %d of seq %d", apos, i); |
| 4191 |
if(! esl_abc_XIsGap(abc, tmp_dsq[apos+1])) { |
| 4192 |
if(! seen_start) { |
| 4193 |
spos_ct[apos]++; |
| 4194 |
seen_start = TRUE; |
| 4195 |
} |
| 4196 |
epos = apos; |
| 4197 |
} |
| 4198 |
|
| 4199 |
if(bp_ct[apos] != NULL) { |
| 4200 |
j = ct[apos+1] - 1; |
| 4201 |
bp_ct[apos][tmp_dsq[(apos+1)]][tmp_dsq[(j+1)]]++; |
| 4202 |
} |
| 4203 |
} |
| 4204 |
epos_ct[epos]++; |
| 4205 |
|
| 4206 |
if(ret_pp_ct != NULL) { |
| 4207 |
if(msa->pp[i] == NULL) ESL_FAIL(eslEINVAL, errbuf, "--prob requires all sequences in the alignment have PP, seq %d does not.", i+1); |
| 4208 |
for(apos = 0; apos < msa->alen; apos++) { |
| 4209 |
if((ppidx = get_pp_idx(abc, msa->pp[i][apos])) == -1) ESL_FAIL(eslEFORMAT, errbuf, "bad #=GR PP char: %c", msa->pp[i][apos]); |
| 4210 |
pp_ct[apos][ppidx] += 1.; |
| 4211 |
} |
| 4212 |
} |
| 4213 |
} |
| 4214 |
|
| 4215 |
*ret_abc_ct = abc_ct; |
| 4216 |
*ret_bp_ct = bp_ct; |
| 4217 |
*ret_spos_ct = spos_ct; |
| 4218 |
*ret_epos_ct = epos_ct; |
| 4219 |
if(ret_pp_ct != NULL) *ret_pp_ct = pp_ct; |
| 4220 |
|
| 4221 |
esl_free(tmp_dsq); |
| 4222 |
esl_free(ss_nopseudo); |
| 4223 |
esl_free(ct); |
| 4224 |
return eslOK; |
| 4225 |
|
| 4226 |
ERROR: |
| 4227 |
esl_arr2_Destroy((void **) abc_ct, msa? msa->alen:0); |
| 4228 |
esl_arr2_Destroy((void **) pp_ct, msa? msa->alen:0); |
| 4229 |
esl_arr3_Destroy((void ***) bp_ct, msa? msa->alen:0, abc? abc->Kp:0); |
| 4230 |
esl_free(spos_ct); |
| 4231 |
esl_free(epos_ct); |
| 4232 |
esl_free(tmp_dsq); |
| 4233 |
ESL_FAIL(status, errbuf, "Error, out of memory while counting important values in the msa."); |
| 4234 |
return status; |
| 4235 |
} |
| 4236 |
|
| 4237 |
|
| 4238 |
|
| 4239 |
|
| 4240 |
|
| 4241 |
|
| 4242 |
|
| 4243 |
|
| 4244 |
static int |
| 4245 |
infocontent_sspostscript(const ESL_GETOPTS *go, ESL_ALPHABET *abc, char *errbuf, SSPostscript_t *ps, double **abc_ct, int msa_nseq, float ***hc_scheme, int hc_scheme_idx, int hc_nbins, float **hc_onecell, int hc_onecell_idx, FILE *tabfp) |
| 4246 |
{ |
| 4247 |
int status; |
| 4248 |
int p, pp, c; |
| 4249 |
int rfpos, apos; |
| 4250 |
int orig_npage = ps->npage; |
| 4251 |
double *tmp_obs = NULL; |
| 4252 |
double *ent = NULL; |
| 4253 |
double *bg = NULL; |
| 4254 |
float *limits = NULL; |
| 4255 |
int zero_obs; |
| 4256 |
int nonecell = 0; |
| 4257 |
int nonecell_masked = 0; |
| 4258 |
int within_mask; |
| 4259 |
int bi; |
| 4260 |
int l; |
| 4261 |
|
| 4262 |
if((status = add_pages_sspostscript(ps, 1, ALIMODE)) != eslOK) ESL_FAIL(status, errbuf, "memory error adding pages to the postscript object."); |
| 4263 |
|
| 4264 |
for(p = orig_npage; p < ps->npage; p++) { |
| 4265 |
ESL_ALLOC(ps->bcolAAA[p], sizeof(float *) * ps->rflen); |
| 4266 |
|
| 4267 |
|
| 4268 |
ESL_ALLOC(ps->occlAAA[p], sizeof(OneCellColorLegend_t *) * 1); |
| 4269 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 4270 |
ESL_ALLOC(ps->rAA[p], sizeof(char) * ps->rflen); |
| 4271 |
ESL_ALLOC(ps->rcolAAA[p], sizeof(float *) * ps->rflen); |
| 4272 |
ESL_ALLOC(ps->tlAAA[p], sizeof(TextLegend_t *) * 1); |
| 4273 |
} |
| 4274 |
for(c = 0; c < ps->rflen; c++) { |
| 4275 |
ESL_ALLOC(ps->bcolAAA[p][c], sizeof(float) * NCMYK); |
| 4276 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 4277 |
ESL_ALLOC(ps->rcolAAA[p][c], sizeof(float) * NCMYK); |
| 4278 |
} |
| 4279 |
} |
| 4280 |
} |
| 4281 |
|
| 4282 |
ESL_ALLOC(ent, sizeof(double) * ps->rflen); |
| 4283 |
ESL_ALLOC(bg, sizeof(double) * abc->K); |
| 4284 |
esl_vec_DSet(bg, abc->K, 1./(abc->K)); |
| 4285 |
ESL_ALLOC(tmp_obs, sizeof(double) * abc->K); |
| 4286 |
esl_vec_DSet(tmp_obs, abc->K, 0.); |
| 4287 |
|
| 4288 |
pp = orig_npage; |
| 4289 |
|
| 4290 |
|
| 4291 |
ESL_ALLOC(limits, sizeof(float) * (hc_nbins+1)); |
| 4292 |
limits[0] = 0.0; |
| 4293 |
limits[1] = 0.4; |
| 4294 |
limits[2] = 0.8; |
| 4295 |
limits[3] = 1.2; |
| 4296 |
limits[4] = 1.6; |
| 4297 |
limits[5] = 1.99; |
| 4298 |
limits[6] = 2.00; |
| 4299 |
ps->sclAA[pp] = create_scheme_colorlegend(hc_scheme_idx, hc_nbins, limits, FALSE, TRUE, TRUE, TRUE); |
| 4300 |
|
| 4301 |
if(tabfp != NULL) { |
| 4302 |
fprintf(tabfp, "# ------------------------\n"); |
| 4303 |
fprintf(tabfp, "# Information content data\n"); |
| 4304 |
fprintf(tabfp, "# ------------------------\n"); |
| 4305 |
fprintf(tabfp, "# This section includes %d non #-prefixed lines, one for each consensus position\n", ps->rflen); |
| 4306 |
fprintf(tabfp, "# in the alignment and corresponding template.\n"); |
| 4307 |
fprintf(tabfp, "# Each line includes %d tokens, separated by whitespace:\n", ps->mask == NULL ? 5 : 6); |
| 4308 |
fprintf(tabfp, "# \ttoken 1: 'infocontent' (tag defining line type to ease parsing)\n"); |
| 4309 |
fprintf(tabfp, "# \ttoken 2: consensus position (starting at 1)\n"); |
| 4310 |
fprintf(tabfp, "# \ttoken 3: information content for position (bits)\n"); |
| 4311 |
fprintf(tabfp, "# \ttoken 4: number of non-gap nucleotides in position (max possible is %d (num seqs in aln))\n", msa_nseq); |
| 4312 |
fprintf(tabfp, "# \ttoken 5: bin index this positions falls in (see bin values below)\n"); |
| 4313 |
if(ps->mask != NULL) { |
| 4314 |
fprintf(tabfp, "# \ttoken 6: '1' if position is included by mask, '0' if not\n"); |
| 4315 |
} |
| 4316 |
fprintf(tabfp, "#\n"); |
| 4317 |
fprintf(tabfp, "# Information content is calculated as 2.0 - H, where\n"); |
| 4318 |
fprintf(tabfp, "# H = - \\sum_x p_x \\log_2 p_x, for x in {A, C, G, U}\n"); |
| 4319 |
fprintf(tabfp, "# p_x is the frequency of x for *non-gap* nucleotides at the position.\n"); |
| 4320 |
fprintf(tabfp, "# For example, p_A in a column that includes 4 As, 3 Cs, 2 Gs, 1 U and 5 gaps\n"); |
| 4321 |
fprintf(tabfp, "# would be 4/10 = 0.4.\n"); |
| 4322 |
fprintf(tabfp, "# Maximum possible value for token 3 is %d, the number of sequences in the file.\n", msa_nseq); |
| 4323 |
fprintf(tabfp, "#\n"); |
| 4324 |
fprintf(tabfp, "# Value ranges for bins:\n"); |
| 4325 |
fprintf(tabfp, "# \tbin 0: special case, 0 non-gap nucleotides in this position\n"); |
| 4326 |
for(l = 0; l < hc_nbins; l++) { |
| 4327 |
fprintf(tabfp, "# \tbin %2d: [%.3f-%.3f%s information per position (bits)\n", l+1, limits[l], limits[l+1], (l == hc_nbins-1) ? "]" : ")"); |
| 4328 |
} |
| 4329 |
fprintf(tabfp, "#\n"); |
| 4330 |
fprintf(tabfp, "# %11s %6s %8s %10s %3s", "type", "cpos", "info", "nongap", "bin"); |
| 4331 |
if(ps->mask != NULL) fprintf(tabfp, " %4s", "mask"); |
| 4332 |
fprintf(tabfp, "\n"); |
| 4333 |
fprintf(tabfp, "# %11s %6s %8s %10s %3s", "-----------", "------", "--------", "----------", "---"); |
| 4334 |
if(ps->mask != NULL) fprintf(tabfp, " %4s", "----"); |
| 4335 |
fprintf(tabfp, "\n"); |
| 4336 |
} |
| 4337 |
|
| 4338 |
if(ps->mask == NULL) nonecell_masked = -1; |
| 4339 |
for(rfpos = 0; rfpos < ps->rflen; rfpos++) { |
| 4340 |
apos = ps->msa_rf2a_map[rfpos]; |
| 4341 |
esl_vec_DCopy(abc_ct[apos], abc->K, tmp_obs); |
| 4342 |
zero_obs = (esl_DCompare_old(esl_vec_DSum(tmp_obs, abc->K), 0., eslSMALLX1) == eslOK) ? TRUE : FALSE; |
| 4343 |
esl_vec_DNorm(tmp_obs, abc->K); |
| 4344 |
ent[rfpos] = esl_vec_DEntropy(bg, abc->K) - esl_vec_DEntropy(tmp_obs, abc->K); |
| 4345 |
|
| 4346 |
if(zero_obs) { |
| 4347 |
if((status = set_onecell_values(errbuf, ps->bcolAAA[pp][rfpos], NCMYK, hc_onecell[hc_onecell_idx])) != eslOK) return status; |
| 4348 |
nonecell++; |
| 4349 |
if(ps->mask != NULL && ps->mask[rfpos] == '1') nonecell_masked++; |
| 4350 |
bi = -1; |
| 4351 |
} |
| 4352 |
else { |
| 4353 |
within_mask = (ps->mask != NULL && ps->mask[rfpos] == '1') ? TRUE : FALSE; |
| 4354 |
if((status = set_scheme_values(errbuf, ps->bcolAAA[pp][rfpos], NCMYK, hc_scheme[hc_scheme_idx], ent[rfpos], ps->sclAA[pp], within_mask, &bi)) != eslOK) return status; |
| 4355 |
} |
| 4356 |
|
| 4357 |
|
| 4358 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 4359 |
if(ps->mask == NULL || ps->mask[rfpos] == '1') { |
| 4360 |
ps->rAA[pp][rfpos] = esl_opt_GetBoolean(go, "--cambig") ? ps->msa_cseq_amb[rfpos] : ps->msa_cseq_maj[rfpos]; |
| 4361 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[WHITEOC])) != eslOK) return status; |
| 4362 |
} |
| 4363 |
else { |
| 4364 |
ps->rAA[pp][rfpos] = ' '; |
| 4365 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[WHITEOC])) != eslOK) return status; |
| 4366 |
} |
| 4367 |
} |
| 4368 |
|
| 4369 |
if(tabfp != NULL) { |
| 4370 |
fprintf(tabfp, " infocontent %6d %8.5f %10d %3d", rfpos+1, ent[rfpos], (int) esl_vec_DSum(abc_ct[apos], abc->K), bi+1); |
| 4371 |
if(ps->mask != NULL) fprintf(tabfp, " %4d", ps->mask[rfpos] == '1' ? 1 : 0); |
| 4372 |
fprintf(tabfp, "\n"); |
| 4373 |
} |
| 4374 |
} |
| 4375 |
|
| 4376 |
|
| 4377 |
ps->occlAAA[pp][0] = create_onecell_colorlegend(hc_onecell[hc_onecell_idx], nonecell, nonecell_masked, FALSE, FALSE); |
| 4378 |
if((status = add_text_to_onecell_colorlegend(ps, ps->occlAAA[pp][0], "100% gaps", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 4379 |
ps->nocclA[pp] = 1; |
| 4380 |
|
| 4381 |
|
| 4382 |
|
| 4383 |
if((status = add_text_to_scheme_colorlegend(ps, ps->sclAA[pp], "information content (bits)", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 4384 |
|
| 4385 |
|
| 4386 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 4387 |
ps->tlAAA[pp][0] = create_text_legend_for_consensus_sequence(go, FALSE); |
| 4388 |
ps->ntlA[pp] = 1; |
| 4389 |
} |
| 4390 |
|
| 4391 |
|
| 4392 |
if((status = add_page_desc_to_sspostscript(ps, pp, "information content per position", errbuf)) != eslOK) return status; |
| 4393 |
|
| 4394 |
free(ent); |
| 4395 |
free(tmp_obs); |
| 4396 |
free(bg); |
| 4397 |
free(limits); |
| 4398 |
|
| 4399 |
if(tabfp != NULL) fprintf(tabfp, "//\n"); |
| 4400 |
return eslOK; |
| 4401 |
|
| 4402 |
ERROR: ESL_FAIL(status, errbuf, "infocontent_sspostscript(): memory allocation error."); |
| 4403 |
return status; |
| 4404 |
} |
| 4405 |
|
| 4406 |
|
| 4407 |
|
| 4408 |
|
| 4409 |
|
| 4410 |
|
| 4411 |
|
| 4412 |
|
| 4413 |
|
| 4414 |
|
| 4415 |
|
| 4416 |
static int |
| 4417 |
delete_sspostscript(const ESL_GETOPTS *go, ESL_ALPHABET *abc, char *errbuf, SSPostscript_t *ps, double **abc_ct, int *span_ct, int msa_nseq, int do_all, float ***hc_scheme, int hc_scheme_idx, int hc_nbins, float **hc_onecell, int hc_zerodel_idx, int hc_fewdel_idx, FILE *tabfp) |
| 4418 |
{ |
| 4419 |
int status; |
| 4420 |
int p, pp, c, l, bi; |
| 4421 |
int rfpos, apos; |
| 4422 |
int orig_npage = ps->npage; |
| 4423 |
double dfreq; |
| 4424 |
int nzerodel = 0; |
| 4425 |
int nzerodel_masked = 0; |
| 4426 |
int nfewdel = 0; |
| 4427 |
int nfewdel_masked = 0; |
| 4428 |
int within_mask; |
| 4429 |
float *limits = NULL; |
| 4430 |
float fewdel_thresh; |
| 4431 |
float n_ext_del; |
| 4432 |
if(ps->mask == NULL) { |
| 4433 |
nzerodel_masked = -1; |
| 4434 |
nfewdel_masked = -1; |
| 4435 |
} |
| 4436 |
|
| 4437 |
if((status = add_pages_sspostscript(ps, 1, ALIMODE)) != eslOK) ESL_FAIL(status, errbuf, "memory error adding pages to the postscript object."); |
| 4438 |
|
| 4439 |
for(p = orig_npage; p < ps->npage; p++) { |
| 4440 |
ESL_ALLOC(ps->bcolAAA[p], sizeof(float *) * ps->rflen); |
| 4441 |
|
| 4442 |
|
| 4443 |
ESL_ALLOC(ps->occlAAA[p], sizeof(OneCellColorLegend_t *) * 2); |
| 4444 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 4445 |
ESL_ALLOC(ps->rAA[p], sizeof(char) * ps->rflen); |
| 4446 |
ESL_ALLOC(ps->rcolAAA[p], sizeof(float *) * ps->rflen); |
| 4447 |
ESL_ALLOC(ps->tlAAA[p], sizeof(TextLegend_t *) * 1); |
| 4448 |
} |
| 4449 |
for(c = 0; c < ps->rflen; c++) { |
| 4450 |
ESL_ALLOC(ps->bcolAAA[p][c], sizeof(float) * NCMYK); |
| 4451 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 4452 |
ESL_ALLOC(ps->rcolAAA[p][c], sizeof(float) * NCMYK); |
| 4453 |
} |
| 4454 |
} |
| 4455 |
} |
| 4456 |
|
| 4457 |
pp = orig_npage; |
| 4458 |
|
| 4459 |
|
| 4460 |
ESL_ALLOC(limits, sizeof(float) * (hc_nbins+1)); |
| 4461 |
fewdel_thresh = 0.001; |
| 4462 |
limits[0] = fewdel_thresh; |
| 4463 |
limits[1] = 0.05; |
| 4464 |
limits[2] = 0.20; |
| 4465 |
limits[3] = 0.35; |
| 4466 |
limits[4] = 0.50; |
| 4467 |
limits[5] = 0.75; |
| 4468 |
limits[6] = 1.00; |
| 4469 |
ps->sclAA[pp] = create_scheme_colorlegend(hc_scheme_idx, hc_nbins, limits, FALSE, FALSE, TRUE, TRUE); |
| 4470 |
|
| 4471 |
if(tabfp != NULL) { |
| 4472 |
if(do_all) { |
| 4473 |
fprintf(tabfp, "# -----------\n"); |
| 4474 |
fprintf(tabfp, "# Delete data\n"); |
| 4475 |
fprintf(tabfp, "# -----------\n"); |
| 4476 |
fprintf(tabfp, "# This section includes %d non #-prefixed lines, one for each consensus position\n", ps->rflen); |
| 4477 |
fprintf(tabfp, "# in the alignment and corresponding template.\n"); |
| 4478 |
fprintf(tabfp, "# Each line includes %d tokens, separated by whitespace:\n", ps->mask == NULL ? 4 : 5); |
| 4479 |
fprintf(tabfp, "# \ttoken 1: 'deleteall' (tag defining line type to ease parsing)\n"); |
| 4480 |
fprintf(tabfp, "# \ttoken 2: consensus position (starting at 1)\n"); |
| 4481 |
fprintf(tabfp, "# \ttoken 3: frequency of deletions (gaps) for position\n"); |
| 4482 |
fprintf(tabfp, "# \ttoken 4: bin index this positions falls in (see bin values below)\n"); |
| 4483 |
if(ps->mask != NULL) { |
| 4484 |
fprintf(tabfp, "# \ttoken 5: '1' if position is included by mask, '0' if not\n"); |
| 4485 |
} |
| 4486 |
fprintf(tabfp, "#\n"); |
| 4487 |
fprintf(tabfp, "# A sequence s has a 'delete' at consensus position x if position\n"); |
| 4488 |
fprintf(tabfp, "# x is a gap for aligned sequence s.\n"); |
| 4489 |
fprintf(tabfp, "# Total number of sequences in the alignment is %d\n", msa_nseq); |
| 4490 |
fprintf(tabfp, "#\n"); |
| 4491 |
fprintf(tabfp, "# Value ranges for bins:\n"); |
| 4492 |
fprintf(tabfp, "# \tbin 0: special case, 0 sequences have a delete at position\n"); |
| 4493 |
fprintf(tabfp, "# \tbin 1: special case, < %.5f fraction of sequences have internal deletes at position\n", fewdel_thresh); |
| 4494 |
for(l = 0; l < hc_nbins; l++) { |
| 4495 |
fprintf(tabfp, "# \tbin %2d: [%.3f-%.3f%s frequency of deletes per position\n", l+2, limits[l], limits[l+1], (l == hc_nbins-1) ? "]" : ")"); |
| 4496 |
} |
| 4497 |
fprintf(tabfp, "#\n"); |
| 4498 |
fprintf(tabfp, "# %9s %6s %8s %3s", "type", "cpos", "dfreq", "bin"); |
| 4499 |
if(ps->mask != NULL) fprintf(tabfp, " %4s", "mask"); |
| 4500 |
fprintf(tabfp, "\n"); |
| 4501 |
fprintf(tabfp, "# %9s %6s %8s %3s", "---------", "------", "--------", "---"); |
| 4502 |
if(ps->mask != NULL) fprintf(tabfp, " %4s", "----"); |
| 4503 |
fprintf(tabfp, "\n"); |
| 4504 |
} |
| 4505 |
else { |
| 4506 |
fprintf(tabfp, "# --------------------\n"); |
| 4507 |
fprintf(tabfp, "# Internal delete data\n"); |
| 4508 |
fprintf(tabfp, "# --------------------\n"); |
| 4509 |
fprintf(tabfp, "# This section includes %d non #-prefixed lines, one for each consensus position\n", ps->rflen); |
| 4510 |
fprintf(tabfp, "# in the alignment and corresponding template.\n"); |
| 4511 |
fprintf(tabfp, "# Each line includes %d tokens, separated by whitespace:\n", ps->mask == NULL ? 5 : 6); |
| 4512 |
fprintf(tabfp, "# \ttoken 1: 'deleteint' (tag defining line type to ease parsing)\n"); |
| 4513 |
fprintf(tabfp, "# \ttoken 2: consensus position (starting at 1)\n"); |
| 4514 |
fprintf(tabfp, "# \ttoken 3: frequency of internal deletions (gaps) for position\n"); |
| 4515 |
fprintf(tabfp, "# \ttoken 4: number of sequences that span (begin at or prior to and end at or after) position (max is %d)\n", msa_nseq); |
| 4516 |
fprintf(tabfp, "# \ttoken 5: bin index this positions falls in (see bin values below)\n"); |
| 4517 |
if(ps->mask != NULL) fprintf(tabfp, "# \ttoken 6: '1' if position is included by mask, '0' if not\n"); |
| 4518 |
fprintf(tabfp, "#\n"); |
| 4519 |
fprintf(tabfp, "# A sequence s has an 'internal delete' at consensus position 'x' that is actual alignment position 'a' if\n"); |
| 4520 |
fprintf(tabfp, "# x is a gap for aligned sequence s, and s has at least one non-gap nucleotide aligned to a position 'b' <= 'a'\n"); |
| 4521 |
fprintf(tabfp, "# and at least one non-gap nucleotide aligned to a position 'c' >= 'a'\n"); |
| 4522 |
fprintf(tabfp, "#\n"); |
| 4523 |
fprintf(tabfp, "# Value ranges for bins:\n"); |
| 4524 |
fprintf(tabfp, "# \tbin 0: special case, 0 sequences have an internal delete at position\n"); |
| 4525 |
fprintf(tabfp, "# \tbin 1: special case, < %.5f fraction of sequences have internal deletes at position\n", fewdel_thresh); |
| 4526 |
for(l = 0; l < hc_nbins; l++) { |
| 4527 |
fprintf(tabfp, "# \tbin %2d: [%.3f-%.3f%s frequency of internal deletes per position\n", l+2, limits[l], limits[l+1], (l == hc_nbins-1) ? "]" : ")"); |
| 4528 |
} |
| 4529 |
fprintf(tabfp, "#\n"); |
| 4530 |
fprintf(tabfp, "# %9s %6s %8s %10s %3s", "type", "cpos", "dfreq", "nspan", "bin"); |
| 4531 |
if(ps->mask != NULL) fprintf(tabfp, " %4s", "mask"); |
| 4532 |
fprintf(tabfp, "\n"); |
| 4533 |
fprintf(tabfp, "# %9s %6s %8s %10s %3s", "---------", "------", "--------", "----------", "---"); |
| 4534 |
if(ps->mask != NULL) fprintf(tabfp, " %4s", "----"); |
| 4535 |
fprintf(tabfp, "\n"); |
| 4536 |
} |
| 4537 |
} |
| 4538 |
|
| 4539 |
|
| 4540 |
for(rfpos = 0; rfpos < ps->rflen; rfpos++) { |
| 4541 |
apos = ps->msa_rf2a_map[rfpos]; |
| 4542 |
n_ext_del = do_all ? -1. : (float) (msa_nseq - span_ct[rfpos]); |
| 4543 |
if((( do_all) && ( abc_ct[apos][abc->K] < eslSMALLX1)) || |
| 4544 |
((!do_all) && ((abc_ct[apos][abc->K] - n_ext_del) < eslSMALLX1))) { |
| 4545 |
if((status = set_onecell_values(errbuf, ps->bcolAAA[pp][rfpos], NCMYK, hc_onecell[hc_zerodel_idx])) != eslOK) return status; |
| 4546 |
nzerodel++; |
| 4547 |
if(ps->mask != NULL && ps->mask[rfpos] == '1') nzerodel_masked++; |
| 4548 |
bi = -2; |
| 4549 |
dfreq = 0.; |
| 4550 |
} |
| 4551 |
else { |
| 4552 |
within_mask = (ps->mask != NULL && ps->mask[rfpos] == '1') ? TRUE : FALSE; |
| 4553 |
dfreq = do_all ? |
| 4554 |
( abc_ct[apos][abc->K] / (float) msa_nseq) : |
| 4555 |
((abc_ct[apos][abc->K] - n_ext_del) / (float) msa_nseq); |
| 4556 |
|
| 4557 |
if (dfreq < fewdel_thresh) { |
| 4558 |
if((status = set_onecell_values(errbuf, ps->bcolAAA[pp][rfpos], NCMYK, hc_onecell[hc_fewdel_idx])) != eslOK) return status; |
| 4559 |
nfewdel++; |
| 4560 |
if(ps->mask != NULL && ps->mask[rfpos] == '1') nfewdel_masked++; |
| 4561 |
bi = -1; |
| 4562 |
} |
| 4563 |
else { |
| 4564 |
if((status = set_scheme_values(errbuf, ps->bcolAAA[pp][rfpos], NCMYK, hc_scheme[hc_scheme_idx], dfreq, ps->sclAA[pp], within_mask, &bi)) != eslOK) return status; |
| 4565 |
} |
| 4566 |
} |
| 4567 |
|
| 4568 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 4569 |
if(ps->mask == NULL || ps->mask[rfpos] == '1') { |
| 4570 |
ps->rAA[pp][rfpos] = esl_opt_GetBoolean(go, "--cambig") ? ps->msa_cseq_amb[rfpos] : ps->msa_cseq_maj[rfpos]; |
| 4571 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[WHITEOC])) != eslOK) return status; |
| 4572 |
} |
| 4573 |
else { |
| 4574 |
ps->rAA[pp][rfpos] = ' '; |
| 4575 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[WHITEOC])) != eslOK) return status; |
| 4576 |
} |
| 4577 |
} |
| 4578 |
|
| 4579 |
if(tabfp != NULL) { |
| 4580 |
if(do_all) fprintf(tabfp, " deleteall %6d %8.5f %3d", rfpos+1, dfreq, bi+2); |
| 4581 |
else fprintf(tabfp, " deleteint %6d %8.5f %10d %3d", rfpos+1, dfreq, span_ct[rfpos], bi+2); |
| 4582 |
if(ps->mask != NULL) fprintf(tabfp, " %4d", ps->mask[rfpos] == '1' ? 1 : 0); |
| 4583 |
fprintf(tabfp, "\n"); |
| 4584 |
} |
| 4585 |
} |
| 4586 |
|
| 4587 |
|
| 4588 |
ps->occlAAA[pp][0] = create_onecell_colorlegend(hc_onecell[hc_zerodel_idx], nzerodel, nzerodel_masked, FALSE, FALSE); |
| 4589 |
ps->occlAAA[pp][1] = create_onecell_colorlegend(hc_onecell[hc_fewdel_idx], nfewdel, nfewdel_masked, FALSE, FALSE); |
| 4590 |
ps->nocclA[pp] = 2; |
| 4591 |
|
| 4592 |
if(do_all) { |
| 4593 |
if((status = add_text_to_onecell_colorlegend(ps, ps->occlAAA[pp][0], "zero deletions", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 4594 |
if((status = add_text_to_onecell_colorlegend(ps, ps->occlAAA[pp][1], "< 0.001 seqs have delete", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 4595 |
} |
| 4596 |
else { |
| 4597 |
if((status = add_text_to_onecell_colorlegend(ps, ps->occlAAA[pp][0], "zero internal deletions", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 4598 |
if((status = add_text_to_onecell_colorlegend(ps, ps->occlAAA[pp][1], "< 0.001 seqs have delete", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 4599 |
} |
| 4600 |
|
| 4601 |
|
| 4602 |
if(do_all) { |
| 4603 |
|
| 4604 |
if((status = add_text_to_scheme_colorlegend(ps, ps->sclAA[pp], "fraction of seqs with deletes", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 4605 |
if((status = add_page_desc_to_sspostscript(ps, ps->npage-1, "frequency of deletions at each position", errbuf)) != eslOK) return status; |
| 4606 |
} |
| 4607 |
else { |
| 4608 |
|
| 4609 |
if((status = add_text_to_scheme_colorlegend(ps, ps->sclAA[pp], "fraction of seqs w/internal deletions", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 4610 |
if((status = add_page_desc_to_sspostscript(ps, ps->npage-1, "frequency of internal deletions in each position", errbuf)) != eslOK) return status; |
| 4611 |
} |
| 4612 |
|
| 4613 |
|
| 4614 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 4615 |
ps->tlAAA[pp][0] = create_text_legend_for_consensus_sequence(go, FALSE); |
| 4616 |
ps->ntlA[pp] = 1; |
| 4617 |
} |
| 4618 |
|
| 4619 |
free(limits); |
| 4620 |
|
| 4621 |
if(tabfp != NULL) fprintf(tabfp, "//\n"); |
| 4622 |
return eslOK; |
| 4623 |
|
| 4624 |
ERROR: ESL_FAIL(status, errbuf, "delete_sspostscript(): memory allocation error."); |
| 4625 |
return status; |
| 4626 |
} |
| 4627 |
|
| 4628 |
|
| 4629 |
|
| 4630 |
|
| 4631 |
|
| 4632 |
|
| 4633 |
|
| 4634 |
|
| 4635 |
|
| 4636 |
static int |
| 4637 |
insertfreq_sspostscript(const ESL_GETOPTS *go, char *errbuf, SSPostscript_t *ps, int *nseq_with_ins_ct, int *span_ct, int msa_nseq, float ***hc_scheme, int hc_scheme_idx, int hc_nbins, float **hc_onecell, int hc_zeroins_idx, int hc_fewins_idx, FILE *tabfp) |
| 4638 |
{ |
| 4639 |
int status; |
| 4640 |
int p, pp, c, l; |
| 4641 |
int rfpos; |
| 4642 |
int orig_npage = ps->npage; |
| 4643 |
|
| 4644 |
int nzeroins = 0; |
| 4645 |
int nzeroins_masked = 0; |
| 4646 |
int nfewins = 0; |
| 4647 |
int nfewins_masked = 0; |
| 4648 |
float *limits; |
| 4649 |
int within_mask; |
| 4650 |
float ifreq; |
| 4651 |
int bi; |
| 4652 |
float fewins_thresh; |
| 4653 |
|
| 4654 |
if(ps->mask == NULL) { |
| 4655 |
nzeroins_masked = -1; |
| 4656 |
nfewins_masked = -1; |
| 4657 |
} |
| 4658 |
|
| 4659 |
if((status = add_pages_sspostscript(ps, 1, ALIMODE)) != eslOK) ESL_FAIL(status, errbuf, "memory error adding pages to the postscript object."); |
| 4660 |
|
| 4661 |
for(p = orig_npage; p < ps->npage; p++) { |
| 4662 |
ESL_ALLOC(ps->bcolAAA[p], sizeof(float *) * ps->rflen); |
| 4663 |
|
| 4664 |
|
| 4665 |
ESL_ALLOC(ps->occlAAA[p], sizeof(OneCellColorLegend_t *) * 2); |
| 4666 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 4667 |
ESL_ALLOC(ps->rAA[p], sizeof(char) * ps->rflen); |
| 4668 |
ESL_ALLOC(ps->rcolAAA[p], sizeof(float *) * ps->rflen); |
| 4669 |
ESL_ALLOC(ps->tlAAA[p], sizeof(TextLegend_t *) * 1); |
| 4670 |
} |
| 4671 |
for(c = 0; c < ps->rflen; c++) { |
| 4672 |
ESL_ALLOC(ps->bcolAAA[p][c], sizeof(float) * NCMYK); |
| 4673 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 4674 |
ESL_ALLOC(ps->rcolAAA[p][c], sizeof(float) * NCMYK); |
| 4675 |
} |
| 4676 |
} |
| 4677 |
} |
| 4678 |
pp = orig_npage; |
| 4679 |
|
| 4680 |
|
| 4681 |
ESL_ALLOC(limits, sizeof(float) * (hc_nbins+1)); |
| 4682 |
fewins_thresh = 0.001; |
| 4683 |
limits[0] = fewins_thresh; |
| 4684 |
limits[1] = 0.01; |
| 4685 |
limits[2] = 0.05; |
| 4686 |
limits[3] = 0.10; |
| 4687 |
limits[4] = 0.20; |
| 4688 |
limits[5] = 0.50; |
| 4689 |
limits[6] = 1.00; |
| 4690 |
ps->sclAA[pp] = create_scheme_colorlegend(hc_scheme_idx, hc_nbins, limits, FALSE, FALSE, TRUE, TRUE); |
| 4691 |
|
| 4692 |
if(tabfp != NULL) { |
| 4693 |
fprintf(tabfp, "# ---------------------\n"); |
| 4694 |
fprintf(tabfp, "# Insert frequency data\n"); |
| 4695 |
fprintf(tabfp, "# ---------------------\n"); |
| 4696 |
fprintf(tabfp, "# This section includes %d non #-prefixed lines, one for each possible insert position\n", ps->rflen+1); |
| 4697 |
fprintf(tabfp, "# after each of the %d consensus positions and one more for inserts prior to the first consensus position.\n", ps->rflen); |
| 4698 |
fprintf(tabfp, "# Each line includes %d tokens, separated by whitespace:\n", ps->mask == NULL ? 5 : 6); |
| 4699 |
fprintf(tabfp, "# \ttoken 1: 'insertfreq' (tag defining line type to ease parsing)\n"); |
| 4700 |
fprintf(tabfp, "# \ttoken 2: consensus position <cpos> after which inserts occur ('0' == before posn 1)\n"); |
| 4701 |
fprintf(tabfp, "# \ttoken 3: fraction of sequences that span <cpos> (see defn of span below) with >= 1 inserted nucleotides after position\n"); |
| 4702 |
fprintf(tabfp, "# \ttoken 4: number of sequences that span (begin at or prior to and end at or after) position (max is %d)\n", msa_nseq); |
| 4703 |
fprintf(tabfp, "# \ttoken 5: bin index this positions falls in (see bin values below)\n"); |
| 4704 |
if(ps->mask != NULL) { |
| 4705 |
fprintf(tabfp, "# \ttoken 6: '1' if position is included by mask, '0' if not\n"); |
| 4706 |
} |
| 4707 |
fprintf(tabfp, "#\n"); |
| 4708 |
fprintf(tabfp, "# Total number of sequences in the alignment is %d\n", msa_nseq); |
| 4709 |
fprintf(tabfp, "#\n"); |
| 4710 |
fprintf(tabfp, "# A sequence s spans consensus position 'x' that is actual alignment position 'a' if s has\n"); |
| 4711 |
fprintf(tabfp, "# at least one non-gap nucleotide aligned to a position 'b' <= 'a' and\n"); |
| 4712 |
fprintf(tabfp, "# at least one non-gap nucleotide aligned to a position 'c' >= 'a'\n"); |
| 4713 |
fprintf(tabfp, "#\n"); |
| 4714 |
fprintf(tabfp, "# Value ranges for bins:\n"); |
| 4715 |
fprintf(tabfp, "# \tbin -1: special case, reserved for inserts before position 1,\n"); |
| 4716 |
fprintf(tabfp, "# \t these are NOT SHOWN in the postscript diagram (!)\n"); |
| 4717 |
fprintf(tabfp, "# \tbin 0: special case, 0 sequences have inserts after this position\n"); |
| 4718 |
fprintf(tabfp, "# \tbin 1: special case, < %.5f fraction of sequences have inserts after this position\n", fewins_thresh); |
| 4719 |
for(l = 0; l < hc_nbins; l++) { |
| 4720 |
fprintf(tabfp, "# \tbin %2d: [%.3f-%.3f%s fraction of sequences with >= 1 inserts after each position\n", l+2, limits[l], limits[l+1], (l == hc_nbins-1) ? "]" : ")"); |
| 4721 |
} |
| 4722 |
fprintf(tabfp, "#\n"); |
| 4723 |
fprintf(tabfp, "# %10s %6s %8s %10s %3s", "type", "cpos", "ifreq", "nspan", "bin"); |
| 4724 |
if(ps->mask != NULL) fprintf(tabfp, " %4s", "mask"); |
| 4725 |
fprintf(tabfp, "\n"); |
| 4726 |
fprintf(tabfp, "# %10s %6s %8s %10s %3s", "----------", "------", "--------", "----------", "---"); |
| 4727 |
if(ps->mask != NULL) fprintf(tabfp, " %4s", "----"); |
| 4728 |
fprintf(tabfp, "\n"); |
| 4729 |
} |
| 4730 |
|
| 4731 |
|
| 4732 |
if(tabfp != NULL) { |
| 4733 |
|
| 4734 |
if(nseq_with_ins_ct[0] > span_ct[0]) ESL_FAIL(eslERANGE, errbuf, "drawing insert page, rfpos: 0 nseq_with_ins_ct (%d) exceeds span_ct (%d)", nseq_with_ins_ct[0], span_ct[0]); |
| 4735 |
ifreq = (float) nseq_with_ins_ct[0] / (float) span_ct[0]; |
| 4736 |
fprintf(tabfp, " insertfreq %6d %8.5f %10d %3d", 0, ifreq, span_ct[0], -1); |
| 4737 |
if(ps->mask != NULL) fprintf(tabfp, " %4d", 0); |
| 4738 |
fprintf(tabfp, "\n"); |
| 4739 |
} |
| 4740 |
|
| 4741 |
for(rfpos = 0; rfpos < ps->rflen; rfpos++) { |
| 4742 |
|
| 4743 |
if(nseq_with_ins_ct[rfpos+1] > span_ct[rfpos]) ESL_FAIL(eslERANGE, errbuf, "drawing insert page, rfpos: %d nseq_with_ins_ct (%d) exceeds span_ct (%d)", rfpos, nseq_with_ins_ct[rfpos+1], span_ct[rfpos]); |
| 4744 |
ifreq = (float) nseq_with_ins_ct[rfpos+1] / (float) span_ct[rfpos]; |
| 4745 |
if(nseq_with_ins_ct[(rfpos+1)] == 0) { |
| 4746 |
if((status = set_onecell_values(errbuf, ps->bcolAAA[pp][rfpos], NCMYK, hc_onecell[hc_zeroins_idx])) != eslOK) return status; |
| 4747 |
nzeroins++; |
| 4748 |
if(ps->mask != NULL && ps->mask[rfpos] == '1') nzeroins_masked++; |
| 4749 |
bi = -2; |
| 4750 |
} |
| 4751 |
else if (ifreq < fewins_thresh) { |
| 4752 |
if((status = set_onecell_values(errbuf, ps->bcolAAA[pp][rfpos], NCMYK, hc_onecell[hc_fewins_idx])) != eslOK) return status; |
| 4753 |
nfewins++; |
| 4754 |
if(ps->mask != NULL && ps->mask[rfpos] == '1') nfewins_masked++; |
| 4755 |
bi = -1; |
| 4756 |
} |
| 4757 |
else { |
| 4758 |
within_mask = (ps->mask != NULL && ps->mask[rfpos] == '1') ? TRUE : FALSE; |
| 4759 |
if((status = set_scheme_values(errbuf, ps->bcolAAA[pp][rfpos], NCMYK, hc_scheme[hc_scheme_idx], ifreq, ps->sclAA[pp], within_mask, &bi)) != eslOK) return status; |
| 4760 |
} |
| 4761 |
|
| 4762 |
|
| 4763 |
|
| 4764 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 4765 |
if(ps->mask == NULL || ps->mask[rfpos] == '1') { |
| 4766 |
ps->rAA[pp][rfpos] = esl_opt_GetBoolean(go, "--cambig") ? ps->msa_cseq_amb[rfpos] : ps->msa_cseq_maj[rfpos]; |
| 4767 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[WHITEOC])) != eslOK) return status; |
| 4768 |
} |
| 4769 |
else { |
| 4770 |
ps->rAA[pp][rfpos] = ' '; |
| 4771 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[WHITEOC])) != eslOK) return status; |
| 4772 |
} |
| 4773 |
} |
| 4774 |
|
| 4775 |
if(tabfp != NULL) { |
| 4776 |
fprintf(tabfp, " insertfreq %6d %8.5f %10d %3d", rfpos+1, ifreq, span_ct[rfpos], bi+1); |
| 4777 |
if(ps->mask != NULL) fprintf(tabfp, " %4d", ps->mask[rfpos] == '1' ? 1 : 0); |
| 4778 |
fprintf(tabfp, "\n"); |
| 4779 |
} |
| 4780 |
} |
| 4781 |
|
| 4782 |
|
| 4783 |
ps->occlAAA[pp][0] = create_onecell_colorlegend(hc_onecell[hc_zeroins_idx], nzeroins, nzeroins_masked, FALSE, FALSE); |
| 4784 |
if((status = add_text_to_onecell_colorlegend(ps, ps->occlAAA[pp][0], "zero insertions", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 4785 |
|
| 4786 |
ps->occlAAA[pp][1] = create_onecell_colorlegend(hc_onecell[hc_fewins_idx], nfewins, nfewins_masked, FALSE, FALSE); |
| 4787 |
if((status = add_text_to_onecell_colorlegend(ps, ps->occlAAA[pp][1], "< 0.001 seqs have insert", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 4788 |
ps->nocclA[pp] = 2; |
| 4789 |
|
| 4790 |
|
| 4791 |
if((status = add_text_to_scheme_colorlegend(ps, ps->sclAA[pp], "fraction of seqs w/insertions", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 4792 |
if((status = add_page_desc_to_sspostscript(ps, ps->npage-1, "frequency of insertions after each position", errbuf)) != eslOK) return status; |
| 4793 |
|
| 4794 |
|
| 4795 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 4796 |
ps->tlAAA[pp][0] = create_text_legend_for_consensus_sequence(go, FALSE); |
| 4797 |
ps->ntlA[pp] = 1; |
| 4798 |
} |
| 4799 |
|
| 4800 |
free(limits); |
| 4801 |
|
| 4802 |
if(tabfp != NULL) fprintf(tabfp, "//\n"); |
| 4803 |
return eslOK; |
| 4804 |
|
| 4805 |
ERROR: ESL_FAIL(status, errbuf, "insertfreq_sspostscript(): memory allocation error."); |
| 4806 |
return status; |
| 4807 |
} |
| 4808 |
|
| 4809 |
|
| 4810 |
|
| 4811 |
|
| 4812 |
|
| 4813 |
|
| 4814 |
|
| 4815 |
|
| 4816 |
|
| 4817 |
|
| 4818 |
static int |
| 4819 |
insertavglen_sspostscript(const ESL_GETOPTS *go, char *errbuf, SSPostscript_t *ps, int *nseq_with_ins_ct, int *nins_ct, int *span_ct, int msa_nseq, float ***hc_scheme, int hc_scheme_idx, int hc_nbins, float **hc_onecell, int hc_zeroins_idx, FILE *tabfp) |
| 4820 |
{ |
| 4821 |
int status; |
| 4822 |
int p, pp, c, l; |
| 4823 |
int rfpos; |
| 4824 |
int orig_npage = ps->npage; |
| 4825 |
|
| 4826 |
int nzeroins = 0; |
| 4827 |
int nzeroins_masked = 0; |
| 4828 |
float *limits; |
| 4829 |
int within_mask; |
| 4830 |
float ifreq; |
| 4831 |
float iavglen; |
| 4832 |
int bi; |
| 4833 |
|
| 4834 |
if(ps->mask == NULL) nzeroins_masked = -1; |
| 4835 |
|
| 4836 |
if((status = add_pages_sspostscript(ps, 1, ALIMODE)) != eslOK) ESL_FAIL(status, errbuf, "memory error adding pages to the postscript object."); |
| 4837 |
|
| 4838 |
for(p = orig_npage; p < ps->npage; p++) { |
| 4839 |
ESL_ALLOC(ps->bcolAAA[p], sizeof(float *) * ps->rflen); |
| 4840 |
|
| 4841 |
|
| 4842 |
ESL_ALLOC(ps->occlAAA[p], sizeof(OneCellColorLegend_t *) * 1); |
| 4843 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 4844 |
ESL_ALLOC(ps->rAA[p], sizeof(char) * ps->rflen); |
| 4845 |
ESL_ALLOC(ps->rcolAAA[p], sizeof(float *) * ps->rflen); |
| 4846 |
ESL_ALLOC(ps->tlAAA[p], sizeof(TextLegend_t *) * 1); |
| 4847 |
} |
| 4848 |
for(c = 0; c < ps->rflen; c++) { |
| 4849 |
ESL_ALLOC(ps->bcolAAA[p][c], sizeof(float) * NCMYK); |
| 4850 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 4851 |
ESL_ALLOC(ps->rcolAAA[p][c], sizeof(float) * NCMYK); |
| 4852 |
} |
| 4853 |
} |
| 4854 |
} |
| 4855 |
pp = orig_npage; |
| 4856 |
|
| 4857 |
|
| 4858 |
ESL_ALLOC(limits, sizeof(float) * (hc_nbins+1)); |
| 4859 |
limits[0] = 1.00; |
| 4860 |
limits[1] = 1.01; |
| 4861 |
limits[2] = 1.50; |
| 4862 |
limits[3] = 3.00; |
| 4863 |
limits[4] = 4.00; |
| 4864 |
limits[5] = 10.00; |
| 4865 |
limits[6] = eslINFINITY; |
| 4866 |
ps->sclAA[pp] = create_scheme_colorlegend(hc_scheme_idx, hc_nbins, limits, FALSE, TRUE, FALSE, TRUE); |
| 4867 |
|
| 4868 |
if(tabfp != NULL) { |
| 4869 |
fprintf(tabfp, "# --------------------------\n"); |
| 4870 |
fprintf(tabfp, "# Average insert length data\n"); |
| 4871 |
fprintf(tabfp, "# --------------------------\n"); |
| 4872 |
fprintf(tabfp, "# This section includes %d non #-prefixed lines, one for each possible insert position\n", ps->rflen+1); |
| 4873 |
fprintf(tabfp, "# after each of the %d consensus positions and one more for inserts prior to the first consensus position.\n", ps->rflen); |
| 4874 |
fprintf(tabfp, "# Each line includes %d tokens, separated by whitespace:\n", ps->mask == NULL ? 5 : 6); |
| 4875 |
fprintf(tabfp, "# \ttoken 1: 'insertlen' (tag defining line type to ease parsing)\n"); |
| 4876 |
fprintf(tabfp, "# \ttoken 2: consensus position <cpos> after which inserts occur ('0' == before posn 1)\n"); |
| 4877 |
fprintf(tabfp, "# \ttoken 3: average number of inserted nucleotides after each position for those seqs with >=1 inserted nucleotides)\n"); |
| 4878 |
fprintf(tabfp, "# \ttoken 4: fraction of sequences that span <cpos> (see defn of span below) with >= 1 inserted nucleotides after position\n"); |
| 4879 |
fprintf(tabfp, "# \ttoken 5: number of sequences that span (begin at or prior to and end at or after) position (max is %d)\n", msa_nseq); |
| 4880 |
fprintf(tabfp, "# \ttoken 6: bin index this positions falls in (see bin values below)\n"); |
| 4881 |
if(ps->mask != NULL) { |
| 4882 |
fprintf(tabfp, "# \ttoken 7: '1' if position is included by mask, '0' if not\n"); |
| 4883 |
} |
| 4884 |
fprintf(tabfp, "#\n"); |
| 4885 |
fprintf(tabfp, "# Total number of sequences in the alignment is %d\n", msa_nseq); |
| 4886 |
fprintf(tabfp, "#\n"); |
| 4887 |
fprintf(tabfp, "# A sequence s spans consensus position 'x' that is actual alignment position 'a' if s has\n"); |
| 4888 |
fprintf(tabfp, "# at least one non-gap nucleotide aligned to a position 'b' <= 'a' and\n"); |
| 4889 |
fprintf(tabfp, "# at least one non-gap nucleotide aligned to a position 'c' >= 'a'\n"); |
| 4890 |
fprintf(tabfp, "#\n"); |
| 4891 |
fprintf(tabfp, "# Value ranges for bins:\n"); |
| 4892 |
fprintf(tabfp, "# \tbin -1: special case, reserved for inserts before position 1,\n"); |
| 4893 |
fprintf(tabfp, "# \t these are NOT SHOWN in the postscript diagram (!)\n"); |
| 4894 |
fprintf(tabfp, "# \tbin 0: special case, 0 sequences have inserts after this position\n"); |
| 4895 |
for(l = 0; l < hc_nbins; l++) { |
| 4896 |
fprintf(tabfp, "# \tbin %2d: [%.3f-%.3f%s average insert length after each position\n", l+1, limits[l], limits[l+1], (l == hc_nbins-1) ? "]" : ")"); |
| 4897 |
} |
| 4898 |
fprintf(tabfp, "#\n"); |
| 4899 |
fprintf(tabfp, "# %12s %6s %8s %8s %10s %3s", "type", "cpos", "iavglen", "ifreq", "nspan", "bin"); |
| 4900 |
if(ps->mask != NULL) fprintf(tabfp, " %4s", "mask"); |
| 4901 |
fprintf(tabfp, "\n"); |
| 4902 |
fprintf(tabfp, "# %12s %6s %8s %8s %10s %3s", "------------", "------", "--------", "--------", "----------", "---"); |
| 4903 |
if(ps->mask != NULL) fprintf(tabfp, " %4s", "----"); |
| 4904 |
fprintf(tabfp, "\n"); |
| 4905 |
} |
| 4906 |
|
| 4907 |
|
| 4908 |
if(tabfp != NULL) { |
| 4909 |
|
| 4910 |
if(nseq_with_ins_ct[0] > span_ct[0]) ESL_FAIL(eslERANGE, errbuf, "drawing insert page, rfpos: 0 nseq_with_ins_ct (%d) exceeds span_ct (%d)", nseq_with_ins_ct[0], span_ct[0]); |
| 4911 |
ifreq = (span_ct[0] == 0) ? 0. : (float) nseq_with_ins_ct[0] / (float) span_ct[0]; |
| 4912 |
iavglen = (nseq_with_ins_ct[0] == 0) ? 0. : (float) nins_ct[0] / (float) nseq_with_ins_ct[0]; |
| 4913 |
fprintf(tabfp, " insertavglen %6d %8.4f %8.5f %10d %3d", 0, iavglen, ifreq, span_ct[0], -1); |
| 4914 |
if(ps->mask != NULL) fprintf(tabfp, " %4d", 0); |
| 4915 |
fprintf(tabfp, "\n"); |
| 4916 |
} |
| 4917 |
|
| 4918 |
for(rfpos = 0; rfpos < ps->rflen; rfpos++) { |
| 4919 |
|
| 4920 |
if(nseq_with_ins_ct[rfpos+1] > span_ct[rfpos]) ESL_FAIL(eslERANGE, errbuf, "drawing insert page, rfpos: %d nseq_with_ins_ct (%d) exceeds span_ct (%d)", rfpos, nseq_with_ins_ct[rfpos+1], span_ct[rfpos]); |
| 4921 |
ifreq = (span_ct[rfpos] == 0) ? 0. : (float) nseq_with_ins_ct[rfpos+1] / (float) span_ct[rfpos]; |
| 4922 |
iavglen = (nseq_with_ins_ct[rfpos+1] == 0) ? 0. : (float) nins_ct[rfpos+1] / (float) nseq_with_ins_ct[rfpos+1]; |
| 4923 |
|
| 4924 |
if(nseq_with_ins_ct[(rfpos+1)] == 0) { |
| 4925 |
if((status = set_onecell_values(errbuf, ps->bcolAAA[pp][rfpos], NCMYK, hc_onecell[hc_zeroins_idx])) != eslOK) return status; |
| 4926 |
nzeroins++; |
| 4927 |
if(ps->mask != NULL && ps->mask[rfpos] == '1') nzeroins_masked++; |
| 4928 |
bi = -1; |
| 4929 |
} |
| 4930 |
else { |
| 4931 |
within_mask = (ps->mask != NULL && ps->mask[rfpos] == '1') ? TRUE : FALSE; |
| 4932 |
if((status = set_scheme_values(errbuf, ps->bcolAAA[pp][rfpos], NCMYK, hc_scheme[hc_scheme_idx], iavglen, ps->sclAA[pp], within_mask, &bi)) != eslOK) return status; |
| 4933 |
} |
| 4934 |
|
| 4935 |
|
| 4936 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 4937 |
if(ps->mask == NULL || ps->mask[rfpos] == '1') { |
| 4938 |
ps->rAA[pp][rfpos] = esl_opt_GetBoolean(go, "--cambig") ? ps->msa_cseq_amb[rfpos] : ps->msa_cseq_maj[rfpos]; |
| 4939 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[WHITEOC])) != eslOK) return status; |
| 4940 |
} |
| 4941 |
else { |
| 4942 |
ps->rAA[pp][rfpos] = ' '; |
| 4943 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[WHITEOC])) != eslOK) return status; |
| 4944 |
} |
| 4945 |
} |
| 4946 |
|
| 4947 |
if(tabfp != NULL) { |
| 4948 |
fprintf(tabfp, " insertavglen %6d %8.4f %8.5f %10d %3d", rfpos+1, iavglen, ifreq, span_ct[rfpos], bi+1); |
| 4949 |
if(ps->mask != NULL) fprintf(tabfp, " %4d", ps->mask[rfpos] == '1' ? 1 : 0); |
| 4950 |
fprintf(tabfp, "\n"); |
| 4951 |
} |
| 4952 |
} |
| 4953 |
|
| 4954 |
|
| 4955 |
ps->occlAAA[pp][0] = create_onecell_colorlegend(hc_onecell[hc_zeroins_idx], nzeroins, nzeroins_masked, FALSE, FALSE); |
| 4956 |
if((status = add_text_to_onecell_colorlegend(ps, ps->occlAAA[pp][0], "zero insertions", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 4957 |
ps->nocclA[pp] = 1; |
| 4958 |
|
| 4959 |
|
| 4960 |
if((status = add_text_to_scheme_colorlegend(ps, ps->sclAA[pp], "average insertion length", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 4961 |
if((status = add_page_desc_to_sspostscript(ps, ps->npage-1, "average insertion length after each position", errbuf)) != eslOK) return status; |
| 4962 |
|
| 4963 |
|
| 4964 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 4965 |
ps->tlAAA[pp][0] = create_text_legend_for_consensus_sequence(go, FALSE); |
| 4966 |
ps->ntlA[pp] = 1; |
| 4967 |
} |
| 4968 |
|
| 4969 |
free(limits); |
| 4970 |
|
| 4971 |
if(tabfp != NULL) fprintf(tabfp, "//\n"); |
| 4972 |
return eslOK; |
| 4973 |
|
| 4974 |
ERROR: ESL_FAIL(status, errbuf, "insertavglen_sspostscript(): memory allocation error."); |
| 4975 |
return status; |
| 4976 |
} |
| 4977 |
|
| 4978 |
|
| 4979 |
|
| 4980 |
|
| 4981 |
|
| 4982 |
|
| 4983 |
|
| 4984 |
|
| 4985 |
|
| 4986 |
|
| 4987 |
|
| 4988 |
|
| 4989 |
static int |
| 4990 |
span_sspostscript(const ESL_GETOPTS *go, char *errbuf, SSPostscript_t *ps, int *span_ct, int msa_nseq, float ***hc_scheme, int hc_scheme_idx, int hc_nbins, float **hc_onecell, int zerocov_idx, int maxcov_idx, FILE *tabfp) |
| 4991 |
{ |
| 4992 |
int status; |
| 4993 |
int p, pp, c, l; |
| 4994 |
int rfpos; |
| 4995 |
int orig_npage = ps->npage; |
| 4996 |
int nzerocov = 0; |
| 4997 |
int nzerocov_masked = 0; |
| 4998 |
int nmaxcov = 0; |
| 4999 |
int nmaxcov_masked = 0; |
| 5000 |
float *limits; |
| 5001 |
int within_mask; |
| 5002 |
float cfract; |
| 5003 |
int bi; |
| 5004 |
|
| 5005 |
if(ps->mask == NULL) nzerocov_masked = nmaxcov_masked = -1; |
| 5006 |
|
| 5007 |
if((status = add_pages_sspostscript(ps, 1, ALIMODE)) != eslOK) ESL_FAIL(status, errbuf, "memory error adding pages to the postscript object."); |
| 5008 |
|
| 5009 |
for(p = orig_npage; p < ps->npage; p++) { |
| 5010 |
ESL_ALLOC(ps->bcolAAA[p], sizeof(float *) * ps->rflen); |
| 5011 |
|
| 5012 |
|
| 5013 |
ESL_ALLOC(ps->occlAAA[p], sizeof(OneCellColorLegend_t *) * 2); |
| 5014 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 5015 |
ESL_ALLOC(ps->rAA[p], sizeof(char) * ps->rflen); |
| 5016 |
ESL_ALLOC(ps->rcolAAA[p], sizeof(float *) * ps->rflen); |
| 5017 |
ESL_ALLOC(ps->tlAAA[p], sizeof(TextLegend_t *) * 1); |
| 5018 |
} |
| 5019 |
for(c = 0; c < ps->rflen; c++) { |
| 5020 |
ESL_ALLOC(ps->bcolAAA[p][c], sizeof(float) * NCMYK); |
| 5021 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 5022 |
ESL_ALLOC(ps->rcolAAA[p][c], sizeof(float) * NCMYK); |
| 5023 |
} |
| 5024 |
} |
| 5025 |
} |
| 5026 |
|
| 5027 |
pp = orig_npage; |
| 5028 |
|
| 5029 |
|
| 5030 |
ESL_ALLOC(limits, sizeof(float) * (hc_nbins+1)); |
| 5031 |
limits[0] = 0.0; |
| 5032 |
limits[1] = 0.167; |
| 5033 |
limits[2] = 0.333; |
| 5034 |
limits[3] = 0.500; |
| 5035 |
limits[4] = 0.667; |
| 5036 |
limits[5] = 0.833; |
| 5037 |
limits[6] = 1.00; |
| 5038 |
ps->sclAA[pp] = create_scheme_colorlegend(hc_scheme_idx, hc_nbins, limits, FALSE, FALSE, FALSE, TRUE); |
| 5039 |
|
| 5040 |
if(tabfp != NULL) { |
| 5041 |
fprintf(tabfp, "# ---------\n"); |
| 5042 |
fprintf(tabfp, "# Span data\n"); |
| 5043 |
fprintf(tabfp, "# ---------\n"); |
| 5044 |
fprintf(tabfp, "# This section includes %d non #-prefixed lines, one for each consensus position\n", ps->rflen); |
| 5045 |
fprintf(tabfp, "# in the alignment and corresponding template.\n"); |
| 5046 |
fprintf(tabfp, "# Each line includes %d tokens, separated by whitespace:\n", ps->mask == NULL ? 4 : 5); |
| 5047 |
fprintf(tabfp, "# \ttoken 1: 'span' (tag defining line type to ease parsing)\n"); |
| 5048 |
fprintf(tabfp, "# \ttoken 2: consensus position (starting at 1)\n"); |
| 5049 |
fprintf(tabfp, "# \ttoken 3: fraction of sequences that 'span' position\n"); |
| 5050 |
fprintf(tabfp, "# \ttoken 4: bin index this positions falls in (see bin values below)\n"); |
| 5051 |
if(ps->mask != NULL) { |
| 5052 |
fprintf(tabfp, "# \ttoken 5: '1' if position is included by mask, '0' if not\n"); |
| 5053 |
} |
| 5054 |
fprintf(tabfp, "#\n"); |
| 5055 |
fprintf(tabfp, "# A sequence s spans consensus position 'x' that is actual alignment position 'a' if s has\n"); |
| 5056 |
fprintf(tabfp, "# at least one non-gap nucleotide aligned to a position 'b' <= 'a' and\n"); |
| 5057 |
fprintf(tabfp, "# at least one non-gap nucleotide aligned to a position 'c' >= 'a'\n"); |
| 5058 |
fprintf(tabfp, "#\n"); |
| 5059 |
fprintf(tabfp, "# Value ranges for bins:\n"); |
| 5060 |
fprintf(tabfp, "# \tbin 0: special case, 0 sequences span this position\n"); |
| 5061 |
fprintf(tabfp, "# \tbin 1: special case, all %d sequences span this position\n", msa_nseq); |
| 5062 |
for(l = 0; l < hc_nbins; l++) { |
| 5063 |
fprintf(tabfp, "# \tbin %2d: [%.3f-%.3f%s fraction of sequences that span each position\n", l+2, limits[l], limits[l+1], (l == hc_nbins-1) ? "]" : ")"); |
| 5064 |
} |
| 5065 |
fprintf(tabfp, "#\n"); |
| 5066 |
fprintf(tabfp, "# %4s %6s %8s %3s", "type", "cpos", "span", "bin"); |
| 5067 |
if(ps->mask != NULL) fprintf(tabfp, " %4s", "mask"); |
| 5068 |
fprintf(tabfp, "\n"); |
| 5069 |
fprintf(tabfp, "# %4s %6s %8s %3s", "----", "------", "--------", "---"); |
| 5070 |
if(ps->mask != NULL) fprintf(tabfp, " %4s", "----"); |
| 5071 |
fprintf(tabfp, "\n"); |
| 5072 |
} |
| 5073 |
|
| 5074 |
for(rfpos = 0; rfpos < ps->rflen; rfpos++) { |
| 5075 |
if(span_ct[rfpos] == 0) { |
| 5076 |
if((status = set_onecell_values(errbuf, ps->bcolAAA[pp][rfpos], NCMYK, hc_onecell[zerocov_idx])) != eslOK) return status; |
| 5077 |
nzerocov++; |
| 5078 |
if(ps->mask != NULL && ps->mask[rfpos] == '1') nzerocov_masked++; |
| 5079 |
cfract = 0.; |
| 5080 |
bi = -2; |
| 5081 |
} |
| 5082 |
else if(span_ct[rfpos] == msa_nseq) { |
| 5083 |
if((status = set_onecell_values(errbuf, ps->bcolAAA[pp][rfpos], NCMYK, hc_onecell[maxcov_idx])) != eslOK) return status; |
| 5084 |
nmaxcov++; |
| 5085 |
if(ps->mask != NULL && ps->mask[rfpos] == '1') nmaxcov_masked++; |
| 5086 |
cfract = 1.; |
| 5087 |
bi = -1; |
| 5088 |
} |
| 5089 |
else { |
| 5090 |
within_mask = (ps->mask != NULL && ps->mask[rfpos] == '1') ? TRUE : FALSE; |
| 5091 |
cfract = (float) span_ct[rfpos] / (float) msa_nseq; |
| 5092 |
if((status = set_scheme_values(errbuf, ps->bcolAAA[pp][rfpos], NCMYK, hc_scheme[hc_scheme_idx], cfract, ps->sclAA[pp], within_mask, &bi)) != eslOK) return status; |
| 5093 |
} |
| 5094 |
|
| 5095 |
|
| 5096 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 5097 |
if(ps->mask == NULL || ps->mask[rfpos] == '1') { |
| 5098 |
ps->rAA[pp][rfpos] = esl_opt_GetBoolean(go, "--cambig") ? ps->msa_cseq_amb[rfpos] : ps->msa_cseq_maj[rfpos]; |
| 5099 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[WHITEOC])) != eslOK) return status; |
| 5100 |
} |
| 5101 |
else { |
| 5102 |
ps->rAA[pp][rfpos] = ' '; |
| 5103 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[WHITEOC])) != eslOK) return status; |
| 5104 |
} |
| 5105 |
} |
| 5106 |
|
| 5107 |
if(tabfp != NULL) { |
| 5108 |
fprintf(tabfp, " span %6d %8.5f %3d", rfpos+1, cfract, bi+2); |
| 5109 |
if(ps->mask != NULL) fprintf(tabfp, " %4d", ps->mask[rfpos] == '1' ? 1 : 0); |
| 5110 |
fprintf(tabfp, "\n"); |
| 5111 |
} |
| 5112 |
} |
| 5113 |
|
| 5114 |
|
| 5115 |
ps->occlAAA[pp][0] = create_onecell_colorlegend(hc_onecell[zerocov_idx], nzerocov, nzerocov_masked, FALSE, FALSE); |
| 5116 |
if((status = add_text_to_onecell_colorlegend(ps, ps->occlAAA[pp][0], "no sequences span", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 5117 |
|
| 5118 |
|
| 5119 |
ps->occlAAA[pp][1] = create_onecell_colorlegend(hc_onecell[maxcov_idx], nmaxcov, nmaxcov_masked, FALSE, FALSE); |
| 5120 |
if((status = add_text_to_onecell_colorlegend(ps, ps->occlAAA[pp][1], "100% of seqs span", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 5121 |
ps->nocclA[pp] = 2; |
| 5122 |
|
| 5123 |
|
| 5124 |
if((status = add_text_to_scheme_colorlegend(ps, ps->sclAA[pp], "fraction of seqs that span each position", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 5125 |
if((status = add_page_desc_to_sspostscript(ps, ps->npage-1, "fraction of sequences that span each position", errbuf)) != eslOK) return status; |
| 5126 |
|
| 5127 |
|
| 5128 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 5129 |
ps->tlAAA[pp][0] = create_text_legend_for_consensus_sequence(go, FALSE); |
| 5130 |
ps->ntlA[pp] = 1; |
| 5131 |
} |
| 5132 |
|
| 5133 |
free(limits); |
| 5134 |
|
| 5135 |
if(tabfp != NULL) fprintf(tabfp, "//\n"); |
| 5136 |
return eslOK; |
| 5137 |
|
| 5138 |
ERROR: ESL_FAIL(status, errbuf, "span_sspostscript(): memory allocation error."); |
| 5139 |
return status; |
| 5140 |
} |
| 5141 |
|
| 5142 |
|
| 5143 |
|
| 5144 |
|
| 5145 |
|
| 5146 |
|
| 5147 |
|
| 5148 |
static int |
| 5149 |
avg_posteriors_sspostscript(const ESL_GETOPTS *go, ESL_ALPHABET *abc, char *errbuf, SSPostscript_t *ps, double **pp_ct, int msa_nseq, float ***hc_scheme, int hc_scheme_idx, int hc_nbins, float **hc_onecell, int hc_onecell_idx, FILE *tabfp) |
| 5150 |
{ |
| 5151 |
int status; |
| 5152 |
int p; |
| 5153 |
int rfpos; |
| 5154 |
int pp; |
| 5155 |
float *limits; |
| 5156 |
int nonecell_allgap = 0; |
| 5157 |
int nonecell_allgap_masked = 0; |
| 5158 |
int within_mask; |
| 5159 |
int orig_npage = ps->npage; |
| 5160 |
float ppavgA[11]; |
| 5161 |
int l; |
| 5162 |
int apos; |
| 5163 |
double nnongap; |
| 5164 |
double ppsum; |
| 5165 |
int ppidx; |
| 5166 |
double ppavg; |
| 5167 |
int bi; |
| 5168 |
|
| 5169 |
ppavgA[0] = 0.025; |
| 5170 |
ppavgA[1] = 0.10; |
| 5171 |
ppavgA[2] = 0.20; |
| 5172 |
ppavgA[3] = 0.30; |
| 5173 |
ppavgA[4] = 0.40; |
| 5174 |
ppavgA[5] = 0.50; |
| 5175 |
ppavgA[6] = 0.60; |
| 5176 |
ppavgA[7] = 0.70; |
| 5177 |
ppavgA[8] = 0.80; |
| 5178 |
ppavgA[9] = 0.90; |
| 5179 |
ppavgA[10] = 0.975; |
| 5180 |
|
| 5181 |
if(ps->mask == NULL) { nonecell_allgap_masked = -1; } |
| 5182 |
|
| 5183 |
if((status = add_pages_sspostscript(ps, 1, ALIMODE)) != eslOK) ESL_FAIL(status, errbuf, "memory error adding pages to the postscript object."); |
| 5184 |
|
| 5185 |
for(p = orig_npage; p < ps->npage; p++) { |
| 5186 |
ESL_ALLOC(ps->bcolAAA[p], sizeof(float *) * ps->rflen); |
| 5187 |
|
| 5188 |
|
| 5189 |
ESL_ALLOC(ps->occlAAA[p], sizeof(OneCellColorLegend_t *) * 1); |
| 5190 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 5191 |
ESL_ALLOC(ps->rAA[p], sizeof(char) * ps->rflen); |
| 5192 |
ESL_ALLOC(ps->rcolAAA[p], sizeof(float *) * ps->rflen); |
| 5193 |
ESL_ALLOC(ps->tlAAA[p], sizeof(TextLegend_t *) * 1); |
| 5194 |
} |
| 5195 |
for(rfpos = 0; rfpos < ps->rflen; rfpos++) { |
| 5196 |
ESL_ALLOC(ps->bcolAAA[p][rfpos], sizeof(float) * NCMYK); |
| 5197 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 5198 |
ESL_ALLOC(ps->rcolAAA[p][rfpos], sizeof(float) * NCMYK); |
| 5199 |
} |
| 5200 |
} |
| 5201 |
} |
| 5202 |
|
| 5203 |
ESL_ALLOC(limits, sizeof(float) * (hc_nbins+1)); |
| 5204 |
limits[0] = 0.0; |
| 5205 |
limits[1] = 0.70; |
| 5206 |
limits[2] = 0.80; |
| 5207 |
limits[3] = 0.85; |
| 5208 |
limits[4] = 0.90; |
| 5209 |
limits[5] = 0.95; |
| 5210 |
limits[6] = 1.00; |
| 5211 |
|
| 5212 |
if(tabfp != NULL) { |
| 5213 |
fprintf(tabfp, "# ----------------------------------\n"); |
| 5214 |
fprintf(tabfp, "# Average posterior probability data\n"); |
| 5215 |
fprintf(tabfp, "# ----------------------------------\n"); |
| 5216 |
fprintf(tabfp, "# This section includes %d non #-prefixed lines, one for each consensus position\n", ps->rflen); |
| 5217 |
fprintf(tabfp, "# in the alignment and corresponding template.\n"); |
| 5218 |
fprintf(tabfp, "# Each line includes %d tokens, separated by whitespace:\n", ps->mask == NULL ? 5 : 6); |
| 5219 |
fprintf(tabfp, "# \ttoken 1: 'avgpostprob' (tag defining line type to ease parsing)\n"); |
| 5220 |
fprintf(tabfp, "# \ttoken 2: consensus position (starting at 1)\n"); |
| 5221 |
fprintf(tabfp, "# \ttoken 3: average posterior probability of non-gap nucleotides for position\n"); |
| 5222 |
fprintf(tabfp, "# \ttoken 4: number of non-gap nucleotides in position (max possible is %d (num seqs in aln))\n", msa_nseq); |
| 5223 |
fprintf(tabfp, "# \ttoken 5: bin index this positions falls in (see bin values below)\n"); |
| 5224 |
if(ps->mask != NULL) fprintf(tabfp, "# \ttoken 6: '1' if position is included by mask, '0' if not\n"); |
| 5225 |
fprintf(tabfp, "#\n"); |
| 5226 |
fprintf(tabfp, "# Posterior probability (PP) values in the alignment file can have 12 possible values,\n"); |
| 5227 |
fprintf(tabfp, "# the average per position is calculated by defining each as the average of its range given\n"); |
| 5228 |
fprintf(tabfp, "# below. (For example, a '8' which indicates PP between 0.75 and 0.85 is treated as 0.8).\n"); |
| 5229 |
fprintf(tabfp, "# \t'.': gap, corresponds to a gap in the sequence (not counted)\n"); |
| 5230 |
fprintf(tabfp, "# \t'0': posterior probability of between 0.00 and 0.05\n"); |
| 5231 |
fprintf(tabfp, "# \t'1': posterior probability of between 0.05 and 0.15\n"); |
| 5232 |
fprintf(tabfp, "# \t'2': posterior probability of between 0.15 and 0.25\n"); |
| 5233 |
fprintf(tabfp, "# \t'3': posterior probability of between 0.25 and 0.35\n"); |
| 5234 |
fprintf(tabfp, "# \t'4': posterior probability of between 0.35 and 0.45\n"); |
| 5235 |
fprintf(tabfp, "# \t'5': posterior probability of between 0.45 and 0.55\n"); |
| 5236 |
fprintf(tabfp, "# \t'6': posterior probability of between 0.55 and 0.65\n"); |
| 5237 |
fprintf(tabfp, "# \t'7': posterior probability of between 0.65 and 0.75\n"); |
| 5238 |
fprintf(tabfp, "# \t'8': posterior probability of between 0.75 and 0.85\n"); |
| 5239 |
fprintf(tabfp, "# \t'9': posterior probability of between 0.85 and 0.95\n"); |
| 5240 |
fprintf(tabfp, "# \t'*': posterior probability of between 0.95 and 1.00\n"); |
| 5241 |
fprintf(tabfp, "#\n"); |
| 5242 |
fprintf(tabfp, "# Value ranges for bins:\n"); |
| 5243 |
fprintf(tabfp, "# \tbin 0: special case, 0 sequences have a non-gap nucleotide at position\n"); |
| 5244 |
for(l = 0; l < hc_nbins; l++) { |
| 5245 |
fprintf(tabfp, "# \tbin %2d: [%.3f-%.3f%s average posterior probability per position\n", l+1, limits[l], limits[l+1], (l == hc_nbins-1) ? "]" : ")"); |
| 5246 |
} |
| 5247 |
fprintf(tabfp, "#\n"); |
| 5248 |
fprintf(tabfp, "# %11s %6s %8s %10s %3s", "type", "cpos", "avgpp", "nongap", "bin"); |
| 5249 |
if(ps->mask != NULL) fprintf(tabfp, " %4s", "mask"); |
| 5250 |
fprintf(tabfp, "\n"); |
| 5251 |
fprintf(tabfp, "# %11s %6s %8s %10s %3s", "-----------", "------", "--------", "----------", "---"); |
| 5252 |
if(ps->mask != NULL) fprintf(tabfp, " %4s", "----"); |
| 5253 |
fprintf(tabfp, "\n"); |
| 5254 |
} |
| 5255 |
|
| 5256 |
|
| 5257 |
pp = orig_npage; |
| 5258 |
ps->sclAA[pp] = create_scheme_colorlegend(hc_scheme_idx, hc_nbins, limits, FALSE, TRUE, TRUE, TRUE); |
| 5259 |
for(rfpos = 0; rfpos < ps->rflen; rfpos++) { |
| 5260 |
apos = ps->msa_rf2a_map[rfpos]; |
| 5261 |
nnongap = esl_vec_DSum(pp_ct[apos], 11); |
| 5262 |
if(esl_FCompare_old(nnongap, 0., eslSMALLX1) == eslOK) { |
| 5263 |
if((status = set_onecell_values(errbuf, ps->bcolAAA[pp][rfpos], NCMYK, hc_onecell[hc_onecell_idx])) != eslOK) return status; |
| 5264 |
nonecell_allgap++; |
| 5265 |
if(ps->mask != NULL && ps->mask[rfpos] == '1') nonecell_allgap_masked++; |
| 5266 |
bi = -1; |
| 5267 |
ppavg = 0.; |
| 5268 |
} |
| 5269 |
else { |
| 5270 |
if(esl_FCompare_old(nnongap, pp_ct[apos][10], eslSMALLX1)) { |
| 5271 |
} |
| 5272 |
else { |
| 5273 |
} |
| 5274 |
ppsum = 0.; |
| 5275 |
for(ppidx = 0; ppidx < 11; ppidx++) { |
| 5276 |
ppsum += pp_ct[apos][ppidx] * ppavgA[ppidx]; |
| 5277 |
} |
| 5278 |
ppavg = ppsum / nnongap; |
| 5279 |
within_mask = (ps->mask != NULL && ps->mask[rfpos] == '1') ? TRUE : FALSE; |
| 5280 |
if((status = set_scheme_values(errbuf, ps->bcolAAA[pp][rfpos], NCMYK, hc_scheme[hc_scheme_idx], ppavg, ps->sclAA[pp], within_mask, &bi)) != eslOK) return status; |
| 5281 |
} |
| 5282 |
|
| 5283 |
|
| 5284 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 5285 |
if(ps->mask == NULL || ps->mask[rfpos] == '1') { |
| 5286 |
ps->rAA[pp][rfpos] = esl_opt_GetBoolean(go, "--cambig") ? ps->msa_cseq_amb[rfpos] : ps->msa_cseq_maj[rfpos]; |
| 5287 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[WHITEOC])) != eslOK) return status; |
| 5288 |
} |
| 5289 |
else { |
| 5290 |
ps->rAA[pp][rfpos] = ' '; |
| 5291 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[WHITEOC])) != eslOK) return status; |
| 5292 |
} |
| 5293 |
} |
| 5294 |
|
| 5295 |
if(tabfp != NULL) { |
| 5296 |
fprintf(tabfp, " avgpostprob %6d %8.5f %10d %3d", rfpos+1, ppavg, (int) nnongap, bi+1); |
| 5297 |
if(ps->mask != NULL) fprintf(tabfp, " %4d", ps->mask[rfpos] == '1' ? 1 : 0); |
| 5298 |
fprintf(tabfp, "\n"); |
| 5299 |
} |
| 5300 |
} |
| 5301 |
|
| 5302 |
|
| 5303 |
ps->occlAAA[pp][0] = create_onecell_colorlegend(hc_onecell[hc_onecell_idx], nonecell_allgap, nonecell_allgap_masked, FALSE, FALSE); |
| 5304 |
if((status = add_text_to_onecell_colorlegend(ps, ps->occlAAA[pp][0], "100% gaps", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 5305 |
|
| 5306 |
ps->nocclA[pp] = 1; |
| 5307 |
|
| 5308 |
|
| 5309 |
if((status = add_text_to_scheme_colorlegend(ps, ps->sclAA[pp], "average posterior probability \\(confidence\\)", ps->legx_max_chars,errbuf)) != eslOK) return status; |
| 5310 |
|
| 5311 |
|
| 5312 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 5313 |
ps->tlAAA[pp][0] = create_text_legend_for_consensus_sequence(go, FALSE); |
| 5314 |
ps->ntlA[pp] = 1; |
| 5315 |
} |
| 5316 |
|
| 5317 |
|
| 5318 |
if((status = add_page_desc_to_sspostscript(ps, pp, "average posterior probability per position", errbuf)) != eslOK) return status; |
| 5319 |
|
| 5320 |
free(limits); |
| 5321 |
|
| 5322 |
if(tabfp != NULL) fprintf(tabfp, "//\n"); |
| 5323 |
return eslOK; |
| 5324 |
|
| 5325 |
ERROR: |
| 5326 |
return status; |
| 5327 |
} |
| 5328 |
|
| 5329 |
|
| 5330 |
|
| 5331 |
|
| 5332 |
|
| 5333 |
|
| 5334 |
|
| 5335 |
|
| 5336 |
|
| 5337 |
|
| 5338 |
static int |
| 5339 |
colormask_sspostscript(const ESL_GETOPTS *go, char *errbuf, SSPostscript_t *ps, ESL_MSA *msa, float **hc_onecell, int incmask_idx, int excmask_idx) |
| 5340 |
{ |
| 5341 |
int status; |
| 5342 |
int p, pp, c; |
| 5343 |
int cpos; |
| 5344 |
int orig_npage = ps->npage; |
| 5345 |
int ncols_inside_mask = 0; |
| 5346 |
int ncols_outside_mask = 0; |
| 5347 |
char *mask_desc = NULL; |
| 5348 |
char *mask_file = NULL; |
| 5349 |
|
| 5350 |
if(ps->mask == NULL) ESL_FAIL(eslEINVAL, errbuf, "ps->mask is null when trying to draw maskcol page"); |
| 5351 |
if((status = add_pages_sspostscript(ps, 1, SIMPLEMASKMODE)) != eslOK) ESL_FAIL(eslEINVAL, errbuf, "memory error adding pages to the postscript object."); |
| 5352 |
|
| 5353 |
for(p = orig_npage; p < ps->npage; p++) { |
| 5354 |
ESL_ALLOC(ps->rAA[p], sizeof(char) * ps->rflen); |
| 5355 |
ESL_ALLOC(ps->bcolAAA[p], sizeof(float *) * ps->rflen); |
| 5356 |
ESL_ALLOC(ps->occlAAA[p], sizeof(OneCellColorLegend_t *) * 2); |
| 5357 |
for(c = 0; c < ps->rflen; c++) { |
| 5358 |
ESL_ALLOC(ps->bcolAAA[p][c], sizeof(float) * NCMYK); |
| 5359 |
} |
| 5360 |
} |
| 5361 |
pp = orig_npage; |
| 5362 |
|
| 5363 |
for(cpos = 0; cpos < ps->rflen; cpos++) { |
| 5364 |
if(ps->mask[cpos] == '1') { |
| 5365 |
if((status = set_onecell_values(errbuf, ps->bcolAAA[pp][cpos], NCMYK, hc_onecell[incmask_idx])) != eslOK) return status; |
| 5366 |
ncols_inside_mask++; |
| 5367 |
} |
| 5368 |
else if(ps->mask[cpos] == '0') { |
| 5369 |
if((status = set_onecell_values(errbuf, ps->bcolAAA[pp][cpos], NCMYK, hc_onecell[excmask_idx])) != eslOK) return status; |
| 5370 |
ncols_outside_mask++; |
| 5371 |
} |
| 5372 |
else ESL_FAIL(eslEINVAL, errbuf, "--mask mask char number %d is not a 1 nor a 0, but a %c\n", cpos, ps->mask[cpos]); |
| 5373 |
ps->rAA[pp][cpos] = ' '; |
| 5374 |
} |
| 5375 |
|
| 5376 |
|
| 5377 |
ps->occlAAA[pp][0] = create_onecell_colorlegend(hc_onecell[incmask_idx], ncols_inside_mask, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 5378 |
if((status = add_text_to_onecell_colorlegend(ps, ps->occlAAA[pp][0], "columns included by mask", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 5379 |
|
| 5380 |
ps->occlAAA[pp][1] = create_onecell_colorlegend(hc_onecell[excmask_idx], ncols_outside_mask, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 5381 |
if((status = add_text_to_onecell_colorlegend(ps, ps->occlAAA[pp][1], "columns excluded by mask", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 5382 |
|
| 5383 |
if((status = esl_strcat(&(mask_desc), -1, "mask file: ", -1)) != eslOK) ESL_FAIL(status, errbuf, "error copying mask file name string");; |
| 5384 |
if((status = esl_FileTail(esl_opt_GetString(go, "--mask"), FALSE, &mask_file)) != eslOK) ESL_FAIL(status, errbuf, "error copying mask file name string (probably out of memory)."); |
| 5385 |
if((strlen(mask_file) + strlen(mask_desc)) > (ps->desc_max_chars*2 - 2)) { |
| 5386 |
|
| 5387 |
if((status = esl_strcat(&(mask_desc), -1, mask_file, ((ps->desc_max_chars*2) - strlen(mask_desc) - 5))) != eslOK) ESL_FAIL(status, errbuf, "error copying mask file name string"); |
| 5388 |
if((status = esl_strcat(&(mask_desc), -1, "...", 3)) != eslOK) ESL_FAIL(status, errbuf, "error copying mask file name string"); |
| 5389 |
} |
| 5390 |
else { |
| 5391 |
if((status = esl_strcat(&(mask_desc), -1, mask_file, -1)) != eslOK) ESL_FAIL(status, errbuf, "error copying mask file name string"); |
| 5392 |
} |
| 5393 |
free(mask_file); |
| 5394 |
if((status = add_page_desc_to_sspostscript(ps, pp, mask_desc, errbuf)) != eslOK) return status; |
| 5395 |
|
| 5396 |
ps->nocclA[pp] = 2; |
| 5397 |
free(mask_desc); |
| 5398 |
return eslOK; |
| 5399 |
|
| 5400 |
ERROR: ESL_FAIL(status, errbuf, "colormask_sspostscript(): memory allocation error."); |
| 5401 |
return status; |
| 5402 |
} |
| 5403 |
|
| 5404 |
|
| 5405 |
|
| 5406 |
|
| 5407 |
|
| 5408 |
|
| 5409 |
|
| 5410 |
|
| 5411 |
|
| 5412 |
|
| 5413 |
static int |
| 5414 |
diffmask_sspostscript(const ESL_GETOPTS *go, char *errbuf, SSPostscript_t *ps, ESL_MSA *msa, char *mask2, float **hc_onecell, int incboth_idx, int inc1_idx, int inc2_idx, int excboth_idx) |
| 5415 |
{ |
| 5416 |
int status; |
| 5417 |
int p, pp, c; |
| 5418 |
int cpos; |
| 5419 |
int orig_npage = ps->npage; |
| 5420 |
int ncols_in_both = 0; |
| 5421 |
int ncols_out_both = 0; |
| 5422 |
int ncols_in_1_out_2 = 0; |
| 5423 |
int ncols_out_1_in_2 = 0; |
| 5424 |
|
| 5425 |
if(ps->mask == NULL) ESL_FAIL(eslEINVAL, errbuf, "ps->mask is null when trying to draw maskdiff page"); |
| 5426 |
if((status = add_pages_sspostscript(ps, 1, SIMPLEMASKMODE)) != eslOK) ESL_FAIL(eslEINVAL, errbuf, "memory error adding pages to the postscript object."); |
| 5427 |
|
| 5428 |
for(p = orig_npage; p < ps->npage; p++) { |
| 5429 |
ESL_ALLOC(ps->rAA[p], sizeof(char) * ps->rflen); |
| 5430 |
ESL_ALLOC(ps->bcolAAA[p], sizeof(float *) * ps->rflen); |
| 5431 |
ESL_ALLOC(ps->occlAAA[p], sizeof(OneCellColorLegend_t *) * 4); |
| 5432 |
for(c = 0; c < ps->rflen; c++) { |
| 5433 |
ESL_ALLOC(ps->bcolAAA[p][c], sizeof(float) * NCMYK); |
| 5434 |
} |
| 5435 |
} |
| 5436 |
pp = orig_npage; |
| 5437 |
|
| 5438 |
for(cpos = 0; cpos < ps->rflen; cpos++) { |
| 5439 |
if(ps->mask[cpos] == '1' && mask2[cpos] == '1') { |
| 5440 |
if((status = set_onecell_values(errbuf, ps->bcolAAA[pp][cpos], NCMYK, hc_onecell[incboth_idx])) != eslOK) return status; |
| 5441 |
ncols_in_both++; |
| 5442 |
} |
| 5443 |
else if(ps->mask[cpos] == '1' && mask2[cpos] == '0') { |
| 5444 |
if((status = set_onecell_values(errbuf, ps->bcolAAA[pp][cpos], NCMYK, hc_onecell[inc1_idx])) != eslOK) return status; |
| 5445 |
ncols_in_1_out_2++; |
| 5446 |
} |
| 5447 |
else if(ps->mask[cpos] == '0' && mask2[cpos] == '1') { |
| 5448 |
if((status = set_onecell_values(errbuf, ps->bcolAAA[pp][cpos], NCMYK, hc_onecell[inc2_idx])) != eslOK) return status; |
| 5449 |
ncols_out_1_in_2++; |
| 5450 |
} |
| 5451 |
else if(ps->mask[cpos] == '0' && mask2[cpos] == '0') { |
| 5452 |
if((status = set_onecell_values(errbuf, ps->bcolAAA[pp][cpos], NCMYK, hc_onecell[excboth_idx])) != eslOK) return status; |
| 5453 |
ncols_out_both++; |
| 5454 |
} |
| 5455 |
else if(ps->mask[cpos] != '0' && ps->mask[cpos] != '1') ESL_FAIL(eslEINVAL, errbuf, "--mask-col char number %d is not a 1 nor a 0, but a %c\n", cpos, ps->mask[cpos]); |
| 5456 |
else if(mask2[cpos] != '0' && mask2[cpos] != '1') ESL_FAIL(eslEINVAL, errbuf, "--mask-diff char number %d is not a 1 nor a 0, but a %c\n", cpos, mask2[cpos]); |
| 5457 |
ps->rAA[pp][cpos] = ' '; |
| 5458 |
} |
| 5459 |
|
| 5460 |
|
| 5461 |
ps->occlAAA[pp][0] = create_onecell_colorlegend(hc_onecell[incboth_idx], ncols_in_both, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 5462 |
if((status = add_text_to_onecell_colorlegend(ps, ps->occlAAA[pp][0], "included by both masks", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 5463 |
|
| 5464 |
ps->occlAAA[pp][1] = create_onecell_colorlegend(hc_onecell[inc1_idx], ncols_in_1_out_2, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 5465 |
if((status = add_text_to_onecell_colorlegend(ps, ps->occlAAA[pp][1], "incl mask 1, excl mask 2", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 5466 |
|
| 5467 |
ps->occlAAA[pp][2] = create_onecell_colorlegend(hc_onecell[inc2_idx], ncols_out_1_in_2, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 5468 |
if((status = add_text_to_onecell_colorlegend(ps, ps->occlAAA[pp][2], "excl mask 1, incl mask 1", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 5469 |
|
| 5470 |
ps->occlAAA[pp][3] = create_onecell_colorlegend(hc_onecell[excboth_idx], ncols_out_both, OCCL_BLANK_COUNT, FALSE, FALSE); |
| 5471 |
if((status = add_text_to_onecell_colorlegend(ps, ps->occlAAA[pp][3], "excluded by both masks", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 5472 |
ps->nocclA[pp] = 4; |
| 5473 |
|
| 5474 |
if((status = add_diffmask_page_desc_to_sspostscript(ps, pp, esl_opt_GetString(go, "--mask"), esl_opt_GetString(go, "--mask-diff"), errbuf)) != eslOK) return status; |
| 5475 |
|
| 5476 |
return eslOK; |
| 5477 |
|
| 5478 |
ERROR: ESL_FAIL(status, errbuf, "diffmask_sspostscript(): memory allocation error."); |
| 5479 |
return status; |
| 5480 |
} |
| 5481 |
|
| 5482 |
|
| 5483 |
|
| 5484 |
|
| 5485 |
int |
| 5486 |
add_pages_sspostscript(SSPostscript_t *ps, int ntoadd, int page_mode) |
| 5487 |
{ |
| 5488 |
int status; |
| 5489 |
void *tmp; |
| 5490 |
int p; |
| 5491 |
|
| 5492 |
if(ps->npage == 0) { |
| 5493 |
assert(ps->rAA == NULL); |
| 5494 |
assert(ps->bcolAAA == NULL); |
| 5495 |
ESL_ALLOC(ps->rAA, sizeof(char *) * (ps->npage + ntoadd)); |
| 5496 |
ESL_ALLOC(ps->rcolAAA, sizeof(float **) * (ps->npage + ntoadd)); |
| 5497 |
ESL_ALLOC(ps->bcolAAA, sizeof(float **) * (ps->npage + ntoadd)); |
| 5498 |
ESL_ALLOC(ps->otypeAA, sizeof(char *) * (ps->npage + ntoadd)); |
| 5499 |
ESL_ALLOC(ps->occlAAA, sizeof(OneCellColorLegend_t **) * (ps->npage + ntoadd)); |
| 5500 |
ESL_ALLOC(ps->nocclA, sizeof(int) * (ps->npage + ntoadd)); |
| 5501 |
ESL_ALLOC(ps->tlAAA, sizeof(TextLegend_t **) * (ps->npage + ntoadd)); |
| 5502 |
ESL_ALLOC(ps->ntlA, sizeof(int) * (ps->npage + ntoadd)); |
| 5503 |
ESL_ALLOC(ps->sclAA, sizeof(SchemeColorLegend_t *) * (ps->npage + ntoadd)); |
| 5504 |
ESL_ALLOC(ps->descA, sizeof(char *) * (ps->npage + ntoadd)); |
| 5505 |
ESL_ALLOC(ps->modeA, sizeof(int) * (ps->npage + ntoadd)); |
| 5506 |
ESL_ALLOC(ps->seqidxA, sizeof(int) * (ps->npage + ntoadd)); |
| 5507 |
} |
| 5508 |
else { |
| 5509 |
assert(ps->rAA != NULL); |
| 5510 |
assert(ps->bcolAAA != NULL); |
| 5511 |
assert(ps->rcolAAA != NULL); |
| 5512 |
ESL_RALLOC(ps->rAA, tmp, sizeof(char *) * (ps->npage + ntoadd)); |
| 5513 |
ESL_RALLOC(ps->rcolAAA,tmp, sizeof(float **) * (ps->npage + ntoadd)); |
| 5514 |
ESL_RALLOC(ps->bcolAAA,tmp, sizeof(float **) * (ps->npage + ntoadd)); |
| 5515 |
ESL_RALLOC(ps->otypeAA,tmp, sizeof(char *) * (ps->npage + ntoadd)); |
| 5516 |
ESL_RALLOC(ps->occlAAA,tmp, sizeof(OneCellColorLegend_t ***) * (ps->npage + ntoadd)); |
| 5517 |
ESL_RALLOC(ps->nocclA, tmp, sizeof(int) * (ps->npage + ntoadd)); |
| 5518 |
ESL_RALLOC(ps->tlAAA, tmp, sizeof(TextLegend_t ***) * (ps->npage + ntoadd)); |
| 5519 |
ESL_RALLOC(ps->ntlA, tmp, sizeof(int) * (ps->npage + ntoadd)); |
| 5520 |
ESL_RALLOC(ps->sclAA, tmp, sizeof(SchemeColorLegend_t **) * (ps->npage + ntoadd)); |
| 5521 |
ESL_RALLOC(ps->descA, tmp, sizeof(char *) * (ps->npage + ntoadd)); |
| 5522 |
ESL_RALLOC(ps->modeA, tmp, sizeof(int) * (ps->npage + ntoadd)); |
| 5523 |
ESL_RALLOC(ps->seqidxA,tmp, sizeof(int) * (ps->npage + ntoadd)); |
| 5524 |
} |
| 5525 |
for(p = ps->npage; p < (ps->npage + ntoadd); p++) { |
| 5526 |
ps->rAA[p] = NULL; |
| 5527 |
ps->rcolAAA[p] = NULL; |
| 5528 |
ps->bcolAAA[p] = NULL; |
| 5529 |
ps->otypeAA[p] = NULL; |
| 5530 |
ps->occlAAA[p] = NULL; |
| 5531 |
ps->nocclA[p] = 0; |
| 5532 |
ps->tlAAA[p] = NULL; |
| 5533 |
ps->ntlA[p] = 0; |
| 5534 |
ps->sclAA[p] = NULL; |
| 5535 |
ps->descA[p] = NULL; |
| 5536 |
ps->modeA[p] = page_mode; |
| 5537 |
ps->seqidxA[p] = -1; |
| 5538 |
} |
| 5539 |
ps->npage += ntoadd; |
| 5540 |
|
| 5541 |
return eslOK; |
| 5542 |
|
| 5543 |
ERROR: |
| 5544 |
return status; |
| 5545 |
} |
| 5546 |
|
| 5547 |
|
| 5548 |
|
| 5549 |
|
| 5550 |
|
| 5551 |
|
| 5552 |
|
| 5553 |
|
| 5554 |
|
| 5555 |
|
| 5556 |
|
| 5557 |
|
| 5558 |
int |
| 5559 |
read_mask_file(char *filename, char *errbuf, char **ret_mask, int *ret_masklen, int *ret_mask_has_internal_zeroes) |
| 5560 |
{ |
| 5561 |
int status; |
| 5562 |
ESL_FILEPARSER *efp; |
| 5563 |
char *tok; |
| 5564 |
char *mask; |
| 5565 |
int toklen; |
| 5566 |
int n; |
| 5567 |
|
| 5568 |
int seen_1 = FALSE; |
| 5569 |
int seen_1_then_0 = FALSE; |
| 5570 |
int seen_1_then_0_then_1 = FALSE; |
| 5571 |
|
| 5572 |
if (esl_fileparser_Open(filename, NULL, &efp) != eslOK) ESL_FAIL(eslFAIL, errbuf, "failed to open %s in read_mask_file\n", filename); |
| 5573 |
esl_fileparser_SetCommentChar(efp, '#'); |
| 5574 |
|
| 5575 |
if((status = esl_fileparser_GetToken(efp, &tok, &toklen)) != eslOK) ESL_FAIL(eslFAIL, errbuf, "failed to read a single token from %s\n", filename); |
| 5576 |
|
| 5577 |
ESL_ALLOC(mask, sizeof(char) * (toklen+1)); |
| 5578 |
|
| 5579 |
for(n = 0; n < toklen; n++) { |
| 5580 |
mask[n] = tok[n]; |
| 5581 |
if(mask[n] == '0') { |
| 5582 |
if((seen_1) && (!seen_1_then_0)) { seen_1_then_0 = TRUE; } |
| 5583 |
} |
| 5584 |
else if (mask[n] == '1') { |
| 5585 |
if(!seen_1) { seen_1 = TRUE; } |
| 5586 |
if((seen_1) && (seen_1_then_0) && (!seen_1_then_0_then_1)) { seen_1_then_0_then_1 = TRUE; } |
| 5587 |
} |
| 5588 |
else { ESL_FAIL(eslEINVAL, errbuf, "character %d of mask file is invalid: %c (must be a '1' or a '0')\n", n, mask[n]); } |
| 5589 |
|
| 5590 |
mask[n] = tok[n]; |
| 5591 |
} |
| 5592 |
mask[n] = '\0'; |
| 5593 |
|
| 5594 |
*ret_mask = mask; |
| 5595 |
*ret_masklen= toklen; |
| 5596 |
*ret_mask_has_internal_zeroes = seen_1_then_0_then_1; |
| 5597 |
|
| 5598 |
esl_fileparser_Close(efp); |
| 5599 |
|
| 5600 |
return eslOK; |
| 5601 |
|
| 5602 |
ERROR: |
| 5603 |
return eslEMEM; |
| 5604 |
} |
| 5605 |
|
| 5606 |
|
| 5607 |
|
| 5608 |
|
| 5609 |
|
| 5610 |
|
| 5611 |
|
| 5612 |
|
| 5613 |
|
| 5614 |
|
| 5615 |
|
| 5616 |
|
| 5617 |
static int |
| 5618 |
mutual_information_sspostscript(const ESL_GETOPTS *go, ESL_ALPHABET *abc, char *errbuf, SSPostscript_t *ps, double ***bp_ct, int msa_nseq, float ***hc_scheme, int hc_scheme_idx, int hc_nbins, float **hc_onecell, int ss_idx, int zerores_idx, FILE *tabfp) |
| 5619 |
{ |
| 5620 |
int status; |
| 5621 |
int p, pp, c, i; |
| 5622 |
int rfpos, apos; |
| 5623 |
int orig_npage = ps->npage; |
| 5624 |
double *bg, *bg_pair; |
| 5625 |
double bg_ent, bg_pair_ent; |
| 5626 |
double *obs_left, *obs_right, *obs_pair; |
| 5627 |
double ent_left, ent_right, ent_pair; |
| 5628 |
int j; |
| 5629 |
ESL_DSQ lres; |
| 5630 |
ESL_DSQ rres; |
| 5631 |
double nres; |
| 5632 |
int nss = 0; |
| 5633 |
int nzerores = 0; |
| 5634 |
int nss_masked = 0; |
| 5635 |
int nzerores_masked = 0; |
| 5636 |
int i_within_mask, j_within_mask; |
| 5637 |
int i_bi, j_bi; |
| 5638 |
float *limits; |
| 5639 |
int l; |
| 5640 |
int idx =1; |
| 5641 |
|
| 5642 |
if(ps->mask == NULL) nss_masked = nzerores_masked = -1; |
| 5643 |
if((status = add_pages_sspostscript(ps, 1, ALIMODE)) != eslOK) ESL_FAIL(status, errbuf, "memory error adding pages to the postscript object."); |
| 5644 |
|
| 5645 |
for(p = orig_npage; p < ps->npage; p++) { |
| 5646 |
ESL_ALLOC(ps->bcolAAA[p], sizeof(float *) * ps->rflen); |
| 5647 |
|
| 5648 |
|
| 5649 |
ESL_ALLOC(ps->occlAAA[p], sizeof(OneCellColorLegend_t *) * 2); |
| 5650 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 5651 |
ESL_ALLOC(ps->rAA[p], sizeof(char) * ps->rflen); |
| 5652 |
ESL_ALLOC(ps->rcolAAA[p], sizeof(float *) * ps->rflen); |
| 5653 |
ESL_ALLOC(ps->tlAAA[p], sizeof(TextLegend_t *) * 1); |
| 5654 |
} |
| 5655 |
for(c = 0; c < ps->rflen; c++) { |
| 5656 |
ESL_ALLOC(ps->bcolAAA[p][c], sizeof(float) * NCMYK); |
| 5657 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 5658 |
ESL_ALLOC(ps->rcolAAA[p][c], sizeof(float) * NCMYK); |
| 5659 |
} |
| 5660 |
} |
| 5661 |
} |
| 5662 |
pp = orig_npage; |
| 5663 |
|
| 5664 |
|
| 5665 |
ESL_ALLOC(limits, sizeof(float) * (hc_nbins+1)); |
| 5666 |
limits[0] = 0.0; |
| 5667 |
limits[1] = 0.167; |
| 5668 |
limits[2] = 0.333; |
| 5669 |
limits[3] = 0.500; |
| 5670 |
limits[4] = 0.667; |
| 5671 |
limits[5] = 0.833; |
| 5672 |
limits[6] = 1.000; |
| 5673 |
ps->sclAA[pp] = create_scheme_colorlegend(hc_scheme_idx, hc_nbins, limits, FALSE, TRUE, TRUE, TRUE); |
| 5674 |
|
| 5675 |
if(tabfp != NULL) { |
| 5676 |
fprintf(tabfp, "# -----------------------\n"); |
| 5677 |
fprintf(tabfp, "# Mutual information data\n"); |
| 5678 |
fprintf(tabfp, "# -----------------------\n"); |
| 5679 |
fprintf(tabfp, "# This section includes %d non #-prefixed lines, one for each consensus position\n", ps->rflen); |
| 5680 |
fprintf(tabfp, "# in the alignment and corresponding template.\n"); |
| 5681 |
fprintf(tabfp, "# Each line includes %d tokens, separated by whitespace:\n", ps->mask == NULL ? 9 : 11); |
| 5682 |
fprintf(tabfp, "# \ttoken 1: 'mutualinfo' (tag defining line type to ease parsing)\n"); |
| 5683 |
fprintf(tabfp, "# \ttoken 2: base pair index\n"); |
| 5684 |
fprintf(tabfp, "# \ttoken 3: 5' consensus position of base pair (starting at 1)\n"); |
| 5685 |
fprintf(tabfp, "# \ttoken 4: 3' consensus position of base pair (starting at 1)\n"); |
| 5686 |
fprintf(tabfp, "# \ttoken 5: sequence information content at 5' position (bits)\n"); |
| 5687 |
fprintf(tabfp, "# \ttoken 6: sequence information content at 3' position (bits)\n"); |
| 5688 |
fprintf(tabfp, "# \ttoken 7: mutual information of the base pair (bits)\n"); |
| 5689 |
fprintf(tabfp, "# \ttoken 8: number of sequences with non-gap at 5' and 3' posn (max possible is %d)\n", msa_nseq); |
| 5690 |
fprintf(tabfp, "# \ttoken 8: number of sequences with non-gap at 5' and 3' position\n"); |
| 5691 |
fprintf(tabfp, "# \ttoken 9: bin index this positions falls in (see bin values below).\n"); |
| 5692 |
if(ps->mask != NULL) { |
| 5693 |
fprintf(tabfp, "# \ttoken 10: '1' if 5' position is included by mask, '0' if not\n"); |
| 5694 |
fprintf(tabfp, "# \ttoken 11: '1' if 3' position is included by mask, '0' if not\n"); |
| 5695 |
} |
| 5696 |
fprintf(tabfp, "#\n"); |
| 5697 |
fprintf(tabfp, "# Information content is calculated as 2.0 - H, where\n"); |
| 5698 |
fprintf(tabfp, "# H = - \\sum_x p_x \\log_2 p_x, for x in {A, C, G, U}\n"); |
| 5699 |
fprintf(tabfp, "# p_x is the frequency of x for *non-gap* nucleotides at the position.\n"); |
| 5700 |
fprintf(tabfp, "# Only nucleotides for sequences which have a non-gap nucleotide at both\n"); |
| 5701 |
fprintf(tabfp, "# the 5' and 3' positions of the pair are counted.\n"); |
| 5702 |
fprintf(tabfp, "# Mutual information is calculated as\n"); |
| 5703 |
fprintf(tabfp, "# \\sum_{x,y} p_{x,y} \\log_2 ((p_x * p_y) / p_{x,y}\n"); |
| 5704 |
fprintf(tabfp, "# Value ranges for bins:\n"); |
| 5705 |
fprintf(tabfp, "# \tbin 0: special case, 0 sequences have non-gaps at both 5' and 3' position of pair\n"); |
| 5706 |
for(l = 0; l < hc_nbins; l++) { |
| 5707 |
fprintf(tabfp, "# \tbin %2d: [%.3f-%.3f%s mutual information per position (bits)\n", l+1, limits[l], limits[l+1], (l == hc_nbins-1) ? "]" : ")"); |
| 5708 |
} |
| 5709 |
fprintf(tabfp, "#\n"); |
| 5710 |
fprintf(tabfp, "# %10s %4s %5s %5s %8s %8s %9s %10s %3s", "type", "idx", "5'pos", "3'pos", "5'info", "3'info", "mutinfo/2", "nongap", "bin"); |
| 5711 |
if(ps->mask != NULL) fprintf(tabfp, " %6s %6s", "5'mask", "3'mask"); |
| 5712 |
fprintf(tabfp, "\n"); |
| 5713 |
fprintf(tabfp, "# %10s %4s %5s %5s %8s %8s %9s %10s %3s", "----------", "----", "-----", "-----", "--------", "--------", "---------", "----------", "---"); |
| 5714 |
if(ps->mask != NULL) fprintf(tabfp, " %6s %6s", "------", "------"); |
| 5715 |
fprintf(tabfp, "\n"); |
| 5716 |
} |
| 5717 |
|
| 5718 |
|
| 5719 |
ESL_ALLOC(bg, sizeof(double) * abc->K); |
| 5720 |
ESL_ALLOC(bg_pair, sizeof(double) * abc->K*abc->K); |
| 5721 |
esl_vec_DSet(bg, abc->K, 1./(abc->K)); |
| 5722 |
esl_vec_DSet(bg_pair, abc->K*abc->K, 1./(abc->K*abc->K)); |
| 5723 |
bg_pair_ent = esl_vec_DEntropy(bg_pair, abc->K*abc->K); |
| 5724 |
bg_ent = esl_vec_DEntropy(bg, abc->K); |
| 5725 |
free(bg); |
| 5726 |
free(bg_pair); |
| 5727 |
|
| 5728 |
ESL_ALLOC(obs_left, sizeof(double) * (abc->K)); |
| 5729 |
ESL_ALLOC(obs_right, sizeof(double) * (abc->K)); |
| 5730 |
ESL_ALLOC(obs_pair, sizeof(double) * (abc->K*abc->K)); |
| 5731 |
|
| 5732 |
|
| 5733 |
for(rfpos = 0; rfpos < ps->rflen; rfpos++) { |
| 5734 |
esl_vec_DSet(obs_left, abc->K, 0.); |
| 5735 |
esl_vec_DSet(obs_right, abc->K, 0.); |
| 5736 |
esl_vec_DSet(obs_pair, abc->K*abc->K, 0.); |
| 5737 |
i = rfpos; |
| 5738 |
nres = 0.; |
| 5739 |
apos = ps->msa_rf2a_map[rfpos]; |
| 5740 |
|
| 5741 |
if(ps->msa_ct[rfpos+1] != 0) { |
| 5742 |
|
| 5743 |
if(ps->msa_ct[rfpos+1] > (rfpos+1)) { |
| 5744 |
|
| 5745 |
|
| 5746 |
|
| 5747 |
|
| 5748 |
j = ps->msa_ct[i+1] - 1; |
| 5749 |
for(lres = 0; lres < abc->K; lres++) { |
| 5750 |
for(rres = 0; rres < abc->K; rres++) { |
| 5751 |
|
| 5752 |
esl_abc_DCount(abc, obs_left, lres, bp_ct[apos][lres][rres]); |
| 5753 |
esl_abc_DCount(abc, obs_right, rres, bp_ct[apos][lres][rres]); |
| 5754 |
PairCount(abc, obs_pair, lres, rres, bp_ct[apos][lres][rres]); |
| 5755 |
nres += bp_ct[apos][lres][rres]; |
| 5756 |
} |
| 5757 |
} |
| 5758 |
for(lres = abc->K+1; lres < abc->Kp-2; lres++) { |
| 5759 |
for(rres = abc->K+1; rres < abc->Kp-2; rres++) { |
| 5760 |
esl_abc_DCount(abc, obs_left, lres, bp_ct[apos][lres][rres]); |
| 5761 |
esl_abc_DCount(abc, obs_right, rres, bp_ct[apos][lres][rres]); |
| 5762 |
PairCount(abc, obs_pair, lres, rres, bp_ct[apos][lres][rres]); |
| 5763 |
nres += bp_ct[apos][lres][rres]; |
| 5764 |
} |
| 5765 |
} |
| 5766 |
|
| 5767 |
|
| 5768 |
|
| 5769 |
|
| 5770 |
esl_vec_DNorm(obs_left, abc->K); |
| 5771 |
esl_vec_DNorm(obs_right, abc->K); |
| 5772 |
esl_vec_DNorm(obs_pair, abc->K*abc->K); |
| 5773 |
ent_left = bg_ent - esl_vec_DEntropy(obs_left, abc->K); |
| 5774 |
ent_right = bg_ent - esl_vec_DEntropy(obs_right, abc->K); |
| 5775 |
ent_pair = bg_pair_ent - esl_vec_DEntropy(obs_pair, abc->K*abc->K); |
| 5776 |
|
| 5777 |
ent_pair -= ent_left + ent_right; |
| 5778 |
ent_pair /= 2.; |
| 5779 |
|
| 5780 |
|
| 5781 |
|
| 5782 |
|
| 5783 |
|
| 5784 |
|
| 5785 |
|
| 5786 |
|
| 5787 |
|
| 5788 |
|
| 5789 |
|
| 5790 |
|
| 5791 |
|
| 5792 |
|
| 5793 |
|
| 5794 |
if(ent_pair < (-1. * eslSMALLX1)) { |
| 5795 |
ESL_FAIL(eslEINCONCEIVABLE, errbuf, "pair information < 0.: %f (lpos: %d rpos: %d)\n", ent_pair, i, j); |
| 5796 |
} |
| 5797 |
if(esl_DCompare_old(nres, 0., eslSMALLX1) == eslOK) { |
| 5798 |
if((status = set_onecell_values(errbuf, ps->bcolAAA[pp][i], NCMYK, hc_onecell[zerores_idx])) != eslOK) return status; |
| 5799 |
if((status = set_onecell_values(errbuf, ps->bcolAAA[pp][j], NCMYK, hc_onecell[zerores_idx])) != eslOK) return status; |
| 5800 |
nzerores += 2; |
| 5801 |
if(ps->mask != NULL && ps->mask[i] == '1') nzerores_masked++; |
| 5802 |
if(ps->mask != NULL && ps->mask[j] == '1') nzerores_masked++; |
| 5803 |
if(tabfp != NULL) { |
| 5804 |
fprintf(tabfp, " mutualinfo %4d %5d %5d %8.5f %8.5f %9.5f %10d %3d", idx++, i+1, j+1, 0., 0., 0., 0, 0); |
| 5805 |
if(ps->mask != NULL) fprintf(tabfp, " %6d %6d", ((ps->mask == NULL || ps->mask[i] == '1') ? 1 : 0), ((ps->mask == NULL || ps->mask[j] == '1') ? 1 : 0)); |
| 5806 |
fprintf(tabfp, "\n"); |
| 5807 |
} |
| 5808 |
} |
| 5809 |
else { |
| 5810 |
i_within_mask = (ps->mask != NULL && ps->mask[i] == '1') ? TRUE : FALSE; |
| 5811 |
j_within_mask = (ps->mask != NULL && ps->mask[j] == '1') ? TRUE : FALSE; |
| 5812 |
if((status = set_scheme_values(errbuf, ps->bcolAAA[pp][i], NCMYK, hc_scheme[hc_scheme_idx], ent_pair, ps->sclAA[pp], i_within_mask, &i_bi)) != eslOK) return status; |
| 5813 |
if((status = set_scheme_values(errbuf, ps->bcolAAA[pp][j], NCMYK, hc_scheme[hc_scheme_idx], ent_pair, ps->sclAA[pp], j_within_mask, &j_bi)) != eslOK) return status; |
| 5814 |
if(tabfp != NULL) { |
| 5815 |
fprintf(tabfp, " mutualinfo %4d %5d %5d %8.5f %8.5f %9.5f %10d %3d", |
| 5816 |
idx++, i+1, j+1, |
| 5817 |
ent_left, |
| 5818 |
ent_right, |
| 5819 |
ent_pair, |
| 5820 |
(int) nres, |
| 5821 |
i_bi+1); |
| 5822 |
if(ps->mask != NULL) fprintf(tabfp, " %6d %6d", ((ps->mask == NULL || ps->mask[i] == '1') ? 1 : 0), ((ps->mask == NULL || ps->mask[j] == '1') ? 1 : 0)); |
| 5823 |
fprintf(tabfp, "\n"); |
| 5824 |
} |
| 5825 |
} |
| 5826 |
} |
| 5827 |
} |
| 5828 |
else { |
| 5829 |
nss++; |
| 5830 |
if(ps->mask != NULL && ps->mask[rfpos] == '1') nss_masked++; |
| 5831 |
if((status = set_onecell_values(errbuf, ps->bcolAAA[pp][rfpos], NCMYK, hc_onecell[ss_idx])) != eslOK) return status; |
| 5832 |
} |
| 5833 |
|
| 5834 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 5835 |
if(ps->mask == NULL || ps->mask[rfpos] == '1') { |
| 5836 |
ps->rAA[pp][rfpos] = esl_opt_GetBoolean(go, "--cambig") ? ps->msa_cseq_amb[rfpos] : ps->msa_cseq_maj[rfpos]; |
| 5837 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[WHITEOC])) != eslOK) return status; |
| 5838 |
} |
| 5839 |
else { |
| 5840 |
ps->rAA[pp][rfpos] = ' '; |
| 5841 |
if((status = set_onecell_values(errbuf, ps->rcolAAA[pp][rfpos], NCMYK, hc_onecell[WHITEOC])) != eslOK) return status; |
| 5842 |
} |
| 5843 |
} |
| 5844 |
} |
| 5845 |
|
| 5846 |
|
| 5847 |
ps->occlAAA[pp][0] = create_onecell_colorlegend(hc_onecell[ss_idx], nss, nss_masked, FALSE, FALSE); |
| 5848 |
if((status = add_text_to_onecell_colorlegend(ps, ps->occlAAA[pp][0], "single-stranded", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 5849 |
|
| 5850 |
|
| 5851 |
ps->occlAAA[pp][1] = create_onecell_colorlegend(hc_onecell[zerores_idx], nzerores, nzerores_masked, FALSE, FALSE); |
| 5852 |
if((status = add_text_to_onecell_colorlegend(ps, ps->occlAAA[pp][1], "0 complete basepairs", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 5853 |
ps->nocclA[pp] = 2; |
| 5854 |
|
| 5855 |
|
| 5856 |
if((status = add_text_to_scheme_colorlegend(ps, ps->sclAA[pp], "mutual information per position (bits)", ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 5857 |
|
| 5858 |
|
| 5859 |
if(! esl_opt_GetBoolean(go, "--no-cnt")) { |
| 5860 |
ps->tlAAA[pp][0] = create_text_legend_for_consensus_sequence(go, FALSE); |
| 5861 |
ps->ntlA[pp] = 1; |
| 5862 |
} |
| 5863 |
|
| 5864 |
|
| 5865 |
if((status = add_page_desc_to_sspostscript(ps, pp, "mutual information per basepaired position", errbuf)) != eslOK) return status; |
| 5866 |
|
| 5867 |
free(limits); |
| 5868 |
free(obs_left); |
| 5869 |
free(obs_right); |
| 5870 |
free(obs_pair); |
| 5871 |
|
| 5872 |
if(tabfp != NULL) fprintf(tabfp, "//\n"); |
| 5873 |
return eslOK; |
| 5874 |
|
| 5875 |
ERROR: ESL_FAIL(status, errbuf, "mutual_information_sspostscript(): memory allocation error."); |
| 5876 |
return status; |
| 5877 |
} |
| 5878 |
|
| 5879 |
|
| 5880 |
|
| 5881 |
|
| 5882 |
|
| 5883 |
|
| 5884 |
|
| 5885 |
|
| 5886 |
|
| 5887 |
|
| 5888 |
|
| 5889 |
|
| 5890 |
|
| 5891 |
|
| 5892 |
|
| 5893 |
|
| 5894 |
static void |
| 5895 |
PairCount(const ESL_ALPHABET *abc, double *counters, ESL_DSQ syml, ESL_DSQ symr, double wt) |
| 5896 |
{ |
| 5897 |
int status; |
| 5898 |
if (syml < abc->K && symr < abc->K) { |
| 5899 |
counters[(int) (syml * abc->K + symr)] += wt; |
| 5900 |
return; |
| 5901 |
} |
| 5902 |
else { |
| 5903 |
int l,r; |
| 5904 |
double *left = NULL; |
| 5905 |
double *right = NULL; |
| 5906 |
ESL_ALLOC(left, sizeof(double) * abc->K); |
| 5907 |
ESL_ALLOC(right, sizeof(double) * abc->K); |
| 5908 |
|
| 5909 |
esl_vec_DSet(left, abc->K, 0.); |
| 5910 |
esl_vec_DSet(right, abc->K, 0.); |
| 5911 |
esl_abc_DCount(abc, left, syml, 1.0); |
| 5912 |
esl_abc_DCount(abc, right, symr, 1.0); |
| 5913 |
|
| 5914 |
for (l = 0; l < abc->K; l++) |
| 5915 |
for (r = 0; r < abc->K; r++) |
| 5916 |
counters[l*abc->K +r] += left[l] * right[r] * wt; |
| 5917 |
free(left); |
| 5918 |
free(right); |
| 5919 |
} |
| 5920 |
return; |
| 5921 |
|
| 5922 |
ERROR: |
| 5923 |
esl_fatal("Memory error"); |
| 5924 |
} |
| 5925 |
|
| 5926 |
|
| 5927 |
|
| 5928 |
|
| 5929 |
|
| 5930 |
|
| 5931 |
|
| 5932 |
|
| 5933 |
|
| 5934 |
static int |
| 5935 |
get_command(const ESL_GETOPTS *go, char *errbuf, char **ret_command) |
| 5936 |
{ |
| 5937 |
int status; |
| 5938 |
int i; |
| 5939 |
char *command = NULL; |
| 5940 |
|
| 5941 |
for (i = 0; i < go->argc; i++) { |
| 5942 |
if((status = esl_strcat(&(command), -1, go->argv[i], -1)) != eslOK) goto ERROR; |
| 5943 |
if(i < (go->argc-1)) if((status = esl_strcat(&(command), -1, " ", 1)) != eslOK) goto ERROR; |
| 5944 |
} |
| 5945 |
*ret_command = command; |
| 5946 |
|
| 5947 |
return eslOK; |
| 5948 |
|
| 5949 |
ERROR: |
| 5950 |
ESL_FAIL(status, errbuf, "get_command(): memory allocation error."); |
| 5951 |
return status; |
| 5952 |
} |
| 5953 |
|
| 5954 |
|
| 5955 |
|
| 5956 |
|
| 5957 |
|
| 5958 |
|
| 5959 |
|
| 5960 |
|
| 5961 |
static int |
| 5962 |
get_date(char *errbuf, char **ret_date) |
| 5963 |
{ |
| 5964 |
int status; |
| 5965 |
time_t date = time(NULL); |
| 5966 |
char *sdate = NULL; |
| 5967 |
|
| 5968 |
if((status = esl_strdup(ctime(&date), -1, &sdate)) != eslOK) goto ERROR; |
| 5969 |
esl_strchop(sdate, -1); |
| 5970 |
|
| 5971 |
*ret_date = sdate; |
| 5972 |
return eslOK; |
| 5973 |
|
| 5974 |
ERROR: |
| 5975 |
ESL_FAIL(status, errbuf, "get_date() error status: %d, probably out of memory.", status); |
| 5976 |
return status; |
| 5977 |
} |
| 5978 |
|
| 5979 |
|
| 5980 |
|
| 5981 |
|
| 5982 |
|
| 5983 |
|
| 5984 |
static int |
| 5985 |
set_scheme_values(char *errbuf, float *vec, int ncolvals, float **scheme, float val, SchemeColorLegend_t *scl, int within_mask, int *ret_bi) |
| 5986 |
{ |
| 5987 |
float min, max; |
| 5988 |
int ci, bi; |
| 5989 |
min = scl->limits[0]; |
| 5990 |
max = scl->limits[scl->nbins]; |
| 5991 |
if((min-val) > eslSMALLX1) { ESL_FAIL(eslEINVAL, errbuf, "set_scheme_values(), val: %.4f < min: %.4f\n", val, min); } |
| 5992 |
if((val-max) > eslSMALLX1) { ESL_FAIL(eslEINVAL, errbuf, "set_scheme_values(), val: %.4f > max: %.4f\n", val, max); } |
| 5993 |
|
| 5994 |
bi = 0; |
| 5995 |
while((bi < (scl->nbins-1)) && |
| 5996 |
((val > scl->limits[bi+1]) || |
| 5997 |
(esl_FCompare_old(val, scl->limits[bi+1], eslSMALLX1) == eslOK))) { |
| 5998 |
bi++; |
| 5999 |
} |
| 6000 |
|
| 6001 |
scl->counts[bi]++; |
| 6002 |
if(within_mask) scl->counts_masked[bi]++; |
| 6003 |
for(ci = 0; ci < ncolvals; ci++) { |
| 6004 |
vec[ci] = scheme[bi][ci]; |
| 6005 |
} |
| 6006 |
|
| 6007 |
if(ret_bi != NULL) *ret_bi = bi; |
| 6008 |
return eslOK; |
| 6009 |
} |
| 6010 |
|
| 6011 |
|
| 6012 |
|
| 6013 |
|
| 6014 |
|
| 6015 |
|
| 6016 |
static int |
| 6017 |
set_onecell_values(char *errbuf, float *vec, int ncolvals, float *onecolor) |
| 6018 |
{ |
| 6019 |
int ci; |
| 6020 |
for(ci = 0; ci < ncolvals; ci++) { vec[ci] = onecolor[ci]; } |
| 6021 |
return eslOK; |
| 6022 |
} |
| 6023 |
|
| 6024 |
|
| 6025 |
|
| 6026 |
|
| 6027 |
|
| 6028 |
|
| 6029 |
|
| 6030 |
static int |
| 6031 |
draw_masked_block(FILE *fp, float x, float y, float *colvec, int do_circle_mask, int do_square_mask, int do_x_mask, int do_border, float cellsize) |
| 6032 |
{ |
| 6033 |
if (do_circle_mask) { |
| 6034 |
if(do_border) { |
| 6035 |
fprintf(fp, "newpath\n"); |
| 6036 |
fprintf(fp, " %.2f %.2f %.1f 0 360 arc closepath\n", x + (cellsize/2.), y + (cellsize/2.), cellsize * (3./8.)); |
| 6037 |
fprintf(fp, " %.4f %.4f %.4f %.4f setcmykcolor\n", colvec[0], colvec[1], colvec[2], colvec[3]); |
| 6038 |
fprintf(fp, " stroke\n"); |
| 6039 |
} |
| 6040 |
else { |
| 6041 |
fprintf(fp, "newpath\n"); |
| 6042 |
fprintf(fp, " %.2f %.2f %.1f 0 360 arc closepath\n", x + (cellsize/2.), y + (cellsize/2.), cellsize * (3./8.)); |
| 6043 |
fprintf(fp, " %.4f %.4f %.4f %.4f setcmykcolor\n", colvec[0], colvec[1], colvec[2], colvec[3]); |
| 6044 |
fprintf(fp, " fill\n"); |
| 6045 |
} |
| 6046 |
} |
| 6047 |
else if(do_square_mask) { |
| 6048 |
if(do_border) { |
| 6049 |
fprintf(fp, "newpath\n"); |
| 6050 |
fprintf(fp, " %.2f %.2f moveto", x +1., y +1.); |
| 6051 |
fprintf(fp, " 0 %.1f rlineto %.1f 0 rlineto 0 -%.1f rlineto closepath\n", cellsize*0.75, cellsize*0.75, cellsize*0.75); |
| 6052 |
fprintf(fp, " %.4f %.4f %.4f %.4f setcmykcolor\n", colvec[0], colvec[1], colvec[2], colvec[3]); |
| 6053 |
fprintf(fp, " stroke\n"); |
| 6054 |
} |
| 6055 |
else { |
| 6056 |
fprintf(fp, "newpath\n"); |
| 6057 |
fprintf(fp, " %.2f %.2f moveto", x + 1.5, y + 1.5); |
| 6058 |
fprintf(fp, " 0 %.1f rlineto %.1f 0 rlineto 0 -%.1f rlineto closepath\n", cellsize*(5./8.), cellsize*(5./8.), cellsize*(5./8.)); |
| 6059 |
fprintf(fp, " %.4f %.4f %.4f %.4f setcmykcolor\n", colvec[0], colvec[1], colvec[2], colvec[3]); |
| 6060 |
fprintf(fp, " fill\n"); |
| 6061 |
} |
| 6062 |
} |
| 6063 |
else if (do_x_mask) { |
| 6064 |
if(do_border) { |
| 6065 |
fprintf(fp, "newpath\n"); |
| 6066 |
fprintf(fp, " %.2f %.2f moveto", x, y); |
| 6067 |
fprintf(fp, " 0 %.1f rlineto %.1f 0 rlineto 0 -%.1f rlineto closepath\n", cellsize, cellsize, cellsize); |
| 6068 |
fprintf(fp, " %.4f %.4f %.4f %.4f setcmykcolor\n", colvec[0], colvec[1], colvec[2], colvec[3]); |
| 6069 |
fprintf(fp, " fill\n"); |
| 6070 |
|
| 6071 |
fprintf(fp, " %.4f %.4f %.4f %.4f setcmykcolor\n", 0., 0., 0., 0.); |
| 6072 |
fprintf(fp, "newpath\n"); |
| 6073 |
fprintf(fp, " %.2f %.2f moveto", x, y); |
| 6074 |
fprintf(fp, " %.1f %.1f rlineto closepath\n", cellsize, cellsize); |
| 6075 |
fprintf(fp, " stroke\n"); |
| 6076 |
fprintf(fp, " %.2f %.2f moveto", x + cellsize, y); |
| 6077 |
fprintf(fp, " -%.1f %.1f rlineto closepath\n", cellsize, cellsize); |
| 6078 |
fprintf(fp, " stroke\n"); |
| 6079 |
} |
| 6080 |
else { |
| 6081 |
fprintf(fp, "newpath\n"); |
| 6082 |
fprintf(fp, " %.4f %.4f %.4f %.4f setcmykcolor\n", colvec[0], colvec[1], colvec[2], colvec[3]); |
| 6083 |
fprintf(fp, " %.2f %.2f moveto", x, y); |
| 6084 |
fprintf(fp, " %.1f %.1f rlineto closepath\n", cellsize, cellsize); |
| 6085 |
fprintf(fp, " stroke\n"); |
| 6086 |
fprintf(fp, "newpath\n"); |
| 6087 |
fprintf(fp, " %.2f %.2f moveto", x + cellsize, y); |
| 6088 |
fprintf(fp, " -%.1f %.1f rlineto closepath\n", cellsize, cellsize); |
| 6089 |
fprintf(fp, " stroke\n"); |
| 6090 |
} |
| 6091 |
} |
| 6092 |
return eslOK; |
| 6093 |
} |
| 6094 |
|
| 6095 |
|
| 6096 |
|
| 6097 |
|
| 6098 |
|
| 6099 |
|
| 6100 |
|
| 6101 |
static int |
| 6102 |
validate_justread_sspostscript(SSPostscript_t *ps, char *errbuf) |
| 6103 |
{ |
| 6104 |
if(ps->modelname == NULL) ESL_FAIL(eslEINVAL, errbuf, "Error, failed to read modelname from template file."); |
| 6105 |
if(ps->nbp == 0) ESL_FAIL(eslEINVAL, errbuf, "Error, failed to read 'lines bpconnects' section from template file."); |
| 6106 |
if(ps->scale < 0) ESL_FAIL(eslEINVAL, errbuf, "Error, failed to read scale from template file."); |
| 6107 |
if(ps->rflen == 0) ESL_FAIL(eslEINVAL, errbuf, "Error, failed to read 'text nucleotides' section from template file."); |
| 6108 |
if(ps->leg_posn == -1) ESL_FAIL(eslEINVAL, errbuf, "Error, failed to read 'legend' section from template file."); |
| 6109 |
if(ps->leg_cellsize == -1) ESL_FAIL(eslEINVAL, errbuf, "Error, failed to read 'legend' section from template file."); |
| 6110 |
|
| 6111 |
|
| 6112 |
|
| 6113 |
|
| 6114 |
|
| 6115 |
|
| 6116 |
return eslOK; |
| 6117 |
} |
| 6118 |
|
| 6119 |
|
| 6120 |
|
| 6121 |
|
| 6122 |
|
| 6123 |
|
| 6124 |
static int |
| 6125 |
validate_and_update_sspostscript_given_msa(const ESL_GETOPTS *go, const ESL_ALPHABET *abc, SSPostscript_t *ps, ESL_MSA *msa, int msa_nseq, char *errbuf) |
| 6126 |
{ |
| 6127 |
int status; |
| 6128 |
int *msa_ct; |
| 6129 |
int msa_nbp = 0; |
| 6130 |
int *tmp_ct; |
| 6131 |
int apos, rfpos_i, rfpos_j, rfpos; |
| 6132 |
int *rf2a_map = NULL; |
| 6133 |
int *a2rf_map = NULL; |
| 6134 |
int rflen = 0; |
| 6135 |
|
| 6136 |
ps->msa = msa; |
| 6137 |
ps->abc = abc; |
| 6138 |
|
| 6139 |
|
| 6140 |
if(msa->rf == NULL) ESL_FAIL(eslEINVAL, errbuf, "Error, msa does not have RF annotation."); |
| 6141 |
if(msa->ss_cons == NULL) ESL_FAIL(eslEINVAL, errbuf, "Error, msa does not have SS_cons annotation."); |
| 6142 |
|
| 6143 |
|
| 6144 |
for(apos = 0; apos < msa->alen; apos++) { |
| 6145 |
if(esl_abc_CIsResidue(abc, msa->rf[apos])) |
| 6146 |
rflen++; |
| 6147 |
} |
| 6148 |
if(ps->rflen != rflen) ESL_FAIL(eslEINVAL, errbuf, "validate_and_update_sspostscript_given_msa(), expected consensus length of %d in MSA, but read %d\n", ps->rflen, rflen); |
| 6149 |
|
| 6150 |
|
| 6151 |
ESL_ALLOC(rf2a_map, sizeof(int) * rflen); |
| 6152 |
ESL_ALLOC(a2rf_map, sizeof(int) * msa->alen); |
| 6153 |
esl_vec_ISet(a2rf_map, msa->alen, -1); |
| 6154 |
rfpos = 0; |
| 6155 |
for(apos = 0; apos < msa->alen; apos++) { |
| 6156 |
if(esl_abc_CIsResidue(abc, msa->rf[apos])) { |
| 6157 |
rf2a_map[rfpos] = apos; |
| 6158 |
a2rf_map[apos] = rfpos; |
| 6159 |
rfpos++; |
| 6160 |
} |
| 6161 |
} |
| 6162 |
|
| 6163 |
|
| 6164 |
ESL_ALLOC(tmp_ct, sizeof(int) * (msa->alen+1)); |
| 6165 |
if (esl_wuss2ct(msa->ss_cons, msa->alen, tmp_ct) != eslOK) ESL_FAIL(eslEINVAL, errbuf, "Problem getting ct from SS_cons, does first alignment of MSA file have SS_cons annotation?"); |
| 6166 |
|
| 6167 |
ESL_ALLOC(msa_ct, sizeof(int) * (rflen+1)); |
| 6168 |
esl_vec_ISet(msa_ct, rflen+1, 0); |
| 6169 |
|
| 6170 |
|
| 6171 |
for(apos = 0; apos < msa->alen; apos++) { |
| 6172 |
if(tmp_ct[apos+1] > (apos+1)) { |
| 6173 |
rfpos_i = a2rf_map[apos]; |
| 6174 |
rfpos_j = a2rf_map[tmp_ct[apos+1]-1]; |
| 6175 |
if(rfpos_i != -1 && rfpos_j != -1) { |
| 6176 |
msa_ct[rfpos_i+1] = rfpos_j+1; |
| 6177 |
msa_ct[rfpos_j+1] = rfpos_i+1; |
| 6178 |
msa_nbp++; |
| 6179 |
} |
| 6180 |
} |
| 6181 |
} |
| 6182 |
free(tmp_ct); |
| 6183 |
if(ps->nbp != 0 && ps->nbp != msa_nbp) ESL_FAIL(eslEINVAL, errbuf, "validate_and_update_sspostscript_given_msa(), expected %d basepairs in MSA's SS_cons, but read %d\n", ps->nbp, msa_nbp); |
| 6184 |
|
| 6185 |
|
| 6186 |
|
| 6187 |
if(ps->msa_ct != NULL) { free(ps->msa_ct); ps->msa_ct = NULL;} |
| 6188 |
if(ps->msa_rf2a_map != NULL) { free(ps->msa_rf2a_map); ps->msa_rf2a_map = NULL; } |
| 6189 |
if(ps->msa_a2rf_map != NULL) { free(ps->msa_a2rf_map); ps->msa_a2rf_map = NULL; } |
| 6190 |
ps->msa_ct = msa_ct; |
| 6191 |
ps->msa_nbp = msa_nbp; |
| 6192 |
ps->msa_ct = msa_ct; |
| 6193 |
ps->msa_rf2a_map = rf2a_map; |
| 6194 |
ps->msa_a2rf_map = a2rf_map; |
| 6195 |
ps->msa_nseq = msa_nseq; |
| 6196 |
|
| 6197 |
return eslOK; |
| 6198 |
|
| 6199 |
ERROR: |
| 6200 |
ESL_FAIL(status, errbuf, "validate_and_update_sspostscript_given_msa(), error status %d, probably out of memory.\n", status); |
| 6201 |
return status; |
| 6202 |
} |
| 6203 |
|
| 6204 |
|
| 6205 |
|
| 6206 |
|
| 6207 |
|
| 6208 |
|
| 6209 |
static int |
| 6210 |
draw_header_and_footer(FILE *fp, const ESL_GETOPTS *go, char *errbuf, SSPostscript_t *ps, int page, int pageidx2print) |
| 6211 |
{ |
| 6212 |
int status; |
| 6213 |
int i, split_idx; |
| 6214 |
float x, y; |
| 6215 |
float header_fontsize; |
| 6216 |
int model_width, desc_width, desc_column_width; |
| 6217 |
char *model_dashes, *desc_dashes, *desc2print; |
| 6218 |
char *desc_string = NULL; |
| 6219 |
float xmodel; |
| 6220 |
char *model2print = NULL; |
| 6221 |
float footer_fontsize, footerx_charsize; |
| 6222 |
|
| 6223 |
header_fontsize = HEADER_FONTSIZE_UNSCALED / ps->scale; |
| 6224 |
|
| 6225 |
fprintf(fp, "%% begin header section\n"); |
| 6226 |
fprintf(fp, "/%s findfont %.2f scalefont setfont\n", DEFAULT_FONT, header_fontsize); |
| 6227 |
fprintf(fp, "0.00 0.00 0.00 1.00 setcmykcolor\n"); |
| 6228 |
|
| 6229 |
if(! (esl_opt_GetBoolean(go, "--no-head"))) { |
| 6230 |
model_width = ESL_MAX(strlen("model"), (int) strlen(ps->modelname)); |
| 6231 |
if(model_width > HEADER_MODELNAME_MAXCHARS) { |
| 6232 |
ESL_ALLOC(model2print, sizeof(char) * (HEADER_MODELNAME_MAXCHARS+1)); |
| 6233 |
for(i = 0; i < (HEADER_MODELNAME_MAXCHARS-3); i++) model2print[i] = ps->modelname[i]; |
| 6234 |
model2print[HEADER_MODELNAME_MAXCHARS-3] = '.'; |
| 6235 |
model2print[HEADER_MODELNAME_MAXCHARS-2] = '.'; |
| 6236 |
model2print[HEADER_MODELNAME_MAXCHARS-1] = '.'; |
| 6237 |
model2print[HEADER_MODELNAME_MAXCHARS] = '\0'; |
| 6238 |
} |
| 6239 |
else { |
| 6240 |
if((status = esl_strdup(ps->modelname, -1, &(model2print))) != eslOK) ESL_FAIL(eslEINVAL, errbuf, "draw_header_and_footer(), error copying modelname"); |
| 6241 |
} |
| 6242 |
|
| 6243 |
model_width = ESL_MIN(model_width, HEADER_MODELNAME_MAXCHARS); |
| 6244 |
ESL_ALLOC(model_dashes, sizeof(char) * (model_width+1)); |
| 6245 |
for(i = 0; i < model_width; i++) model_dashes[i] = '-'; |
| 6246 |
model_dashes[model_width] = '\0'; |
| 6247 |
|
| 6248 |
if(ps->modeA[page] == ALIMODE || ps->modeA[page] == SIMPLEMASKMODE) { |
| 6249 |
if((status = esl_strdup("description", -1, &(desc_string))) != eslOK) ESL_FAIL(eslEINVAL, errbuf, "draw_header_and_footer(), error copying description"); |
| 6250 |
} |
| 6251 |
else if(ps->modeA[page] == INDIMODE) { |
| 6252 |
if((status = esl_strdup("sequence name", -1, &(desc_string))) != eslOK) ESL_FAIL(eslEINVAL, errbuf, "draw_header_and_footer(), error copying description"); |
| 6253 |
} |
| 6254 |
|
| 6255 |
xmodel = ps->headerx_desc - (ps->headerx_charsize * (model_width + 6 + 6 + 8 + 2)); |
| 6256 |
x = xmodel; |
| 6257 |
y = ps->headery; |
| 6258 |
|
| 6259 |
fprintf(fp, "(%-*s %4s %4s) %.2f %.2f moveto show\n", model_width, "model", "#pos", "#bps", x, y); |
| 6260 |
y -= header_fontsize * 0.75; |
| 6261 |
fprintf(fp, "(%-*s %4s %4s) %.2f %.2f moveto show\n", model_width, model_dashes, "----", "----", x, y); |
| 6262 |
y -= header_fontsize * 0.75; |
| 6263 |
fprintf(fp, "(%-*s %4d %4d) %.2f %.2f moveto show\n", model_width, model2print, ps->rflen, ps->msa_nbp, x, y); |
| 6264 |
free(model_dashes); |
| 6265 |
x += (model_width + 6 + 6 +2) * ps->headerx_charsize; |
| 6266 |
|
| 6267 |
if(ps->modeA[page] == ALIMODE) { |
| 6268 |
y+= header_fontsize * 1.5; |
| 6269 |
fprintf(fp, "(%6s) %.2f %.2f moveto show\n", "#seqs", x, y); |
| 6270 |
y -= header_fontsize * 0.75; |
| 6271 |
fprintf(fp, "(%6s) %.2f %.2f moveto show\n", "------", x, y); |
| 6272 |
y -= header_fontsize * 0.75; |
| 6273 |
fprintf(fp, "(%6d) %.2f %.2f moveto show", ps->msa_nseq, x, y); |
| 6274 |
} |
| 6275 |
else if(ps->modeA[page] == INDIMODE && (ps->seqidxA[page] != -1)) { |
| 6276 |
y+= header_fontsize * 1.5; |
| 6277 |
fprintf(fp, "(%6s) %.2f %.2f moveto show\n", "seqlen", x, y); |
| 6278 |
y -= header_fontsize * 0.75; |
| 6279 |
fprintf(fp, "(%6s) %.2f %.2f moveto show\n", "------", x, y); |
| 6280 |
y -= header_fontsize * 0.75; |
| 6281 |
fprintf(fp, "(%6d) %.2f %.2f moveto show", ps->uaseqlenA[ps->seqidxA[page]], x, y); |
| 6282 |
} |
| 6283 |
|
| 6284 |
if(ps->descA[page] != NULL) { |
| 6285 |
x = ps->headerx_desc; |
| 6286 |
y += 2. * header_fontsize * 0.75; |
| 6287 |
desc_width = ESL_MAX((int) strlen(desc_string), (int) strlen(ps->descA[page])); |
| 6288 |
if(desc_width > ps->desc_max_chars) { |
| 6289 |
|
| 6290 |
i = 0; |
| 6291 |
while(ps->descA[page][i] != '\n') { |
| 6292 |
i++; |
| 6293 |
if(i >= desc_width) ESL_FAIL(eslEINVAL, errbuf, "drawing header, failed to find split point from add_page_desc_to_() in two-line description (%s)", ps->descA[page]); |
| 6294 |
} |
| 6295 |
split_idx = i; |
| 6296 |
desc_column_width = split_idx; |
| 6297 |
} |
| 6298 |
else desc_column_width = desc_width; |
| 6299 |
|
| 6300 |
ESL_ALLOC(desc_dashes, sizeof(char) * (desc_column_width+1)); |
| 6301 |
for(i = 0; i < desc_column_width; i++) desc_dashes[i] = '-'; |
| 6302 |
desc_dashes[desc_column_width] = '\0'; |
| 6303 |
|
| 6304 |
fprintf(fp, "(%-*s) %.2f %.2f moveto show\n", desc_column_width, desc_string, x, y); |
| 6305 |
y -= header_fontsize * 0.75; |
| 6306 |
fprintf(fp, "(%-*s) %.2f %.2f moveto show\n", desc_column_width, desc_dashes, x, y); |
| 6307 |
y -= header_fontsize * 0.75; |
| 6308 |
free(desc_dashes); |
| 6309 |
|
| 6310 |
if(desc_width > ps->desc_max_chars) { |
| 6311 |
ESL_ALLOC(desc2print, sizeof(char) * (split_idx+1)); |
| 6312 |
for(i = 0; i < split_idx; i++) desc2print[i] = ps->descA[page][i]; |
| 6313 |
desc2print[split_idx] = '\0'; |
| 6314 |
fprintf(fp, "(%-*s) %.2f %.2f moveto show\n", desc_column_width, desc2print, x, y); |
| 6315 |
free(desc2print); |
| 6316 |
|
| 6317 |
x = ps->headerx_desc; |
| 6318 |
y-= ps->headery_charsize * 1; |
| 6319 |
ESL_ALLOC(desc2print, sizeof(char) * ((desc_width - split_idx) -1+1)); |
| 6320 |
for(i = split_idx+1; i < desc_width; i++) desc2print[(i-(split_idx+1))] = ps->descA[page][i]; |
| 6321 |
desc2print[(desc_width-(split_idx+1))] = '\0'; |
| 6322 |
fprintf(fp, "(%-*s) %.2f %.2f moveto show\n", desc_column_width, desc2print, x, y); |
| 6323 |
free(desc2print); |
| 6324 |
} |
| 6325 |
else { |
| 6326 |
fprintf(fp, "(%-*s) %.2f %.2f moveto show\n", desc_width, ps->descA[page], x, y); |
| 6327 |
} |
| 6328 |
} |
| 6329 |
|
| 6330 |
} |
| 6331 |
fprintf(fp, "%% end header section\n\n"); |
| 6332 |
|
| 6333 |
|
| 6334 |
footer_fontsize = LEG_FONTSIZE_UNSCALED / ps->scale; |
| 6335 |
footerx_charsize = ps->legx_charsize; |
| 6336 |
|
| 6337 |
if(! (esl_opt_GetBoolean(go, "--no-foot"))) { |
| 6338 |
fprintf(fp, "%% begin footer section\n"); |
| 6339 |
fprintf(fp, "/%s findfont %.2f scalefont setfont\n", FOOTER_FONT, footer_fontsize); |
| 6340 |
|
| 6341 |
if(ps->mask != NULL) { |
| 6342 |
if(esl_opt_GetString(go, "--mask-diff") != NULL) { |
| 6343 |
fprintf(fp, "(alignment file: %s; mask 1 file: %s; mask 2 file: %s;) %.2f %.2f moveto show\n", esl_opt_GetArg(go, 1), esl_opt_GetString(go, "--mask"), esl_opt_GetString(go, "--mask-diff"), PAGE_SIDEBUF, PAGE_BOTBUF); |
| 6344 |
} |
| 6345 |
else { |
| 6346 |
fprintf(fp, "(alignment file: %s; mask file: %s;) %.2f %.2f moveto show\n", esl_opt_GetArg(go, 1), esl_opt_GetString(go, "--mask"), PAGE_SIDEBUF, PAGE_BOTBUF); |
| 6347 |
} |
| 6348 |
} |
| 6349 |
else { |
| 6350 |
fprintf(fp, "(alignment file: %s) %.2f %.2f moveto show\n", esl_opt_GetArg(go, 1), PAGE_SIDEBUF, PAGE_BOTBUF); |
| 6351 |
} |
| 6352 |
|
| 6353 |
|
| 6354 |
|
| 6355 |
int tmp, ndigits; |
| 6356 |
tmp = pageidx2print; |
| 6357 |
ndigits = 1; |
| 6358 |
while(tmp >= 10) { tmp /= 10; ndigits++; } |
| 6359 |
x = ps->pagex_max - (PAGE_SIDEBUF) - (footerx_charsize * (5 + ndigits)); |
| 6360 |
fprintf(fp, "(page %d) %.2f %.2f moveto show\n", pageidx2print, x, PAGE_BOTBUF); |
| 6361 |
|
| 6362 |
fprintf(fp, "%% end footer section\n\n"); |
| 6363 |
} |
| 6364 |
|
| 6365 |
if(model2print != NULL) free(model2print); |
| 6366 |
if(desc_string != NULL) free(desc_string); |
| 6367 |
return eslOK; |
| 6368 |
|
| 6369 |
ERROR: ESL_FAIL(eslEINVAL, errbuf, "draw_header_and_footer(), memory error."); |
| 6370 |
} |
| 6371 |
|
| 6372 |
|
| 6373 |
|
| 6374 |
|
| 6375 |
|
| 6376 |
|
| 6377 |
|
| 6378 |
|
| 6379 |
|
| 6380 |
|
| 6381 |
|
| 6382 |
|
| 6383 |
|
| 6384 |
|
| 6385 |
|
| 6386 |
|
| 6387 |
|
| 6388 |
|
| 6389 |
|
| 6390 |
void |
| 6391 |
get_insert_info_from_msa(const ESL_ALPHABET *abc, ESL_MSA *msa, int rflen, int **ret_nseq_with_ins_ct, int **ret_nins_ct, int ***ret_per_seq_ins_ct) |
| 6392 |
{ |
| 6393 |
int status; |
| 6394 |
int i; |
| 6395 |
int *nseq_with_ins_ct = NULL; |
| 6396 |
int *nins_ct = NULL; |
| 6397 |
int **per_seq_ins_ct = NULL; |
| 6398 |
int rfpos, apos; |
| 6399 |
|
| 6400 |
|
| 6401 |
if(msa->rf == NULL) esl_fatal("Error in get_insert_info_from_msa(), msa->rf is NULL."); |
| 6402 |
|
| 6403 |
|
| 6404 |
ESL_ALLOC(nseq_with_ins_ct, sizeof(int) * (rflen+1)); |
| 6405 |
esl_vec_ISet(nseq_with_ins_ct, rflen+1, 0); |
| 6406 |
ESL_ALLOC(nins_ct, sizeof(int) * (rflen+1)); |
| 6407 |
esl_vec_ISet(nins_ct, rflen+1, 0); |
| 6408 |
ESL_ALLOC(per_seq_ins_ct, sizeof(int *) * (msa->nseq)); |
| 6409 |
for(i = 0; i < msa->nseq; i++) { |
| 6410 |
ESL_ALLOC(per_seq_ins_ct[i], sizeof(int) * (rflen+1)); |
| 6411 |
esl_vec_ISet(per_seq_ins_ct[i], (rflen+1), 0); |
| 6412 |
} |
| 6413 |
|
| 6414 |
|
| 6415 |
rfpos = 0; |
| 6416 |
for(apos = 0; apos < msa->alen; apos++) { |
| 6417 |
if(esl_abc_CIsResidue(abc, msa->rf[apos])) { |
| 6418 |
rfpos++; |
| 6419 |
if(rfpos > rflen) esl_fatal("Error in get_insert_info_from_msa(), expected consensus length (%d) is incorrect."); |
| 6420 |
} |
| 6421 |
else { |
| 6422 |
for(i = 0; i < msa->nseq; i++) { |
| 6423 |
if(! esl_abc_CIsGap(abc, msa->aseq[i][apos])) { |
| 6424 |
per_seq_ins_ct[i][rfpos]++; |
| 6425 |
nins_ct[rfpos]++; |
| 6426 |
if(per_seq_ins_ct[i][rfpos] == 1) nseq_with_ins_ct[rfpos]++; |
| 6427 |
} |
| 6428 |
} |
| 6429 |
} |
| 6430 |
} |
| 6431 |
|
| 6432 |
if(ret_nseq_with_ins_ct != NULL) *ret_nseq_with_ins_ct = nseq_with_ins_ct; |
| 6433 |
else free(nseq_with_ins_ct); |
| 6434 |
if(ret_nins_ct != NULL) *ret_nins_ct = nins_ct; |
| 6435 |
else free(nins_ct); |
| 6436 |
if(ret_per_seq_ins_ct != NULL) *ret_per_seq_ins_ct = per_seq_ins_ct; |
| 6437 |
else esl_arr2_Destroy((void **) per_seq_ins_ct, msa->nseq); |
| 6438 |
|
| 6439 |
return; |
| 6440 |
|
| 6441 |
ERROR: |
| 6442 |
esl_fatal("Error in get_insert_info_from_msa(), memory allocation error."); |
| 6443 |
return; |
| 6444 |
} |
| 6445 |
|
| 6446 |
|
| 6447 |
|
| 6448 |
|
| 6449 |
|
| 6450 |
|
| 6451 |
|
| 6452 |
|
| 6453 |
|
| 6454 |
|
| 6455 |
|
| 6456 |
|
| 6457 |
|
| 6458 |
|
| 6459 |
|
| 6460 |
|
| 6461 |
|
| 6462 |
|
| 6463 |
|
| 6464 |
|
| 6465 |
|
| 6466 |
|
| 6467 |
|
| 6468 |
|
| 6469 |
|
| 6470 |
|
| 6471 |
|
| 6472 |
|
| 6473 |
|
| 6474 |
|
| 6475 |
|
| 6476 |
|
| 6477 |
|
| 6478 |
|
| 6479 |
|
| 6480 |
|
| 6481 |
|
| 6482 |
|
| 6483 |
|
| 6484 |
|
| 6485 |
|
| 6486 |
|
| 6487 |
|
| 6488 |
|
| 6489 |
|
| 6490 |
|
| 6491 |
|
| 6492 |
|
| 6493 |
|
| 6494 |
|
| 6495 |
|
| 6496 |
|
| 6497 |
|
| 6498 |
|
| 6499 |
|
| 6500 |
|
| 6501 |
|
| 6502 |
|
| 6503 |
|
| 6504 |
|
| 6505 |
|
| 6506 |
|
| 6507 |
|
| 6508 |
|
| 6509 |
|
| 6510 |
|
| 6511 |
|
| 6512 |
|
| 6513 |
|
| 6514 |
|
| 6515 |
|
| 6516 |
|
| 6517 |
|
| 6518 |
|
| 6519 |
|
| 6520 |
|
| 6521 |
|
| 6522 |
|
| 6523 |
|
| 6524 |
|
| 6525 |
|
| 6526 |
|
| 6527 |
|
| 6528 |
|
| 6529 |
|
| 6530 |
|
| 6531 |
|
| 6532 |
|
| 6533 |
|
| 6534 |
|
| 6535 |
|
| 6536 |
void |
| 6537 |
get_insert_info_from_ifile(char *ifile, int rflen, int msa_nseq, ESL_KEYHASH *useme_keyhash, int **ret_nseq_with_ins_ct, int **ret_nins_ct, int ***ret_per_seq_ins_ct, int **ret_srfoff_ct, int **ret_erfoff_ct) |
| 6538 |
{ |
| 6539 |
int status; |
| 6540 |
ESL_FILEPARSER *efp; |
| 6541 |
char *tok; |
| 6542 |
int nseq_read = 0; |
| 6543 |
int nseq_stored = 0; |
| 6544 |
int **per_seq_ins_ct = NULL; |
| 6545 |
int *nins_ct = NULL; |
| 6546 |
int *nseq_with_ins_ct = NULL; |
| 6547 |
int nins; |
| 6548 |
int i; |
| 6549 |
int rfpos; |
| 6550 |
int uapos; |
| 6551 |
|
| 6552 |
int seen_model_name_line = FALSE; |
| 6553 |
int seen_end_of_model_line = FALSE; |
| 6554 |
int nseq2store; |
| 6555 |
int seqlen; |
| 6556 |
int spos; |
| 6557 |
int epos; |
| 6558 |
int *srfoff_ct = NULL; |
| 6559 |
|
| 6560 |
|
| 6561 |
int *erfoff_ct = NULL; |
| 6562 |
int already_handled_special_spos = FALSE; |
| 6563 |
int prv_e_increment, prv_e_decrement; |
| 6564 |
|
| 6565 |
if (esl_fileparser_Open(ifile, NULL, &efp) != eslOK) esl_fatal("Error: failed to open insert file %s\n", ifile); |
| 6566 |
esl_fileparser_SetCommentChar(efp, '#'); |
| 6567 |
|
| 6568 |
|
| 6569 |
nseq2store = (useme_keyhash == NULL) ? msa_nseq : esl_keyhash_GetNumber(useme_keyhash); |
| 6570 |
|
| 6571 |
|
| 6572 |
ESL_ALLOC(nseq_with_ins_ct, sizeof(int) * (rflen+1)); |
| 6573 |
esl_vec_ISet(nseq_with_ins_ct, rflen+1, 0); |
| 6574 |
|
| 6575 |
ESL_ALLOC(nins_ct, sizeof(int) * (rflen+1)); |
| 6576 |
esl_vec_ISet(nins_ct, rflen+1, 0); |
| 6577 |
|
| 6578 |
if(ret_srfoff_ct != NULL) { |
| 6579 |
ESL_ALLOC(srfoff_ct, sizeof(int) * rflen); |
| 6580 |
esl_vec_ISet(srfoff_ct, rflen, 0); |
| 6581 |
} |
| 6582 |
if(ret_erfoff_ct != NULL) { |
| 6583 |
ESL_ALLOC(erfoff_ct, sizeof(int) * rflen); |
| 6584 |
esl_vec_ISet(erfoff_ct, rflen, 0); |
| 6585 |
} |
| 6586 |
if(ret_per_seq_ins_ct != NULL) { |
| 6587 |
ESL_ALLOC(per_seq_ins_ct, sizeof(int *) * (nseq2store)); |
| 6588 |
for(i = 0; i < nseq2store; i++) { |
| 6589 |
ESL_ALLOC(per_seq_ins_ct[i], sizeof(int) * (rflen+1)); |
| 6590 |
esl_vec_ISet(per_seq_ins_ct[i], (rflen+1), 0); |
| 6591 |
} |
| 6592 |
} |
| 6593 |
|
| 6594 |
|
| 6595 |
|
| 6596 |
|
| 6597 |
|
| 6598 |
|
| 6599 |
i = 0; |
| 6600 |
while (esl_fileparser_NextLine(efp) == eslOK) { |
| 6601 |
if (esl_fileparser_GetTokenOnLine(efp, &tok, NULL) != eslOK) { |
| 6602 |
if(seen_model_name_line) esl_fatal("Error reading insert file, failed to read seq name on line %d of file %s\n", efp->linenumber, ifile); |
| 6603 |
else esl_fatal("Error reading insert file, failed to read model name on line %d of file %s\n", efp->linenumber, ifile); |
| 6604 |
} |
| 6605 |
if(! seen_model_name_line) { |
| 6606 |
seen_model_name_line = TRUE; |
| 6607 |
seen_end_of_model_line = FALSE; |
| 6608 |
if (esl_fileparser_GetTokenOnLine(efp, &tok, NULL) != eslOK) { |
| 6609 |
esl_fatal("Error reading insert file, failed to read consensus length on line %d of file %s\n", efp->linenumber, ifile); |
| 6610 |
} |
| 6611 |
if(rflen != atoi(tok)) { |
| 6612 |
esl_fatal("Error reading insert file, read consensus length of %d on line %d of file %s, but expected length %d\n", atoi(tok), efp->linenumber, ifile, rflen); |
| 6613 |
} |
| 6614 |
} |
| 6615 |
else if (strncmp(tok, "//", 2) == 0) { |
| 6616 |
seen_model_name_line = FALSE; |
| 6617 |
seen_end_of_model_line = TRUE; |
| 6618 |
} |
| 6619 |
else { |
| 6620 |
|
| 6621 |
i++; |
| 6622 |
if(useme_keyhash == NULL || (esl_keyhash_Lookup(useme_keyhash, tok, -1, NULL) == eslOK)) { |
| 6623 |
already_handled_special_spos = FALSE; |
| 6624 |
prv_e_decrement = prv_e_increment = -1; |
| 6625 |
|
| 6626 |
if(esl_fileparser_GetTokenOnLine(efp, &tok, NULL) != eslOK) esl_fatal("Error reading insert file, failed to read unaligned length for sequence on line %d of file %s.\n", efp->linenumber, ifile); |
| 6627 |
seqlen = atoi(tok); |
| 6628 |
|
| 6629 |
if(esl_fileparser_GetTokenOnLine(efp, &tok, NULL) != eslOK) esl_fatal("Error reading insert file, failed to read first nongap consensus position for sequence on line %d of file %s.\n", efp->linenumber, ifile); |
| 6630 |
spos = atoi(tok); |
| 6631 |
if(spos > rflen) esl_fatal("Error reading insert file, read spos of %d that exceeds expected consensus length %d on line %d of file %s.\n", spos, rflen, efp->linenumber, ifile); |
| 6632 |
|
| 6633 |
if(esl_fileparser_GetTokenOnLine(efp, &tok, NULL) != eslOK) esl_fatal("Error reading insert file, failed to read final nongap consensus position for sequence on line %d of file %s.\n", efp->linenumber, ifile); |
| 6634 |
epos = atoi(tok); |
| 6635 |
if(epos > rflen) esl_fatal("Error reading insert file, read epos of %d that exceeds expected consensus length %d on line %d of file %s.\n", epos, rflen, efp->linenumber, ifile); |
| 6636 |
|
| 6637 |
if(spos == -1 && epos != -1) esl_fatal("insert file is corrupt, spos is -1 but epos is not -1, on line %d\n", efp->linenumber); |
| 6638 |
if(spos != -1 && epos == -1) esl_fatal("insert file is corrupt, spos is not -1 but epos is -1, on line %d\n", efp->linenumber); |
| 6639 |
|
| 6640 |
while(esl_fileparser_GetTokenOnLine(efp, &tok, NULL) == eslOK) { |
| 6641 |
|
| 6642 |
rfpos = atoi(tok); |
| 6643 |
if(rfpos > rflen) esl_fatal("Error reading insert file, read insert info for position %d that exceeds expected consensus length %d on line %d of file %s.\n", rfpos, rflen, efp->linenumber, ifile); |
| 6644 |
|
| 6645 |
|
| 6646 |
if((status = esl_fileparser_GetTokenOnLine(efp, &tok, NULL)) != eslOK) esl_fatal("Error reading insert file, didn't read unaligned sequence position for rfpos %d on line %d of file %s.\n", rfpos, efp->linenumber, ifile); |
| 6647 |
uapos = atoi(tok); |
| 6648 |
if(uapos > seqlen) esl_fatal("Error reading insert file, read insert info for position %d that exceeds expected sequence length %d on line %d of file %s.\n", rfpos, seqlen, efp->linenumber, ifile); |
| 6649 |
|
| 6650 |
|
| 6651 |
if((status = esl_fileparser_GetTokenOnLine(efp, &tok, NULL)) != eslOK) esl_fatal("Error reading insert file, didn't read number of inserts for position %d on line %d of file %s.\n", rfpos, efp->linenumber, ifile); |
| 6652 |
nins = atoi(tok); |
| 6653 |
nins_ct[rfpos] += nins; |
| 6654 |
if(per_seq_ins_ct != NULL) per_seq_ins_ct[nseq_stored][rfpos] = nins; |
| 6655 |
if(nins > 0) nseq_with_ins_ct[rfpos]++; |
| 6656 |
|
| 6657 |
|
| 6658 |
if(spos != -1) { |
| 6659 |
|
| 6660 |
|
| 6661 |
|
| 6662 |
|
| 6663 |
if(srfoff_ct != NULL) { |
| 6664 |
if((rfpos < (spos-1)) && (! already_handled_special_spos)) { |
| 6665 |
|
| 6666 |
|
| 6667 |
|
| 6668 |
|
| 6669 |
|
| 6670 |
srfoff_ct[(spos-1)]--; |
| 6671 |
srfoff_ct[(rfpos-1)+1]++; |
| 6672 |
|
| 6673 |
|
| 6674 |
|
| 6675 |
already_handled_special_spos = TRUE; |
| 6676 |
} |
| 6677 |
} |
| 6678 |
|
| 6679 |
|
| 6680 |
if(erfoff_ct != NULL) { |
| 6681 |
if(rfpos > epos) { |
| 6682 |
|
| 6683 |
|
| 6684 |
|
| 6685 |
|
| 6686 |
|
| 6687 |
erfoff_ct[(epos-1)]--; |
| 6688 |
erfoff_ct[(rfpos-1)]++; |
| 6689 |
|
| 6690 |
|
| 6691 |
|
| 6692 |
|
| 6693 |
|
| 6694 |
if(prv_e_decrement != -1 && prv_e_increment != -1) { |
| 6695 |
erfoff_ct[prv_e_increment]--; |
| 6696 |
erfoff_ct[prv_e_decrement]++; |
| 6697 |
prv_e_decrement = (epos-1); |
| 6698 |
prv_e_increment = (rfpos-1); |
| 6699 |
} |
| 6700 |
} |
| 6701 |
} |
| 6702 |
} |
| 6703 |
} |
| 6704 |
nseq_stored++; |
| 6705 |
} |
| 6706 |
nseq_read++; |
| 6707 |
if(nseq_read > msa_nseq) esl_fatal("Error reading insert file, read info for more sequences than expected (%d) at line %d of file %s.", msa_nseq, efp->linenumber, ifile); |
| 6708 |
} |
| 6709 |
} |
| 6710 |
esl_fileparser_Close(efp); |
| 6711 |
|
| 6712 |
|
| 6713 |
if(! seen_end_of_model_line) esl_fatal("Error reading insert file, didn't read the special '//' line at the end of file %s.\n", rfpos, efp->linenumber, ifile); |
| 6714 |
|
| 6715 |
|
| 6716 |
if((useme_keyhash != NULL) && (nseq_stored != nseq2store)) { |
| 6717 |
esl_fatal("Error reading insert file, wanted to read insert info on %d seqs, but only found %d of them in the insert file %s\n", nseq2store, nseq_stored, ifile); |
| 6718 |
} |
| 6719 |
if(nseq_read != msa_nseq) esl_fatal("Error reading insert file, expected to read info on %d seqs, but only found %d in the insert file %s\n", msa_nseq, nseq_read, ifile); |
| 6720 |
|
| 6721 |
if (ret_nins_ct) *ret_nins_ct = nins_ct; else esl_free(nins_ct); |
| 6722 |
if (ret_nseq_with_ins_ct) *ret_nseq_with_ins_ct = nseq_with_ins_ct; else esl_free(nseq_with_ins_ct); |
| 6723 |
if (ret_srfoff_ct) *ret_srfoff_ct = srfoff_ct; else esl_free(srfoff_ct); |
| 6724 |
if (ret_erfoff_ct) *ret_erfoff_ct = erfoff_ct; else esl_free(erfoff_ct); |
| 6725 |
if (ret_per_seq_ins_ct) *ret_per_seq_ins_ct = per_seq_ins_ct; else esl_arr2_Destroy((void **) per_seq_ins_ct, msa_nseq); |
| 6726 |
return; |
| 6727 |
|
| 6728 |
ERROR: |
| 6729 |
esl_fatal("Memory allocation error while reading insert file %s.", ifile); |
| 6730 |
return;; |
| 6731 |
} |
| 6732 |
|
| 6733 |
|
| 6734 |
|
| 6735 |
|
| 6736 |
|
| 6737 |
|
| 6738 |
|
| 6739 |
|
| 6740 |
|
| 6741 |
|
| 6742 |
|
| 6743 |
|
| 6744 |
|
| 6745 |
|
| 6746 |
|
| 6747 |
|
| 6748 |
|
| 6749 |
|
| 6750 |
|
| 6751 |
|
| 6752 |
|
| 6753 |
|
| 6754 |
|
| 6755 |
|
| 6756 |
|
| 6757 |
|
| 6758 |
|
| 6759 |
|
| 6760 |
|
| 6761 |
|
| 6762 |
|
| 6763 |
|
| 6764 |
|
| 6765 |
|
| 6766 |
void |
| 6767 |
get_insert_info_from_abc_ct(double **abc_ct, ESL_ALPHABET *abc, char *msa_rf, int64_t msa_alen, int rflen, int **ret_nseq_with_ins_ct, int **ret_nins_ct) |
| 6768 |
{ |
| 6769 |
int status; |
| 6770 |
int *nins_ct; |
| 6771 |
int *nseq_with_ins_ct; |
| 6772 |
int nins, nmaxins; |
| 6773 |
int rfpos, apos; |
| 6774 |
|
| 6775 |
|
| 6776 |
ESL_ALLOC(nseq_with_ins_ct, sizeof(int) * (rflen+1)); |
| 6777 |
esl_vec_ISet(nseq_with_ins_ct, rflen+1, 0); |
| 6778 |
ESL_ALLOC(nins_ct, sizeof(int) * (rflen+1)); |
| 6779 |
esl_vec_ISet(nins_ct, rflen+1, 0); |
| 6780 |
|
| 6781 |
nmaxins = 0; |
| 6782 |
rfpos = 0; |
| 6783 |
for(apos = 0; apos < msa_alen; apos++) { |
| 6784 |
if(esl_abc_CIsResidue(abc, msa_rf[apos])) { |
| 6785 |
nseq_with_ins_ct[rfpos] = nmaxins; |
| 6786 |
nmaxins = 0; |
| 6787 |
rfpos++; |
| 6788 |
if(rfpos > rflen) esl_fatal("Error in get_insert_info_from_abc_ct(), expected consensus length (%d) is incorrect."); |
| 6789 |
} |
| 6790 |
else { |
| 6791 |
nins = (int) esl_vec_DSum(abc_ct[apos], abc->K); |
| 6792 |
nins_ct[rfpos] += nins; |
| 6793 |
nmaxins = ESL_MAX(nmaxins, nins); |
| 6794 |
} |
| 6795 |
} |
| 6796 |
|
| 6797 |
nseq_with_ins_ct[rfpos] = nmaxins; |
| 6798 |
|
| 6799 |
if(ret_nins_ct != NULL) *ret_nins_ct = nins_ct; |
| 6800 |
else free(nins_ct); |
| 6801 |
if(ret_nseq_with_ins_ct != NULL) *ret_nseq_with_ins_ct = nseq_with_ins_ct; |
| 6802 |
else free(nseq_with_ins_ct); |
| 6803 |
|
| 6804 |
return; |
| 6805 |
|
| 6806 |
ERROR: |
| 6807 |
esl_fatal("Error in get_insert_info_from_abc_ct(), memory allocation error."); |
| 6808 |
return; |
| 6809 |
} |
| 6810 |
|
| 6811 |
|
| 6812 |
|
| 6813 |
|
| 6814 |
|
| 6815 |
|
| 6816 |
|
| 6817 |
|
| 6818 |
|
| 6819 |
|
| 6820 |
|
| 6821 |
|
| 6822 |
|
| 6823 |
|
| 6824 |
|
| 6825 |
|
| 6826 |
|
| 6827 |
|
| 6828 |
|
| 6829 |
|
| 6830 |
int |
| 6831 |
get_pp_idx(const ESL_ALPHABET *abc, char ppchar) |
| 6832 |
{ |
| 6833 |
if(esl_abc_CIsGap(abc, ppchar)) return 11; |
| 6834 |
if(ppchar == '*') return 10; |
| 6835 |
if(ppchar == '9') return 9; |
| 6836 |
if(ppchar == '8') return 8; |
| 6837 |
if(ppchar == '7') return 7; |
| 6838 |
if(ppchar == '6') return 6; |
| 6839 |
if(ppchar == '5') return 5; |
| 6840 |
if(ppchar == '4') return 4; |
| 6841 |
if(ppchar == '3') return 3; |
| 6842 |
if(ppchar == '2') return 2; |
| 6843 |
if(ppchar == '1') return 1; |
| 6844 |
if(ppchar == '0') return 0; |
| 6845 |
return -1; |
| 6846 |
} |
| 6847 |
|
| 6848 |
|
| 6849 |
|
| 6850 |
|
| 6851 |
|
| 6852 |
|
| 6853 |
|
| 6854 |
|
| 6855 |
|
| 6856 |
|
| 6857 |
|
| 6858 |
|
| 6859 |
|
| 6860 |
|
| 6861 |
|
| 6862 |
|
| 6863 |
|
| 6864 |
|
| 6865 |
|
| 6866 |
|
| 6867 |
|
| 6868 |
int |
| 6869 |
get_span_ct(int *msa_rf2a_map, int64_t alen, int rflen, int nseq, int *spos_ct, int *epos_ct, int *srfoff_ct, int *erfoff_ct, int **ret_span_ct) |
| 6870 |
{ |
| 6871 |
int status; |
| 6872 |
int *nseq_start_after_rfpos = NULL; |
| 6873 |
int *nseq_end_before_rfpos = NULL; |
| 6874 |
int *span_ct = NULL; |
| 6875 |
int rfpos; |
| 6876 |
int do_correction; |
| 6877 |
int apos, nxt_apos, prv_apos; |
| 6878 |
|
| 6879 |
ESL_ALLOC(span_ct, sizeof(int) * rflen); |
| 6880 |
ESL_ALLOC(nseq_start_after_rfpos, sizeof(int) * rflen); |
| 6881 |
ESL_ALLOC(nseq_end_before_rfpos, sizeof(int) * rflen); |
| 6882 |
|
| 6883 |
esl_vec_ISet(nseq_start_after_rfpos, rflen, 0); |
| 6884 |
esl_vec_ISet(nseq_end_before_rfpos, rflen, 0); |
| 6885 |
|
| 6886 |
|
| 6887 |
if(srfoff_ct != NULL && erfoff_ct == NULL) esl_fatal("Internal error, get_span_ct: srfoff_ct != NULL and erfoff_ct == NULL"); |
| 6888 |
if(srfoff_ct == NULL && erfoff_ct != NULL) esl_fatal("Internal error, get_span_ct: srfoff_ct == NULL and erfoff_ct != NULL"); |
| 6889 |
|
| 6890 |
|
| 6891 |
do_correction = (alen == rflen && srfoff_ct != NULL) ? TRUE : FALSE; |
| 6892 |
|
| 6893 |
|
| 6894 |
|
| 6895 |
|
| 6896 |
nseq_start_after_rfpos[rflen-1] = 0; |
| 6897 |
nxt_apos = (int) alen - 1; |
| 6898 |
for(rfpos = rflen-2; rfpos >= 0; rfpos--) { |
| 6899 |
for(apos = nxt_apos; apos > msa_rf2a_map[rfpos]; apos--) { |
| 6900 |
nseq_start_after_rfpos[rfpos] += spos_ct[apos]; |
| 6901 |
if(do_correction) nseq_start_after_rfpos[rfpos] += srfoff_ct[apos]; |
| 6902 |
} |
| 6903 |
nseq_start_after_rfpos[rfpos] += nseq_start_after_rfpos[rfpos+1]; |
| 6904 |
nxt_apos = msa_rf2a_map[rfpos]; |
| 6905 |
} |
| 6906 |
|
| 6907 |
|
| 6908 |
nseq_end_before_rfpos[0] = 0; |
| 6909 |
prv_apos = 0; |
| 6910 |
for(rfpos = 1; rfpos < rflen; rfpos++) { |
| 6911 |
for(apos = prv_apos; apos < msa_rf2a_map[rfpos]; apos++) { |
| 6912 |
nseq_end_before_rfpos[rfpos] += epos_ct[apos]; |
| 6913 |
if(do_correction) nseq_end_before_rfpos[rfpos] += erfoff_ct[apos]; |
| 6914 |
} |
| 6915 |
nseq_end_before_rfpos[rfpos] += nseq_end_before_rfpos[rfpos-1]; |
| 6916 |
prv_apos = msa_rf2a_map[rfpos]; |
| 6917 |
} |
| 6918 |
|
| 6919 |
|
| 6920 |
|
| 6921 |
|
| 6922 |
|
| 6923 |
|
| 6924 |
|
| 6925 |
|
| 6926 |
for(rfpos = 0; rfpos < rflen; rfpos++) { |
| 6927 |
span_ct[rfpos] = nseq - (nseq_start_after_rfpos[rfpos] + nseq_end_before_rfpos[rfpos]); |
| 6928 |
|
| 6929 |
} |
| 6930 |
|
| 6931 |
*ret_span_ct = span_ct; |
| 6932 |
free(nseq_start_after_rfpos); |
| 6933 |
free(nseq_end_before_rfpos); |
| 6934 |
return eslOK; |
| 6935 |
|
| 6936 |
ERROR: |
| 6937 |
return eslEMEM; |
| 6938 |
} |
| 6939 |
|
| 6940 |
|
| 6941 |
|
| 6942 |
|
| 6943 |
|
| 6944 |
|
| 6945 |
|
| 6946 |
|
| 6947 |
|
| 6948 |
|
| 6949 |
|
| 6950 |
|
| 6951 |
|
| 6952 |
static int |
| 6953 |
drawfile2sspostscript(const ESL_GETOPTS *go, char *errbuf, SSPostscript_t *ps, float ***hc_scheme, int hc_scheme_idx, int hc_nbins) |
| 6954 |
{ |
| 6955 |
int status; |
| 6956 |
int p, pp; |
| 6957 |
int rfpos, c; |
| 6958 |
int orig_npage = ps->npage; |
| 6959 |
ESL_FILEPARSER *efp; |
| 6960 |
char *s; |
| 6961 |
char *dfile = esl_opt_GetString(go, "--dfile"); |
| 6962 |
float *limits; |
| 6963 |
float value; |
| 6964 |
int l; |
| 6965 |
int bi, within_mask; |
| 6966 |
char *desc = NULL; |
| 6967 |
char *legheader = NULL; |
| 6968 |
|
| 6969 |
|
| 6970 |
ESL_ALLOC(limits, sizeof(float) * (hc_nbins+1)); |
| 6971 |
|
| 6972 |
if (esl_fileparser_Open(dfile, NULL, &efp) != eslOK) ESL_FAIL(eslFAIL, errbuf, "failed to open %s in draw_file2sspostscript\n", dfile); |
| 6973 |
esl_fileparser_SetCommentChar(efp, '#'); |
| 6974 |
|
| 6975 |
pp = orig_npage - 1; |
| 6976 |
|
| 6977 |
|
| 6978 |
|
| 6979 |
|
| 6980 |
|
| 6981 |
|
| 6982 |
|
| 6983 |
|
| 6984 |
|
| 6985 |
|
| 6986 |
|
| 6987 |
|
| 6988 |
|
| 6989 |
|
| 6990 |
rfpos = -1; |
| 6991 |
while (esl_fileparser_NextLine(efp) == eslOK) |
| 6992 |
{ |
| 6993 |
if(rfpos == -1) { |
| 6994 |
|
| 6995 |
|
| 6996 |
if(desc != NULL) { free(desc); desc = NULL; } |
| 6997 |
while((status = esl_fileparser_GetTokenOnLine(efp, &s, NULL)) == eslOK) { |
| 6998 |
if((status = esl_strcat(&desc, -1, s, -1)) != eslOK) esl_fatal("Out of memory"); |
| 6999 |
if((status = esl_strcat(&desc, -1, " ", -1)) != eslOK) esl_fatal("Out of memory"); |
| 7000 |
} |
| 7001 |
if(strlen(desc) > (ps->desc_max_chars*2.)) esl_fatal("Error reading --dfile, description length (%d) exceeds max allowed (%d)", strlen(desc), (ps->desc_max_chars*2)); |
| 7002 |
if(esl_fileparser_NextLine(efp) != eslOK) esl_fatal("Error reading --dfile, expected legend header line at line %d\n", efp->linenumber); |
| 7003 |
|
| 7004 |
|
| 7005 |
if(legheader != NULL) { free(legheader); legheader = NULL; } |
| 7006 |
while((status = esl_fileparser_GetTokenOnLine(efp, &s, NULL)) == eslOK) { |
| 7007 |
if((status = esl_strcat(&legheader, -1, s, -1)) != eslOK) esl_fatal("Out of memory"); |
| 7008 |
if((status = esl_strcat(&legheader, -1, " ", -1)) != eslOK) esl_fatal("Out of memory"); |
| 7009 |
} |
| 7010 |
if(strlen(legheader) > ps->legx_max_chars) esl_fatal("Error reading --dfile, legend header length (%d) exceeds max allowed (%d)", strlen(legheader), ps->legx_max_chars); |
| 7011 |
if(esl_fileparser_NextLine(efp) != eslOK) esl_fatal("Error reading --dfile, expected limits line at line %d\n", efp->linenumber); |
| 7012 |
|
| 7013 |
|
| 7014 |
for(l = 0; l < hc_nbins+1; l++) { |
| 7015 |
if (esl_fileparser_GetTokenOnLine(efp, &s, NULL) != eslOK) esl_fatal("Error reading --dfile, expected limits line at line %d to have %d limits (numbers) in increasing order, it doesn't", efp->linenumber, hc_nbins+1); |
| 7016 |
limits[l] = atof(s); |
| 7017 |
if(l > 0 && limits[l] < limits[l-1]) esl_fatal("Error reading --dfile, expected limits line at line %d with %d limits (numbers) in increasing order", efp->linenumber, hc_nbins+1); |
| 7018 |
} |
| 7019 |
rfpos++; |
| 7020 |
} |
| 7021 |
else if(rfpos == (ps->rflen)) { |
| 7022 |
if (esl_fileparser_GetTokenOnLine(efp, &s, NULL) != eslOK) |
| 7023 |
esl_fatal("Failed to read a final token at the end of description of page %d on line %d of drawfile %s\n", (pp - orig_npage + 1), efp->linenumber, dfile); |
| 7024 |
if (strcmp(s, "//") != 0) |
| 7025 |
esl_fatal("Failed to read a final \"//\" token (read %s) at the end of description of draw page %d on line %d of drawfile %s\n", s, (pp - orig_npage + 1), efp->linenumber, dfile); |
| 7026 |
rfpos = -1; |
| 7027 |
|
| 7028 |
if((status = add_text_to_scheme_colorlegend(ps, ps->sclAA[pp], legheader, ps->legx_max_chars, errbuf)) != eslOK) return status; |
| 7029 |
if((status = add_page_desc_to_sspostscript(ps, ps->npage-1, desc, errbuf)) != eslOK) return status; |
| 7030 |
} |
| 7031 |
else { |
| 7032 |
rfpos++; |
| 7033 |
if(rfpos == 1) { |
| 7034 |
if((status = add_pages_sspostscript(ps, 1, ALIMODE)) != eslOK) ESL_FAIL(status, errbuf, "memory error adding pages to the postscript object."); |
| 7035 |
for(p = (ps->npage-1); p < ps->npage; p++) { |
| 7036 |
ESL_ALLOC(ps->bcolAAA[p], sizeof(float *) * ps->rflen); |
| 7037 |
ESL_ALLOC(ps->sclAA[p], sizeof(SchemeColorLegend_t) * 1); |
| 7038 |
for(c = 0; c < ps->rflen; c++) { |
| 7039 |
ESL_ALLOC(ps->bcolAAA[p][c], sizeof(float) * NCMYK); |
| 7040 |
} |
| 7041 |
} |
| 7042 |
pp++; |
| 7043 |
if(ps->sclAA[pp]!= NULL){ |
| 7044 |
free(ps->sclAA[pp]); |
| 7045 |
} |
| 7046 |
ps->sclAA[pp] = create_scheme_colorlegend(hc_scheme_idx, hc_nbins, limits, FALSE, TRUE, TRUE, TRUE); |
| 7047 |
} |
| 7048 |
|
| 7049 |
if (esl_fileparser_GetTokenOnLine(efp, &s, NULL) != eslOK) esl_fatal("Failed to read value for position %d for page %d on line %d of dfile\n", rfpos, (pp - orig_npage + 1), efp->linenumber); |
| 7050 |
value = atof(s); |
| 7051 |
if(value < limits[0] || value > limits[hc_nbins]) esl_fatal("--dfile value %.4f out of allowed range [%.3f-%.3f] on line %d\n", value, limits[0], limits[hc_nbins], efp->linenumber, dfile); |
| 7052 |
within_mask = (ps->mask != NULL && ps->mask[rfpos-1] == '1') ? TRUE : FALSE; |
| 7053 |
if((status = set_scheme_values(errbuf, ps->bcolAAA[pp][rfpos-1], NCMYK, hc_scheme[hc_scheme_idx], value, ps->sclAA[pp], within_mask, &bi)) != eslOK) return status; |
| 7054 |
} |
| 7055 |
} |
| 7056 |
if(pp == (orig_npage - 1)) { |
| 7057 |
esl_fatal("Failed to read a single page from drawfile %s\n", dfile); |
| 7058 |
} |
| 7059 |
esl_fileparser_Close(efp); |
| 7060 |
|
| 7061 |
free(limits); |
| 7062 |
if(desc != NULL) { free(desc); desc = NULL; } |
| 7063 |
if(legheader != NULL) { free(legheader); legheader = NULL; } |
| 7064 |
|
| 7065 |
return eslOK; |
| 7066 |
|
| 7067 |
ERROR: ESL_FAIL(status, errbuf, "drawfile2sspostscript(): memory allocation error."); |
| 7068 |
return status; |
| 7069 |
} |
| 7070 |
|
| 7071 |
|
| 7072 |
|
| 7073 |
|
| 7074 |
|
| 7075 |
|
| 7076 |
|
| 7077 |
|
| 7078 |
|
| 7079 |
|
| 7080 |
|
| 7081 |
|
| 7082 |
|
| 7083 |
|
| 7084 |
static int |
| 7085 |
expertfile2sspostscript(const ESL_GETOPTS *go, char *errbuf, SSPostscript_t *ps) |
| 7086 |
{ |
| 7087 |
int status; |
| 7088 |
int p, pp; |
| 7089 |
int cpos, c; |
| 7090 |
int orig_npage = ps->npage; |
| 7091 |
ESL_FILEPARSER *efp; |
| 7092 |
char *s; |
| 7093 |
char *efile = esl_opt_GetString(go, "--efile"); |
| 7094 |
|
| 7095 |
if (esl_fileparser_Open(efile, NULL, &efp) != eslOK) ESL_FAIL(eslFAIL, errbuf, "failed to open %s in draw_file2sspostscript\n", efile); |
| 7096 |
esl_fileparser_SetCommentChar(efp, '#'); |
| 7097 |
|
| 7098 |
pp = orig_npage - 1; |
| 7099 |
cpos = 0; |
| 7100 |
|
| 7101 |
while (esl_fileparser_NextLine(efp) == eslOK) |
| 7102 |
{ |
| 7103 |
|
| 7104 |
|
| 7105 |
|
| 7106 |
|
| 7107 |
|
| 7108 |
|
| 7109 |
|
| 7110 |
cpos++; |
| 7111 |
if(cpos == 1) { |
| 7112 |
if((status = add_pages_sspostscript(ps, 1, SIMPLEMASKMODE)) != eslOK) ESL_FAIL(status, errbuf, "memory error adding pages to the postscript object."); |
| 7113 |
|
| 7114 |
for(p = (ps->npage-1); p < ps->npage; p++) { |
| 7115 |
ESL_ALLOC(ps->rAA[p], sizeof(char) * (ps->rflen+1)); |
| 7116 |
ESL_ALLOC(ps->bcolAAA[p], sizeof(float *) * ps->rflen); |
| 7117 |
for(c = 0; c < ps->rflen; c++) { |
| 7118 |
ESL_ALLOC(ps->bcolAAA[p][c], sizeof(float) * NCMYK); |
| 7119 |
} |
| 7120 |
} |
| 7121 |
pp++; |
| 7122 |
} |
| 7123 |
if(cpos == (ps->rflen+1)) { |
| 7124 |
if (esl_fileparser_GetTokenOnLine(efp, &s, NULL) != eslOK) |
| 7125 |
esl_fatal("Failed to read a final token at the end of description of draw page %d on line %d of expertfile %s\n", (pp - orig_npage + 1), efp->linenumber, efile); |
| 7126 |
if (strcmp(s, "//") != 0) |
| 7127 |
esl_fatal("Failed to read a final \"//\" token (read %s) at the end of description of draw page %d on line %d of expertfile %s\n", s, (pp - orig_npage + 1), efp->linenumber, efile); |
| 7128 |
cpos = 0; |
| 7129 |
} |
| 7130 |
else { |
| 7131 |
|
| 7132 |
if (esl_fileparser_GetTokenOnLine(efp, &s, NULL) != eslOK) |
| 7133 |
esl_fatal("Failed to read C of CMYK value on line %d of expertfile %s\n", efp->linenumber, efile); |
| 7134 |
ps->bcolAAA[pp][(cpos-1)][0] = atof(s); |
| 7135 |
|
| 7136 |
|
| 7137 |
if (esl_fileparser_GetTokenOnLine(efp, &s, NULL) != eslOK) |
| 7138 |
esl_fatal("Failed to read M of CMYK value on line %d of expertfile %s\n", efp->linenumber, efile); |
| 7139 |
ps->bcolAAA[pp][(cpos-1)][1] = atof(s); |
| 7140 |
|
| 7141 |
|
| 7142 |
if (esl_fileparser_GetTokenOnLine(efp, &s, NULL) != eslOK) |
| 7143 |
esl_fatal("Failed to read Y of CMYK value on line %d of expertfile %s\n", efp->linenumber, efile); |
| 7144 |
ps->bcolAAA[pp][(cpos-1)][2] = atof(s); |
| 7145 |
|
| 7146 |
|
| 7147 |
if (esl_fileparser_GetTokenOnLine(efp, &s, NULL) != eslOK) |
| 7148 |
esl_fatal("Failed to read K of CMYK value on line %d of expertfile %s\n", efp->linenumber, efile); |
| 7149 |
ps->bcolAAA[pp][(cpos-1)][3] = atof(s); |
| 7150 |
|
| 7151 |
|
| 7152 |
if (esl_fileparser_GetTokenOnLine(efp, &s, NULL) == eslOK) { |
| 7153 |
if(((int) strlen(s)) != 1) esl_fatal("Read multi-character string (%s) for consensus nucleotide %d on line %d of expertfile %s\n", s, cpos, efp->linenumber, efile); |
| 7154 |
ps->rAA[pp][(cpos-1)] = s[0]; |
| 7155 |
} |
| 7156 |
else ps->rAA[pp][(cpos-1)] = ' '; |
| 7157 |
} |
| 7158 |
} |
| 7159 |
if(pp == (orig_npage - 1)) { |
| 7160 |
esl_fatal("Failed to read a single page from expertfile %s\n", efile); |
| 7161 |
} |
| 7162 |
|
| 7163 |
esl_fileparser_Close(efp); |
| 7164 |
return eslOK; |
| 7165 |
|
| 7166 |
ERROR: ESL_FAIL(status, errbuf, "expertfile2sspostscript(): memory allocation error."); |
| 7167 |
return status; |
| 7168 |
} |
| 7169 |
|
| 7170 |
|
| 7171 |
|
| 7172 |
|
| 7173 |
|
| 7174 |
static int |
| 7175 |
is_watson_crick_bp(char i, char j) |
| 7176 |
{ |
| 7177 |
switch (toupper(i)) { |
| 7178 |
case 'A': |
| 7179 |
switch (toupper(j)) { |
| 7180 |
case 'U': return TRUE; break; |
| 7181 |
case 'T': return TRUE; break; |
| 7182 |
default: break; |
| 7183 |
} |
| 7184 |
break; |
| 7185 |
case 'C': |
| 7186 |
switch (toupper(j)) { |
| 7187 |
case 'G': return TRUE; break; |
| 7188 |
default: break; |
| 7189 |
} |
| 7190 |
break; |
| 7191 |
case 'G': |
| 7192 |
switch (toupper(j)) { |
| 7193 |
case 'C': return TRUE; break; |
| 7194 |
default: break; |
| 7195 |
} |
| 7196 |
break; |
| 7197 |
case 'U': |
| 7198 |
switch (toupper(j)) { |
| 7199 |
case 'A': return TRUE; break; |
| 7200 |
default: break; |
| 7201 |
} |
| 7202 |
break; |
| 7203 |
case 'T': |
| 7204 |
switch (toupper(j)) { |
| 7205 |
case 'A': return TRUE; break; |
| 7206 |
default: break; |
| 7207 |
} |
| 7208 |
break; |
| 7209 |
default: break; |
| 7210 |
} |
| 7211 |
|
| 7212 |
return FALSE; |
| 7213 |
} |
| 7214 |
|
| 7215 |
static int |
| 7216 |
is_gu_or_ug_bp(char i, char j) |
| 7217 |
{ |
| 7218 |
switch (toupper(i)) { |
| 7219 |
case 'G': |
| 7220 |
switch (toupper(j)) { |
| 7221 |
case 'U': return TRUE; break; |
| 7222 |
case 'T': return TRUE; break; |
| 7223 |
default: break; |
| 7224 |
} |
| 7225 |
break; |
| 7226 |
case 'U': |
| 7227 |
switch (toupper(j)) { |
| 7228 |
case 'G': return TRUE; break; |
| 7229 |
default: break; |
| 7230 |
} |
| 7231 |
break; |
| 7232 |
case 'T': |
| 7233 |
switch (toupper(j)) { |
| 7234 |
case 'G': return TRUE; break; |
| 7235 |
default: break; |
| 7236 |
} |
| 7237 |
break; |
| 7238 |
default: break; |
| 7239 |
} |
| 7240 |
|
| 7241 |
return FALSE; |
| 7242 |
} |
| 7243 |
|
| 7244 |
|
| 7245 |
|
| 7246 |
|
| 7247 |
|
| 7248 |
|
| 7249 |
|
| 7250 |
|
| 7251 |
|
| 7252 |
|
| 7253 |
|
| 7254 |
|
| 7255 |
|
| 7256 |
|
| 7257 |
|
| 7258 |
|
| 7259 |
|
| 7260 |
|
| 7261 |
|
| 7262 |
|
| 7263 |
|
| 7264 |
|
| 7265 |
|
| 7266 |
|
| 7267 |
|
| 7268 |
|
| 7269 |
|
| 7270 |
|
| 7271 |
|
| 7272 |
typedef struct nt2sort_s { |
| 7273 |
double ntfreq; |
| 7274 |
int ntidx; |
| 7275 |
} nt2sort_t; |
| 7276 |
|
| 7277 |
|
| 7278 |
int |
| 7279 |
compare_by_ntfreq(const void *a_void, const void *b_void) |
| 7280 |
{ |
| 7281 |
nt2sort_t *a, *b; |
| 7282 |
|
| 7283 |
a = (nt2sort_t *) a_void; |
| 7284 |
b = (nt2sort_t *) b_void; |
| 7285 |
|
| 7286 |
if (a->ntfreq > b->ntfreq) return -1; |
| 7287 |
else if (a->ntfreq < b->ntfreq) return 1; |
| 7288 |
else return 0; |
| 7289 |
} |
| 7290 |
|
| 7291 |
|
| 7292 |
|
| 7293 |
|
| 7294 |
|
| 7295 |
|
| 7296 |
|
| 7297 |
|
| 7298 |
|
| 7299 |
|
| 7300 |
|
| 7301 |
|
| 7302 |
|
| 7303 |
|
| 7304 |
|
| 7305 |
|
| 7306 |
|
| 7307 |
|
| 7308 |
|
| 7309 |
|
| 7310 |
|
| 7311 |
|
| 7312 |
|
| 7313 |
|
| 7314 |
|
| 7315 |
|
| 7316 |
int get_consensus_nucleotide(int *useme, int K) |
| 7317 |
{ |
| 7318 |
|
| 7319 |
if((! useme[0]) && (! useme[1]) && (! useme[2]) && ( useme[3])) { return 'U'; } |
| 7320 |
if((! useme[0]) && (! useme[1]) && ( useme[2]) && (! useme[3])) { return 'G'; } |
| 7321 |
if((! useme[0]) && ( useme[1]) && (! useme[2]) && (! useme[3])) { return 'C'; } |
| 7322 |
if(( useme[0]) && (! useme[1]) && (! useme[2]) && (! useme[3])) { return 'A'; } |
| 7323 |
|
| 7324 |
if(( useme[0]) && ( useme[1]) && ( useme[2]) && ( useme[3])) { return 'N'; } |
| 7325 |
|
| 7326 |
if((! useme[0]) && ( useme[1]) && ( useme[2]) && ( useme[3])) { return 'B'; } |
| 7327 |
if(( useme[0]) && (! useme[1]) && ( useme[2]) && ( useme[3])) { return 'D'; } |
| 7328 |
if(( useme[0]) && ( useme[1]) && ( useme[2]) && (! useme[3])) { return 'V'; } |
| 7329 |
if(( useme[0]) && ( useme[1]) && (! useme[2]) && ( useme[3])) { return 'H'; } |
| 7330 |
|
| 7331 |
if((! useme[0]) && (! useme[1]) && ( useme[2]) && ( useme[3])) { return 'K'; } |
| 7332 |
if((! useme[0]) && ( useme[1]) && ( useme[2]) && (! useme[3])) { return 'S'; } |
| 7333 |
if(( useme[0]) && ( useme[1]) && (! useme[2]) && (! useme[3])) { return 'M'; } |
| 7334 |
if((! useme[0]) && ( useme[1]) && (! useme[2]) && ( useme[3])) { return 'Y'; } |
| 7335 |
if(( useme[0]) && (! useme[1]) && (! useme[2]) && ( useme[3])) { return 'W'; } |
| 7336 |
if(( useme[0]) && (! useme[1]) && ( useme[2]) && (! useme[3])) { return 'R'; } |
| 7337 |
|
| 7338 |
if((! useme[0]) && (! useme[1]) && (! useme[2]) && (! useme[3])) { return '-'; } |
| 7339 |
esl_fatal("coding error in consensus_nucleotide"); |
| 7340 |
return ' '; |
| 7341 |
} |
| 7342 |
|
| 7343 |
int |
| 7344 |
get_consensus_seqs_from_abc_ct(const ESL_GETOPTS *go, SSPostscript_t *ps, char *errbuf, double **abc_ct, ESL_ALPHABET *abc, int64_t msa_alen) |
| 7345 |
{ |
| 7346 |
int status; |
| 7347 |
char *cseq_maj = NULL; |
| 7348 |
char *cseq_amb = NULL; |
| 7349 |
int rfpos, apos; |
| 7350 |
float nongap_freq; |
| 7351 |
float covered; |
| 7352 |
|
| 7353 |
int *nt_is_used; |
| 7354 |
|
| 7355 |
nt2sort_t *sorted_ntfreq; |
| 7356 |
int sorted_idx; |
| 7357 |
int a; |
| 7358 |
float cthresh = esl_opt_GetReal(go, "--cthresh"); |
| 7359 |
float athresh = esl_opt_GetReal(go, "--athresh"); |
| 7360 |
|
| 7361 |
|
| 7362 |
ESL_ALLOC(cseq_maj, sizeof(char) * (ps->rflen+1)); |
| 7363 |
ESL_ALLOC(cseq_amb, sizeof(char) * (ps->rflen+1)); |
| 7364 |
cseq_maj[ps->rflen] = '\0'; |
| 7365 |
cseq_amb[ps->rflen] = '\0'; |
| 7366 |
ESL_ALLOC(sorted_ntfreq, sizeof(nt2sort_t) * (abc->K)); |
| 7367 |
ESL_ALLOC(nt_is_used, sizeof(int) * (abc->K)); |
| 7368 |
|
| 7369 |
rfpos = 0; |
| 7370 |
for(apos = 0; apos < msa_alen; apos++) { |
| 7371 |
if(esl_abc_CIsResidue(abc, ps->msa->rf[apos])) { |
| 7372 |
nongap_freq = esl_vec_DSum(abc_ct[apos], abc->K); |
| 7373 |
if(esl_DCompare_old(nongap_freq, 0., eslSMALLX1) == eslOK) { |
| 7374 |
cseq_maj[rfpos] = cseq_amb[rfpos] = '-'; |
| 7375 |
} |
| 7376 |
else { |
| 7377 |
for(a = 0; a < abc->K; a++) { |
| 7378 |
sorted_ntfreq[a].ntfreq = abc_ct[apos][a] / nongap_freq; |
| 7379 |
sorted_ntfreq[a].ntidx = a; |
| 7380 |
} |
| 7381 |
|
| 7382 |
qsort(sorted_ntfreq, abc->K, sizeof(nt2sort_t), compare_by_ntfreq); |
| 7383 |
covered = 0.; |
| 7384 |
esl_vec_ISet(nt_is_used, abc->K, FALSE); |
| 7385 |
sorted_idx = 0; |
| 7386 |
|
| 7387 |
cseq_maj[rfpos] = (sorted_ntfreq[sorted_idx].ntfreq >= cthresh) ? |
| 7388 |
toupper(abc->sym[sorted_ntfreq[sorted_idx].ntidx]) : |
| 7389 |
tolower(abc->sym[sorted_ntfreq[sorted_idx].ntidx]); |
| 7390 |
|
| 7391 |
while(covered < athresh) { |
| 7392 |
nt_is_used[sorted_ntfreq[sorted_idx].ntidx] = TRUE; |
| 7393 |
covered += sorted_ntfreq[sorted_idx].ntfreq; |
| 7394 |
|
| 7395 |
|
| 7396 |
|
| 7397 |
|
| 7398 |
|
| 7399 |
sorted_idx++; |
| 7400 |
} |
| 7401 |
cseq_amb[rfpos] = get_consensus_nucleotide(nt_is_used, abc->K); |
| 7402 |
} |
| 7403 |
rfpos++; |
| 7404 |
} |
| 7405 |
} |
| 7406 |
|
| 7407 |
ps->msa_cseq_maj = cseq_maj; |
| 7408 |
ps->msa_cseq_amb = cseq_amb; |
| 7409 |
|
| 7410 |
free(sorted_ntfreq); |
| 7411 |
free(nt_is_used); |
| 7412 |
|
| 7413 |
return eslOK; |
| 7414 |
|
| 7415 |
ERROR: |
| 7416 |
ESL_FAIL(eslEMEM, errbuf, "Ran out of memory in get_consensus_seqs_from_abc_ct."); |
| 7417 |
return eslEMEM; |
| 7418 |
} |
| 7419 |
|
| 7420 |
|
| 7421 |
|
| 7422 |
|
| 7423 |
|
| 7424 |
|
| 7425 |
|
| 7426 |
|
| 7427 |
|
| 7428 |
|
| 7429 |
|
| 7430 |
|
| 7431 |
|
| 7432 |
|
| 7433 |
|
| 7434 |
|
| 7435 |
|
| 7436 |
|
| 7437 |
|
| 7438 |
|
| 7439 |
int compare_two_cmyk_colors(float acol_C, float acol_M, float acol_Y, float acol_K, float bcol_C, float bcol_M, float bcol_Y, float bcol_K) |
| 7440 |
{ |
| 7441 |
if(esl_FCompare_old(acol_C, bcol_C, eslSMALLX1) != eslOK) return FALSE; |
| 7442 |
if(esl_FCompare_old(acol_M, bcol_M, eslSMALLX1) != eslOK) return FALSE; |
| 7443 |
if(esl_FCompare_old(acol_Y, bcol_Y, eslSMALLX1) != eslOK) return FALSE; |
| 7444 |
if(esl_FCompare_old(acol_K, bcol_K, eslSMALLX1) != eslOK) return FALSE; |
| 7445 |
return TRUE; |
| 7446 |
} |
| 7447 |
|
| 7448 |
|
| 7449 |
|
| 7450 |
|
| 7451 |
|
| 7452 |
|
| 7453 |
|
| 7454 |
|
| 7455 |
|
| 7456 |
|
| 7457 |
|
| 7458 |
void define_outline_procedure(FILE *fp) |
| 7459 |
{ |
| 7460 |
fprintf(fp, "\n/%s %% stack: x y cellsize linewidth (empty)\n", OUTLINE_PROCEDURE); |
| 7461 |
fprintf(fp, "{\n");; |
| 7462 |
fprintf(fp, " 0. 0. 0. 1. setcmykcolor\n"); |
| 7463 |
fprintf(fp, " setlinewidth\n"); |
| 7464 |
fprintf(fp, " /cellsize exch def\n"); |
| 7465 |
fprintf(fp, " newpath moveto\n"); |
| 7466 |
fprintf(fp, " currentlinewidth 2. div currentlinewidth 2. div rmoveto\n"); |
| 7467 |
fprintf(fp, " 0 cellsize currentlinewidth sub rlineto\n"); |
| 7468 |
fprintf(fp, " cellsize currentlinewidth sub 0 rlineto\n"); |
| 7469 |
fprintf(fp, " 0 cellsize currentlinewidth sub -1 mul rlineto\n"); |
| 7470 |
fprintf(fp, " closepath stroke\n"); |
| 7471 |
fprintf(fp, "} def\n\n"); |
| 7472 |
|
| 7473 |
|
| 7474 |
|
| 7475 |
|
| 7476 |
|
| 7477 |
|
| 7478 |
|
| 7479 |
|
| 7480 |
|
| 7481 |
|
| 7482 |
|
| 7483 |
|
| 7484 |
|
| 7485 |
|
| 7486 |
|
| 7487 |
|
| 7488 |
|
| 7489 |
|
| 7490 |
|
| 7491 |
|
| 7492 |
|
| 7493 |
|
| 7494 |
|
| 7495 |
|
| 7496 |
|
| 7497 |
|
| 7498 |
|
| 7499 |
|
| 7500 |
|
| 7501 |
|
| 7502 |
|
| 7503 |
|
| 7504 |
|
| 7505 |
|
| 7506 |
|
| 7507 |
|
| 7508 |
|
| 7509 |
|
| 7510 |
|
| 7511 |
|
| 7512 |
|
| 7513 |
|
| 7514 |
|
| 7515 |
|
| 7516 |
|
| 7517 |
|
| 7518 |
|
| 7519 |
|
| 7520 |
|
| 7521 |
|
| 7522 |
|
| 7523 |
|
| 7524 |
|
| 7525 |
|
| 7526 |
|
| 7527 |
|
| 7528 |
|
| 7529 |
|
| 7530 |
|
| 7531 |
|
| 7532 |
|
| 7533 |
|
| 7534 |
|
| 7535 |
|
| 7536 |
return; |
| 7537 |
} |
| 7538 |
|
| 7539 |
|