  				if (e_min - b_max >= min_l * opt->mask_level) { // significant overlap
  					if (a[j].sub == 0) a[j].sub = a[i].score;
  					if (a[j].score - a[i].score <= tmp && (a[j].is_alt || !a[i].is_alt))
-@@ -838,6 +840,7 @@ void mem_aln2sam(const mem_opt_t *opt, c
- 	ks_resize(str, str->l + s->l_seq + l_name + (s->qual? s->l_seq : 0) + 20);
- 	kputsn(s->name, l_name, str); kputc('\t', str); // QNAME
- 	kputw((p->flag&0xffff) | (p->flag&0x10000? 0x100 : 0), str); kputc('\t', str); // FLAG
-+	int ngaps = 0, nextends = 0;
- 	if (p->rid >= 0) { // with coordinate
- 		kputs(bns->anns[p->rid].name, str); kputc('\t', str); // RNAME
- 		kputl(p->pos + 1, str); kputc('\t', str); // POS
-@@ -847,6 +850,10 @@ void mem_aln2sam(const mem_opt_t *opt, c
- 				int c = p->cigar[i]&0xf;
- 				if (!(opt->flag&MEM_F_SOFTCLIP) && !p->is_alt && (c == 3 || c == 4))
- 					c = which? 4 : 3; // use hard clipping for supplementary alignments
-+				if(c == 1 || c == 2) {
-+					ngaps++;
-+					nextends += (p->cigar[i] >> 4);
-+				}
- 				kputw(p->cigar[i]>>4, str); kputc("MIDSH"[c], str);
- 			}
- 		} else kputc('*', str); // having a coordinate but unaligned (e.g. when copy_mate is true)
-@@ -942,6 +949,54 @@ void mem_aln2sam(const mem_opt_t *opt, c
+@@ -942,6 +944,48 @@ void mem_aln2sam(const mem_opt_t *opt, c
  		for (i = tmp; i < str->l; ++i) // replace TAB in the comment to SPACE
  			if (str->s[i] == '\t') str->s[i] = ' ';
  	}

+			kputsn("NA", 2, str);
+		}
+		kputc(',', str);
+		kputw(ngaps, str); // ztz2
+		kputc(',', str);
+		kputw(nextends, str); // ztz3
+		kputc(',', str);
+		if(p->sub >= 0) {
+			kputw(p->score - p->sub, str); // ztz4
+		} else {
+			kputsn("NA", 2, str);
+		}
+		kputc(',', str);
+		kputw(p->osub, str); // ztz5
+		kputc(',', str);
+		kputw(p->pair_score, str); // ztz6
+		kputc(',', str);
+		if(p->pair_sub >= 0) {
+			kputw(p->pair_score - p->pair_sub, str); // ztz7
+		} else {
+			kputsn("NA", 2, str);
+		}
+		kputc(',', str);
+		kputw(p->n_comp, str); // ztz8
+		kputc(',', str);
+		kputw(p->seedlen0, str); // ztz9
+		kputc(',', str);
+		kputw(p->sub_n, str); // ztz10
+		kputc(',', str);
+		kputw(p->osub_n, str); // ztz11
+		kputc(',', str);
+		kputw(p->pair_nsub, str); // ztz12
+		kputc(',', str);
+		kputw((int)(p->frac_rep * 1000.0), str); // ztz13
+		kputc(',', str);
+		kputw((int)(p->pair_frac_rep * 1000.0), str); // ztz14
+		kputc(',', str);
+		kputw((int)(p->seedcov * 1000.0), str); // ztz15
+		kputc(',', str);
+		kputw((int)(p->pair_seedcov * 1000.0), str); // ztz16
+	}
 	kputc('\n', str);
 }
 
@@ -1129,8 +1184,17 @@ mem_aln_t mem_reg2aln(const mem_opt_t *o
 	a.rid = bns_pos2rid(bns, pos);
 	assert(a.rid == ar->rid);
 	a.pos = pos - bns->anns[a.rid].offset;

diff -rupN -x Xcode -x .git bwa/bwamem.c bwa-mod/bwamem.c
--- bwa/bwamem.c	2015-07-08 13:14:28.000000000 -0400
+++ bwa-mod/bwamem.c	2016-07-30 16:22:05.000000000 -0400
@@ -512,6 +512,8 @@ static void mem_mark_primary_se_core(con
 			int e_min = a[j].qe < a[i].qe? a[j].qe : a[i].qe;
 			if (e_min > b_max) { // have overlap
