]> git.donarmstrong.com Git - fastq-tools.git/commitdiff
Added a program to adjust quality scores by a fixed offset.
authorDaniel Jones <dcjones@cs.washington.edu>
Tue, 22 Nov 2011 20:40:21 +0000 (12:40 -0800)
committerDaniel Jones <dcjones@cs.washington.edu>
Tue, 22 Nov 2011 20:40:21 +0000 (12:40 -0800)
README.md
doc/fastq-qualadj.1 [new file with mode: 0644]
src/Makefile.am
src/fastq-grep.c
src/fastq-qualadj.c [new file with mode: 0644]

index 75a28d3cabdc1153a66bb344f95969276c83c725..c9066774869a03c30c076b4f3f3c426a4e0ab9f1 100644 (file)
--- a/README.md
+++ b/README.md
@@ -26,6 +26,7 @@ information.
 
 * *fastq-uniq* : count duplicate reads
 
+* *fastq-qualadj* : adjust quality scores by a fixed offset
 
 
 install
diff --git a/doc/fastq-qualadj.1 b/doc/fastq-qualadj.1
new file mode 100644 (file)
index 0000000..8945d37
--- /dev/null
@@ -0,0 +1,28 @@
+.TH FASTQ-GREP 1
+
+.SH NAME
+fastq-qualadj - adjust quality scores by a fixed offset
+
+.SH SYNOPSIS
+.B fastq-grep [OPTION]... OFFSET [FILE]...
+
+.SH DESCRIPTION
+The given offset is added to each and every quality score, where the offset may
+be negative. This helps in converting from one scale to another. For example, to
+convert reads in Phred+64 (Illumina 1.3) scale to the Phred+33 scale, on offset
+of -31 can be specified.
+
+One ore more FILEs may be specified, otherwise input is read from standard input.
+Input files may be gziped.
+
+.SH OPTIONS
+.TP
+\fB\-h\fR, \fB\-\-help\fR
+Output a help message and exit.
+.TP
+\fB\-V\fR, \fB\-\-version\fR
+Output version information and exit.
+
+.SH AUTHOR
+Written by Daniel C. Jones <dcjones@cs.washington.edu>
+
index 7bc48d0a98227d61d086d743718d132fbaedf53d..84707f23fe3f31e564e56fc81f943deb8ab876e8 100644 (file)
@@ -1,5 +1,5 @@
 
-bin_PROGRAMS = fastq-grep fastq-kmers fastq-match fastq-uniq fastq-qual fastq-sample
+bin_PROGRAMS = fastq-grep fastq-kmers fastq-match fastq-uniq fastq-qual fastq-sample fastq-qualadj
 
 fastq_common_src=common.h common.c
 fastq_parse_src=parse.h parse.c
@@ -25,3 +25,5 @@ fastq_qual_LDADD   = -lz
 fastq_sample_SOURCES = fastq-sample.c $(fastq_common_src) $(fastq_parse_src) $(fastq_rng_src)
 fastq_sample_LDADD   = -lz
 
+fastq_qualadj_SOURCES = fastq-qualadj.c $(fastq_common_src) $(fastq_parse_src)
+fastq_qualadj_LDADD   = -lz
index 7c9e3bf60ec844a944719d9e87c03d93dfdf424b..994ab587324eb24133baecac8cb75824a4d52f77 100644 (file)
@@ -120,7 +120,7 @@ int main(int argc, char* argv[])
     while (1) {
         opt = getopt_long(argc, argv, "ivchV", long_options, &opt_idx);
 
-        if( opt == -1 ) break;
+        if (opt == -1) break;
 
         switch (opt) {
             case 0:
diff --git a/src/fastq-qualadj.c b/src/fastq-qualadj.c
new file mode 100644 (file)
index 0000000..b14e8c9
--- /dev/null
@@ -0,0 +1,136 @@
+
+/*
+ * This file is part of fastq-tools.
+ *
+ * Copyright (c) 2011 by Daniel C. Jones <dcjones@cs.washington.edu>
+ *
+ * fastq-qualadj:
+ * Adjust quality scores by a given offset.
+ *
+ */
+
+
+#include "common.h"
+#include "parse.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <getopt.h>
+#include <zlib.h>
+
+
+#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
+#  include <fcntl.h>
+#  include <io.h>
+#  define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
+#else
+#  define SET_BINARY_MODE(file)
+#endif
+
+
+static const char* prog_name = "fastq-grep";
+
+void print_help()
+{
+    fprintf(stdout, 
+"fastq-qualadj [OPTION]... OFFSET [FILE]...\n"
+"The given offset is added to each and every quality score, where\n"
+"the offset may be negative.\n"
+"Options:\n"
+"  -h, --help              print this message\n"
+"  -V, --version           output version information and exit\n"
+    );
+}
+
+void fastq_qualadj(FILE* fin, FILE* fout, int offset)
+{
+    fastq_t* fqf = fastq_open(fin);
+    seq_t* seq = fastq_alloc_seq();
+    size_t i;
+    int c;
+
+    while (fastq_next(fqf, seq)) {
+        for (i = 0; i < seq->qual.n; ++i) {
+            c = (int) seq->qual.s[i] - offset;
+            c = c < 0 ? 0 : (c > 126 ? 126: c);
+            seq->qual.s[i] = (char) c;
+        }
+
+        fastq_print(fout, seq);
+    }
+
+    fastq_free_seq(seq);
+    fastq_close(fqf);
+}
+
+
+int main(int argc, char* argv[])
+{
+    SET_BINARY_MODE(stdin);
+    SET_BINARY_MODE(stdout);
+
+    char offset = 0;
+
+    static struct option long_options[] =
+        { 
+          {"help",         no_argument, NULL, 'h'},
+          {"version",      no_argument, NULL, 'V'},
+          {0, 0, 0, 0}
+        };
+
+    int opt;
+    int opt_idx;
+
+    while (1) {
+        opt = getopt_long(argc, argv, "hV", long_options, &opt_idx);
+
+        if (opt == -1) break;
+
+        switch(opt) {
+            case 'h':
+                print_help();
+                return 0;
+
+            case 'V':
+                print_version(stdout, prog_name);
+                return 0;
+
+            case '?':
+                return 1;
+
+            default:
+                abort();
+        }
+    }
+
+    if (optind >= argc) {
+        fprintf(stderr, "An offset must be specified.\n");
+        return 1;
+    }
+
+    offset = atoi(argv[optind++]);
+
+
+    FILE* fin;
+
+    if (optind >= argc || (argc - optind == 1 && strcmp(argv[optind],"-") == 0)) {
+        fastq_qualadj(stdin, stdout, offset);
+    }
+    else {
+        for (; optind < argc; optind++) {
+            fin = fopen(argv[optind], "rb");
+            if (fin == NULL) {
+                fprintf(stderr, "No such file '%s'.\n", argv[optind]);
+                continue;
+            }
+
+            fastq_qualadj(fin, stdout, offset);
+
+            fclose(fin);
+        }
+    }
+
+    return 0;
+}
+
+