From: Heng Li Date: Sat, 13 Jun 2009 10:17:14 +0000 (+0000) Subject: * samtools-0.1.4-9 (r340) X-Git-Url: https://git.donarmstrong.com/?p=samtools.git;a=commitdiff_plain;h=63e8f525a5fd57be4c3471739a3996016e0c25f9 * samtools-0.1.4-9 (r340) * added a warning to razf.c if zlib<1.2.2.1 * fixed a compilation warning * fixed a segfault caused by @RG parsing * detect NCURSES in bam_tview.c --- diff --git a/INSTALL b/INSTALL index 71a91bc..f1cf7aa 100644 --- a/INSTALL +++ b/INSTALL @@ -11,8 +11,7 @@ The text-based viewer (tview) requires the GNU ncurses library , which comes with Mac OS X and most of the modern Linux/Unix distributions. If you do not have this library installed, you can still compile the rest of SAMtools by -manually modifying two lines in Makefile as is described in the -Makefile. +manually modifying one line in Makefile. Compilation diff --git a/Makefile b/Makefile index 77523d9..724552f 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,6 @@ CC= gcc CXX= g++ CFLAGS= -g -Wall -O2 #-m64 #-arch ppc CXXFLAGS= $(CFLAGS) -### For ncurses: please apply `-D_NO_CURSES' if you do not have ncurses installed DFLAGS= -D_IOLIB=2 -D_FILE_OFFSET_BITS=64 #-D_NO_CURSES OBJS= bam.o bam_import.o bam_pileup.o bam_lpileup.o bam_sort.o bam_index.o \ razf.o bgzf.o faidx.o bam_tview.o bam_maqcns.o bam_aux.o bam_plcmd.o \ @@ -34,7 +33,7 @@ lib:libbam.a libbam.a:$(OBJS) $(AR) -cru $@ $(OBJS) -### For ncurses: comment out `-lcurses' if you do not have ncurses installed +### For the curses library: comment out `-lcurses' if you do not have curses installed samtools:lib bamtk.o $(CC) $(CFLAGS) -o $@ bamtk.o -lm -L. -lbam -lcurses -lz diff --git a/bam_aux.c b/bam_aux.c index 137f9af..f36bc23 100644 --- a/bam_aux.c +++ b/bam_aux.c @@ -169,7 +169,9 @@ int bam_strmap_put(void *rg2lib, const char *rg, const char *lib) int ret; khint_t k; khash_t(r2l) *h = (khash_t(r2l)*)rg2lib; - char *key = strdup(rg); + char *key; + if (h == 0) return 1; + key = strdup(rg); k = kh_put(r2l, h, key, &ret); if (ret) kh_val(h, k) = strdup(lib); else { @@ -183,6 +185,7 @@ const char *bam_strmap_get(const void *rg2lib, const char *rg) { const khash_t(r2l) *h = (const khash_t(r2l)*)rg2lib; khint_t k; + if (h == 0) return 0; k = kh_get(r2l, h, rg); if (k != kh_end(h)) return (const char*)kh_val(h, k); else return 0; @@ -191,9 +194,11 @@ const char *bam_strmap_get(const void *rg2lib, const char *rg) void *bam_strmap_dup(const void *rg2lib) { const khash_t(r2l) *h = (const khash_t(r2l)*)rg2lib; - khash_t(r2l) *g = kh_init(r2l); + khash_t(r2l) *g; khint_t k, l; int ret; + if (h == 0) return 0; + g = kh_init(r2l); for (k = kh_begin(h); k < kh_end(h); ++k) { if (kh_exist(h, k)) { char *key = strdup(kh_key(h, k)); diff --git a/bam_import.c b/bam_import.c index c085473..c7f8667 100644 --- a/bam_import.c +++ b/bam_import.c @@ -153,7 +153,9 @@ int sam_header_parse_rg(bam_header_t *h) char *p, *q, *s, *r; int n = 0; - bam_strmap_destroy(h->rg2lib); + // free + bam_strmap_destroy(h->rg2lib); h->rg2lib = 0; + if (h->l_text < 3) return 0; // parse @RG lines h->rg2lib = bam_strmap_init(); rgid = calloc(1, sizeof(kstring_t)); @@ -193,6 +195,10 @@ int sam_header_parse_rg(bam_header_t *h) } free(rgid->s); free(rgid); free(rglib->s); free(rglib); + if (n == 0) { + bam_strmap_destroy(h->rg2lib); + h->rg2lib = 0; + } return n; } diff --git a/bam_tview.c b/bam_tview.c index 5858e3b..c26273c 100644 --- a/bam_tview.c +++ b/bam_tview.c @@ -1,5 +1,6 @@ #ifndef _NO_CURSES #include +#ifdef NCURSES_VERSION #include #include #include @@ -303,7 +304,7 @@ void tv_loop(tview_t *tv) tid = tv->curr_tid; pos = tv->left_pos; while (1) { int c = getch(); - if(256 < c) {c = 1 + (c%256);} // Terminal was displaying ctrl-H as 263 via ssh from Mac OS X 10.5 computer + //if(256 < c) {c = 1 + (c%256);} // Terminal was displaying ctrl-H as 263 via ssh from Mac OS X 10.5 computer switch (c) { case '?': tv_win_help(tv); break; case '\033': @@ -361,4 +362,12 @@ int bam_tview_main(int argc, char *argv[]) tv_destroy(tv); return 0; } +#else // #ifdef NCURSES_VERSION +#warning "The ncurses library is unavailable; tview is disabled." +int bam_tview_main(int argc, char *argv[]) +{ + fprintf(stderr, "[bam_tview_main] The ncurses library is unavailable; tview is not compiled.\n"); + return 1; +} #endif +#endif // #ifndef _NO_CURSES diff --git a/bamtk.c b/bamtk.c index 852213e..54b19f3 100644 --- a/bamtk.c +++ b/bamtk.c @@ -3,7 +3,7 @@ #include "bam.h" #ifndef PACKAGE_VERSION -#define PACKAGE_VERSION "0.1.4-8 (r338)" +#define PACKAGE_VERSION "0.1.4-9 (r340)" #endif int bam_taf2baf(int argc, char *argv[]); diff --git a/razf.c b/razf.c index c782cad..b56065b 100644 --- a/razf.c +++ b/razf.c @@ -27,8 +27,6 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * To compile razf.c, zlib-1.2.3(or greater) is required. */ #ifndef _NO_RAZF @@ -56,6 +54,7 @@ struct _gz_header_s { int hcrc; int done; }; +#warning "zlib < 1.2.2.1; RAZF writing is disabled." #endif #define DEF_MEM_LEVEL 8 diff --git a/sam_view.c b/sam_view.c index 50192f1..95a52c8 100644 --- a/sam_view.c +++ b/sam_view.c @@ -14,7 +14,7 @@ static inline int __g_skip_aln(const bam_header_t *h, const bam1_t *b) if (g_library) { uint8_t *s = bam_aux_get(b, "RG"); if (s) { - const char *p = bam_strmap_get(h->rg2lib, s + 1); + const char *p = bam_strmap_get(h->rg2lib, (char*)(s + 1)); return (p && strcmp(p, g_library) == 0)? 0 : 1; } else return 1; } else return 0;