Skip to content

Commit 1bdd791

Browse files
committedSep 16, 2014
r837: removed BAM support
This is not necessary.
1 parent 7244d66 commit 1bdd791

12 files changed

+24
-268
lines changed
 

‎Makefile

+3-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ CC= gcc
22
#CC= clang --analyze
33
CFLAGS= -g -Wall -Wno-unused-function -O2
44
WRAP_MALLOC=-DUSE_MALLOC_WRAPPERS
5-
HTSLIB_PATH=
65
AR= ar
76
DFLAGS= -DHAVE_PTHREAD $(WRAP_MALLOC)
87
LOBJS= utils.o kthread.o kstring.o ksw.o bwt.o bntseq.o bwa.o bwamem.o bwamem_pair.o bwamem_extra.o malloc_wrap.o
@@ -18,27 +17,15 @@ SUBDIRS= .
1817
.SUFFIXES:.c .o .cc
1918

2019
.c.o:
21-
ifneq ($(HTSLIB_PATH),)
22-
$(CC) -c $(CFLAGS) $(DFLAGS) -DUSE_HTSLIB $(INCLUDES) -I$(HTSLIB_PATH) $< -o $@
23-
else
24-
$(CC) -c $(CFLAGS) $(DFLAGS) $(INCLUDES) $< -o $@
25-
endif
20+
$(CC) -c $(CFLAGS) $(DFLAGS) $(INCLUDES) $< -o $@
2621

2722
all:$(PROG)
2823

2924
bwa:libbwa.a $(AOBJS) main.o
30-
ifneq ($(HTSLIB_PATH),)
31-
$(CC) $(CFLAGS) $(DFLAGS) $(AOBJS) main.o -o $@ $(HTSLIB_PATH)/libhts.a -L. -lbwa $(LIBS)
32-
else
33-
$(CC) $(CFLAGS) $(DFLAGS) $(AOBJS) main.o -o $@ -L. -lbwa $(LIBS)
34-
endif
25+
$(CC) $(CFLAGS) $(DFLAGS) $(AOBJS) main.o -o $@ -L. -lbwa $(LIBS)
3526

3627
bwamem-lite:libbwa.a example.o
37-
ifneq ($(HTSLIB_PATH),)
38-
$(CC) $(CFLAGS) $(DFLAGS) example.o -o $@ $(HTSLIB_PATH)/libhts.a -L. -lbwa $(LIBS)
39-
else
40-
$(CC) $(CFLAGS) $(DFLAGS) example.o -o $@ -L. -lbwa $(LIBS)
41-
endif
28+
$(CC) $(CFLAGS) $(DFLAGS) example.o -o $@ -L. -lbwa $(LIBS)
4229

4330
libbwa.a:$(LOBJS)
4431
$(AR) -csru $@ $(LOBJS)

‎bamlite.c

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#ifndef USE_HTSLIB
21
#include <stdlib.h>
32
#include <ctype.h>
43
#include <string.h>
@@ -209,4 +208,3 @@ int bamlite_gzclose(gzFile file) {
209208
return ret;
210209
}
211210
#endif /* USE_VERBOSE_ZLIB_WRAPPERS */
212-
#endif

‎bamlite.h

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#ifndef BAMLITE_H_
22
#define BAMLITE_H_
3-
#ifndef USE_HTSLIB
43

54
#include <stdint.h>
65
#include <zlib.h>
@@ -113,4 +112,3 @@ extern "C" {
113112
#endif
114113

115114
#endif
116-
#endif

‎bwa.c

-41
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
#include "ksw.h"
88
#include "utils.h"
99
#include "kstring.h"
10-
#ifdef USE_HTSLIB
11-
#include <htslib/sam.h>
12-
#endif
1310

1411
#ifdef USE_MALLOC_WRAPPERS
1512
# include "malloc_wrap.h"
@@ -271,27 +268,12 @@ void bwa_print_sam_hdr(const bntseq_t *bns, const char *rg_line)
271268
{
272269
int i;
273270
extern char *bwa_pg;
274-
err_printf("@HD\tVN:1.4\tSO:unknown\n");
275271
for (i = 0; i < bns->n_seqs; ++i)
276272
err_printf("@SQ\tSN:%s\tLN:%d\n", bns->anns[i].name, bns->anns[i].len);
277273
if (rg_line) err_printf("%s\n", rg_line);
278274
err_printf("%s\n", bwa_pg);
279275
}
280276

281-
#ifdef USE_HTSLIB
282-
void bwa_format_sam_hdr(const bntseq_t *bns, const char *rg_line, kstring_t *str)
283-
{
284-
int i;
285-
extern char *bwa_pg;
286-
str->l = 0; str->s = 0;
287-
ksprintf(str, "@HD\tVN:1.4\tSO:unknown\n");
288-
for (i = 0; i < bns->n_seqs; ++i)
289-
ksprintf(str, "@SQ\tSN:%s\tLN:%d\n", bns->anns[i].name, bns->anns[i].len);
290-
if (rg_line) ksprintf(str, "%s\n", rg_line);
291-
ksprintf(str, "%s\n", bwa_pg);
292-
}
293-
#endif
294-
295277
static char *bwa_escape(char *s)
296278
{
297279
char *p, *q;
@@ -337,26 +319,3 @@ char *bwa_set_rg(const char *s)
337319
return 0;
338320
}
339321

340-
#ifdef USE_HTSLIB
341-
bams_t *bams_init() {
342-
return calloc(1, sizeof(bams_t));
343-
}
344-
345-
void bams_add(bams_t *bams, bam1_t *b) {
346-
if (bams->m == bams->l) {
347-
bams->m = bams->m << 2;
348-
bams->bams = realloc(bams->bams, sizeof(bam1_t) * bams->m);
349-
}
350-
bams->bams[bams->l] = b;
351-
bams->l++;
352-
}
353-
354-
void bams_destroy(bams_t *bams) {
355-
int i;
356-
for (i = 0; i < bams->l; i++) {
357-
bam_destroy1(bams->bams[i]);
358-
}
359-
free(bams->bams);
360-
free(bams);
361-
}
362-
#endif

‎bwa.h

-32
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
#include <stdint.h>
55
#include "bntseq.h"
66
#include "bwt.h"
7-
#ifdef USE_HTSLIB
8-
#include <htslib/sam.h>
9-
#endif
107

118
#define BWA_IDX_BWT 0x1
129
#define BWA_IDX_BNS 0x2
@@ -19,31 +16,11 @@ typedef struct {
1916
uint8_t *pac; // the actual 2-bit encoded reference sequences with 'N' converted to a random base
2017
} bwaidx_t;
2118

22-
#ifdef USE_HTSLIB
23-
typedef struct {
24-
int l, m;
25-
bam1_t **bams;
26-
} bams_t;
27-
#endif
28-
2919
typedef struct {
3020
int l_seq;
31-
#ifdef USE_HTSLIB
32-
char *name, *comment, *seq, *qual;
33-
bams_t *bams;
34-
#else
3521
char *name, *comment, *seq, *qual, *sam;
36-
#endif
3722
} bseq1_t;
3823

39-
// This is here to faciliate passing around HTSLIB's bam_hdr_t structure when we are not compiling with HTSLIB
40-
#ifndef USE_HTSLIB
41-
typedef struct {
42-
void *ptr;
43-
} bam_hdr_t; // DO NOT USE
44-
#endif
45-
46-
4724
extern int bwa_verbose;
4825
extern char bwa_rg_id[256];
4926

@@ -64,17 +41,8 @@ extern "C" {
6441
void bwa_idx_destroy(bwaidx_t *idx);
6542

6643
void bwa_print_sam_hdr(const bntseq_t *bns, const char *rg_line);
67-
#ifdef USE_HTSLIB
68-
void bwa_format_sam_hdr(const bntseq_t *bns, const char *rg_line, kstring_t *str);
69-
#endif
7044
char *bwa_set_rg(const char *s);
7145

72-
#ifdef USE_HTSLIB
73-
bams_t *bams_init();
74-
void bams_add(bams_t *bams, bam1_t *b);
75-
void bams_destroy(bams_t *bams);
76-
#endif
77-
7846
#ifdef __cplusplus
7947
}
8048
#endif

‎bwamem.c

+8-37
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
#include "ksort.h"
1717
#include "utils.h"
1818

19-
#ifdef USE_HTSLIB
20-
#include <htslib/sam.h>
21-
#endif
22-
2319
#ifdef USE_MALLOC_WRAPPERS
2420
# include "malloc_wrap.h"
2521
#endif
@@ -787,7 +783,7 @@ static inline int get_rlen(int n_cigar, const uint32_t *cigar)
787783
return l;
788784
}
789785

790-
void mem_aln2sam(const mem_opt_t *opt, const bntseq_t *bns, kstring_t *str, bseq1_t *s, int n, const mem_aln_t *list, int which, const mem_aln_t *m_, bam_hdr_t *h)
786+
void mem_aln2sam(const mem_opt_t *opt, const bntseq_t *bns, kstring_t *str, bseq1_t *s, int n, const mem_aln_t *list, int which, const mem_aln_t *m_)
791787
{
792788
int i, l_name;
793789
mem_aln_t ptmp = list[which], *p = &ptmp, mtmp, *m = 0; // make a copy of the alignment to convert
@@ -912,15 +908,6 @@ void mem_aln2sam(const mem_opt_t *opt, const bntseq_t *bns, kstring_t *str, bseq
912908
if (str->s[i] == '\t') str->s[i] = ' ';
913909
}
914910
kputc('\n', str);
915-
916-
#ifdef USE_HTSLIB
917-
bam1_t *b = bam_init1();
918-
if (sam_parse1(str, h, b) < 0) {
919-
// TODO: error!
920-
}
921-
bams_add(s->bams, b);
922-
str->l = 0; str->s = 0;
923-
#endif
924911
}
925912

926913
/************************
@@ -954,7 +941,7 @@ int mem_approx_mapq_se(const mem_opt_t *opt, const mem_alnreg_t *a)
954941
}
955942

956943
// TODO (future plan): group hits into a uint64_t[] array. This will be cleaner and more flexible
957-
void mem_reg2sam(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, bseq1_t *s, mem_alnreg_v *a, int extra_flag, const mem_aln_t *m, bam_hdr_t *h)
944+
void mem_reg2sam(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, bseq1_t *s, mem_alnreg_v *a, int extra_flag, const mem_aln_t *m)
958945
{
959946
extern char **mem_gen_alt(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, mem_alnreg_v *a, int l_query, const char *query);
960947
kstring_t str;
@@ -986,16 +973,14 @@ void mem_reg2sam(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac,
986973
mem_aln_t t;
987974
t = mem_reg2aln(opt, bns, pac, s->l_seq, s->seq, 0);
988975
t.flag |= extra_flag;
989-
mem_aln2sam(opt, bns, &str, s, 1, &t, 0, m, h);
976+
mem_aln2sam(opt, bns, &str, s, 1, &t, 0, m);
990977
} else {
991978
for (k = 0; k < aa.n; ++k)
992-
mem_aln2sam(opt, bns, &str, s, aa.n, aa.a, k, m, h);
979+
mem_aln2sam(opt, bns, &str, s, aa.n, aa.a, k, m);
993980
for (k = 0; k < aa.n; ++k) free(aa.a[k].cigar);
994981
free(aa.a);
995982
}
996-
#ifndef USE_HTSLIB
997983
s->sam = str.s;
998-
#endif
999984
if (XA) {
1000985
for (k = 0; k < a->n; ++k) free(XA[k]);
1001986
free(XA);
@@ -1123,7 +1108,6 @@ typedef struct {
11231108
bseq1_t *seqs;
11241109
mem_alnreg_v *regs;
11251110
int64_t n_processed;
1126-
bam_hdr_t *h;
11271111
} worker_t;
11281112

11291113
static void worker1(void *data, int i, int tid)
@@ -1142,33 +1126,26 @@ static void worker1(void *data, int i, int tid)
11421126

11431127
static void worker2(void *data, int i, int tid)
11441128
{
1145-
extern int mem_sam_pe(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, const mem_pestat_t pes[4], uint64_t id, bseq1_t s[2], mem_alnreg_v a[2], bam_hdr_t *h);
1129+
extern int mem_sam_pe(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, const mem_pestat_t pes[4], uint64_t id, bseq1_t s[2], mem_alnreg_v a[2]);
11461130
extern void mem_reg2ovlp(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, bseq1_t *s, mem_alnreg_v *a);
11471131
worker_t *w = (worker_t*)data;
11481132
if (!(w->opt->flag&MEM_F_PE)) {
1149-
#ifdef USE_HTSLIB
1150-
w->seqs[i].bams = bams_init();
1151-
#endif
11521133
if (bwa_verbose >= 4) printf("=====> Finalizing read '%s' <=====\n", w->seqs[i].name);
11531134
if (w->opt->flag & MEM_F_ALN_REG) {
11541135
mem_reg2ovlp(w->opt, w->bns, w->pac, &w->seqs[i], &w->regs[i]);
11551136
} else {
11561137
mem_mark_primary_se(w->opt, w->regs[i].n, w->regs[i].a, w->n_processed + i);
1157-
mem_reg2sam(w->opt, w->bns, w->pac, &w->seqs[i], &w->regs[i], 0, 0, w->h);
1138+
mem_reg2sam(w->opt, w->bns, w->pac, &w->seqs[i], &w->regs[i], 0, 0);
11581139
}
11591140
free(w->regs[i].a);
11601141
} else {
11611142
if (bwa_verbose >= 4) printf("=====> Finalizing read pair '%s' <=====\n", w->seqs[i<<1|0].name);
1162-
#ifdef USE_HTSLIB
1163-
w->seqs[i<<1].bams = bams_init();
1164-
w->seqs[1+(i<<1)].bams = bams_init();
1165-
#endif
1166-
mem_sam_pe(w->opt, w->bns, w->pac, w->pes, (w->n_processed>>1) + i, &w->seqs[i<<1], &w->regs[i<<1], w->h);
1143+
mem_sam_pe(w->opt, w->bns, w->pac, w->pes, (w->n_processed>>1) + i, &w->seqs[i<<1], &w->regs[i<<1]);
11671144
free(w->regs[i<<1|0].a); free(w->regs[i<<1|1].a);
11681145
}
11691146
}
11701147

1171-
void mem_process_seqs2(const mem_opt_t *opt, const bwt_t *bwt, const bntseq_t *bns, const uint8_t *pac, int64_t n_processed, int n, bseq1_t *seqs, const mem_pestat_t *pes0, bam_hdr_t *h)
1148+
void mem_process_seqs(const mem_opt_t *opt, const bwt_t *bwt, const bntseq_t *bns, const uint8_t *pac, int64_t n_processed, int n, bseq1_t *seqs, const mem_pestat_t *pes0)
11721149
{
11731150
extern void kt_for(int n_threads, void (*func)(void*,int,int), void *data, int n);
11741151
worker_t w;
@@ -1185,7 +1162,6 @@ void mem_process_seqs2(const mem_opt_t *opt, const bwt_t *bwt, const bntseq_t *b
11851162
w.aux = malloc(opt->n_threads * sizeof(smem_aux_t));
11861163
for (i = 0; i < opt->n_threads; ++i)
11871164
w.aux[i] = smem_aux_init();
1188-
w.h = h;
11891165
kt_for(opt->n_threads, worker1, &w, (opt->flag&MEM_F_PE)? n>>1 : n); // find mapping positions
11901166
for (i = 0; i < opt->n_threads; ++i)
11911167
smem_aux_destroy(w.aux[i]);
@@ -1199,8 +1175,3 @@ void mem_process_seqs2(const mem_opt_t *opt, const bwt_t *bwt, const bntseq_t *b
11991175
if (bwa_verbose >= 3)
12001176
fprintf(stderr, "[M::%s] Processed %d reads in %.3f CPU sec, %.3f real sec\n", __func__, n, cputime() - ctime, realtime() - rtime);
12011177
}
1202-
1203-
void mem_process_seqs(const mem_opt_t *opt, const bwt_t *bwt, const bntseq_t *bns, const uint8_t *pac, int64_t n_processed, int n, bseq1_t *seqs, const mem_pestat_t *pes0)
1204-
{
1205-
mem_process_seqs2(opt, bwt, bns, pac, n_processed, n, seqs, pes0, 0);
1206-
}

‎bwamem.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ typedef struct {
5353
int max_matesw; // perform maximally max_matesw rounds of mate-SW for each end
5454
int max_hits; // if there are max_hits or fewer, output them all
5555
int8_t mat[25]; // scoring matrix; mat[0] == 0 if unset
56-
#ifdef USE_HTSLIB
57-
int bam_output;
58-
#endif
5956
} mem_opt_t;
6057

6158
typedef struct {
@@ -130,10 +127,8 @@ extern "C" {
130127
* @param seqs query sequences; $seqs[i].seq/sam to be modified after the call
131128
* @param pes0 insert-size info; if NULL, infer from data; if not NULL, it should be an array with 4 elements,
132129
* corresponding to each FF, FR, RF and RR orientation. See mem_pestat() for more info.
133-
* @param h the BAM header, NULL if not using HTSLIB
134130
*/
135131
void mem_process_seqs(const mem_opt_t *opt, const bwt_t *bwt, const bntseq_t *bns, const uint8_t *pac, int64_t n_processed, int n, bseq1_t *seqs, const mem_pestat_t *pes0);
136-
void mem_process_seqs2(const mem_opt_t *opt, const bwt_t *bwt, const bntseq_t *bns, const uint8_t *pac, int64_t n_processed, int n, bseq1_t *seqs, const mem_pestat_t *pes0, bam_hdr_t *h);
137132

138133
/**
139134
* Find the aligned regions for one query sequence
@@ -165,6 +160,7 @@ extern "C" {
165160
* @return CIGAR, strand, mapping quality and forward-strand position
166161
*/
167162
mem_aln_t mem_reg2aln(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, int l_seq, const char *seq, const mem_alnreg_t *ar);
163+
mem_aln_t mem_reg2aln2(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, int l_seq, const char *seq, const mem_alnreg_t *ar, const char *name);
168164

169165
/**
170166
* Infer the insert size distribution from interleaved alignment regions

‎bwamem_extra.c

-12
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,7 @@ mem_alnreg_v mem_align1(const mem_opt_t *opt, const bwt_t *bwt, const bntseq_t *
9393
return ar;
9494
}
9595

96-
#ifdef USE_HTSLIB
97-
void mem_reg2ovlp(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, bseq1_t *s, mem_alnreg_v *a, bam_hdr_t *h)
98-
#else
9996
void mem_reg2ovlp(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, bseq1_t *s, mem_alnreg_v *a)
100-
#endif
10197
{
10298
int i;
10399
kstring_t str = {0,0,0};
@@ -119,15 +115,7 @@ void mem_reg2ovlp(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac,
119115
ksprintf(&str, "%.3f", (double)p->truesc / opt->a / (qe - qb > re - rb? qe - qb : re - rb));
120116
kputc('\n', &str);
121117
}
122-
#ifdef USE_HTSLIB
123-
bam1_t *b = bam_init1();
124-
if (sam_parse1(&str, h, b) < 0) {
125-
// TODO: error!
126-
}
127-
bams_add(s->bams, b);
128-
#else
129118
s->sam = str.s;
130-
#endif
131119
}
132120

133121
// Okay, returning strings is bad, but this has happened a lot elsewhere. If I have time, I need serious code cleanup.

‎bwamem_pair.c

+7-13
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,12 @@ int mem_pair(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, cons
242242

243243
#define raw_mapq(diff, a) ((int)(6.02 * (diff) / (a) + .499))
244244

245-
int mem_sam_pe(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, const mem_pestat_t pes[4], uint64_t id, bseq1_t s[2], mem_alnreg_v a[2], bam_hdr_t *header)
245+
int mem_sam_pe(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, const mem_pestat_t pes[4], uint64_t id, bseq1_t s[2], mem_alnreg_v a[2])
246246
{
247247
extern int mem_mark_primary_se(const mem_opt_t *opt, int n, mem_alnreg_t *a, int64_t id);
248248
extern int mem_approx_mapq_se(const mem_opt_t *opt, const mem_alnreg_t *a);
249-
extern void mem_reg2sam(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, bseq1_t *s, mem_alnreg_v *a, int extra_flag, const mem_aln_t *m, bam_hdr_t *h);
250-
extern void mem_aln2sam(const mem_opt_t *opt, const bntseq_t *bns, kstring_t *str, bseq1_t *s, int n, const mem_aln_t *list, int which, const mem_aln_t *m, bam_hdr_t *h);
249+
extern void mem_reg2sam(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, bseq1_t *s, mem_alnreg_v *a, int extra_flag, const mem_aln_t *m);
250+
extern void mem_aln2sam(const mem_opt_t *opt, const bntseq_t *bns, kstring_t *str, bseq1_t *s, int n, const mem_aln_t *list, int which, const mem_aln_t *m);
251251
extern char **mem_gen_alt(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, const mem_alnreg_v *a, int l_query, const char *query);
252252

253253
int n = 0, i, j, z[2], o, subo, n_sub, extra_flag = 1, n_pri[2];
@@ -327,14 +327,8 @@ int mem_sam_pe(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, co
327327
// write SAM
328328
h[0] = mem_reg2aln(opt, bns, pac, s[0].l_seq, s[0].seq, &a[0].a[z[0]]); h[0].mapq = q_se[0]; h[0].flag |= 0x40 | extra_flag; h[0].XA = XA[0]? XA[0][z[0]] : 0;
329329
h[1] = mem_reg2aln(opt, bns, pac, s[1].l_seq, s[1].seq, &a[1].a[z[1]]); h[1].mapq = q_se[1]; h[1].flag |= 0x80 | extra_flag; h[1].XA = XA[1]? XA[1][z[1]] : 0;
330-
mem_aln2sam(opt, bns, &str, &s[0], 1, &h[0], 0, &h[1], header);
331-
#ifndef USE_HTSLIB
332-
s[0].sam = strdup(str.s); str.l = 0;
333-
#endif
334-
mem_aln2sam(opt, bns, &str, &s[1], 1, &h[1], 0, &h[0], header);
335-
#ifndef USE_HTSLIB
336-
s[1].sam = str.s;
337-
#endif
330+
mem_aln2sam(opt, bns, &str, &s[0], 1, &h[0], 0, &h[1]); s[0].sam = strdup(str.s); str.l = 0;
331+
mem_aln2sam(opt, bns, &str, &s[1], 1, &h[1], 0, &h[0]); s[1].sam = str.s;
338332
if (strcmp(s[0].name, s[1].name) != 0) err_fatal(__func__, "paired reads have different names: \"%s\", \"%s\"\n", s[0].name, s[1].name);
339333
free(h[0].cigar); // h[0].XA will be freed in the following block
340334
free(h[1].cigar);
@@ -360,8 +354,8 @@ int mem_sam_pe(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, co
360354
d = mem_infer_dir(bns->l_pac, a[0].a[0].rb, a[1].a[0].rb, &dist);
361355
if (!pes[d].failed && dist >= pes[d].low && dist <= pes[d].high) extra_flag |= 2;
362356
}
363-
mem_reg2sam(opt, bns, pac, &s[0], &a[0], 0x41|extra_flag, &h[1], header);
364-
mem_reg2sam(opt, bns, pac, &s[1], &a[1], 0x81|extra_flag, &h[0], header);
357+
mem_reg2sam(opt, bns, pac, &s[0], &a[0], 0x41|extra_flag, &h[1]);
358+
mem_reg2sam(opt, bns, pac, &s[1], &a[1], 0x81|extra_flag, &h[0]);
365359
if (strcmp(s[0].name, s[1].name) != 0) err_fatal(__func__, "paired reads have different names: \"%s\", \"%s\"\n", s[0].name, s[1].name);
366360
free(h[0].cigar); free(h[1].cigar);
367361
return n;

‎bwaseqio.c

-44
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
#include <ctype.h>
33
#include "bwtaln.h"
44
#include "utils.h"
5-
#ifdef USE_HTSLIB
6-
#include <htslib/sam.h>
7-
#else
85
#include "bamlite.h"
9-
#endif
106

117
#include "kseq.h"
128
KSEQ_DECLARE(gzFile)
@@ -21,37 +17,22 @@ static char bam_nt16_nt4_table[] = { 4, 0, 1, 4, 2, 4, 4, 4, 3, 4, 4, 4, 4, 4, 4
2117
struct __bwa_seqio_t {
2218
// for BAM input
2319
int is_bam, which; // 1st bit: read1, 2nd bit: read2, 3rd: SE
24-
#ifdef USE_HTSLIB
25-
samFile *fp;
26-
bam_hdr_t *h;
27-
#else
2820
bamFile fp;
29-
#endif
3021
// for fastq input
3122
kseq_t *ks;
3223
};
3324

3425
bwa_seqio_t *bwa_bam_open(const char *fn, int which)
3526
{
3627
bwa_seqio_t *bs;
37-
#ifndef USE_HTSLIB
3828
bam_header_t *h;
39-
#endif
4029
bs = (bwa_seqio_t*)calloc(1, sizeof(bwa_seqio_t));
4130
bs->is_bam = 1;
4231
bs->which = which;
43-
#ifdef USE_HTSLIB
44-
bs->fp = sam_open(fn, "rb");
45-
#else
4632
bs->fp = bam_open(fn, "r");
47-
#endif
4833
if (0 == bs->fp) err_fatal_simple("Couldn't open bam file");
49-
#ifdef USE_HTSLIB
50-
bs->h = sam_hdr_read(bs->fp);
51-
#else
5234
h = bam_header_read(bs->fp);
5335
bam_header_destroy(h);
54-
#endif
5536
return bs;
5637
}
5738

@@ -69,12 +50,7 @@ void bwa_seq_close(bwa_seqio_t *bs)
6950
{
7051
if (bs == 0) return;
7152
if (bs->is_bam) {
72-
#ifdef USE_HTSLIB
73-
if (0 != sam_close(bs->fp)) err_fatal_simple("Error closing sam/bam file");
74-
bam_hdr_destroy(bs->h);
75-
#else
7653
if (0 != bam_close(bs->fp)) err_fatal_simple("Error closing bam file");
77-
#endif
7854
} else {
7955
err_gzclose(bs->ks->f->f);
8056
kseq_destroy(bs->ks);
@@ -125,11 +101,7 @@ static bwa_seq_t *bwa_read_bam(bwa_seqio_t *bs, int n_needed, int *n, int is_com
125101
b = bam_init1();
126102
n_seqs = 0;
127103
seqs = (bwa_seq_t*)calloc(n_needed, sizeof(bwa_seq_t));
128-
#ifdef USE_HTSLIB
129-
while ((res = sam_read1(bs->fp, bs->h, b)) >= 0) {
130-
#else
131104
while ((res = bam_read1(bs->fp, b)) >= 0) {
132-
#endif
133105
uint8_t *s, *q;
134106
int go = 0;
135107
if ((bs->which & 1) && (b->core.flag & BAM_FREAD1)) go = 1;
@@ -142,26 +114,14 @@ static bwa_seq_t *bwa_read_bam(bwa_seqio_t *bs, int n_needed, int *n, int is_com
142114
p->qual = 0;
143115
p->full_len = p->clip_len = p->len = l;
144116
n_tot += p->full_len;
145-
#ifdef USE_HTSLIB
146-
s = bam_get_seq(b); q = bam_get_qual(b);
147-
#else
148117
s = bam1_seq(b); q = bam1_qual(b);
149-
#endif
150118
p->seq = (ubyte_t*)calloc(p->len + 1, 1);
151119
p->qual = (ubyte_t*)calloc(p->len + 1, 1);
152120
for (i = 0; i != p->full_len; ++i) {
153-
#ifdef USE_HTSLIB
154-
p->seq[i] = bam_nt16_nt4_table[(int)bam_seqi(s, i)];
155-
#else
156121
p->seq[i] = bam_nt16_nt4_table[(int)bam1_seqi(s, i)];
157-
#endif
158122
p->qual[i] = q[i] + 33 < 126? q[i] + 33 : 126;
159123
}
160-
#ifdef USE_HTSLIB
161-
if (bam_is_rev(b)) { // then reverse
162-
#else
163124
if (bam1_strand(b)) { // then reverse
164-
#endif
165125
seq_reverse(p->len, p->seq, 1);
166126
seq_reverse(p->len, p->qual, 0);
167127
}
@@ -170,11 +130,7 @@ static bwa_seq_t *bwa_read_bam(bwa_seqio_t *bs, int n_needed, int *n, int is_com
170130
memcpy(p->rseq, p->seq, p->len);
171131
seq_reverse(p->len, p->seq, 0); // *IMPORTANT*: will be reversed back in bwa_refine_gapped()
172132
seq_reverse(p->len, p->rseq, is_comp);
173-
#ifdef USE_HTSLIB
174-
p->name = strdup((const char*)bam_get_qname(b));
175-
#else
176133
p->name = strdup((const char*)bam1_qname(b));
177-
#endif
178134
if (n_seqs == n_needed) break;
179135
}
180136
if (res < 0 && res != -1) err_fatal_simple("Error reading bam file");

‎fastmap.c

+4-56
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,7 @@ int main_mem(int argc, char *argv[])
5555

5656
opt = mem_opt_init();
5757
memset(&opt0, 0, sizeof(mem_opt_t));
58-
#ifdef USE_HTSLIB
59-
while ((c = getopt(argc, argv, "epaFMCSPHVYk:c:v:s:r:t:R:A:B:O:E:U:w:L:d:T:Q:D:m:I:N:W:x:G:h:y:K:o:")) >= 0)
60-
#else
61-
while ((c = getopt(argc, argv, "epaFMCSPHVYk:c:v:s:r:t:R:A:B:O:E:U:w:L:d:T:Q:D:m:I:N:W:x:G:h:y:K:")) >= 0)
62-
#endif
63-
{
58+
while ((c = getopt(argc, argv, "epaFMCSPHVYk:c:v:s:r:t:R:A:B:O:E:U:w:L:d:T:Q:D:m:I:N:W:x:G:h:y:K:")) >= 0) {
6459
if (c == 'k') opt->min_seed_len = atoi(optarg), opt0.min_seed_len = 1;
6560
else if (c == 'x') mode = optarg;
6661
else if (c == 'w') opt->w = atoi(optarg), opt0.w = 1;
@@ -130,10 +125,6 @@ int main_mem(int argc, char *argv[])
130125
if (bwa_verbose >= 3)
131126
fprintf(stderr, "[M::%s] mean insert size: %.3f, stddev: %.3f, max: %d, min: %d\n",
132127
__func__, pes[1].avg, pes[1].std, pes[1].high, pes[1].low);
133-
#ifdef USE_HTSLIB
134-
} else if (c == 'o') {
135-
opt->bam_output = atoi(optarg);
136-
#endif
137128
}
138129
else return 1;
139130
}
@@ -182,9 +173,6 @@ int main_mem(int argc, char *argv[])
182173
fprintf(stderr, " specify the mean, standard deviation (10%% of the mean if absent), max\n");
183174
fprintf(stderr, " (4 sigma from the mean if absent) and min of the insert size distribution.\n");
184175
fprintf(stderr, " FR orientation only. [inferred]\n");
185-
#ifdef USE_HTSLIB
186-
fprintf(stderr, " -o INT 0 - BAM (compressed), 1 - BAM (uncompressed), 2 - SAM [%d]\n", opt->bam_output);
187-
#endif
188176
fprintf(stderr, "\n");
189177
fprintf(stderr, "Note: Please read the man page for detailed description of the command line and options.\n");
190178
fprintf(stderr, "\n");
@@ -245,33 +233,8 @@ int main_mem(int argc, char *argv[])
245233
opt->flag |= MEM_F_PE;
246234
}
247235
}
248-
bam_hdr_t *h = NULL; // TODO
249-
#ifdef USE_HTSLIB
250-
samFile *out = NULL;
251-
char *modes[] = {"wb", "wbu", "w"};
252-
switch (opt->bam_output) {
253-
case 0: // BAM compressed
254-
case 1: // BAM uncompressed
255-
case 2: // SAM
256-
out = sam_open("-", modes[opt->bam_output]);
257-
break;
258-
default:
259-
fprintf(stderr, "Error: output format was out of range [%d]\n", opt->bam_output);
260-
return 1;
261-
}
262-
#endif
263-
if (!(opt->flag & MEM_F_ALN_REG)) {
264-
#ifdef USE_HTSLIB
265-
kstring_t str;
266-
str.l = str.m = 0; str.s = 0;
267-
bwa_format_sam_hdr(idx->bns, rg_line, &str);
268-
h = sam_hdr_parse(str.l, str.s);
269-
h->l_text = str.l; h->text = str.s;
270-
sam_hdr_write(out, h);
271-
#else
236+
if (!(opt->flag & MEM_F_ALN_REG))
272237
bwa_print_sam_hdr(idx->bns, rg_line);
273-
#endif
274-
}
275238
actual_chunk_size = fixed_chunk_size > 0? fixed_chunk_size : opt->chunk_size * opt->n_threads;
276239
while ((seqs = bseq_read(actual_chunk_size, &n, ks, ks2)) != 0) {
277240
int64_t size = 0;
@@ -287,22 +250,11 @@ int main_mem(int argc, char *argv[])
287250
for (i = 0; i < n; ++i) size += seqs[i].l_seq;
288251
if (bwa_verbose >= 3)
289252
fprintf(stderr, "[M::%s] read %d sequences (%ld bp)...\n", __func__, n, (long)size);
290-
mem_process_seqs2(opt, idx->bwt, idx->bns, idx->pac, n_processed, n, seqs, pes0, h);
253+
mem_process_seqs(opt, idx->bwt, idx->bns, idx->pac, n_processed, n, seqs, pes0);
291254
n_processed += n;
292255
for (i = 0; i < n; ++i) {
293-
#ifdef USE_HTSLIB
294-
if (seqs[i].bams) {
295-
int j;
296-
for (j = 0; j < seqs[i].bams->l; j++) {
297-
sam_write1(out, h, seqs[i].bams->bams[j]);
298-
}
299-
}
300-
bams_destroy(seqs[i].bams); seqs[i].bams = NULL;
301-
#else
302256
if (seqs[i].sam) err_fputs(seqs[i].sam, stdout);
303-
free(seqs[i].sam);
304-
#endif
305-
free(seqs[i].name); free(seqs[i].comment); free(seqs[i].seq); free(seqs[i].qual);
257+
free(seqs[i].name); free(seqs[i].comment); free(seqs[i].seq); free(seqs[i].qual); free(seqs[i].sam);
306258
}
307259
free(seqs);
308260
}
@@ -311,10 +263,6 @@ int main_mem(int argc, char *argv[])
311263
bwa_idx_destroy(idx);
312264
kseq_destroy(ks);
313265
err_gzclose(fp); kclose(ko);
314-
#ifdef USE_HTSLIB
315-
sam_close(out);
316-
bam_hdr_destroy(h);
317-
#endif
318266
if (ks2) {
319267
kseq_destroy(ks2);
320268
err_gzclose(fp2); kclose(ko2);

‎main.c

+1-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "utils.h"
55

66
#ifndef PACKAGE_VERSION
7-
#define PACKAGE_VERSION "0.7.10-r836-dirty"
7+
#define PACKAGE_VERSION "0.7.10-r837-dirty"
88
#endif
99

1010
int bwa_fa2pac(int argc, char *argv[]);
@@ -86,15 +86,8 @@ int main(int argc, char *argv[])
8686
fprintf(stderr, "[main] unrecognized command '%s'\n", argv[1]);
8787
return 1;
8888
}
89-
#ifdef USE_HTSLIB
90-
if (strcmp(argv[1], "mem") != 0) {
91-
err_fflush(stdout);
92-
err_fclose(stdout);
93-
}
94-
#else
9589
err_fflush(stdout);
9690
err_fclose(stdout);
97-
#endif
9891
if (ret == 0) {
9992
fprintf(stderr, "[%s] Version: %s\n", __func__, PACKAGE_VERSION);
10093
fprintf(stderr, "[%s] CMD:", __func__);

0 commit comments

Comments
 (0)
Please sign in to comment.