-
Notifications
You must be signed in to change notification settings - Fork 24
/
plugin_filter.c
68 lines (60 loc) · 1.43 KB
/
plugin_filter.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<stdio.h>
#include<pandaseq-plugin.h>
HELP("Filters sequences based on the contents of a file of ids, one sequence ID per line.", "filter:file");
VER_INFO("1.0");
static bool precheck_func(
PandaLogProxy logger,
const panda_seq_identifier *id,
const panda_qual *forward,
size_t forward_length,
const panda_qual *reverse,
size_t reverse_length,
void *user_data) {
(void) logger;
(void) forward;
(void) forward_length;
(void) reverse;
(void) reverse_length;
return panda_idset_contains((PandaSet) user_data, id);
}
OPEN {
char buffer[1024];
bool close = false;
FILE *file;
PandaSet set;
(void) check;
if (args == NULL || *args == '\0') {
file = stdin;
} else {
file = fopen(args, "r");
if (file == NULL) {
panda_log_proxy_perror(logger, args);
return false;
}
close = true;
}
set = panda_idset_new();
while (fgets(buffer, sizeof(buffer), file) != NULL) {
int it;
for (it = 0; buffer[it] != '\n'; it++) ;
buffer[it] = '\0';
if (!panda_idset_add_str(set, buffer[0] == '@' ? (buffer + 1) : buffer, PANDA_TAG_OPTIONAL, NULL, NULL)) {
panda_log_proxy_write_f(logger, "ERR\tFILTER\tBAD\t%s\n", buffer);
if (close)
fclose(file);
return false;
}
}
if (ferror(file)) {
panda_log_proxy_perror(logger, args);
if (close)
fclose(file);
return false;
}
if (close)
fclose(file);
*precheck = precheck_func;
*user_data = set;
*destroy = (PandaDestroy) panda_idset_unref;
return true;
}