From 9305e6aff665d3af46a6f170cdb2aefc60983395 Mon Sep 17 00:00:00 2001 From: cypridina Date: Tue, 17 Oct 2017 23:15:44 -0700 Subject: [PATCH 1/2] arithemetic mean of qual rather than geometric --- addon.c | 12 ++++++++++++ addon.h | 2 ++ lex.c | 1 + 3 files changed, 15 insertions(+) diff --git a/addon.c b/addon.c index 7f6d6c3..bae4879 100644 --- a/addon.c +++ b/addon.c @@ -230,6 +230,18 @@ Cell *bio_func(int f, Cell *x, Node **a) if (buf[i] - 33 >= thres) ++cnt; setfval(y, (Awkfloat)cnt); } + } else if (f == BIO_FARITHMEANQUAL) { + char *buf; + int i, l = 0; + double total_qual = 0.0; + buf = getsval(x); + /*printf("%s \n", buf);*/ + l = strlen(buf); + if (l) { /* don't try for empty strings */ + for (i = 0; i < l; ++i) + total_qual += pow(10, -((double)(buf[i] - 33) / 10) ); + setfval(y, (Awkfloat)(-10 * log10(total_qual / l)) ); + } } /* else: never happens */ return y; } diff --git a/addon.h b/addon.h index e86552e..e5b96f6 100644 --- a/addon.h +++ b/addon.h @@ -41,6 +41,8 @@ int bio_getrec(char **pbuf, int *psize, int isrecord); #define BIO_FMEANQUAL 204 #define BIO_FQUALCOUNT 205 #define BIO_FTRIMQ 206 +#define BIO_FARITHMEANQUAL 207 + struct Cell; diff --git a/lex.c b/lex.c index d470364..a3cf5d3 100644 --- a/lex.c +++ b/lex.c @@ -48,6 +48,7 @@ Keyword keywords[] ={ /* keep sorted: binary searched */ { "END", XEND, XEND }, { "NF", VARNF, VARNF }, { "and", BIO_FAND, BLTIN }, + { "arithmeanqual", BIO_FARITHMEANQUAL, BLTIN }, { "atan2", FATAN, BLTIN }, { "break", BREAK, BREAK }, { "close", CLOSE, CLOSE }, From 8cfe170b9fb5340f25a725fcb49ca22489f13ffa Mon Sep 17 00:00:00 2001 From: cypridina Date: Tue, 17 Oct 2017 23:18:50 -0700 Subject: [PATCH 2/2] spaces to tabs, commented --- addon.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addon.c b/addon.c index bae4879..d8e58ed 100644 --- a/addon.c +++ b/addon.c @@ -233,14 +233,14 @@ Cell *bio_func(int f, Cell *x, Node **a) } else if (f == BIO_FARITHMEANQUAL) { char *buf; int i, l = 0; - double total_qual = 0.0; + double total_qual = 0.0; buf = getsval(x); - /*printf("%s \n", buf);*/ l = strlen(buf); if (l) { /* don't try for empty strings */ - for (i = 0; i < l; ++i) + for (i = 0; i < l; ++i) /*convert Q-score to e-rate*/ total_qual += pow(10, -((double)(buf[i] - 33) / 10) ); - setfval(y, (Awkfloat)(-10 * log10(total_qual / l)) ); + /* mean of e-rate -> Q-score */ + setfval(y, (Awkfloat)(-10 * log10(total_qual / l)) ); } } /* else: never happens */ return y;