/* 5.Resolving implicit levels. */ static int bidi_resolveImplicit(TYPERUN **ptype_rl_list, int base_level) { TYPERUN *type_rl_list = *ptype_rl_list, *pp = NULL; int max_level = base_level; DBGLOG ("\n5:Resolving implicit levels\n"); for (pp = type_rl_list->next; pp->next; pp = pp->next) { BidiCharType this_type; int level; this_type = TYPE(pp); level = LEVEL(pp); /* I1. Even */ /* I2. Odd */ if (BIDI_IS_NUMBER(this_type)) LEVEL(pp) = (level + 2) & ~1; else LEVEL(pp) = (level ^ BIDI_DIR_TO_LEVEL(this_type)) + (level & 1); if (LEVEL(pp) > max_level) max_level = LEVEL(pp); } compact_list (type_rl_list); #ifdef BIDI_DEBUG if (bidi_debug) { print_run_types(type_rl_list); print_resolved_levels (type_rl_list); print_resolved_types (type_rl_list); } #endif return max_level; }
/* 4.Resolving Neutral Types */ static void bidi_resolveNeutrals(TYPERUN **ptype_rl_list, BidiCharType base_bir) { TYPERUN *type_rl_list = *ptype_rl_list, *pp = NULL; DBGLOG ("\n4:Resolving neutral types\n"); for (pp = type_rl_list->next; pp->next; pp = pp->next) { BidiCharType prev_type, this_type, next_type; prev_type = TYPE(pp->prev); this_type = TYPE(pp); next_type = (pp->next) ? TYPE(pp->next) : this_type; /* "European and arabic numbers are treated as though they were R, NUMBER_TO_RTL does this. */ this_type = BIDI_NUMBER_TO_RTL(this_type); prev_type = BIDI_NUMBER_TO_RTL(prev_type); next_type = BIDI_NUMBER_TO_RTL(next_type); if (BIDI_IS_NEUTRAL (this_type)) TYPE (pp) = (prev_type == next_type) ? prev_type : /* N1. */ BIDI_EMBEDDING_DIR(pp); /* N2. */ } compact_list (type_rl_list); #ifdef BIDI_DEBUG if (bidi_debug) { print_run_types(type_rl_list); print_resolved_levels (type_rl_list); print_resolved_types (type_rl_list); } #endif }
int describe(char *name, char *mapset, int compact, char *no_data_str, int range, int windowed, int nsteps, int as_int, int skip_nulls) { int fd; struct Cell_stats statf; CELL *buf, *b; int nrows, ncols; int row, col; struct Cell_head window; CELL negmin = 0, negmax = 0, zero = 0, posmin = 0, posmax = 0; CELL null = 0; RASTER_MAP_TYPE map_type; struct Quant q; struct FPRange r; DCELL dmin, dmax; int (*get_row) (); if (windowed) { get_row = G_get_c_raster_row; } else { char msg[100]; if (G_get_cellhd(name, mapset, &window) < 0) { sprintf(msg, "can't get cell header for [%s] in [%s]", name, mapset); G_fatal_error(msg); } G_set_window(&window); get_row = G_get_c_raster_row_nomask; } fd = G_open_cell_old(name, mapset); if (fd < 0) return 0; map_type = G_get_raster_map_type(fd); if (as_int) map_type = CELL_TYPE; /* read as int */ /* allocate the cell buffer */ buf = G_allocate_cell_buf(); if (map_type != CELL_TYPE && range) /* this will make it report fp range */ { range = 0; nsteps = 1; } /* start the cell stats */ if (!range) { G_init_cell_stats(&statf); } else { zero = 0; negmin = 0; negmax = 0; posmin = 0; posmax = 0; null = 0; dmin = 0.0; dmax = 0.0; } /* set up quantization rules */ if (map_type != CELL_TYPE) { G_quant_init(&q); G_read_fp_range(name, mapset, &r); G_get_fp_range_min_max(&r, &dmin, &dmax); G_quant_add_rule(&q, dmin, dmax, 1, nsteps); G_set_quant_rules(fd, &q); } nrows = G_window_rows(); ncols = G_window_cols(); G_verbose_message("Reading [%s in %s] ...", name, mapset); for (row = 0; row < nrows; row++) { G_percent(row, nrows, 2); if ((*get_row) (fd, b = buf, row) < 0) break; if (range) { for (col = ncols; col-- > 0; b++) { if (G_is_c_null_value(b)) null = 1; else if (*b == 0) zero = 1; else if (*b < 0) { if (!negmin) negmin = negmax = *b; else if (*b > negmax) negmax = *b; else if (*b < negmin) negmin = *b; } else { if (!posmin) posmin = posmax = *b; else if (*b > posmax) posmax = *b; else if (*b < posmin) posmin = *b; } } } else G_update_cell_stats(buf, ncols, &statf); } G_percent(nrows, nrows, 2); G_close_cell(fd); G_free(buf); if (range) { if (compact) compact_range_list(negmin, negmax, zero, posmin, posmax, null, no_data_str, skip_nulls); else range_list(negmin, negmax, zero, posmin, posmax, null, no_data_str, skip_nulls); } else { G_rewind_cell_stats(&statf); if (compact) compact_list(&statf, dmin, dmax, no_data_str, skip_nulls, map_type, nsteps); else long_list(&statf, dmin, dmax, no_data_str, skip_nulls, map_type, nsteps); G_free_cell_stats(&statf); } return 1; }
Sim4::edit_script_list * Sim4::SIM4(int *dist_ptr, Exon **Exons, int *pA, int *pT, sim4_stats_t *st) { int rollbflag; Exon *Lblock=0L, *tmp_Lblock=0L; Exon *Rblock=0L, *tmp_Rblock=0L; Exon *tmp_block=0L; Exon *tmp_block1=0L; *dist_ptr = 0; *Exons = 0L; *pA = 0; *pT = 0; // // The call to exon_cores() that used to be here is now done in sim4string. // // See if there are too many MSPs found. If so, fail. // st->tooManyMSPs = false; if (_mspManager.tooManyMSPs()) { st->tooManyMSPs = true; st->numberOfMatches = _mspManager.numberOfMSPs(); return(0L); } PRINTEXONS("initial exon set\n", exon_list); tmp_block = Lblock = exon_list; while (tmp_block) { if (tmp_block->next_exon==NULL) Rblock = tmp_block; tmp_block = tmp_block->next_exon; } if (Lblock && ((Lblock->frGEN>50000 && Lblock->frEST>100) || ((_genLen - Rblock->toGEN > 50000) && (_estLen - Rblock->toEST > 100)))) { //freeExonList(exon_list); garbage collected exon_list = _mspManager.doLinking(globalParams->_relinkWeight, DEFAULT_DRANGE, 1, 1, 0, true, _genSeq, _estSeq); PRINTEXONS("relink the initial stuff\n", exon_list); tmp_block = Lblock = exon_list; while (tmp_block) { if (tmp_block->next_exon==NULL) Rblock = tmp_block; tmp_block = tmp_block->next_exon; } } _mspManager.clear(); tmp_block = Lblock = exon_list; while (tmp_block) { if (tmp_block->next_exon==NULL) Rblock = tmp_block; tmp_block = tmp_block->next_exon; } PRINTEXONS("initial exon set after possibly relinking\n", exon_list); /* enclose the current path in the (0,0,0,0) and (M+1,N+1,0,0) brackets */ #ifdef SHOW_PROGRESS fprintf(stderr, "exon bracket at start\n"); #endif Lblock = _exonManager.newExon(0,0,0,0,0,0,0,Lblock); if (Rblock == NULL) Rblock = Lblock; #ifdef SHOW_PROGRESS fprintf(stderr, "exon bracket at end; Lblock = 0x%08lx, Rblock = 0x%08lx\n", Lblock, Rblock); #endif Rblock->next_exon = _exonManager.newExon(_genLen+1,_estLen+1,0,0,0,0,0,NULL); PRINTEXONS("initial exon set after inserting brackets\n", Lblock); /* compute current statistics */ bool good_match = get_match_quality(Lblock, Rblock, st, _estLen); PRINTEXONS("after get_match_quality\n", Lblock); #ifdef SHOW_PROGRESS fprintf(stderr, "before big nasty while loop\n"); #endif tmp_block = Lblock; while ((tmp_block1 = tmp_block->next_exon)!=NULL) { PRINTEXONS("start of loop to fill in missing pieces\n", Lblock); rollbflag = 0; // This is the distance from this exon to the next exon // in the EST // int diff = (int)(tmp_block1->frEST - tmp_block->toEST - 1); #ifdef SHOW_PROGRESS fprintf(stdout, "tmp_block: %8d %8d %8d %8d %d diff=%d\n", tmp_block->frGEN, tmp_block->toGEN, tmp_block->frEST, tmp_block->toEST, tmp_block->flag, diff); #endif if (diff) { if (diff < 0) { // If the diff is less than zero, then there is an overlap in // the EST. Wobble the boundary using GTAG signals (so // obviously, this won't work correctly if we are not cDNA). // #ifdef SHOW_PROGRESS fprintf(stderr, "Called SIM4_block1() with diff=%d\n", diff); #endif rollbflag = SIM4_block1(Lblock, tmp_block, tmp_block1); } else { // Otherwise, there is a gap in the EST, and we need to fill // it in. This is done only if there is no overlap in the // genomic. // if (tmp_block1->frGEN - tmp_block->toGEN - 1 > 0) { if (tmp_block1->toEST && tmp_block->toEST) { // We are not the first or last gap -- an interior gap // between two exons. // #ifdef SHOW_PROGRESS fprintf(stderr, "Called SIM4_block2()\n"); #endif rollbflag = SIM4_block2(tmp_Lblock, tmp_Rblock, tmp_block, tmp_block1); } else if (tmp_block1->toGEN) { // Not the last gap, so must be the first gap. // #ifdef SHOW_PROGRESS fprintf(stderr, "Called SIM4_block3()\n"); #endif rollbflag = SIM4_block3(good_match, tmp_Lblock, tmp_Rblock, tmp_block, tmp_block1); } else { // By default, the last gap. // #ifdef SHOW_PROGRESS fprintf(stderr, "Called SIM4_block4()\n"); #endif rollbflag = SIM4_block4(good_match, tmp_Lblock, tmp_Rblock, tmp_block, tmp_block1); } } else { // Overlapping genomic. What these do when set to // NULL is unknown. // tmp_Rblock = tmp_Lblock = NULL; } // Merge block in the exon list; make connections to the // previous list of blocks; maintain increasing order // if (tmp_Lblock) { tmp_block->next_exon = tmp_Lblock; tmp_Rblock->next_exon = tmp_block1; PRINTEXONS("before merge tmp_block\n", tmp_block); PRINTEXONS("before merge tmp_block1\n", tmp_block1); PRINTEXONS("before merge tmp_Lblock\n", tmp_Lblock); PRINTEXONS("before merge tmp_Rblock\n", tmp_Rblock); merge(&tmp_block,&tmp_block1); } } } // If this exon block was not removed, move to the next. If it was removed, // we're already there. // if (rollbflag == 0) tmp_block = tmp_block1; } PRINTEXONS("all done -- final Lblock\n", Lblock); #ifdef SHOW_PROGRESS fprintf(stderr, "sim4b1 -- before compact_list\n"); #endif /* compaction step; note: it resets the right end of the list to */ /* the last item in the block list */ compact_list(&(Lblock->next_exon), &Rblock, (globalParams->_interspecies ? SHORT_INTRON : wordSize)); if (globalParams->_interspecies) filter(&Lblock, &Rblock); #ifdef SHOW_PROGRESS fprintf(stderr, "sim4b1 -- before small block at start removal\n"); #endif /* eliminate marginal small blocks at the start of the sequence; */ /* resets the empty alignment to one block (Lblock) only */ tmp_block = Lblock->next_exon; while ((tmp_block!=NULL) && (tmp_block->length<wordSize) && tmp_block->toGEN) { tmp_block1 = tmp_block; tmp_block = tmp_block->next_exon; //freeExon(tmp_block1); garbage collected } Lblock->next_exon = tmp_block; PRINTEXONS("all done -- after removing small blocks at the start\n", Lblock); // eliminate marginal small blocks at the end of the sequence // XXX: Yes, there is a leak here. That's why we garbage collect! #ifdef SHOW_PROGRESS fprintf(stderr, "Rblock before end of list removal 0x%08lx\n", Rblock); #endif Exon *last = Lblock->next_exon; tmp_block = last; while (tmp_block!=NULL) { if (tmp_block->length>=wordSize) last = tmp_block; tmp_block = tmp_block->next_exon; } if (last && last->toGEN) last->next_exon = Rblock->next_exon; Rblock = last; #ifdef SHOW_PROGRESS fprintf(stderr, "Rblock after end of list removal 0x%08lx\n", Rblock); #endif PRINTEXONS("all done -- after removing small blocks at the end\n", Lblock); /* if high accuracy requirement, adjust boundaries of marginal exons */ if (_accurateSequences) adjustBoundariesOfMarginalExons(Lblock); /* Slide exon boundaries for optimal intron signals */ if (globalParams->_slideIntrons) { if (globalParams->_interspecies == 1) { SLIDE_INTRON(MIN(15,MAX_SLIDE), Lblock->next_exon, Rblock, spliceModel, st, 1); } else { if (get_sync_flag(Lblock, Rblock, 6) == 1) SLIDE_INTRON(6, Lblock->next_exon, Rblock, SPLICE_ORIGINAL, st, 1); else SLIDE_INTRON(6, Lblock->next_exon, Rblock, SPLICE_ORIGINAL, st, 0); } } else { // Set orientation flag on introns to be unknown -- this has an // undesired side effect of forcing the resulting match to have a // strand orientation the same as the intron orientation (if one // exon) instead of 'unknown'. Exon *t0 = Lblock->next_exon; Exon *t1 = NULL; while (t0 && (t1=t0->next_exon) && t1->toGEN) { t0->ori = 'E'; t0 = t1; } } /* decreasingly; script will be in reverse order */ struct edit_script_list *Shead = NULL; flip_list(&Lblock, &Rblock); pluri_align(dist_ptr, Lblock, &Shead, st); flip_list(&Lblock, &Rblock); /* increasingly */ *pT = 0; *pA = 0; if (Shead) { if (globalParams->_ignorePolyTails) { remove_polyT_front(&Shead, Lblock, _genSeq, _estSeq, pT); remove_polyA_back(&Shead, Lblock, _genSeq, _estSeq, _estLen, pA); if (*pA || *pT) updateStatistics(Lblock, st); } get_stats(Lblock, st); *Exons = Lblock->next_exon; //freeExon(Lblock); garbage collected } else { *Exons = 0L; //freeExonList(Lblock); garbage collected } // Memory leak when Script_head == 0L -- see pluri_align, too! return(Shead); }