X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bam_tview.c;h=c6a31cd7fc73d20797d3c1d7e1d0fd4545cf8942;hb=a5a8f24beaa6b65b40f29d89a62cf2c643100c6d;hp=e5b83a11c17e6ce393e119945cf43e048ad07e8a;hpb=6dd512ba2a4a68c07cd08698a8e972bb553d0c38;p=samtools.git diff --git a/bam_tview.c b/bam_tview.c index e5b83a1..c6a31cd 100644 --- a/bam_tview.c +++ b/bam_tview.c @@ -1,6 +1,21 @@ -#ifndef _NO_CURSES +#undef _HAVE_CURSES + +#if _CURSES_LIB == 0 +#elif _CURSES_LIB == 1 #include -#ifdef NCURSES_VERSION +#ifndef NCURSES_VERSION +#warning "_CURSES_LIB=1 but NCURSES_VERSION not defined; tview is NOT compiled" +#else +#define _HAVE_CURSES +#endif +#elif _CURSES_LIB == 2 +#include +#define _HAVE_CURSES +#else +#warning "_CURSES_LIB is not 0, 1 or 2; tview is NOT compiled" +#endif + +#ifdef _HAVE_CURSES #include #include #include @@ -50,11 +65,11 @@ int tv_pl_func(uint32_t tid, uint32_t pos, int n, const bam_pileup1_t *pl, void // print referece rb = (tv->ref && pos - tv->left_pos < tv->l_ref)? tv->ref[pos - tv->left_pos] : 'N'; for (i = tv->last_pos + 1; i < pos; ++i) { - if (i%10 == 0) mvprintw(0, tv->ccol, "%-d", i+1); + if (i%10 == 0 && tv->mcol - tv->ccol >= 10) mvprintw(0, tv->ccol, "%-d", i+1); c = tv->ref? tv->ref[i - tv->left_pos] : 'N'; mvaddch(1, tv->ccol++, c); } - if (pos%10 == 0) mvprintw(0, tv->ccol, "%-d", pos+1); + if (pos%10 == 0 && tv->mcol - tv->ccol >= 10) mvprintw(0, tv->ccol, "%-d", pos+1); // print consensus call = bam_maqcns_call(n, pl, tv->bmc); attr = A_UNDERLINE; @@ -161,6 +176,7 @@ tview_t *tv_init(const char *fn, const char *fn_fa) tview_t *tv = (tview_t*)calloc(1, sizeof(tview_t)); tv->is_dot = 1; tv->idx = bam_index_load(fn); + if (tv->idx == 0) exit(1); tv->fp = bam_open(fn, "r"); bgzf_set_cache_size(tv->fp, 8 * 1024 *1024); assert(tv->fp); @@ -176,11 +192,8 @@ tview_t *tv_init(const char *fn, const char *fn_fa) clear(); noecho(); cbreak(); -#ifdef NCURSES_VERSION + tv->mrow = 24; tv->mcol = 80; getmaxyx(stdscr, tv->mrow, tv->mcol); -#else - tv->mrow = 80; tv->mcol = 40; -#endif tv->wgoto = newwin(3, TV_MAX_GOTO + 10, 10, 5); tv->whelp = newwin(27, 40, 5, 5); tv->color_for = TV_COLOR_MAPQ; @@ -239,6 +252,13 @@ int tv_draw_aln(tview_t *tv, int tid, int pos) bam_lplbuf_reset(tv->lplbuf); bam_fetch(tv->fp, tv->idx, tv->curr_tid, tv->left_pos, tv->left_pos + tv->mcol, tv, tv_fetch_func); bam_lplbuf_push(0, tv->lplbuf); + + while (tv->ccol < tv->mcol) { + int pos = tv->last_pos + 1; + if (pos%10 == 0 && tv->mcol - tv->ccol >= 10) mvprintw(0, tv->ccol, "%-d", pos+1); + mvaddch(1, tv->ccol++, (tv->ref && pos < tv->l_ref)? tv->ref[pos - tv->left_pos] : 'N'); + ++tv->last_pos; + } return 0; } @@ -309,7 +329,6 @@ void tv_loop(tview_t *tv) tid = tv->curr_tid; pos = tv->left_pos; while (1) { int c = getch(); - //if(256 < c) {c = 1 + (c%256);} // Terminal was displaying ctrl-H as 263 via ssh from Mac OS X 10.5 computer switch (c) { case '?': tv_win_help(tv); break; case '\033': @@ -341,9 +360,7 @@ void tv_loop(tview_t *tv) case 'k': ++tv->row_shift; break; case KEY_BACKSPACE: case '\177': pos -= tv->mcol; break; -#ifdef KEY_RESIZE case KEY_RESIZE: getmaxyx(stdscr, tv->mrow, tv->mcol); break; -#endif default: continue; } if (pos < 0) pos = 0; @@ -374,5 +391,4 @@ int bam_tview_main(int argc, char *argv[]) fprintf(stderr, "[bam_tview_main] The ncurses library is unavailable; tview is not compiled.\n"); return 1; } -#endif -#endif // #ifndef _NO_CURSES +#endif // #ifdef _HAVE_CURSES