]> git.donarmstrong.com Git - samtools.git/commitdiff
Merge branch 'master' into mt
authorHeng Li <lh3@me.com>
Tue, 20 Mar 2012 15:49:52 +0000 (11:49 -0400)
committerHeng Li <lh3@me.com>
Tue, 20 Mar 2012 15:49:52 +0000 (11:49 -0400)
1  2 
sam_view.c

diff --combined sam_view.c
index b6896c908cb367c1083eb3fbe994fe3c83a753f4,ce1e1092b791386d27d8e88f61dee1ed8332dc3f..d1178ffd4dd36c8805ef00230c51ff161af226c6
@@@ -22,7 -22,8 +22,8 @@@ 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, g_qual_scale = 0;
- static float g_subsam = -1;
+ static uint32_t g_subsam_seed = 0;
+ static double g_subsam_frac = -1.;
  static char *g_library, *g_rg;
  static void *g_bed;
  
@@@ -44,10 -45,9 +45,9 @@@ static int process_aln(const bam_header
                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_subsam_frac > 0.) {
+               uint32_t k = __ac_X31_hash_string(bam1_qname(b)) + g_subsam_seed;
+               if ((double)(k&0xffffff) / 0x1000000 >= g_subsam_frac) return 1;
        }
        if (g_rg || g_rghash) {
                uint8_t *s = bam_aux_get(b, "RG");
@@@ -119,16 -119,22 +119,22 @@@ static int usage(int is_long_help)
  int main_samview(int argc, char *argv[])
  {
        int c, is_header = 0, is_header_only = 0, is_bamin = 1, ret = 0, compress_level = -1, is_bamout = 0, is_count = 0;
 -      int of_type = BAM_OFDEC, is_long_help = 0;
 +      int of_type = BAM_OFDEC, is_long_help = 0, n_threads = 0;
        int count = 0;
        samfile_t *in = 0, *out = 0;
-       char in_mode[5], out_mode[5], *fn_out = 0, *fn_list = 0, *fn_ref = 0, *fn_rg = 0;
+       char in_mode[5], out_mode[5], *fn_out = 0, *fn_list = 0, *fn_ref = 0, *fn_rg = 0, *q;
  
        /* parse command-line options */
        strcpy(in_mode, "r"); strcpy(out_mode, "w");
 -      while ((c = getopt(argc, argv, "SbBct:h1Ho:q:f:F:ul:r:xX?T:R:L:s:Q:")) >= 0) {
 +      while ((c = getopt(argc, argv, "SbBct:h1Ho:q:f:F:ul:r:xX?T:R:L:s:Q:@:")) >= 0) {
                switch (c) {
-               case 's': g_subsam = atof(optarg); break;
+               case 's':
+                       if ((g_subsam_seed = strtol(optarg, &q, 10)) != 0) {
+                               srand(g_subsam_seed);
+                               g_subsam_seed = rand();
+                       }
+                       g_subsam_frac = strtod(q, &q);
+                       break;
                case 'c': is_count = 1; break;
                case 'S': is_bamin = 0; break;
                case 'b': is_bamout = 1; break;
                case 'T': fn_ref = strdup(optarg); is_bamin = 0; break;
                case 'B': bam_no_B = 1; break;
                case 'Q': g_qual_scale = atoi(optarg); break;
 +              case '@': n_threads = strtol(optarg, 0, 0); break;
                default: return usage(is_long_help);
                }
        }
                ret = 1;
                goto view_end;
        }
 +      if (n_threads > 1) samthreads(out, n_threads, 256); 
        if (is_header_only) goto view_end; // no need to print alignments
  
        if (argc == optind + 1) { // convert/print the entire file
@@@ -290,7 -294,6 +296,7 @@@ static int usage(int is_long_help
        fprintf(stderr, "         -X       output FLAG in string (samtools-C specific)\n");
        fprintf(stderr, "         -c       print only the count of matching records\n");
        fprintf(stderr, "         -B       collapse the backward CIGAR operation\n");
 +      fprintf(stderr, "         -@ INT   number of BAM compression threads [0]\n");
        fprintf(stderr, "         -L FILE  output alignments overlapping the input BED FILE [null]\n");
        fprintf(stderr, "         -t FILE  list of reference names and lengths (force -S) [null]\n");
        fprintf(stderr, "         -T FILE  reference sequence file (force -S) [null]\n");