From: Heng Li Date: Tue, 13 Jul 2010 18:50:12 +0000 (+0000) Subject: * samtools-0.1.8-1 (r615) X-Git-Url: https://git.donarmstrong.com/?p=samtools.git;a=commitdiff_plain;h=8b0f98e2ac96b5ab07fd482cbaaa06d458254a90 * samtools-0.1.8-1 (r615) * allow to get mpileup at required sites --- diff --git a/bam_plcmd.c b/bam_plcmd.c index 6804795..c665a92 100644 --- a/bam_plcmd.c +++ b/bam_plcmd.c @@ -449,8 +449,9 @@ int bam_pileup(int argc, char *argv[]) ***********/ typedef struct { - char *reg; + char *reg, *fn_pos; faidx_t *fai; + kh_64_t *hash; } mplp_conf_t; typedef struct { @@ -473,6 +474,7 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) bam_mplp_t iter; bam_header_t *h = 0; char *ref; + khash_t(64) *hash = 0; // allocate data = calloc(n, sizeof(void*)); plp = calloc(n, sizeof(void*)); @@ -505,11 +507,17 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) bam_header_destroy(h_tmp); } } + if (conf->fn_pos) hash = load_pos(conf->fn_pos, h); // mpileup ref_tid = -1; ref = 0; iter = bam_mplp_init(n, mplp_func, (void**)data); while (bam_mplp_auto(iter, &tid, &pos, n_plp, plp) > 0) { if (conf->reg && (pos < beg0 || pos >= end0)) continue; // out of the region requested + if (hash) { + khint_t k; + k = kh_get(64, hash, (uint64_t)tid<<32 | pos); + if (k == kh_end(hash)) continue; + } if (tid != ref_tid) { free(ref); if (conf->fai) ref = fai_fetch(conf->fai, h->target_name[tid], &ref_len); @@ -534,6 +542,12 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) } putchar('\n'); } + if (hash) { // free the hash table + khint_t k; + for (k = kh_begin(hash); k < kh_end(hash); ++k) + if (kh_exist(hash, k)) free(kh_val(hash, k)); + kh_destroy(64, hash); + } bam_mplp_destroy(iter); bam_header_destroy(h); for (i = 0; i < n; ++i) { @@ -550,17 +564,18 @@ int bam_mpileup(int argc, char *argv[]) int c; mplp_conf_t mplp; memset(&mplp, 0, sizeof(mplp_conf_t)); - while ((c = getopt(argc, argv, "f:r:")) >= 0) { + while ((c = getopt(argc, argv, "f:r:l:")) >= 0) { switch (c) { case 'f': mplp.fai = fai_load(optarg); if (mplp.fai == 0) return 1; break; - case 'r': mplp.reg = strdup(optarg); + case 'r': mplp.reg = strdup(optarg); break; + case 'l': mplp.fn_pos = strdup(optarg); break; } } if (argc == 1) { - fprintf(stderr, "Usage: samtools mpileup [-r reg] [-f in.fa] in1.bam [in2.bam [...]]\n"); + fprintf(stderr, "Usage: samtools mpileup [-r reg] [-f in.fa] [-l pos] in1.bam [in2.bam [...]]\n"); return 1; } mpileup(&mplp, argc - optind, argv + optind); diff --git a/bamtk.c b/bamtk.c index 94c4d3f..f93cf52 100644 --- a/bamtk.c +++ b/bamtk.c @@ -9,7 +9,7 @@ #endif #ifndef PACKAGE_VERSION -#define PACKAGE_VERSION "0.1.8 (r613)" +#define PACKAGE_VERSION "0.1.8-1 (r615)" #endif int bam_taf2baf(int argc, char *argv[]); diff --git a/misc/Makefile b/misc/Makefile index 2d7139d..6c25c78 100644 --- a/misc/Makefile +++ b/misc/Makefile @@ -1,6 +1,6 @@ CC= gcc CXX= g++ -CFLAGS= -g -Wall #-O2 #-m64 #-arch ppc +CFLAGS= -g -Wall -O2 #-m64 #-arch ppc CXXFLAGS= $(CFLAGS) DFLAGS= -D_FILE_OFFSET_BITS=64 OBJS=