3 * This file is part of fastq-tools.
5 * Copyright (c) 2011 by Daniel C. Jones <dcjones@cs.washington.edu>
8 * Smith-Waterman alignments against sequences within a fastq file.
21 #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
24 # define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
26 # define SET_BINARY_MODE(file)
30 static const char* prog_name = "fastq-match";
36 "fastq-match [OPTION]... QUERY [FILE]...\n"
37 "Perform Smith-Waterman local alignment of a query sequence\n"
38 "against each sequence in a fastq file.\n\n"
40 " -h, --help print this message\n"
41 " -V, --version output version information and exit\n"
46 void fastq_match(FILE* fin, FILE* fout, sw_t* sw)
50 fastq_t* fqf = fastq_open(fin);
51 seq_t* seq = fastq_alloc_seq();
53 while (fastq_next(fqf, seq)) {
54 fprintf(fout, "%s\t", seq->seq.s);
56 fastq_sw_conv_seq((unsigned char*)seq->seq.s, seq->seq.n);
57 score = fastq_sw(sw, (unsigned char*)seq->seq.s, seq->seq.n);
59 fprintf(fout, "%d\n", score);
68 int main(int argc, char* argv[])
70 SET_BINARY_MODE(stdin);
71 SET_BINARY_MODE(stdout);
83 static struct option long_options[] =
85 {"help", no_argument, NULL, 'h'},
86 {"version", no_argument, NULL, 'V'},
92 opt = getopt_long(argc, argv, "hV", long_options, &opt_idx);
98 if (long_options[opt_idx].flag != 0) break;
108 print_version(stdout, prog_name);
120 if (optind >= argc) {
121 fprintf(stderr, "A query sequence must be specified.\n");
125 query = (unsigned char*)argv[optind++];
126 query_len = strlen((char*)query);
127 fastq_sw_conv_seq(query, query_len);
129 sw = fastq_alloc_sw(query, query_len);
131 if (optind >= argc || (argc - optind == 1 && strcmp(argv[optind],"-") == 0)) {
132 fastq_match(stdin, stdout, sw);
135 for (; optind < argc; optind++) {
136 fin = fopen(argv[optind], "rb");
138 fprintf(stderr, "No such file '%s'.\n", argv[optind]);
142 fastq_match(fin, stdout, sw);