-
Notifications
You must be signed in to change notification settings - Fork 24
/
plugin_other_primer.c
73 lines (62 loc) · 1.84 KB
/
plugin_other_primer.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
69
70
71
72
73
#include<pandaseq-plugin.h>
#include<math.h>
HELP("Remove reads with another primer. Use f for forward, r for reverse.", "other_primer:[fr]:NNNNN");
VER_INFO("1.0");
struct data {
size_t primer_length;
bool forward;
panda_nt primer[1];
};
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,
struct data *data) {
(void) logger;
(void) id;
return panda_compute_offset_qual(log(0.9), 0.01, !data->forward, data->forward ? forward : reverse, data->forward ? forward_length : reverse_length, data->primer, data->primer_length) == 0;
}
OPEN {
struct data *data;
bool forward;
size_t it;
(void) check;
if (args == NULL || *args == '\0') {
return false;
}
if (*args == 'f' || *args == 'p') {
forward = true;
} else if (*args == 'r' || *args == 'q') {
forward = false;
} else {
panda_log_proxy_write_f(logger, "ERR\tOTHER_PRIMER\tINIT\tExpected f or r, but got %c.\n", (int) *args);
return false;
}
args++;
if (*args != ':') {
panda_log_proxy_write_f(logger, "ERR\tOTHER_PRIMER\tINIT\tExpected :, but got %c.\n", (int) *args);
return false;
}
args++;
if (*args == '\0') {
panda_log_proxy_write_f(logger, "ERR\tOTHER_PRIMER\tINIT\tPrimer cannot be empty.\n");
return false;
}
data = malloc(sizeof(struct data) + sizeof(panda_nt) * strlen(args));
data->forward = forward;
data->primer_length = strlen(args);
for (it = 0; it < data->primer_length; it++) {
if ((data->primer[it] = (forward ? panda_nt_from_ascii : panda_nt_from_ascii_complement) (args[it])) == '\0') {
panda_log_proxy_write_f(logger, "ERR\tOTHER_PRIMER\tBADNT\t%c\n", (int) args[it]);
free(data);
return false;
}
}
*precheck = (PandaPreCheck) precheck_func;
*user_data = data;
*destroy = (PandaDestroy) free;
return true;
}