From d7596e7a08cbc56aaafd1c201e0e482f86590ba7 Mon Sep 17 00:00:00 2001 From: Ali Gholami Rudi Date: Tue, 16 Oct 2012 21:45:06 +0330 Subject: [PATCH] bl2exp: extract blast e-value from blastp output --- Makefile | 6 ++++-- bl2exp.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 bl2exp.c diff --git a/Makefile b/Makefile index 499a2c2..80dba9a 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ CC = cc CFLAGS = -O2 -Wall LDFLAGS = -lpthread -all: rangi conv genrq meval fastafilt +all: rangi conv genrq meval fastafilt bl2exp %.o: %.c rangi.h $(CC) -c $(CFLAGS) $< rangi: rangi.o mat.o proc.o @@ -15,5 +15,7 @@ meval: meval.o $(CC) -o $@ $^ $(LDFLAGS) fastafilt: fastafilt.o $(CC) -o $@ $^ $(LDFLAGS) +bl2exp: bl2exp.o + $(CC) -o $@ $^ $(LDFLAGS) clean: - rm -f *.o rangi conv genrq meval fastafilt + rm -f *.o rangi conv genrq meval fastafilt bl2exp diff --git a/bl2exp.c b/bl2exp.c new file mode 100644 index 0000000..7a9a22d --- /dev/null +++ b/bl2exp.c @@ -0,0 +1,71 @@ +/* + * bl2exp, extract blast E-values from blastp output + * + * Copyright (C) 2012 Ali Gholami Rudi + * + * This program is released under the modified BSD license. + */ +#include +#include +#include + +#define ETHRESH 0.001 + +static char *readword(char *d, char *s) +{ + while (isspace(*s)) + s++; + while (*s && !isspace(*s)) + *d++ = *s++; + *d = '\0'; + return s; +} + +static int readentries(void) +{ + char line[1024]; + char query[128]; + char other[128]; + char s_score[128]; + int junk; + double score; + while (1) { + if (!fgets(line, sizeof(line), stdin)) + return 1; + if (!strncmp(line, "Query= ", 6)) { + readword(query, line + 7); + break; + } + } + while (1) { + if (!fgets(line, sizeof(line), stdin)) + return 1; + if (!strncmp(line, "Sequences producing", 16)) + break; + if (!strncmp(line, " ***** No hits found", 16)) + return 0; + } + fgets(line, sizeof(line), stdin); + while (1) { + if (!fgets(line, sizeof(line), stdin)) + return 1; + if (sscanf(line, "%s %d %s", other, &junk, s_score) != 3) + break; + sprintf(line, "%s%s", s_score[0] == 'e' ? "1" : "", s_score); + sscanf(line, "%lf", &score); + if (score < ETHRESH) + printf("%s\t%s\t%lg\n", query, other, score); + } + return 0; +} + +int main(int argc, char *argv[]) +{ + if (argc > 1) { + printf("usage: %s e_values\n", argv[0]); + return 0; + } + while (!readentries()) + ; + return 0; +} -- 2.11.4.GIT