rangi: improve some of the comments
[rangi.git] / bl2exp.c
blob7a9a22d2ec05613bbc0ee943059134492e435046
1 /*
2 * bl2exp, extract blast E-values from blastp output
4 * Copyright (C) 2012 Ali Gholami Rudi <ali at rudi dot ir>
6 * This program is released under the modified BSD license.
7 */
8 #include <ctype.h>
9 #include <stdio.h>
10 #include <string.h>
12 #define ETHRESH 0.001
14 static char *readword(char *d, char *s)
16 while (isspace(*s))
17 s++;
18 while (*s && !isspace(*s))
19 *d++ = *s++;
20 *d = '\0';
21 return s;
24 static int readentries(void)
26 char line[1024];
27 char query[128];
28 char other[128];
29 char s_score[128];
30 int junk;
31 double score;
32 while (1) {
33 if (!fgets(line, sizeof(line), stdin))
34 return 1;
35 if (!strncmp(line, "Query= ", 6)) {
36 readword(query, line + 7);
37 break;
40 while (1) {
41 if (!fgets(line, sizeof(line), stdin))
42 return 1;
43 if (!strncmp(line, "Sequences producing", 16))
44 break;
45 if (!strncmp(line, " ***** No hits found", 16))
46 return 0;
48 fgets(line, sizeof(line), stdin);
49 while (1) {
50 if (!fgets(line, sizeof(line), stdin))
51 return 1;
52 if (sscanf(line, "%s %d %s", other, &junk, s_score) != 3)
53 break;
54 sprintf(line, "%s%s", s_score[0] == 'e' ? "1" : "", s_score);
55 sscanf(line, "%lf", &score);
56 if (score < ETHRESH)
57 printf("%s\t%s\t%lg\n", query, other, score);
59 return 0;
62 int main(int argc, char *argv[])
64 if (argc > 1) {
65 printf("usage: %s <blast >e_values\n", argv[0]);
66 return 0;
68 while (!readentries())
70 return 0;