diff --git a/addon.c b/addon.c index 7f6d6c3..d8e58ed 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); + l = strlen(buf); + if (l) { /* don't try for empty strings */ + for (i = 0; i < l; ++i) /*convert Q-score to e-rate*/ + total_qual += pow(10, -((double)(buf[i] - 33) / 10) ); + /* mean of e-rate -> Q-score */ + 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 },