From: Heng Li <lh3@live.co.uk>
Date: Fri, 31 Jul 2009 09:19:59 +0000 (+0000)
Subject:  * samtools-0.1.5-18 (r423)
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=2ec779405b1f89e1407c24956bbb3af584234bc9;p=samtools.git

 * samtools-0.1.5-18 (r423)
 * output additional information in pileup indel lines, for the purepose
   of debugging at the moment
 * in tview, optionally allow to treat reference skip as deletion
---

diff --git a/bam_maqcns.c b/bam_maqcns.c
index 464288a..f36b0ee 100644
--- a/bam_maqcns.c
+++ b/bam_maqcns.c
@@ -439,7 +439,7 @@ bam_maqindel_ret_t *bam_maqindel(int n, int pos, const bam_maqindel_opt_t *mi, c
 				}
 				if (score[i*n+j] < s) score[i*n+j] = s; // choose the higher of the two scores
 				if (pscore[i*n+j] > ps) pscore[i*n+j] = ps;
-				if (types[i] != 0) score[i*n+j] -= mi->indel_err;
+				//if (types[i] != 0) score[i*n+j] -= mi->indel_err;
 				//printf("%d, %d, %d, %d, %d, %d, %d\n", p->b->core.pos + 1, seg.qbeg, i, types[i], j,
 				//	   score[i*n+j], pscore[i*n+j]);
 			}
@@ -499,6 +499,15 @@ bam_maqindel_ret_t *bam_maqindel(int n, int pos, const bam_maqindel_opt_t *mi, c
 				if (s1 > s2) ret->gl[0] += s1 - s2 < mi->q_indel? s1 - s2 : mi->q_indel;
 				else ret->gl[1] += s2 - s1 < mi->q_indel? s2 - s1 : mi->q_indel;
 			}
+			// write cnt_ref and cnt_ambi
+			if (max1_i != 0 && max2_i != 0) {
+				for (j = 0; j < n; ++j) {
+					int diff1 = score[j] - score[max1_i * n + j];
+					int diff2 = score[j] - score[max2_i * n + j];
+					if (diff1 > 0 && diff2 > 0) ++ret->cnt_ref;
+					else if (diff1 == 0 || diff2 == 0) ++ret->cnt_ambi;
+				}
+			}
 		}
 		free(score); free(pscore); free(ref2); free(inscns);
 	}
diff --git a/bam_maqcns.h b/bam_maqcns.h
index 36704d7..2a82aee 100644
--- a/bam_maqcns.h
+++ b/bam_maqcns.h
@@ -24,7 +24,8 @@ typedef struct {
 
 typedef struct {
 	int indel1, indel2;
-	int cnt1, cnt2, cnt_ambi, cnt_anti;
+	int cnt1, cnt2, cnt_anti;
+	int cnt_ref, cnt_ambi;
 	char *s[2];
 	//
 	int gt, gl[2];
diff --git a/bam_plcmd.c b/bam_plcmd.c
index 391767a..5bf1ed0 100644
--- a/bam_plcmd.c
+++ b/bam_plcmd.c
@@ -284,7 +284,8 @@ static int pileup_func(uint32_t tid, uint32_t pos, int n, const bam_pileup1_t *p
 		printf("%d\t%d\t", rms_mapq, n);
 		printf("%s\t%s\t", r->s[0], r->s[1]);
 		//printf("%d\t%d\t", r->gl[0], r->gl[1]);
-		printf("%d\t%d\t%d\n", r->cnt1, r->cnt2, r->cnt_anti);
+		printf("%d\t%d\t%d\t", r->cnt1, r->cnt2, r->cnt_anti);
+		printf("%d\t%d\n", r->cnt_ref, r->cnt_ambi);
 		bam_maqindel_ret_destroy(r);
 	}
 	return 0;
diff --git a/bam_tview.c b/bam_tview.c
index 441a1b4..019e377 100644
--- a/bam_tview.c
+++ b/bam_tview.c
@@ -52,7 +52,7 @@ typedef struct {
 	faidx_t *fai;
 	bam_maqcns_t *bmc;
 
-	int ccol, last_pos, row_shift, base_for, color_for, is_dot, l_ref, ins;
+	int ccol, last_pos, row_shift, base_for, color_for, is_dot, l_ref, ins, no_skip;
 	char *ref;
 } tview_t;
 
@@ -195,7 +195,7 @@ tview_t *tv_init(const char *fn, const char *fn_fa)
 	tv->mrow = 24; tv->mcol = 80;
 	getmaxyx(stdscr, tv->mrow, tv->mcol);
 	tv->wgoto = newwin(3, TV_MAX_GOTO + 10, 10, 5);
-	tv->whelp = newwin(27, 40, 5, 5);
+	tv->whelp = newwin(28, 40, 5, 5);
 	tv->color_for = TV_COLOR_MAPQ;
 	start_color();
 	init_pair(1, COLOR_BLUE, COLOR_BLACK);
@@ -228,6 +228,14 @@ void tv_destroy(tview_t *tv)
 int tv_fetch_func(const bam1_t *b, void *data)
 {
 	tview_t *tv = (tview_t*)data;
+	if (tv->no_skip) {
+		uint32_t *cigar = bam1_cigar(b); // this is cheating...
+		int i;
+		for (i = 0; i <b->core.n_cigar; ++i) {
+			if ((cigar[i]&0xf) == BAM_CREF_SKIP)
+				cigar[i] = cigar[i]>>4<<4 | BAM_CDEL;
+		}
+	}
 	bam_lplbuf_push(b, tv->lplbuf);
 	return 0;
 }
@@ -311,6 +319,7 @@ static void tv_win_help(tview_t *tv) {
 	mvwprintw(win, r++, 2, "c          Color for cs color");
 	mvwprintw(win, r++, 2, "z          Color for cs qual");
 	mvwprintw(win, r++, 2, ".          Toggle on/off dot view");
+	mvwprintw(win, r++, 2, "s          Toggle on/off ref skip");
 	mvwprintw(win, r++, 2, "N          Turn on nt view");
 	mvwprintw(win, r++, 2, "C          Turn on cs view");
 	mvwprintw(win, r++, 2, "i          Toggle on/off ins");
@@ -339,6 +348,7 @@ void tv_loop(tview_t *tv)
 			case 'n': tv->color_for = TV_COLOR_NUCL; break;
 			case 'c': tv->color_for = TV_COLOR_COL; break;
 			case 'z': tv->color_for = TV_COLOR_COLQ; break;
+			case 's': tv->no_skip = !tv->no_skip; break;
 			case KEY_LEFT:
 			case 'h': --pos; break;
 			case KEY_RIGHT:
diff --git a/bamtk.c b/bamtk.c
index 9e76673..f827aec 100644
--- a/bamtk.c
+++ b/bamtk.c
@@ -4,7 +4,7 @@
 #include "bam.h"
 
 #ifndef PACKAGE_VERSION
-#define PACKAGE_VERSION "0.1.5-17 (r422)"
+#define PACKAGE_VERSION "0.1.5-18 (r423)"
 #endif
 
 int bam_taf2baf(int argc, char *argv[]);
diff --git a/misc/samtools.pl b/misc/samtools.pl
index 06c24dc..ade5289 100755
--- a/misc/samtools.pl
+++ b/misc/samtools.pl
@@ -24,6 +24,7 @@ sub showALEN {
   die(qq/Usage: samtools.pl showALEN <in.sam>\n/) if (@ARGV == 0 && -t STDIN);
   while (<>) {
 	my @t = split;
+	next if (/^\@/ || @t < 11);
 	my $l = 0;
 	$_ = $t[5];
 	s/(\d+)[SMI]/$l+=$1/eg;