From: Heng Li Date: Wed, 13 May 2009 09:07:55 +0000 (+0000) Subject: * samtools-0.1.3-20 (r276) X-Git-Url: https://git.donarmstrong.com/?p=samtools.git;a=commitdiff_plain;h=00e380817d6a94c7f6c54d88c56ef8dbfd20b6bb * samtools-0.1.3-20 (r276) * remove bam1_t::hash again. We need to modify the Perl API anyway to make it work with the latest SVN. * As is suggested by Tim, scan "{base}.bai" and "{base}.bam.bai" for index --- diff --git a/bam.h b/bam.h index a784a1f..163dc89 100644 --- a/bam.h +++ b/bam.h @@ -190,7 +190,6 @@ typedef struct { bam1_core_t core; int l_aux, data_len, m_data; uint8_t *data; - void *hash; // for backward compatibility. It is NEVER used. } bam1_t; #define bam1_strand(b) (((b)->core.flag&BAM_FREVERSE) != 0) diff --git a/bam_index.c b/bam_index.c index 7670c2f..4a41f52 100644 --- a/bam_index.c +++ b/bam_index.c @@ -268,7 +268,16 @@ bam_index_t *bam_index_load(const char *fn) fnidx = (char*)calloc(strlen(fn) + 5, 1); strcpy(fnidx, fn); strcat(fnidx, ".bai"); - if ((fp = fopen(fnidx, "r")) == 0) { + fp = fopen(fnidx, "r"); + if (fp == 0) { // try "{base}.bai" + char *s = strstr(fn, "bam"); + if (s == fn + strlen(fn) - 3) { + strcpy(fnidx, fn); + fnidx[strlen(fn)-1] = 'i'; + fp = fopen(fnidx, "r"); + } + } + if (fp == 0) { fprintf(stderr, "[bam_index_load] the alignment is not indexed. Please run `index' command first. Abort!\n"); exit(1); } @@ -327,7 +336,7 @@ bam_index_t *bam_index_load(const char *fn) return idx; } -int bam_index_build(const char *fn) +int bam_index_build2(const char *fn, const char *_fnidx) { char *fnidx; FILE *fpidx; @@ -336,9 +345,16 @@ int bam_index_build(const char *fn) assert(fp = bam_open(fn, "r")); idx = bam_index_core(fp); bam_close(fp); - fnidx = (char*)calloc(strlen(fn) + 5, 1); - strcpy(fnidx, fn); strcat(fnidx, ".bai"); - assert(fpidx = fopen(fnidx, "w")); + if (_fnidx == 0) { + fnidx = (char*)calloc(strlen(fn) + 5, 1); + strcpy(fnidx, fn); strcat(fnidx, ".bai"); + } else fnidx = strdup(_fnidx); + fpidx = fopen(fnidx, "w"); + if (fpidx == 0) { + fprintf(stderr, "[bam_index_build2] fail to create the index file.\n"); + free(fnidx); + return 1; + } bam_index_save(idx, fpidx); bam_index_destroy(idx); fclose(fpidx); @@ -346,13 +362,19 @@ int bam_index_build(const char *fn) return 0; } +int bam_index_build(const char *fn) +{ + return bam_index_build2(fn, 0); +} + int bam_index(int argc, char *argv[]) { if (argc < 2) { - fprintf(stderr, "Usage: samtools index \n"); + fprintf(stderr, "Usage: samtools index []\n"); return 1; } - bam_index_build(argv[1]); + if (argc >= 3) bam_index_build2(argv[1], argv[2]); + else bam_index_build(argv[1]); return 0; } diff --git a/bamtk.c b/bamtk.c index 9bb236b..d17cf85 100644 --- a/bamtk.c +++ b/bamtk.c @@ -3,7 +3,7 @@ #include "bam.h" #ifndef PACKAGE_VERSION -#define PACKAGE_VERSION "0.1.3-19 (r275)" +#define PACKAGE_VERSION "0.1.3-20 (r276)" #endif int bam_taf2baf(int argc, char *argv[]);