annotate pyPRADA_1.2/tools/samtools-0.1.16/bam_tview.c @ 3:f17965495ec9 draft default tip

Uploaded
author siyuan
date Tue, 11 Mar 2014 12:14:01 -0400
parents acc2ca1a3ba4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
1 #undef _HAVE_CURSES
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
2
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
3 #if _CURSES_LIB == 0
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
4 #elif _CURSES_LIB == 1
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
5 #include <curses.h>
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
6 #ifndef NCURSES_VERSION
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
7 #warning "_CURSES_LIB=1 but NCURSES_VERSION not defined; tview is NOT compiled"
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
8 #else
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
9 #define _HAVE_CURSES
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
10 #endif
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
11 #elif _CURSES_LIB == 2
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
12 #include <xcurses.h>
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
13 #define _HAVE_CURSES
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
14 #else
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
15 #warning "_CURSES_LIB is not 0, 1 or 2; tview is NOT compiled"
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
16 #endif
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
17
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
18 #ifdef _HAVE_CURSES
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
19 #include <ctype.h>
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
20 #include <assert.h>
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
21 #include <string.h>
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
22 #include "bam.h"
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
23 #include "faidx.h"
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
24 #include "bam_maqcns.h"
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
25
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
26 char bam_aux_getCEi(bam1_t *b, int i);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
27 char bam_aux_getCSi(bam1_t *b, int i);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
28 char bam_aux_getCQi(bam1_t *b, int i);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
29
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
30 #define TV_MIN_ALNROW 2
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
31 #define TV_MAX_GOTO 40
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
32 #define TV_LOW_MAPQ 10
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
33
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
34 #define TV_COLOR_MAPQ 0
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
35 #define TV_COLOR_BASEQ 1
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
36 #define TV_COLOR_NUCL 2
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
37 #define TV_COLOR_COL 3
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
38 #define TV_COLOR_COLQ 4
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
39
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
40 #define TV_BASE_NUCL 0
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
41 #define TV_BASE_COLOR_SPACE 1
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
42
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
43 typedef struct {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
44 int mrow, mcol;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
45 WINDOW *wgoto, *whelp;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
46
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
47 bam_index_t *idx;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
48 bam_lplbuf_t *lplbuf;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
49 bam_header_t *header;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
50 bamFile fp;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
51 int curr_tid, left_pos;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
52 faidx_t *fai;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
53 bam_maqcns_t *bmc;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
54
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
55 int ccol, last_pos, row_shift, base_for, color_for, is_dot, l_ref, ins, no_skip, show_name;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
56 char *ref;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
57 } tview_t;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
58
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
59 int tv_pl_func(uint32_t tid, uint32_t pos, int n, const bam_pileup1_t *pl, void *data)
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
60 {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
61 tview_t *tv = (tview_t*)data;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
62 int i, j, c, rb, attr, max_ins = 0;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
63 uint32_t call = 0;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
64 if (pos < tv->left_pos || tv->ccol > tv->mcol) return 0; // out of screen
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
65 // print referece
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
66 rb = (tv->ref && pos - tv->left_pos < tv->l_ref)? tv->ref[pos - tv->left_pos] : 'N';
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
67 for (i = tv->last_pos + 1; i < pos; ++i) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
68 if (i%10 == 0 && tv->mcol - tv->ccol >= 10) mvprintw(0, tv->ccol, "%-d", i+1);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
69 c = tv->ref? tv->ref[i - tv->left_pos] : 'N';
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
70 mvaddch(1, tv->ccol++, c);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
71 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
72 if (pos%10 == 0 && tv->mcol - tv->ccol >= 10) mvprintw(0, tv->ccol, "%-d", pos+1);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
73 // print consensus
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
74 call = bam_maqcns_call(n, pl, tv->bmc);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
75 attr = A_UNDERLINE;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
76 c = ",ACMGRSVTWYHKDBN"[call>>28&0xf];
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
77 i = (call>>8&0xff)/10+1;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
78 if (i > 4) i = 4;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
79 attr |= COLOR_PAIR(i);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
80 if (c == toupper(rb)) c = '.';
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
81 attron(attr);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
82 mvaddch(2, tv->ccol, c);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
83 attroff(attr);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
84 if(tv->ins) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
85 // calculate maximum insert
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
86 for (i = 0; i < n; ++i) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
87 const bam_pileup1_t *p = pl + i;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
88 if (p->indel > 0 && max_ins < p->indel) max_ins = p->indel;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
89 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
90 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
91 // core loop
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
92 for (j = 0; j <= max_ins; ++j) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
93 for (i = 0; i < n; ++i) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
94 const bam_pileup1_t *p = pl + i;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
95 int row = TV_MIN_ALNROW + p->level - tv->row_shift;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
96 if (j == 0) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
97 if (!p->is_del) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
98 if (tv->base_for == TV_BASE_COLOR_SPACE &&
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
99 (c = bam_aux_getCSi(p->b, p->qpos))) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
100 c = bam_aux_getCSi(p->b, p->qpos);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
101 // assume that if we found one color, we will be able to get the color error
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
102 if (tv->is_dot && '-' == bam_aux_getCEi(p->b, p->qpos)) c = bam1_strand(p->b)? ',' : '.';
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
103 } else {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
104 if (tv->show_name) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
105 char *name = bam1_qname(p->b);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
106 c = (p->qpos + 1 >= p->b->core.l_qname)? ' ' : name[p->qpos];
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
107 } else {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
108 c = bam_nt16_rev_table[bam1_seqi(bam1_seq(p->b), p->qpos)];
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
109 if (tv->is_dot && toupper(c) == toupper(rb)) c = bam1_strand(p->b)? ',' : '.';
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
110 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
111 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
112 } else c = p->is_refskip? (bam1_strand(p->b)? '<' : '>') : '*';
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
113 } else { // padding
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
114 if (j > p->indel) c = '*';
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
115 else { // insertion
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
116 if (tv->base_for == TV_BASE_NUCL) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
117 if (tv->show_name) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
118 char *name = bam1_qname(p->b);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
119 c = (p->qpos + j + 1 >= p->b->core.l_qname)? ' ' : name[p->qpos + j];
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
120 } else {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
121 c = bam_nt16_rev_table[bam1_seqi(bam1_seq(p->b), p->qpos + j)];
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
122 if (j == 0 && tv->is_dot && toupper(c) == toupper(rb)) c = bam1_strand(p->b)? ',' : '.';
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
123 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
124 } else {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
125 c = bam_aux_getCSi(p->b, p->qpos + j);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
126 if (tv->is_dot && '-' == bam_aux_getCEi(p->b, p->qpos + j)) c = bam1_strand(p->b)? ',' : '.';
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
127 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
128 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
129 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
130 if (row > TV_MIN_ALNROW && row < tv->mrow) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
131 int x;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
132 attr = 0;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
133 if (((p->b->core.flag&BAM_FPAIRED) && !(p->b->core.flag&BAM_FPROPER_PAIR))
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
134 || (p->b->core.flag & BAM_FSECONDARY)) attr |= A_UNDERLINE;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
135 if (tv->color_for == TV_COLOR_BASEQ) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
136 x = bam1_qual(p->b)[p->qpos]/10 + 1;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
137 if (x > 4) x = 4;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
138 attr |= COLOR_PAIR(x);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
139 } else if (tv->color_for == TV_COLOR_MAPQ) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
140 x = p->b->core.qual/10 + 1;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
141 if (x > 4) x = 4;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
142 attr |= COLOR_PAIR(x);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
143 } else if (tv->color_for == TV_COLOR_NUCL) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
144 x = bam_nt16_nt4_table[bam1_seqi(bam1_seq(p->b), p->qpos)] + 5;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
145 attr |= COLOR_PAIR(x);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
146 } else if(tv->color_for == TV_COLOR_COL) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
147 x = 0;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
148 switch(bam_aux_getCSi(p->b, p->qpos)) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
149 case '0': x = 0; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
150 case '1': x = 1; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
151 case '2': x = 2; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
152 case '3': x = 3; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
153 case '4': x = 4; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
154 default: x = bam_nt16_nt4_table[bam1_seqi(bam1_seq(p->b), p->qpos)]; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
155 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
156 x+=5;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
157 attr |= COLOR_PAIR(x);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
158 } else if(tv->color_for == TV_COLOR_COLQ) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
159 x = bam_aux_getCQi(p->b, p->qpos);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
160 if(0 == x) x = bam1_qual(p->b)[p->qpos];
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
161 x = x/10 + 1;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
162 if (x > 4) x = 4;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
163 attr |= COLOR_PAIR(x);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
164 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
165 attron(attr);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
166 mvaddch(row, tv->ccol, bam1_strand(p->b)? tolower(c) : toupper(c));
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
167 attroff(attr);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
168 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
169 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
170 c = j? '*' : rb;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
171 if (c == '*') {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
172 attr = COLOR_PAIR(8);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
173 attron(attr);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
174 mvaddch(1, tv->ccol++, c);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
175 attroff(attr);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
176 } else mvaddch(1, tv->ccol++, c);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
177 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
178 tv->last_pos = pos;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
179 return 0;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
180 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
181
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
182 tview_t *tv_init(const char *fn, const char *fn_fa)
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
183 {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
184 tview_t *tv = (tview_t*)calloc(1, sizeof(tview_t));
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
185 tv->is_dot = 1;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
186 tv->fp = bam_open(fn, "r");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
187 bgzf_set_cache_size(tv->fp, 8 * 1024 *1024);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
188 assert(tv->fp);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
189 tv->header = bam_header_read(tv->fp);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
190 tv->idx = bam_index_load(fn);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
191 if (tv->idx == 0) exit(1);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
192 tv->lplbuf = bam_lplbuf_init(tv_pl_func, tv);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
193 if (fn_fa) tv->fai = fai_load(fn_fa);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
194 tv->bmc = bam_maqcns_init();
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
195 tv->ins = 1;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
196 bam_maqcns_prepare(tv->bmc);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
197
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
198 initscr();
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
199 keypad(stdscr, TRUE);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
200 clear();
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
201 noecho();
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
202 cbreak();
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
203 tv->mrow = 24; tv->mcol = 80;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
204 getmaxyx(stdscr, tv->mrow, tv->mcol);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
205 tv->wgoto = newwin(3, TV_MAX_GOTO + 10, 10, 5);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
206 tv->whelp = newwin(29, 40, 5, 5);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
207 tv->color_for = TV_COLOR_MAPQ;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
208 start_color();
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
209 init_pair(1, COLOR_BLUE, COLOR_BLACK);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
210 init_pair(2, COLOR_GREEN, COLOR_BLACK);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
211 init_pair(3, COLOR_YELLOW, COLOR_BLACK);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
212 init_pair(4, COLOR_WHITE, COLOR_BLACK);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
213 init_pair(5, COLOR_GREEN, COLOR_BLACK);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
214 init_pair(6, COLOR_CYAN, COLOR_BLACK);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
215 init_pair(7, COLOR_YELLOW, COLOR_BLACK);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
216 init_pair(8, COLOR_RED, COLOR_BLACK);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
217 init_pair(9, COLOR_BLUE, COLOR_BLACK);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
218 return tv;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
219 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
220
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
221 void tv_destroy(tview_t *tv)
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
222 {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
223 delwin(tv->wgoto); delwin(tv->whelp);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
224 endwin();
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
225
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
226 bam_lplbuf_destroy(tv->lplbuf);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
227 bam_maqcns_destroy(tv->bmc);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
228 bam_index_destroy(tv->idx);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
229 if (tv->fai) fai_destroy(tv->fai);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
230 free(tv->ref);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
231 bam_header_destroy(tv->header);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
232 bam_close(tv->fp);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
233 free(tv);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
234 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
235
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
236 int tv_fetch_func(const bam1_t *b, void *data)
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
237 {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
238 tview_t *tv = (tview_t*)data;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
239 if (tv->no_skip) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
240 uint32_t *cigar = bam1_cigar(b); // this is cheating...
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
241 int i;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
242 for (i = 0; i <b->core.n_cigar; ++i) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
243 if ((cigar[i]&0xf) == BAM_CREF_SKIP)
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
244 cigar[i] = cigar[i]>>4<<4 | BAM_CDEL;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
245 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
246 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
247 bam_lplbuf_push(b, tv->lplbuf);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
248 return 0;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
249 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
250
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
251 int tv_draw_aln(tview_t *tv, int tid, int pos)
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
252 {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
253 // reset
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
254 clear();
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
255 tv->curr_tid = tid; tv->left_pos = pos;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
256 tv->last_pos = tv->left_pos - 1;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
257 tv->ccol = 0;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
258 // print ref and consensus
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
259 if (tv->fai) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
260 char *str;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
261 if (tv->ref) free(tv->ref);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
262 str = (char*)calloc(strlen(tv->header->target_name[tv->curr_tid]) + 30, 1);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
263 sprintf(str, "%s:%d-%d", tv->header->target_name[tv->curr_tid], tv->left_pos + 1, tv->left_pos + tv->mcol);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
264 tv->ref = fai_fetch(tv->fai, str, &tv->l_ref);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
265 free(str);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
266 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
267 // draw aln
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
268 bam_lplbuf_reset(tv->lplbuf);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
269 bam_fetch(tv->fp, tv->idx, tv->curr_tid, tv->left_pos, tv->left_pos + tv->mcol, tv, tv_fetch_func);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
270 bam_lplbuf_push(0, tv->lplbuf);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
271
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
272 while (tv->ccol < tv->mcol) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
273 int pos = tv->last_pos + 1;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
274 if (pos%10 == 0 && tv->mcol - tv->ccol >= 10) mvprintw(0, tv->ccol, "%-d", pos+1);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
275 mvaddch(1, tv->ccol++, (tv->ref && pos < tv->l_ref)? tv->ref[pos - tv->left_pos] : 'N');
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
276 ++tv->last_pos;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
277 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
278 return 0;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
279 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
280
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
281 static void tv_win_goto(tview_t *tv, int *tid, int *pos)
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
282 {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
283 char str[256], *p;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
284 int i, l = 0;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
285 wborder(tv->wgoto, '|', '|', '-', '-', '+', '+', '+', '+');
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
286 mvwprintw(tv->wgoto, 1, 2, "Goto: ");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
287 for (;;) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
288 int c = wgetch(tv->wgoto);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
289 wrefresh(tv->wgoto);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
290 if (c == KEY_BACKSPACE || c == '\010' || c == '\177') {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
291 --l;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
292 } else if (c == KEY_ENTER || c == '\012' || c == '\015') {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
293 int _tid = -1, _beg, _end;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
294 if (str[0] == '=') {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
295 _beg = strtol(str+1, &p, 10) - 1;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
296 if (_beg > 0) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
297 *pos = _beg;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
298 return;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
299 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
300 } else {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
301 bam_parse_region(tv->header, str, &_tid, &_beg, &_end);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
302 if (_tid >= 0) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
303 *tid = _tid; *pos = _beg;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
304 return;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
305 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
306 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
307 } else if (isgraph(c)) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
308 if (l < TV_MAX_GOTO) str[l++] = c;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
309 } else if (c == '\027') l = 0;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
310 else if (c == '\033') return;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
311 str[l] = '\0';
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
312 for (i = 0; i < TV_MAX_GOTO; ++i) mvwaddch(tv->wgoto, 1, 8 + i, ' ');
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
313 mvwprintw(tv->wgoto, 1, 8, "%s", str);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
314 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
315 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
316
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
317 static void tv_win_help(tview_t *tv) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
318 int r = 1;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
319 WINDOW *win = tv->whelp;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
320 wborder(win, '|', '|', '-', '-', '+', '+', '+', '+');
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
321 mvwprintw(win, r++, 2, " -=- Help -=- ");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
322 r++;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
323 mvwprintw(win, r++, 2, "? This window");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
324 mvwprintw(win, r++, 2, "Arrows Small scroll movement");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
325 mvwprintw(win, r++, 2, "h,j,k,l Small scroll movement");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
326 mvwprintw(win, r++, 2, "H,J,K,L Large scroll movement");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
327 mvwprintw(win, r++, 2, "ctrl-H Scroll 1k left");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
328 mvwprintw(win, r++, 2, "ctrl-L Scroll 1k right");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
329 mvwprintw(win, r++, 2, "space Scroll one screen");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
330 mvwprintw(win, r++, 2, "backspace Scroll back one screen");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
331 mvwprintw(win, r++, 2, "g Go to specific location");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
332 mvwprintw(win, r++, 2, "m Color for mapping qual");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
333 mvwprintw(win, r++, 2, "n Color for nucleotide");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
334 mvwprintw(win, r++, 2, "b Color for base quality");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
335 mvwprintw(win, r++, 2, "c Color for cs color");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
336 mvwprintw(win, r++, 2, "z Color for cs qual");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
337 mvwprintw(win, r++, 2, ". Toggle on/off dot view");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
338 mvwprintw(win, r++, 2, "s Toggle on/off ref skip");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
339 mvwprintw(win, r++, 2, "r Toggle on/off rd name");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
340 mvwprintw(win, r++, 2, "N Turn on nt view");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
341 mvwprintw(win, r++, 2, "C Turn on cs view");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
342 mvwprintw(win, r++, 2, "i Toggle on/off ins");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
343 mvwprintw(win, r++, 2, "q Exit");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
344 r++;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
345 mvwprintw(win, r++, 2, "Underline: Secondary or orphan");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
346 mvwprintw(win, r++, 2, "Blue: 0-9 Green: 10-19");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
347 mvwprintw(win, r++, 2, "Yellow: 20-29 White: >=30");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
348 wrefresh(win);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
349 wgetch(win);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
350 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
351
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
352 void tv_loop(tview_t *tv)
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
353 {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
354 int tid, pos;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
355 tid = tv->curr_tid; pos = tv->left_pos;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
356 while (1) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
357 int c = getch();
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
358 switch (c) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
359 case '?': tv_win_help(tv); break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
360 case '\033':
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
361 case 'q': goto end_loop;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
362 case '/':
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
363 case 'g': tv_win_goto(tv, &tid, &pos); break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
364 case 'm': tv->color_for = TV_COLOR_MAPQ; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
365 case 'b': tv->color_for = TV_COLOR_BASEQ; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
366 case 'n': tv->color_for = TV_COLOR_NUCL; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
367 case 'c': tv->color_for = TV_COLOR_COL; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
368 case 'z': tv->color_for = TV_COLOR_COLQ; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
369 case 's': tv->no_skip = !tv->no_skip; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
370 case 'r': tv->show_name = !tv->show_name; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
371 case KEY_LEFT:
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
372 case 'h': --pos; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
373 case KEY_RIGHT:
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
374 case 'l': ++pos; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
375 case KEY_SLEFT:
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
376 case 'H': pos -= 20; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
377 case KEY_SRIGHT:
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
378 case 'L': pos += 20; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
379 case '.': tv->is_dot = !tv->is_dot; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
380 case 'N': tv->base_for = TV_BASE_NUCL; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
381 case 'C': tv->base_for = TV_BASE_COLOR_SPACE; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
382 case 'i': tv->ins = !tv->ins; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
383 case '\010': pos -= 1000; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
384 case '\014': pos += 1000; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
385 case ' ': pos += tv->mcol; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
386 case KEY_UP:
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
387 case 'j': --tv->row_shift; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
388 case KEY_DOWN:
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
389 case 'k': ++tv->row_shift; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
390 case KEY_BACKSPACE:
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
391 case '\177': pos -= tv->mcol; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
392 case KEY_RESIZE: getmaxyx(stdscr, tv->mrow, tv->mcol); break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
393 default: continue;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
394 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
395 if (pos < 0) pos = 0;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
396 if (tv->row_shift < 0) tv->row_shift = 0;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
397 tv_draw_aln(tv, tid, pos);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
398 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
399 end_loop:
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
400 return;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
401 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
402
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
403 int bam_tview_main(int argc, char *argv[])
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
404 {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
405 tview_t *tv;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
406 if (argc == 1) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
407 fprintf(stderr, "Usage: bamtk tview <aln.bam> [ref.fasta]\n");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
408 return 1;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
409 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
410 tv = tv_init(argv[1], (argc == 2)? 0 : argv[2]);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
411 tv_draw_aln(tv, 0, 0);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
412 tv_loop(tv);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
413 tv_destroy(tv);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
414 return 0;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
415 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
416 #else // #ifdef _HAVE_CURSES
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
417 #include <stdio.h>
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
418 #warning "No curses library is available; tview is disabled."
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
419 int bam_tview_main(int argc, char *argv[])
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
420 {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
421 fprintf(stderr, "[bam_tview_main] The ncurses library is unavailable; tview is not compiled.\n");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
422 return 1;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
423 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
424 #endif // #ifdef _HAVE_CURSES