3 * This file is part of fastq-tools.
5 * Copyright (c) 2011 by Daniel C. Jones <dcjones@cs.washington.edu>
8 * Adjust quality scores by a given offset.
22 #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
25 # define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
27 # define SET_BINARY_MODE(file)
31 static const char* prog_name = "fastq-grep";
36 "fastq-qualadj [OPTION]... OFFSET [FILE]...\n"
37 "The given offset is added to each and every quality score, where\n"
38 "the offset may be negative.\n"
40 " -h, --help print this message\n"
41 " -V, --version output version information and exit\n"
45 void fastq_qualadj(FILE* fin, FILE* fout, int offset)
47 fastq_t* fqf = fastq_open(fin);
48 seq_t* seq = fastq_alloc_seq();
52 while (fastq_next(fqf, seq)) {
53 for (i = 0; i < seq->qual.n; ++i) {
54 c = (int) seq->qual.s[i] - offset;
55 c = c < 0 ? 0 : (c > 126 ? 126: c);
56 seq->qual.s[i] = (char) c;
59 fastq_print(fout, seq);
67 int main(int argc, char* argv[])
69 SET_BINARY_MODE(stdin);
70 SET_BINARY_MODE(stdout);
74 static struct option long_options[] =
76 {"help", no_argument, NULL, 'h'},
77 {"version", no_argument, NULL, 'V'},
85 opt = getopt_long(argc, argv, "hV", long_options, &opt_idx);
95 print_version(stdout, prog_name);
106 if (optind >= argc) {
107 fprintf(stderr, "An offset must be specified.\n");
111 offset = atoi(argv[optind++]);
116 if (optind >= argc || (argc - optind == 1 && strcmp(argv[optind],"-") == 0)) {
117 fastq_qualadj(stdin, stdout, offset);
120 for (; optind < argc; optind++) {
121 fin = fopen(argv[optind], "rb");
123 fprintf(stderr, "No such file '%s'.\n", argv[optind]);
127 fastq_qualadj(fin, stdout, offset);