--- /dev/null
+.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>
+
--- /dev/null
+
+/*
+ * 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;
+}
+
+