From 4de08ceaa55e98129c35beba4440ed91d04a0217 Mon Sep 17 00:00:00 2001 From: Anders Kaplan Date: Thu, 23 Mar 2017 19:02:06 +0100 Subject: [PATCH 1/6] Documentation. --- cram/cram_encode.c | 2 +- test/test_view.c | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/cram/cram_encode.c b/cram/cram_encode.c index d7f08f17c..1d9f70ce2 100644 --- a/cram/cram_encode.c +++ b/cram/cram_encode.c @@ -1935,7 +1935,7 @@ static int cram_add_insertion(cram_container *c, cram_slice *s, cram_record *r, } /* - * Encodes auxiliary data. + * Encodes auxiliary data, CRAM 1.0 format. * Returns the read-group parsed out of the BAM aux fields on success * NULL on failure or no rg present (FIXME) */ diff --git a/test/test_view.c b/test/test_view.c index 7f173fd95..22c7b88bc 100644 --- a/test/test_view.c +++ b/test/test_view.c @@ -54,23 +54,39 @@ int main(int argc, char *argv[]) while ((c = getopt(argc, argv, "IbDCSl:t:i:o:N:BZ:@:")) >= 0) { switch (c) { - case 'S': flag |= 1; break; + case 'I': ignore_sam_err = 1; break; case 'b': flag |= 2; break; case 'D': flag |= 4; break; case 'C': flag |= 8; break; - case 'B': benchmark = 1; break; + case 'S': flag |= 1; break; case 'l': clevel = atoi(optarg); flag |= 2; break; case 't': fn_ref = optarg; break; - case 'I': ignore_sam_err = 1; break; case 'i': if (hts_opt_add(&in_opts, optarg)) return 1; break; case 'o': if (hts_opt_add(&out_opts, optarg)) return 1; break; case 'N': nreads = atoi(optarg); break; + case 'B': benchmark = 1; break; case 'Z': extra_hdr_nuls = atoi(optarg); break; case '@': nthreads = atoi(optarg); break; } } if (argc == optind) { - fprintf(stderr, "Usage: samview [-bSCSIB] [-N num_reads] [-l level] [-o option=value] [-Z hdr_nuls] || [region]\n"); + fprintf(stderr, "Usage: test_view [-IbDCS] [-l level] [-t fn_ref] [-i option=value] [-o option=value] [-N num_reads] [-B] [-Z hdr_nuls] [-@ num_threads] || [region]\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "-D: read CRAM format (mode 'c')\n"); + fprintf(stderr, "-S: read compressed BCF, BAM, FAI (mode 'b')\n"); + fprintf(stderr, "-I: ignore SAM parsing errors\n"); + fprintf(stderr, "-t: fn_ref: load CRAM references from the specificed fasta file instead of @SQ headers when writing a CRAM file\n"); + fprintf(stderr, "-i: option=value: set an option for CRAM input\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "-b: write compressed BCF, BAM, FAI (mode 'b')\n"); + fprintf(stderr, "-C: write CRAM format (mode 'c')\n"); + fprintf(stderr, "-l 0-9: set zlib compression level\n"); + fprintf(stderr, "-o option=value: set an option for CRAM output\n"); + fprintf(stderr, "-N: num_reads: limit the output to the first num_reads reads\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "-B: enable benchmarking\n"); + fprintf(stderr, "-Z hdr_nuls: append specified number of null bytes to the SAM header\n"); + fprintf(stderr, "-@ num_threads: use thread pool with specified number of threads\n"); return 1; } strcpy(moder, "r"); From c00892b06233135fdc38ffb02bb28e64ce8530c3 Mon Sep 17 00:00:00 2001 From: Anders Kaplan Date: Thu, 23 Mar 2017 19:02:06 +0100 Subject: [PATCH 2/6] Adaptations to Windows line endings and binary/text files: -let hfile call setmode(O_BINARY) on _all_ file handles, not only stdin and stdout. -stop git from converting line endings on the reference fasta files. -make the test scripts handle CRLF line endings, too. Perl should take care of it, according to the docs, but it doesn't. --- .gitignore | 3 +++ hfile.c | 6 +++--- test/.gitattributes | 4 ++++ test/compare_sam.pl | 2 ++ test/hfile.c | 9 +++++---- test/test.pl | 4 +++- test/test_bgzf.c | 2 ++ 7 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 test/.gitattributes diff --git a/.gitignore b/.gitignore index 6972b555e..5fb8c3109 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ *.pico *.dSYM *.exe +*.dll +*.obj *.pc.tmp *-uninstalled.pc /version.h @@ -47,5 +49,6 @@ lib*.so.* /test/thrash_threads[1-6] /test/*.tmp /test/*.tmp.* +/test/*.new /TAGS diff --git a/hfile.c b/hfile.c index 5fc58c736..ebad06f0e 100644 --- a/hfile.c +++ b/hfile.c @@ -573,6 +573,9 @@ static hFILE *hopen_fd(const char *filename, const char *mode) hFILE *hdopen(int fd, const char *mode) { +#if defined HAVE_SETMODE && defined O_BINARY + if (setmode(fd, O_BINARY) < 0) return NULL; +#endif hFILE_fd *fp = (hFILE_fd*) hfile_init(sizeof (hFILE_fd), mode, blksize(fd)); if (fp == NULL) return NULL; @@ -594,9 +597,6 @@ static hFILE *hopen_fd_fileuri(const char *url, const char *mode) static hFILE *hopen_fd_stdinout(const char *mode) { int fd = (strchr(mode, 'r') != NULL)? STDIN_FILENO : STDOUT_FILENO; -#if defined HAVE_SETMODE && defined O_BINARY - if (setmode(fd, O_BINARY) < 0) return NULL; -#endif return hdopen(fd, mode); } diff --git a/test/.gitattributes b/test/.gitattributes new file mode 100644 index 000000000..39c994397 --- /dev/null +++ b/test/.gitattributes @@ -0,0 +1,4 @@ +# Remove the text attribute from reference files, so that git doesn't convert +# line separators on Windows machines. It causes the index files to become out +# of sync with the fasta files. +*.fa* -text diff --git a/test/compare_sam.pl b/test/compare_sam.pl index a241c6b68..6860c91a5 100755 --- a/test/compare_sam.pl +++ b/test/compare_sam.pl @@ -64,6 +64,8 @@ # Compare lines while ($ln1 && $ln2) { + $ln1 =~ s/\015?\012/\n/; + $ln2 =~ s/\015?\012/\n/; chomp($ln1); chomp($ln2); diff --git a/test/hfile.c b/test/hfile.c index 16ad6708a..d1f3b388b 100644 --- a/test/hfile.c +++ b/test/hfile.c @@ -61,16 +61,17 @@ char *slurp(const char *filename) { char *text; struct stat sbuf; - size_t filesize; - FILE *f = fopen(filename, "r"); - if (f == NULL) fail("fopen(\"%s\", \"r\")", filename); + size_t filesize, readsize; + FILE *f = fopen(filename, "rb"); + if (f == NULL) fail("fopen(\"%s\", \"rb\")", filename); if (fstat(fileno(f), &sbuf) != 0) fail("fstat(\"%s\")", filename); filesize = sbuf.st_size; text = (char *) malloc(filesize + 1); if (text == NULL) fail("malloc(text)"); - if (fread(text, 1, filesize, f) != filesize) fail("fread"); + readsize = fread(text, 1, filesize, f); + if (readsize != filesize) fail("fread"); fclose(f); text[filesize] = '\0'; diff --git a/test/test.pl b/test/test.pl index 5f94e5f3f..6c8afcb9a 100755 --- a/test/test.pl +++ b/test/test.pl @@ -148,11 +148,13 @@ sub test_cmd { my @exp = <$fh>; $exp = join('',@exp); + $exp =~ s/\015?\012/\n/g; close($fh); } elsif ( !$$opts{redo_outputs} ) { failed($opts,$test,"$$opts{path}/$args{out}: $!"); return; } - if ( $exp ne $out ) + (my $out_lf = $out) =~ s/\015?\012/\n/g; + if ( $exp ne $out_lf ) { open(my $fh,'>',"$$opts{path}/$args{out}.new") or error("$$opts{path}/$args{out}.new"); print $fh $out; diff --git a/test/test_bgzf.c b/test/test_bgzf.c index e34b22f01..12a7e3443 100644 --- a/test/test_bgzf.c +++ b/test/test_bgzf.c @@ -23,6 +23,8 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include + #include #include #include From 55af531e20f9d0faa7dc171bc83479b3d5008996 Mon Sep 17 00:00:00 2001 From: Anders Kaplan Date: Thu, 23 Mar 2017 19:02:06 +0100 Subject: [PATCH 3/6] Added a fail-fast flag to test/test.pl. When the flag is given, the test stops on the first error it encounters. --- test/test.pl | 56 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/test/test.pl b/test/test.pl index 6c8afcb9a..bcdb10819 100755 --- a/test/test.pl +++ b/test/test.pl @@ -63,6 +63,7 @@ sub error "Options:\n", " -r, --redo-outputs Recreate expected output files.\n", " -t, --temp-dir When given, temporary files will not be removed.\n", + " -f, --fail-fast Fail-fast mode: exit as soon as a test fails.\n", " -h, -?, --help This help message.\n", "\n"; exit 1; @@ -75,6 +76,7 @@ sub parse_params my $ret = GetOptions ( 't|temp-dir:s' => \$$opts{keep_files}, 'r|redo-outputs' => \$$opts{redo_outputs}, + 'f|fail-fast' => \$$opts{fail_fast}, 'h|?|help' => \$help ); if ( !$ret or $help ) { error(); } @@ -182,6 +184,9 @@ sub failed if ( defined $reason ) { print STDERR "\t$reason\n"; } print STDERR ".. failed ...\n\n"; STDERR->flush(); + if ($$opts{fail_fast}) { + die "\n"; + } } sub passed { @@ -203,7 +208,7 @@ sub is_file_newer my $test_view_failures; sub testv { - my ($cmd) = @_; + my ($opts, $cmd) = @_; print " $cmd\n"; my ($ret, $out) = _cmd($cmd); if ($ret != 0) { @@ -211,6 +216,9 @@ sub testv { print STDERR "FAILED\n$out\n"; STDERR->flush(); $test_view_failures++; + if ($$opts{fail_fast}) { + die "\n"; + } } } @@ -235,50 +243,50 @@ sub test_view $test_view_failures = 0; # SAM -> BAM -> SAM - testv "./test_view $tv_args -S -b $sam > $bam"; - testv "./test_view $tv_args $bam > $bam.sam_"; - testv "./compare_sam.pl $sam $bam.sam_"; + testv $opts, "./test_view $tv_args -S -b $sam > $bam"; + testv $opts, "./test_view $tv_args $bam > $bam.sam_"; + testv $opts, "./compare_sam.pl $sam $bam.sam_"; # SAM -> CRAM -> SAM - testv "./test_view $tv_args -t $ref -S -C $sam > $cram"; - testv "./test_view $tv_args -D $cram > $cram.sam_"; - testv "./compare_sam.pl $md $sam $cram.sam_"; + testv $opts, "./test_view $tv_args -t $ref -S -C $sam > $cram"; + testv $opts, "./test_view $tv_args -D $cram > $cram.sam_"; + testv $opts, "./compare_sam.pl $md $sam $cram.sam_"; # BAM -> CRAM -> BAM -> SAM $cram = "$bam.cram"; - testv "./test_view $tv_args -t $ref -C $bam > $cram"; - testv "./test_view $tv_args -b -D $cram > $cram.bam"; - testv "./test_view $tv_args $cram.bam > $cram.bam.sam_"; - testv "./compare_sam.pl $md $sam $cram.bam.sam_"; + testv $opts, "./test_view $tv_args -t $ref -C $bam > $cram"; + testv $opts, "./test_view $tv_args -b -D $cram > $cram.bam"; + testv $opts, "./test_view $tv_args $cram.bam > $cram.bam.sam_"; + testv $opts, "./compare_sam.pl $md $sam $cram.bam.sam_"; # SAM -> CRAM3 -> SAM $cram = "$base.tmp.cram"; - testv "./test_view $tv_args -t $ref -S -C -o VERSION=3.0 $sam > $cram"; - testv "./test_view $tv_args -D $cram > $cram.sam_"; - testv "./compare_sam.pl $md $sam $cram.sam_"; + testv $opts, "./test_view $tv_args -t $ref -S -C -o VERSION=3.0 $sam > $cram"; + testv $opts, "./test_view $tv_args -D $cram > $cram.sam_"; + testv $opts, "./compare_sam.pl $md $sam $cram.sam_"; # BAM -> CRAM3 -> BAM -> SAM $cram = "$bam.cram"; - testv "./test_view $tv_args -t $ref -C -o VERSION=3.0 $bam > $cram"; - testv "./test_view $tv_args -b -D $cram > $cram.bam"; - testv "./test_view $tv_args $cram.bam > $cram.bam.sam_"; - testv "./compare_sam.pl $md $sam $cram.bam.sam_"; + testv $opts, "./test_view $tv_args -t $ref -C -o VERSION=3.0 $bam > $cram"; + testv $opts, "./test_view $tv_args -b -D $cram > $cram.bam"; + testv $opts, "./test_view $tv_args $cram.bam > $cram.bam.sam_"; + testv $opts, "./compare_sam.pl $md $sam $cram.bam.sam_"; # CRAM3 -> CRAM2 $cram = "$base.tmp.cram"; - testv "./test_view $tv_args -t $ref -C -o VERSION=2.1 $cram > $cram.cram"; + testv $opts, "./test_view $tv_args -t $ref -C -o VERSION=2.1 $cram > $cram.cram"; # CRAM2 -> CRAM3 - testv "./test_view $tv_args -t $ref -C -o VERSION=3.0 $cram.cram > $cram"; - testv "./test_view $tv_args $cram > $cram.sam_"; - testv "./compare_sam.pl $md $sam $cram.sam_"; + testv $opts, "./test_view $tv_args -t $ref -C -o VERSION=3.0 $cram.cram > $cram"; + testv $opts, "./test_view $tv_args $cram > $cram.sam_"; + testv $opts, "./compare_sam.pl $md $sam $cram.sam_"; # Java pre-made CRAM -> SAM my $jcram = "${base}_java.cram"; if (-e $jcram) { my $jsam = "${base}_java.tmp.sam_"; - testv "./test_view $tv_args -i reference=$ref $jcram > $jsam"; - testv "./compare_sam.pl -Baux $md $sam $jsam"; + testv $opts, "./test_view $tv_args -i reference=$ref $jcram > $jsam"; + testv $opts, "./compare_sam.pl -Baux $md $sam $jsam"; } if ($test_view_failures == 0) From b117a87b75a6fa20626f8494c9fd26d42c198aa3 Mon Sep 17 00:00:00 2001 From: Anders Kaplan Date: Thu, 23 Mar 2017 19:02:06 +0100 Subject: [PATCH 4/6] Updated after review. Note that there are still some open questions. --- .gitattributes | 5 +++++ .gitignore | 3 +-- test/.gitattributes | 4 ---- test/hfile.c | 3 +-- 4 files changed, 7 insertions(+), 8 deletions(-) delete mode 100644 test/.gitattributes diff --git a/.gitattributes b/.gitattributes index 173dcd329..da0ea8308 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10,3 +10,8 @@ .git* export-ignore /.travis.yml export-ignore README.md export-ignore + +# Remove the text attribute from reference files, so that git doesn't convert +# line separators on Windows machines. It causes the index files to become out +# of sync with the fasta files. +*.fa* -text diff --git a/.gitignore b/.gitignore index 5fb8c3109..6101b215b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,9 @@ *.o *.pico +*.obj *.dSYM *.exe *.dll -*.obj *.pc.tmp *-uninstalled.pc /version.h @@ -49,6 +49,5 @@ lib*.so.* /test/thrash_threads[1-6] /test/*.tmp /test/*.tmp.* -/test/*.new /TAGS diff --git a/test/.gitattributes b/test/.gitattributes deleted file mode 100644 index 39c994397..000000000 --- a/test/.gitattributes +++ /dev/null @@ -1,4 +0,0 @@ -# Remove the text attribute from reference files, so that git doesn't convert -# line separators on Windows machines. It causes the index files to become out -# of sync with the fasta files. -*.fa* -text diff --git a/test/hfile.c b/test/hfile.c index d1f3b388b..358ac709c 100644 --- a/test/hfile.c +++ b/test/hfile.c @@ -70,8 +70,7 @@ char *slurp(const char *filename) text = (char *) malloc(filesize + 1); if (text == NULL) fail("malloc(text)"); - readsize = fread(text, 1, filesize, f); - if (readsize != filesize) fail("fread"); + if (fread(text, 1, filesize, f) != filesize) fail("fread"); fclose(f); text[filesize] = '\0'; From 352a28f3b7f862f1c2bea8693bdceeb180c1c8df Mon Sep 17 00:00:00 2001 From: Anders Kaplan Date: Thu, 23 Mar 2017 19:02:06 +0100 Subject: [PATCH 5/6] Reverted the setmode change in hfile.c and replaced it with a patch for the failing test case. Added comment that the file descriptor must be binary in hopen and bgzf_dopen. --- hfile.c | 6 +++--- htslib/bgzf.h | 3 +++ htslib/hfile.h | 4 ++++ test/test_bgzf.c | 13 ++----------- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/hfile.c b/hfile.c index ebad06f0e..5fc58c736 100644 --- a/hfile.c +++ b/hfile.c @@ -573,9 +573,6 @@ static hFILE *hopen_fd(const char *filename, const char *mode) hFILE *hdopen(int fd, const char *mode) { -#if defined HAVE_SETMODE && defined O_BINARY - if (setmode(fd, O_BINARY) < 0) return NULL; -#endif hFILE_fd *fp = (hFILE_fd*) hfile_init(sizeof (hFILE_fd), mode, blksize(fd)); if (fp == NULL) return NULL; @@ -597,6 +594,9 @@ static hFILE *hopen_fd_fileuri(const char *url, const char *mode) static hFILE *hopen_fd_stdinout(const char *mode) { int fd = (strchr(mode, 'r') != NULL)? STDIN_FILENO : STDOUT_FILENO; +#if defined HAVE_SETMODE && defined O_BINARY + if (setmode(fd, O_BINARY) < 0) return NULL; +#endif return hdopen(fd, mode); } diff --git a/htslib/bgzf.h b/htslib/bgzf.h index 15c76cd37..b2f41654b 100644 --- a/htslib/bgzf.h +++ b/htslib/bgzf.h @@ -92,6 +92,9 @@ typedef struct __kstring_t { * Open an existing file descriptor for reading or writing. * * @param fd file descriptor + * Note that the file must be opened in binary mode, or else + * there will be problems on platforms that make a difference + * between text and binary mode. * @param mode mode matching /[rwag][u0-9]+/: 'r' for reading, 'w' for * writing, 'a' for appending, 'g' for gzip rather than BGZF * compression (with 'w' only), and digit specifies the zlib diff --git a/htslib/hfile.h b/htslib/hfile.h index d07a755d1..fa8971842 100644 --- a/htslib/hfile.h +++ b/htslib/hfile.h @@ -66,6 +66,10 @@ hFILE *hopen(const char *filename, const char *mode, ...) HTS_RESULT_USED; /// Associate a stream with an existing open file descriptor /** @return An hFILE pointer, or `NULL` (with _errno_ set) if an error occurred. +Note that the file must be opened in binary mode, or else +there will be problems on platforms that make a difference +between text and binary mode. + For socket descriptors (on Windows), _mode_ should contain `s`. */ hFILE *hdopen(int fd, const char *mode) HTS_RESULT_USED; diff --git a/test/test_bgzf.c b/test/test_bgzf.c index 12a7e3443..c98382940 100644 --- a/test/test_bgzf.c +++ b/test/test_bgzf.c @@ -34,6 +34,7 @@ DEALINGS IN THE SOFTWARE. #include #include "htslib/bgzf.h" #include "htslib/hfile.h" +#include "hfile_internal.h" const char *bgzf_suffix = ".gz"; const char *idx_suffix = ".gzi"; @@ -115,17 +116,7 @@ static BGZF * try_bgzf_open(const char *name, const char *mode, static BGZF * try_bgzf_dopen(const char *name, const char *mode, const char *func) { BGZF *bgz = NULL; - int fd = -1; - if (strchr(mode, 'r')) { - fd = open(name, O_RDONLY); - } else if (strchr(mode, 'w')) { - fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0666); - } else if (strchr(mode, 'a')) { - fd = open(name, O_WRONLY | O_CREAT | O_APPEND, 0666); - } else { - errno = EINVAL; - } - + int fd = open(name, hfile_oflags(mode), 0666); if (fd < 0) { fprintf(stderr, "%s : Failed to open %s with mode %s : %s\n", func, name, mode, strerror(errno)); From 7bef41d566dfe63b091036829064c68e573609ff Mon Sep 17 00:00:00 2001 From: Anders Kaplan Date: Thu, 23 Mar 2017 19:02:06 +0100 Subject: [PATCH 6/6] Aligned the order of the getopt parameters and switch cases in test_view to match the usage instructions. Also replaced magic numbers with constants to make the code more readable. --- test/test_view.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/test/test_view.c b/test/test_view.c index 22c7b88bc..9d2678a53 100644 --- a/test/test_view.c +++ b/test/test_view.c @@ -35,6 +35,13 @@ DEALINGS IN THE SOFTWARE. */ #include "htslib/sam.h" +enum test_op { + READ_COMPRESSED = 1, + WRITE_COMPRESSED = 2, + READ_CRAM = 4, + WRITE_CRAM = 8 +}; + int main(int argc, char *argv[]) { samFile *in; @@ -52,16 +59,16 @@ int main(int argc, char *argv[]) int benchmark = 0; int nthreads = 0; // shared pool - while ((c = getopt(argc, argv, "IbDCSl:t:i:o:N:BZ:@:")) >= 0) { + while ((c = getopt(argc, argv, "DSIt:i:bCl:o:N:BZ:@:")) >= 0) { switch (c) { + case 'D': flag |= READ_CRAM; break; + case 'S': flag |= READ_COMPRESSED; break; case 'I': ignore_sam_err = 1; break; - case 'b': flag |= 2; break; - case 'D': flag |= 4; break; - case 'C': flag |= 8; break; - case 'S': flag |= 1; break; - case 'l': clevel = atoi(optarg); flag |= 2; break; case 't': fn_ref = optarg; break; - case 'i': if (hts_opt_add(&in_opts, optarg)) return 1; break; + case 'i': if (hts_opt_add(&in_opts, optarg)) return 1; break; + case 'b': flag |= WRITE_COMPRESSED; break; + case 'C': flag |= WRITE_CRAM; break; + case 'l': clevel = atoi(optarg); flag |= WRITE_COMPRESSED; break; case 'o': if (hts_opt_add(&out_opts, optarg)) return 1; break; case 'N': nreads = atoi(optarg); break; case 'B': benchmark = 1; break; @@ -70,7 +77,7 @@ int main(int argc, char *argv[]) } } if (argc == optind) { - fprintf(stderr, "Usage: test_view [-IbDCS] [-l level] [-t fn_ref] [-i option=value] [-o option=value] [-N num_reads] [-B] [-Z hdr_nuls] [-@ num_threads] || [region]\n"); + fprintf(stderr, "Usage: test_view [-DSI] [-t fn_ref] [-i option=value] [-bC] [-l level] [-o option=value] [-N num_reads] [-B] [-Z hdr_nuls] [-@ num_threads] || [region]\n"); fprintf(stderr, "\n"); fprintf(stderr, "-D: read CRAM format (mode 'c')\n"); fprintf(stderr, "-S: read compressed BCF, BAM, FAI (mode 'b')\n"); @@ -90,8 +97,8 @@ int main(int argc, char *argv[]) return 1; } strcpy(moder, "r"); - if (flag&4) strcat(moder, "c"); - else if ((flag&1) == 0) strcat(moder, "b"); + if (flag & READ_CRAM) strcat(moder, "c"); + else if ((flag & READ_COMPRESSED) == 0) strcat(moder, "b"); in = sam_open(argv[optind], moder); if (in == NULL) { @@ -119,8 +126,8 @@ int main(int argc, char *argv[]) strcpy(modew, "w"); if (clevel >= 0 && clevel <= 9) sprintf(modew + 1, "%d", clevel); - if (flag&8) strcat(modew, "c"); - else if (flag&2) strcat(modew, "b"); + if (flag & WRITE_CRAM) strcat(modew, "c"); + else if (flag & WRITE_COMPRESSED) strcat(modew, "b"); out = hts_open("-", modew); if (out == NULL) { fprintf(stderr, "Error opening standard output\n"); @@ -128,7 +135,7 @@ int main(int argc, char *argv[]) } /* CRAM output */ - if (flag & 8) { + if (flag & WRITE_CRAM) { int ret; // Parse input header and use for CRAM output @@ -171,7 +178,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Error writing output header.\n"); exit_code = 1; } - if (optind + 1 < argc && !(flag&1)) { // BAM input and has a region + if (optind + 1 < argc && !(flag & READ_COMPRESSED)) { // BAM input and has a region int i; hts_idx_t *idx; if ((idx = sam_index_load(in, argv[optind])) == 0) {