From 10b2ce25ac2988e2bcc9ba2abb79f8bd07fb1a8b Mon Sep 17 00:00:00 2001 From: Ondrej Novak <novako20@fit.cvut.cz> Date: Fri, 11 Dec 2015 10:16:13 +0100 Subject: [PATCH] add results argument --- dtw.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/dtw.c b/dtw.c index 9821eaf..8403aeb 100644 --- a/dtw.c +++ b/dtw.c @@ -5,7 +5,7 @@ #define TEST_CNT 2740 // 2740 // # of test sequences to compare (up to 9999) #define TEST_MAX 8992 // 8992 // length of longest test sequence + 1 -#define RESULTS 100 // # of results to display +// #define RESULTS 100 // # of results to display // #define DEBUG @@ -178,15 +178,17 @@ void sum (const char * arg, int * seq, int seq_len, int * tab) { } int main (int argc, char * argv[]) { - if (argc != 7) { + if (argc != 8) { fprintf( stderr, - "Usage: %s <A> <C> <G> <T> <SPEED> <SEQUENCE>\n\n" + "Usage: %s <A> <C> <G> <T> <SPEED> <RESULTS> <SEQUENCE>\n\n" "\t<A/C/G/T> - int values for sequence conversion, usually in range [-10,10]\n" "\t<SPEED> - int value (percentage) telling how far you can go off the diagonal,\n" "\t from 5 (very fast, not precise) to 100 (full computation)\n" + "\t<RESULTS> - # of results to output as <DTW score>:<sequence number>,\n" + "\t currently %d test sequences available\n" "\t<SEQUENCE> - DNA sequence made of A/C/G/T letters\n", - argv[0] + argv[0], TEST_CNT ); return 1; } @@ -195,6 +197,7 @@ int main (int argc, char * argv[]) { int speed; // speed (but also precision) of computation int tab[4]; // A/C/G/T conversion values + int results; // # of results to output int res[TEST_CNT]; // resulting DTW score for each comparison int * seq, seq_len; // one input sequence int * test, test_len; // current test sequence @@ -210,8 +213,11 @@ int main (int argc, char * argv[]) { dtwm = (int **) malloc (sizeof(int*) * seq_len); for (i = 0; i < seq_len; i++) dtwm[i] = (int *) malloc (sizeof(int) * TEST_MAX); - for (i = 0; i < 4; i++) tab[i] = atoi(argv[i+1]); - speed = atoi(argv[i+1]); + for (i = 1; i <= 4; i++) tab[i] = atoi(argv[i]); + speed = atoi(argv[i++]); + results = atoi(argv[i++]); + if (results < 0) results = 10; + if (results > TEST_CNT) results = TEST_CNT; sum(argv[argc-1], seq, seq_len, tab); for (i = 0; i < TEST_CNT; i++) { sprintf(test_path, "./test/%d.seq", i); @@ -226,14 +232,12 @@ int main (int argc, char * argv[]) { #endif } - for (j = 0; j < RESULTS; j++) { - i = 0; - while (res[i] < 0) i++; - x = i; - for (i++; i < TEST_CNT; i++) { + for (j = 0; j < results; j++) { + x = 0; + for (i = 1; i < TEST_CNT; i++) { if (res[i] < res[x] && res[i] >= 0) x = i; } - // <DTW score>:<test file number> + // <DTW score>:<test sequence number> printf("%d:%d\n", res[x], x); res[x] = -1; } -- GitLab