X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=samtools.git;a=blobdiff_plain;f=sam_view.c;fp=sam_view.c;h=efda4e8b93cef37a1a354724695b039bfbf0017f;hp=0821a613bb8b415410f01813f77f1b2465a1198c;hb=0f906dafb2ad22371a753557562ef95c3034480d;hpb=b301e959d73eee0955c57004f344f17af00703f4 diff --git a/sam_view.c b/sam_view.c index 0821a61..efda4e8 100644 --- a/sam_view.c +++ b/sam_view.c @@ -19,8 +19,10 @@ typedef struct { typedef khash_t(rg) *rghash_t; +// FIXME: we'd better use no global variables... static rghash_t g_rghash = 0; static int g_min_mapQ = 0, g_flag_on = 0, g_flag_off = 0; +static float g_subsam = -1; static char *g_library, *g_rg; static void *g_bed; @@ -34,6 +36,11 @@ static inline int __g_skip_aln(const bam_header_t *h, const bam1_t *b) return 1; if (g_bed && b->core.tid >= 0 && !bed_overlap(g_bed, h->target_name[b->core.tid], b->core.pos, bam_calend(&b->core, bam1_cigar(b)))) return 1; + if (g_subsam > 0.) { + int x = (int)(g_subsam + .499); + uint32_t k = __ac_X31_hash_string(bam1_qname(b)) + x; + if (k%1024 / 1024.0 >= g_subsam - x) return 1; + } if (g_rg || g_rghash) { uint8_t *s = bam_aux_get(b, "RG"); if (s) { @@ -111,8 +118,9 @@ int main_samview(int argc, char *argv[]) /* parse command-line options */ strcpy(in_mode, "r"); strcpy(out_mode, "w"); - while ((c = getopt(argc, argv, "Sbct:h1Ho:q:f:F:ul:r:xX?T:R:L:")) >= 0) { + while ((c = getopt(argc, argv, "Sbct:h1Ho:q:f:F:ul:r:xX?T:R:L:s:")) >= 0) { switch (c) { + case 's': g_subsam = atof(optarg); break; case 'c': is_count = 1; break; case 'S': is_bamin = 0; break; case 'b': is_bamout = 1; break; @@ -279,6 +287,7 @@ static int usage(int is_long_help) fprintf(stderr, " -q INT minimum mapping quality [0]\n"); fprintf(stderr, " -l STR only output reads in library STR [null]\n"); fprintf(stderr, " -r STR only output reads in read group STR [null]\n"); + fprintf(stderr, " -s FLOAT fraction of templates to subsample; integer part as seed [-1]\n"); fprintf(stderr, " -? longer help\n"); fprintf(stderr, "\n"); if (is_long_help)