From 8a9ee843efcc2ec0cfb553d0b571536cf621864d Mon Sep 17 00:00:00 2001 From: Heng Li Date: Thu, 30 Jul 2009 10:24:39 +0000 Subject: [PATCH] * samtools-0.1.5-17 (r422) * fixed a but in knetfile.c when seek type is not SEEK_SET * write an empty BGZF block to every BGZF file * check BGZF EOF marker in bam_header_read() * update ChangeLog --- ChangeLog | 284 +++++++++++++++++++++++++++++++++++++++++++++++++++++ bam.c | 6 +- bamtk.c | 2 +- bgzf.c | 28 +++++- bgzf.h | 2 + knetfile.c | 5 +- sam.c | 1 + sam_view.c | 2 +- 8 files changed, 324 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3bf82a5..d6a6f33 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,287 @@ +------------------------------------------------------------------------ +r421 | lh3lh3 | 2009-07-30 10:03:39 +0100 (Thu, 30 Jul 2009) | 3 lines +Changed paths: + M /trunk/samtools/bam_import.c + M /trunk/samtools/bam_plcmd.c + M /trunk/samtools/bamtk.c + M /trunk/samtools/misc/samtools.pl + M /trunk/samtools/sam.c + M /trunk/samtools/sam.h + M /trunk/samtools/sam_view.c + + * samtools-0.1.5-16 (r421) + * in view and pileup, load header from FASTA index if the input is SAM. + +------------------------------------------------------------------------ +r420 | lh3lh3 | 2009-07-29 09:18:55 +0100 (Wed, 29 Jul 2009) | 2 lines +Changed paths: + M /trunk/samtools/misc/maq2sam.c + +do not set "read 1" if reads are not mapped in the PE mode of maq + +------------------------------------------------------------------------ +r419 | lh3lh3 | 2009-07-28 09:52:33 +0100 (Tue, 28 Jul 2009) | 5 lines +Changed paths: + M /trunk/samtools/bam_import.c + M /trunk/samtools/bamtk.c + M /trunk/samtools/misc/samtools.pl + M /trunk/samtools/misc/wgsim_eval.pl + + * samtools-0.1.5-15 (r419) + * in sam_open(), return NULL when the file cannot be opened. + * make wgsim_eval.pl more robust to imperfect SAM + * add "unique" command to samtools.pl + +------------------------------------------------------------------------ +r418 | lh3lh3 | 2009-07-24 14:04:19 +0100 (Fri, 24 Jul 2009) | 2 lines +Changed paths: + M /trunk/samtools/misc/wgsim_eval.pl + +skip @header lines in SAM + +------------------------------------------------------------------------ +r417 | lh3lh3 | 2009-07-24 12:42:38 +0100 (Fri, 24 Jul 2009) | 3 lines +Changed paths: + M /trunk/samtools/bamtk.c + M /trunk/samtools/sam_view.c + + * samtools-0.1.5-14 (r417) + * more help in "samtools view" due to the recent changes. + +------------------------------------------------------------------------ +r416 | lh3lh3 | 2009-07-24 12:34:30 +0100 (Fri, 24 Jul 2009) | 3 lines +Changed paths: + M /trunk/samtools/bam.c + M /trunk/samtools/bam.h + M /trunk/samtools/bam_import.c + M /trunk/samtools/bamtk.c + M /trunk/samtools/sam.c + M /trunk/samtools/sam.h + M /trunk/samtools/sam_view.c + + * samtools-0.1.5-17 (r416) + * support import/export SAM with string tags + +------------------------------------------------------------------------ +r415 | lh3lh3 | 2009-07-24 11:39:26 +0100 (Fri, 24 Jul 2009) | 3 lines +Changed paths: + M /trunk/samtools/bam.c + M /trunk/samtools/bam.h + M /trunk/samtools/bam_import.c + M /trunk/samtools/bamtk.c + M /trunk/samtools/sam.c + M /trunk/samtools/sam.h + M /trunk/samtools/sam_view.c + + * samtools-0.1.5-12 (r415) + * FLAG now can be in HEX + +------------------------------------------------------------------------ +r414 | lh3lh3 | 2009-07-22 22:03:49 +0100 (Wed, 22 Jul 2009) | 2 lines +Changed paths: + M /trunk/samtools/kstring.h + +fixed a compiling error (thank Ken for fixing it) + +------------------------------------------------------------------------ +r412 | lh3lh3 | 2009-07-21 22:19:40 +0100 (Tue, 21 Jul 2009) | 2 lines +Changed paths: + M /trunk/samtools/kstring.c + M /trunk/samtools/kstring.h + +Implemented Boyer-Moore search in the kstring library. + +------------------------------------------------------------------------ +r409 | lh3lh3 | 2009-07-17 17:10:20 +0100 (Fri, 17 Jul 2009) | 2 lines +Changed paths: + M /trunk/samtools/bam_index.c + +do not include knetfile.h when _USE_KNETFILE is not defined + +------------------------------------------------------------------------ +r408 | lh3lh3 | 2009-07-17 15:29:21 +0100 (Fri, 17 Jul 2009) | 5 lines +Changed paths: + M /trunk/samtools/bam_md.c + M /trunk/samtools/bam_tview.c + M /trunk/samtools/bamtk.c + M /trunk/samtools/bgzf.c + + * samtools-0.1.5-11 (r408) + * force to overwirte existing MD if it is different from the one calculated + from fillmd. + * bgzf.c: improved the compatibility with Windows headers + +------------------------------------------------------------------------ +r407 | lh3lh3 | 2009-07-17 14:46:56 +0100 (Fri, 17 Jul 2009) | 5 lines +Changed paths: + M /trunk/samtools/bam.h + M /trunk/samtools/bam_aux.c + M /trunk/samtools/bam_md.c + M /trunk/samtools/bamtk.c + M /trunk/samtools/sam.h + + * samtools-0.1.5-10 (r407) + * implemented bam_aux_del() to remove a tag + * fillmd: generate the NM tag + * fillmd: cmd interface improvement + +------------------------------------------------------------------------ +r406 | lh3lh3 | 2009-07-16 23:30:40 +0100 (Thu, 16 Jul 2009) | 2 lines +Changed paths: + M /trunk/samtools/Makefile + +Sorry. The old Makefile is for PDCurses... + +------------------------------------------------------------------------ +r405 | lh3lh3 | 2009-07-16 23:30:11 +0100 (Thu, 16 Jul 2009) | 3 lines +Changed paths: + M /trunk/samtools/Makefile + M /trunk/samtools/bam_tview.c + M /trunk/samtools/bamtk.c + + * samtools-0.1.5-9 (r405) + * improved the compatibility with PDCurses a little bit + +------------------------------------------------------------------------ +r404 | lh3lh3 | 2009-07-16 23:23:52 +0100 (Thu, 16 Jul 2009) | 3 lines +Changed paths: + M /trunk/samtools/Makefile + M /trunk/samtools/bam_tview.c + M /trunk/samtools/bamtk.c + + * samtools-0.1.5-8 (r404) + * compatible with PDCurses + +------------------------------------------------------------------------ +r403 | lh3lh3 | 2009-07-16 22:39:39 +0100 (Thu, 16 Jul 2009) | 3 lines +Changed paths: + M /trunk/samtools/bamtk.c + M /trunk/samtools/kseq.h + + * samtools-0.1.5-7 (r403) + * fixed a bug in kseq.h for binary files (text files are fine) + +------------------------------------------------------------------------ +r402 | lh3lh3 | 2009-07-16 11:49:53 +0100 (Thu, 16 Jul 2009) | 4 lines +Changed paths: + M /trunk/samtools/bam_import.c + M /trunk/samtools/bam_index.c + M /trunk/samtools/bamtk.c + M /trunk/samtools/bgzf.c + + * samtools-0.1.5-6 (r402) + * fixed compiling error when "-D_USE_NETFILE" is not applied + * improve portability to MinGW + +------------------------------------------------------------------------ +r398 | lh3lh3 | 2009-07-13 10:21:36 +0100 (Mon, 13 Jul 2009) | 3 lines +Changed paths: + A /trunk/bam-lite/bam.h (from /trunk/samtools/bam.h:395) + A /trunk/bam-lite/bam_lite.c (from /trunk/samtools/bam_lite.c:395) + D /trunk/samtools/bam_lite.c + + * move bam_lite.c to bam-lite + * copy bam.h to bam-lite + +------------------------------------------------------------------------ +r395 | lh3lh3 | 2009-07-13 10:12:57 +0100 (Mon, 13 Jul 2009) | 3 lines +Changed paths: + M /trunk/samtools/bam.h + M /trunk/samtools/bam_lite.c + M /trunk/samtools/bam_lpileup.c + M /trunk/samtools/bam_pileup.c + M /trunk/samtools/bamtk.c + + * samtools-0.1.5-5 (r395) + * added bam_pileup_file() and removed bam_lpileup_file() + +------------------------------------------------------------------------ +r394 | lh3lh3 | 2009-07-13 00:35:10 +0100 (Mon, 13 Jul 2009) | 3 lines +Changed paths: + M /trunk/samtools/bamtk.c + M /trunk/samtools/knetfile.c + M /trunk/samtools/knetfile.h + + * samtools-0.1.5-4 (r394) + * http_proxy support in knetfile library (check http_proxy ENV) + +------------------------------------------------------------------------ +r393 | lh3lh3 | 2009-07-12 23:57:07 +0100 (Sun, 12 Jul 2009) | 5 lines +Changed paths: + M /trunk/samtools/bam_index.c + M /trunk/samtools/bam_tview.c + M /trunk/samtools/bamtk.c + M /trunk/samtools/knetfile.c + M /trunk/samtools/knetfile.h + + * samtools-0.1.5-3 (r393) + * knetfile now supports HTTP (no proxy at the moment) + * fixed a potential issue in knetfile on opening ordinary file, although I have + not seen the sideeffect so far. + +------------------------------------------------------------------------ +r392 | lh3lh3 | 2009-07-12 18:50:55 +0100 (Sun, 12 Jul 2009) | 2 lines +Changed paths: + M /trunk/samtools/samtools.1 + +Remove the warning in tview + +------------------------------------------------------------------------ +r391 | lh3lh3 | 2009-07-12 18:42:43 +0100 (Sun, 12 Jul 2009) | 3 lines +Changed paths: + M /trunk/samtools/bam_tview.c + M /trunk/samtools/bamtk.c + + * samtools-0.1.5-2 (r391) + * do not show a blank screen when no reads mapped + +------------------------------------------------------------------------ +r390 | lh3lh3 | 2009-07-09 14:01:42 +0100 (Thu, 09 Jul 2009) | 4 lines +Changed paths: + M /trunk/samtools/bam.h + A /trunk/samtools/bam_lite.c + M /trunk/samtools/bamtk.c + + * samtools-0.1.5-1 (r390) + * removed useless _IOLIB in bam.h. This should cause no change at all. + * added bam_lite.c for light-weight BAM reading + +------------------------------------------------------------------------ +r385 | lh3lh3 | 2009-07-07 16:53:29 +0100 (Tue, 07 Jul 2009) | 2 lines +Changed paths: + M /trunk/samtools/bamtk.c + M /trunk/samtools/knetfile.c + +Release samtools-0.1.5c (fixed a bug in piping) + +------------------------------------------------------------------------ +r383 | lh3lh3 | 2009-07-07 11:39:55 +0100 (Tue, 07 Jul 2009) | 2 lines +Changed paths: + M /trunk/samtools/bamtk.c + M /trunk/samtools/sam.c + +Release samtools-0.1.5b (BUG! so embarrassing!) + +------------------------------------------------------------------------ +r381 | lh3lh3 | 2009-07-07 11:20:06 +0100 (Tue, 07 Jul 2009) | 2 lines +Changed paths: + M /trunk/samtools/Makefile + M /trunk/samtools/bam.h + M /trunk/samtools/bam_aux.c + M /trunk/samtools/bamtk.c + +Release samtools-0.1.5a (for compatibility with Bio::DB::Sam) + +------------------------------------------------------------------------ +r373 | lh3lh3 | 2009-07-07 10:26:57 +0100 (Tue, 07 Jul 2009) | 2 lines +Changed paths: + M /trunk/samtools/ChangeLog + M /trunk/samtools/NEWS + M /trunk/samtools/bamtk.c + M /trunk/samtools/samtools.1 + +Release samtools-0.1.5 + ------------------------------------------------------------------------ r372 | lh3lh3 | 2009-07-07 09:49:27 +0100 (Tue, 07 Jul 2009) | 3 lines Changed paths: diff --git a/bam.c b/bam.c index 2edb2a8..52d97a6 100644 --- a/bam.c +++ b/bam.c @@ -91,7 +91,11 @@ bam_header_t *bam_header_read(bamFile fp) { bam_header_t *header; char buf[4]; - int32_t i, name_len; + int32_t i = 1, name_len; + // check EOF + i = bgzf_check_EOF(fp); + if (i < 0) fprintf(stderr, "[bam_header_read] read from pipe; skip EOF checking.\n"); + else if (i == 0) fprintf(stderr, "[bam_header_read] EOF marker is absent.\n"); // read "BAM1" if (bam_read(fp, buf, 4) != 4) return 0; if (strncmp(buf, "BAM\001", 4)) { diff --git a/bamtk.c b/bamtk.c index 234f465..9e76673 100644 --- a/bamtk.c +++ b/bamtk.c @@ -4,7 +4,7 @@ #include "bam.h" #ifndef PACKAGE_VERSION -#define PACKAGE_VERSION "0.1.5-16 (r421)" +#define PACKAGE_VERSION "0.1.5-17 (r422)" #endif int bam_taf2baf(int argc, char *argv[]); diff --git a/bgzf.c b/bgzf.c index 71d8c81..2cd1c5e 100644 --- a/bgzf.c +++ b/bgzf.c @@ -571,6 +571,14 @@ bgzf_close(BGZF* fp) if (flush_block(fp) != 0) { return -1; } + { // add an empty block + int count, block_length = deflate_block(fp, 0); +#ifdef _USE_KNETFILE + count = fwrite(fp->compressed_block, 1, block_length, fp->x.fpw); +#else + count = fwrite(fp->compressed_block, 1, block_length, fp->file); +#endif + } #ifdef _USE_KNETFILE if (fflush(fp->x.fpw) != 0) { #else @@ -610,6 +618,25 @@ void bgzf_set_cache_size(BGZF *fp, int cache_size) if (fp) fp->cache_size = cache_size; } +int bgzf_check_EOF(BGZF *fp) +{ + static uint8_t magic[28] = "\037\213\010\4\0\0\0\0\0\377\6\0\102\103\2\0\033\0\3\0\0\0\0\0\0\0\0\0"; + uint8_t buf[28]; + off_t offset; +#ifdef _USE_KNETFILE + offset = knet_tell(fp->x.fpr); + if (knet_seek(fp->x.fpr, -28, SEEK_END) != 0) return -1; + knet_read(fp->x.fpr, buf, 28); + knet_seek(fp->x.fpr, offset, SEEK_SET); +#else + offset = ftello(fp->file); + if (fseeko(fp->file, -28, SEEK_END) != 0) return -1; + fread(buf, 1, 28, fp->file); + fseeko(fp->file, offset, SEEK_SET); +#endif + return (memcmp(magic, buf, 28) == 0)? 1 : 0; +} + int64_t bgzf_seek(BGZF* fp, int64_t pos, int where) { @@ -636,4 +663,3 @@ bgzf_seek(BGZF* fp, int64_t pos, int where) fp->block_offset = block_offset; return 0; } - diff --git a/bgzf.h b/bgzf.h index d5eeafe..f685c44 100644 --- a/bgzf.h +++ b/bgzf.h @@ -113,6 +113,8 @@ int64_t bgzf_seek(BGZF* fp, int64_t pos, int where); */ void bgzf_set_cache_size(BGZF *fp, int cache_size); +int bgzf_check_EOF(BGZF *fp); + #ifdef __cplusplus } #endif diff --git a/knetfile.c b/knetfile.c index bcf74a8..358ee64 100644 --- a/knetfile.c +++ b/knetfile.c @@ -344,11 +344,12 @@ int knet_seek(knetFile *fp, off_t off, int whence) { if (whence == SEEK_SET && off == fp->offset) return 0; if (fp->type == KNF_TYPE_LOCAL) { - if (lseek(fp->fd, off, whence) == -1) { + off_t offset = lseek(fp->fd, off, whence); + if (offset == -1) { perror("lseek"); return -1; } - fp->offset = off; + fp->offset = offset; return 0; } else if (fp->type == KNF_TYPE_FTP || fp->type == KNF_TYPE_HTTP) { if (whence != SEEK_SET) { // FIXME: we can surely allow SEEK_CUR and SEEK_END in future diff --git a/sam.c b/sam.c index b8e7350..a74c557 100644 --- a/sam.c +++ b/sam.c @@ -158,6 +158,7 @@ int sampileup(samfile_t *fp, int mask, bam_pileup_f func, void *func_data) char *samfaipath(const char *fn_ref) { char *fn_list = 0; + if (fn_ref == 0) return 0; fn_list = calloc(strlen(fn_ref) + 5, 1); strcat(strcpy(fn_list, fn_ref), ".fai"); if (access(fn_list, R_OK) == -1) { // fn_list is unreadable diff --git a/sam_view.c b/sam_view.c index 1776b8e..c2056ba 100644 --- a/sam_view.c +++ b/sam_view.c @@ -86,7 +86,7 @@ int main_samview(int argc, char *argv[]) goto view_end; } if (in->header == 0) { - fprintf(stderr, "[main_samview] fail to read SAM header.\n"); + fprintf(stderr, "[main_samview] fail to read the header.\n"); goto view_end; } if ((out = samopen(fn_out? fn_out : "-", out_mode, in->header)) == 0) { -- 2.39.2