]> git.donarmstrong.com Git - samtools.git/commitdiff
* no changes to samtools itself
authorHeng Li <lh3@live.co.uk>
Fri, 12 Jun 2009 16:20:12 +0000 (16:20 +0000)
committerHeng Li <lh3@live.co.uk>
Fri, 12 Jun 2009 16:20:12 +0000 (16:20 +0000)
 * remove zlib source codes
 * make RAZF reading compatible with old version of zlib
 * on old version of zlib, writing is not available

Makefile
misc/Makefile
razf.c
razf.h
razip.c

index 358120d97650b1391fc39c53ca448477e2d68da8..77523d93a80f9f5fa0c984f1506f47e38cf413fa 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -8,9 +8,9 @@ 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 \
                        bam_mate.o bam_rmdup.o glf.o bam_stat.o kstring.o bam_md.o sam.o sam_view.o \
                        bam_rmdupse.o
-PROG=          razip bgzip samtools
-INCLUDES=      -Izlib
-SUBDIRS=       zlib . misc
+PROG=          bgzip samtools
+INCLUDES=      
+SUBDIRS=       . misc
 
 .SUFFIXES:.c .o
 
@@ -36,13 +36,13 @@ libbam.a:$(OBJS)
 
 ### For ncurses: comment out `-lcurses' if you do not have ncurses installed
 samtools:lib bamtk.o
-               $(CC) $(CFLAGS) -o $@ bamtk.o -lm -L. -lbam -lcurses -Lzlib -lz
+               $(CC) $(CFLAGS) -o $@ bamtk.o -lm -L. -lbam -lcurses -lz
 
 razip:razip.o razf.o
-               $(CC) $(CFLAGS) -o $@ razf.o razip.o -Lzlib -lz
+               $(CC) $(CFLAGS) -o $@ razf.o razip.o -lz
 
 bgzip:bgzip.o bgzf.o
-               $(CC) $(CFLAGS) -o $@ bgzf.o bgzip.o -Lzlib -lz
+               $(CC) $(CFLAGS) -o $@ bgzf.o bgzip.o -lz
 
 razip.o:razf.h
 bam.o:bam.h razf.h bam_endian.h kstring.h
@@ -56,13 +56,12 @@ bam_tview.o:bam.h faidx.h bam_maqcns.h
 bam_maqcns.o:bam.h ksort.h bam_maqcns.h
 bam_sort.o:bam.h ksort.h razf.h
 bam_md.o:bam.h faidx.h
-razf.o:razf.h
 glf.o:glf.h
 
 faidx.o:faidx.h razf.h khash.h
 faidx_main.o:faidx.h razf.h
 
 cleanlocal:
-               rm -fr gmon.out *.o a.out *.dSYM $(PROG) *~ *.a
+               rm -fr gmon.out *.o a.out *.dSYM razip $(PROG) *~ *.a
 
 clean:cleanlocal-recur
index 1008e91cd10f13fd89ddb1ccaa5dac092ab3a337..4404cccd1e8169b1c3a40538099a4e9d9285cfa8 100644 (file)
@@ -31,7 +31,7 @@ wgsim:wgsim.o
                $(CC) $(CFLAGS) -o $@ wgsim.o -lm
 
 md5fa:md5.o md5fa.o md5.h ../kseq.h
-               $(CC) $(CFLAGS) -o $@ md5.o md5fa.o -L../zlib -lz
+               $(CC) $(CFLAGS) -o $@ md5.o md5fa.o -lz
 
 md5sum-lite:md5sum-lite.o
                $(CC) $(CFLAGS) -o $@ md5sum-lite.o
@@ -40,10 +40,10 @@ md5sum-lite.o:md5.c md5.h
                $(CC) -c $(CFLAGS) -DMD5SUM_MAIN -o $@ md5.c
 
 maq2sam-short:maq2sam.c
-               $(CC) $(CFLAGS) -I../zlib -o $@ maq2sam.c -L../zlib -lz
+               $(CC) $(CFLAGS) -o $@ maq2sam.c -lz
 
 maq2sam-long:maq2sam.c
-               $(CC) $(CFLAGS) -I../zlib -DMAQ_LONGREADS -o $@ maq2sam.c -L../zlib -lz
+               $(CC) $(CFLAGS) -DMAQ_LONGREADS -o $@ maq2sam.c -lz
 
 md5fa.o:md5.h md5fa.c
                $(CC) $(CFLAGS) -c -I.. -o $@ md5fa.c
diff --git a/razf.c b/razf.c
index 80aef2c5b7faa4e9b1a785e416c470bad9355f1d..c782cad33f323ff8af511c805945e10c7f41a8cf 100644 (file)
--- a/razf.c
+++ b/razf.c
 
 #include <fcntl.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 #include "razf.h"
 
+#if ZLIB_VERNUM < 0x1221
+struct _gz_header_s {
+    int     text;
+    uLong   time;
+    int     xflags;
+    int     os;
+    Bytef   *extra;
+    uInt    extra_len;
+    uInt    extra_max;
+    Bytef   *name;
+    uInt    name_max;
+    Bytef   *comment;
+    uInt    comm_max;
+    int     hcrc;
+    int     done;
+};
+#endif
+
+#define DEF_MEM_LEVEL 8
+
 static inline uint32_t byte_swap_4(uint32_t v){
        v = ((v & 0x0000FFFFU) << 16) | (v >> 16);
        return ((v & 0x00FF00FFU) << 8) | ((v & 0xFF00FF00U) >> 8);
@@ -55,6 +77,7 @@ static inline int is_big_endian(){
        return (c[0] != 0x01);
 }
 
+#ifndef _RZ_READONLY
 static void add_zindex(RAZF *rz, int64_t in, int64_t out){
        if(rz->index->size == rz->index->cap){
                rz->index->cap = rz->index->cap * 1.5 + 2;
@@ -83,6 +106,7 @@ static void save_zindex(RAZF *rz, int fd){
        write(fd, rz->index->bin_offsets, sizeof(int64_t) * v32);
        write(fd, rz->index->cell_offsets, sizeof(int32_t) * rz->index->size);
 }
+#endif
 
 static void load_zindex(RAZF *rz, int fd){
        int32_t i, v32;
@@ -104,6 +128,13 @@ static void load_zindex(RAZF *rz, int fd){
        }
 }
 
+#ifdef _RZ_READONLY
+static RAZF* razf_open_w(int fd)
+{
+       fprintf(stderr, "[razf_open_w] Writing is not available with zlib ver < 1.2.2.1\n");
+       return 0;
+}
+#else
 static RAZF* razf_open_w(int fd){
        RAZF *rz;
        rz = calloc(1, sizeof(RAZF));
@@ -233,6 +264,7 @@ int razf_write(RAZF* rz, const void *data, int size){
        _razf_buffered_write(rz, data, size);
        return ori_size;
 }
+#endif
 
 /* gzip flag byte */
 #define ASCII_FLAG   0x01 /* bit 0 set: file probably ascii text */
@@ -614,8 +646,8 @@ int64_t razf_seek2(RAZF *rz, uint64_t voffset, int where)
 }
 
 void razf_close(RAZF *rz){
-       uint64_t v64;
        if(rz->mode == 'w'){
+#ifndef _RZ_READONLY
                razf_end_flush(rz);
                deflateEnd(rz->stream);
                save_zindex(rz, rz->filedes);
@@ -623,11 +655,12 @@ void razf_close(RAZF *rz){
                        write(rz->filedes, &rz->in, sizeof(int64_t));
                        write(rz->filedes, &rz->out, sizeof(int64_t));
                } else {
-                       v64 = byte_swap_8((uint64_t)rz->in);
+                       uint64_t v64 = byte_swap_8((uint64_t)rz->in);
                        write(rz->filedes, &v64, sizeof(int64_t));
                        v64 = byte_swap_8((uint64_t)rz->out);
                        write(rz->filedes, &v64, sizeof(int64_t));
                }
+#endif
        } else if(rz->mode == 'r'){
                if(rz->stream) inflateEnd(rz->stream);
        }
diff --git a/razf.h b/razf.h
index d39177664398164d11407bb613d2c6dd751df18e..f7e5097687359d02cf5019a642435a25ba781811 100644 (file)
--- a/razf.h
+++ b/razf.h
 #include <stdint.h>
 #include <stdio.h>
 #include "zlib.h"
-#include "zutil.h"
+
+#if ZLIB_VERNUM < 0x1221
+#define _RZ_READONLY
+struct _gz_header_s;
+typedef struct _gz_header_s _gz_header;
+#define gz_header _gz_header
+#endif
 
 #define WINDOW_BITS   15
 
diff --git a/razip.c b/razip.c
index 0b67c6c50cf62f4ccb12948fdf96dbc813633b87..2b49883aefc6d607e7a44fbc9a3906443f8b7cbd 100644 (file)
--- a/razip.c
+++ b/razip.c
@@ -2,6 +2,8 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <errno.h>
+#include <stdlib.h>
+#include <string.h>
 #include "razf.h"
 
 #define WINDOW_SIZE 4096