From 1de61b556ee3bcb7b44a28b10b8c81a98dda35a2 Mon Sep 17 00:00:00 2001 From: Heng Li Date: Fri, 8 Aug 2014 13:36:56 -0400 Subject: [PATCH] r806: polish BAM support --- Makefile | 19 +++++++++---------- bwamem.c | 7 ++++++- bwamem.h | 4 ++-- fastmap.c | 6 ++---- main.c | 2 +- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 0f9cae0..b10cf81 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,9 @@ CC= gcc #CC= clang --analyze CFLAGS= -g -Wall -Wno-unused-function -O2 WRAP_MALLOC=-DUSE_MALLOC_WRAPPERS -# set to 1 if you wish to have bam support, type 'make clean; make all' -USE_HTSLIB=0 +HTSLIB_PATH= AR= ar -DFLAGS= -DHAVE_PTHREAD $(WRAP_MALLOC) +DFLAGS= -DHAVE_PTHREAD $(WRAP_MALLOC) 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 AOBJS= QSufSort.o bwt_gen.o bwase.o bwaseqio.o bwtgap.o bwtaln.o bamlite.o \ is.o bwtindex.o bwape.o kopen.o pemerge.o \ @@ -13,14 +12,14 @@ AOBJS= QSufSort.o bwt_gen.o bwase.o bwaseqio.o bwtgap.o bwtaln.o bamlite.o \ bwtsw2_chain.o fastmap.o bwtsw2_pair.o PROG= bwa INCLUDES= -LIBS= -lm -lz -lpthread +LIBS= -lm -lz -lpthread SUBDIRS= . .SUFFIXES:.c .o .cc .c.o: -ifeq ($(USE_HTSLIB),1) - $(CC) -c $(CFLAGS) $(DFLAGS) -DUSE_HTSLIB $(INCLUDES) -I ../htslib $< -o $@ +ifneq ($(HTSLIB_PATH),) + $(CC) -c $(CFLAGS) $(DFLAGS) -DUSE_HTSLIB $(INCLUDES) -I$(HTSLIB_PATH) $< -o $@ else $(CC) -c $(CFLAGS) $(DFLAGS) $(INCLUDES) $< -o $@ endif @@ -28,15 +27,15 @@ endif all:$(PROG) bwa:libbwa.a $(AOBJS) main.o -ifeq ($(USE_HTSLIB),1) - $(CC) $(CFLAGS) $(DFLAGS) $(AOBJS) main.o -o $@ ../htslib/libhts.a -L. -L../htslib -lbwa $(LIBS) +ifneq ($(HTSLIB_PATH),) + $(CC) $(CFLAGS) $(DFLAGS) $(AOBJS) main.o -o $@ $(HTSLIB_PATH)/libhts.a -L. -lbwa $(LIBS) else $(CC) $(CFLAGS) $(DFLAGS) $(AOBJS) main.o -o $@ -L. -lbwa $(LIBS) endif bwamem-lite:libbwa.a example.o -ifeq ($(USE_HTSLIB),1) - $(CC) $(CFLAGS) $(DFLAGS) example.o -o $@ ../htslib/libhts.a -L. -L../htslib -lbwa $(LIBS) +ifneq ($(HTSLIB_PATH),) + $(CC) $(CFLAGS) $(DFLAGS) example.o -o $@ $(HTSLIB_PATH)/libhts.a -L. -lbwa $(LIBS) else $(CC) $(CFLAGS) $(DFLAGS) example.o -o $@ -L. -lbwa $(LIBS) endif diff --git a/bwamem.c b/bwamem.c index 2e255af..0e4c6cc 100644 --- a/bwamem.c +++ b/bwamem.c @@ -1125,7 +1125,7 @@ static void worker2(void *data, int i, int tid) } } -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, bam_hdr_t *h) +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) { extern void kt_for(int n_threads, void (*func)(void*,int,int), void *data, int n); worker_t w; @@ -1157,3 +1157,8 @@ void mem_process_seqs(const mem_opt_t *opt, const bwt_t *bwt, const bntseq_t *bn if (bwa_verbose >= 3) fprintf(stderr, "[M::%s] Processed %d reads in %.3f CPU sec, %.3f real sec\n", __func__, n, cputime() - ctime, realtime() - rtime); } + +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) +{ + mem_process_seqs2(opt, bwt, bns, pac, n_processed, n, seqs, pes0, 0); +} diff --git a/bwamem.h b/bwamem.h index b822664..f74cb44 100644 --- a/bwamem.h +++ b/bwamem.h @@ -128,7 +128,8 @@ extern "C" { * corresponding to each FF, FR, RF and RR orientation. See mem_pestat() for more info. * @param h the BAM header, NULL if not using HTSLIB */ - 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, bam_hdr_t *h); + 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); + 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); /** * Find the aligned regions for one query sequence @@ -160,7 +161,6 @@ extern "C" { * @return CIGAR, strand, mapping quality and forward-strand position */ 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); - 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); /** * Infer the insert size distribution from interleaved alignment regions diff --git a/fastmap.c b/fastmap.c index ebcb826..b528ae9 100644 --- a/fastmap.c +++ b/fastmap.c @@ -127,10 +127,8 @@ int main_mem(int argc, char *argv[]) #ifdef USE_HTSLIB } else if (c == 'o') { opt->bam_output = atoi(optarg); - } -#else - } #endif + } else return 1; } if (opt->n_threads < 1) opt->n_threads = 1; @@ -280,7 +278,7 @@ int main_mem(int argc, char *argv[]) for (i = 0; i < n; ++i) size += seqs[i].l_seq; if (bwa_verbose >= 3) fprintf(stderr, "[M::%s] read %d sequences (%ld bp)...\n", __func__, n, (long)size); - mem_process_seqs(opt, idx->bwt, idx->bns, idx->pac, n_processed, n, seqs, pes0, h); + mem_process_seqs2(opt, idx->bwt, idx->bns, idx->pac, n_processed, n, seqs, pes0, h); n_processed += n; for (i = 0; i < n; ++i) { #ifdef USE_HTSLIB diff --git a/main.c b/main.c index db8d83a..c202a7c 100644 --- a/main.c +++ b/main.c @@ -4,7 +4,7 @@ #include "utils.h" #ifndef PACKAGE_VERSION -#define PACKAGE_VERSION "0.7.10-r789" +#define PACKAGE_VERSION "0.7.10-r806-dirty" #endif int bwa_fa2pac(int argc, char *argv[]);