Skip to content

Commit 1bdd791

Browse files
committed
r837: removed BAM support
This is not necessary.
1 parent 7244d66 commit 1bdd791

12 files changed

+24
-268
lines changed

Makefile

Lines changed: 3 additions & 16 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 41 deletions
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

Lines changed: 0 additions & 32 deletions
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

Lines changed: 8 additions & 37 deletions
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

Lines changed: 1 addition & 5 deletions
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

Lines changed: 0 additions & 12 deletions
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.

0 commit comments

Comments
 (0)