X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Ffastq-match.c;h=1e4d9c705344af121b645869edaba736b78736a8;hb=6b0f9cdb1802ed33c21ae30b9b410e94fba1cbf4;hp=69eff70b079a22d455ea4b0d9884481284c8fab0;hpb=48a5939e574874106f1450fd278f602b731d2a83;p=fastq-tools.git diff --git a/src/fastq-match.c b/src/fastq-match.c index 69eff70..1e4d9c7 100644 --- a/src/fastq-match.c +++ b/src/fastq-match.c @@ -10,12 +10,9 @@ */ -#include "fastq-common.h" -#include "fastq-parse.h" -#include "swsse2/blosum62.h" -#include "swsse2/swsse2.h" -#include "swsse2/matrix.h" -#include "swsse2/swstriped.h" +#include "common.h" +#include "parse.h" +#include "sw.h" #include #include #include @@ -30,72 +27,40 @@ #endif -static int help_flag; +static const char* prog_name = "fastq-match"; void print_help() { - fprintf( stderr, + fprintf(stdout, "fastq-match [OPTION]... QUERY [FILE]...\n" "Perform Smith-Waterman local alignment of a query sequence\n" "against each sequence in a fastq file.\n\n" "Options:\n" " -h, --help print this message\n" +" -V, --version output version information and exit\n" ); } -void convert_sequence(unsigned char* s, int n) -{ - int i; - for (i = 0; i < n; i++) { - s[i] = (char)AMINO_ACID_VALUE[(int)s[i]]; - } -} - - -void fastq_match(FILE* fin, FILE* fout, - SwStripedData* sw_data, - unsigned char* query, int n, - SEARCH_OPTIONS* options) +void fastq_match(FILE* fin, FILE* fout, sw_t* sw) { int score; - int gap_init = -(options->gapInit + options->gapExt); - int gap_ext = -options->gapExt; - int threshold = options->threshold; - - fastq_t* fqf = fastq_open(fin); - seq_t* seq = fastq_alloc_seq(); + fastq_t* fqf = fastq_create(fin); + seq_t* seq = seq_create(); - while (fastq_next(fqf, seq)) { + while (fastq_read(fqf, seq)) { fprintf(fout, "%s\t", seq->seq.s); - convert_sequence((unsigned char*)seq->seq.s, seq->seq.n); - - score = swStripedByte(query, n, - (unsigned char*)seq->seq.s, seq->seq.n, - gap_init, gap_ext, - sw_data->pvbQueryProf, - sw_data->pvH1, - sw_data->pvH2, - sw_data->pvE, - sw_data->bias); - if (score >= 255) { - score = swStripedWord(query, n, - (unsigned char*)seq->seq.s, seq->seq.n, - gap_init, gap_ext, - sw_data->pvbQueryProf, - sw_data->pvH1, - sw_data->pvH2, - sw_data->pvE); - } + fastq_sw_conv_seq((unsigned char*)seq->seq.s, seq->seq.n); + score = fastq_sw(sw, (unsigned char*)seq->seq.s, seq->seq.n); fprintf(fout, "%d\n", score); } - fastq_free_seq(seq); - fastq_close(fqf); + seq_free(seq); + fastq_free(fqf); } @@ -107,32 +72,26 @@ int main(int argc, char* argv[]) unsigned char* query; int query_len; - SwStripedData* sw_data; - signed char* mat = blosum62; - SEARCH_OPTIONS options; - options.gapInit = -10; - options.gapExt = -2; - options.threshold = -1; + sw_t* sw; FILE* fin; - help_flag = 0; - int opt; int opt_idx; static struct option long_options[] = { - {"help", no_argument, &help_flag, 1}, + {"help", no_argument, NULL, 'h'}, + {"version", no_argument, NULL, 'V'}, {0, 0, 0, 0} }; while (1) { - opt = getopt_long(argc, argv, "h", long_options, &opt_idx); + opt = getopt_long(argc, argv, "hV", long_options, &opt_idx); - if( opt == -1 ) break; + if (opt == -1) break; switch (opt) { case 0: @@ -142,8 +101,12 @@ int main(int argc, char* argv[]) break; case 'h': - help_flag = 1; - break; + print_help(); + return 0; + + case 'V': + print_version(stdout, prog_name); + return 0; case '?': return 1; @@ -153,10 +116,6 @@ int main(int argc, char* argv[]) } } - if (help_flag) { - print_help(); - return 0; - } if (optind >= argc) { fprintf(stderr, "A query sequence must be specified.\n"); @@ -165,12 +124,12 @@ int main(int argc, char* argv[]) query = (unsigned char*)argv[optind++]; query_len = strlen((char*)query); - convert_sequence(query, query_len); + fastq_sw_conv_seq(query, query_len); - sw_data = swStripedInit(query, query_len, mat); + sw = fastq_alloc_sw(query, query_len); if (optind >= argc || (argc - optind == 1 && strcmp(argv[optind],"-") == 0)) { - fastq_match(stdin, stdout, sw_data, query, query_len, &options); + fastq_match(stdin, stdout, sw); } else { for (; optind < argc; optind++) { @@ -180,11 +139,11 @@ int main(int argc, char* argv[]) continue; } - fastq_match(fin, stdout, sw_data, query, query_len, &options); + fastq_match(fin, stdout, sw); } } - swStripedComplete(sw_data); + fastq_free_sw(sw); return 0; }