From 647cc6ebb358b3089baad06998772457ab9cf093 Mon Sep 17 00:00:00 2001 From: Heng Li Date: Sat, 13 Jun 2009 16:52:31 +0000 Subject: [PATCH] * samtools-0.1.4-11 (r346) * allow to select a read group at view command-line --- Makefile | 2 +- bamtk.c | 2 +- sam_view.c | 18 ++++++++++++------ samtools.1 | 2 -- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 9bf6d80..c529c7e 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ LOBJS= bgzf.o kstring.o bam_aux.o bam.o bam_import.o sam.o bam_index.o \ AOBJS= bam_sort.o bam_tview.o bam_maqcns.o bam_plcmd.o sam_view.o \ bam_rmdup.o bam_rmdupse.o bam_mate.o bam_stat.o bam_color.o \ bamtk.o -PROG= samtools bgzip +PROG= samtools INCLUDES= SUBDIRS= . misc diff --git a/bamtk.c b/bamtk.c index ff5f642..27dde03 100644 --- a/bamtk.c +++ b/bamtk.c @@ -3,7 +3,7 @@ #include "bam.h" #ifndef PACKAGE_VERSION -#define PACKAGE_VERSION "0.1.4-10 (r341)" +#define PACKAGE_VERSION "0.1.4-11 (r346)" #endif int bam_taf2baf(int argc, char *argv[]); diff --git a/sam_view.c b/sam_view.c index 95a52c8..e96afee 100644 --- a/sam_view.c +++ b/sam_view.c @@ -5,17 +5,20 @@ #include "sam.h" static int g_min_mapQ = 0, g_flag_on = 0, g_flag_off = 0; -static char *g_library; +static char *g_library, *g_rg; static inline int __g_skip_aln(const bam_header_t *h, const bam1_t *b) { if (b->core.qual < g_min_mapQ || ((b->core.flag & g_flag_on) != g_flag_on) || (b->core.flag & g_flag_off)) return 1; - if (g_library) { + if (g_library || g_rg) { uint8_t *s = bam_aux_get(b, "RG"); if (s) { - const char *p = bam_strmap_get(h->rg2lib, (char*)(s + 1)); - return (p && strcmp(p, g_library) == 0)? 0 : 1; + if (g_rg && strcmp(g_rg, (char*)(s + 1)) == 0) return 0; + if (g_library) { + const char *p = bam_strmap_get(h->rg2lib, (char*)(s + 1)); + return (p && strcmp(p, g_library) == 0)? 0 : 1; + } return 1; } else return 1; } else return 0; } @@ -38,7 +41,7 @@ int main_samview(int argc, char *argv[]) /* parse command-line options */ strcpy(in_mode, "r"); strcpy(out_mode, "w"); - while ((c = getopt(argc, argv, "Sbt:hHo:q:f:F:ul:")) >= 0) { + while ((c = getopt(argc, argv, "Sbt:hHo:q:f:F:ul:r:")) >= 0) { switch (c) { case 'S': is_bamin = 0; break; case 'b': is_bamout = 1; break; @@ -51,6 +54,7 @@ int main_samview(int argc, char *argv[]) case 'q': g_min_mapQ = atoi(optarg); break; case 'u': is_uncompressed = 1; break; case 'l': g_library = strdup(optarg); break; + case 'r': g_rg = strdup(optarg); break; default: return usage(); } } @@ -104,7 +108,7 @@ int main_samview(int argc, char *argv[]) view_end: // close files, free and return - free(fn_list); free(fn_out); free(g_library); + free(fn_list); free(fn_out); free(g_library); free(g_rg); samclose(in); samclose(out); return ret; @@ -124,6 +128,8 @@ static int usage() fprintf(stderr, " -f INT required flag, 0 for unset [0]\n"); fprintf(stderr, " -F INT filtering flag, 0 for unset [0]\n"); 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, "\n\ Notes:\n\ \n\ diff --git a/samtools.1 b/samtools.1 index 99ab3f6..c4bd77e 100644 --- a/samtools.1 +++ b/samtools.1 @@ -368,8 +368,6 @@ _ Unaligned words used in bam_import.c, bam_endian.h, bam.c and bam_aux.c. .IP o 2 CIGAR operation P is not properly handled at the moment. -.IP o 2 -The text viewer mysteriously crashes in a very rare case. .SH AUTHOR .PP -- 2.39.2