-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathhang.c
114 lines (104 loc) · 3.31 KB
/
hang.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* PANDAseq -- Assemble paired FASTQ Illumina reads and strip the region between amplification primers.
Copyright (C) 2011-2013 Andre Masella
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include<stdlib.h>
#include "config.h"
#ifdef HAVE_PTHREAD
# include<pthread.h>
#endif
#include "pandaseq.h"
#include "misc.h"
struct hang_data {
MANAGED_MEMBER(
PandaNextSeq,
next);
PandaLogProxy logger;
panda_nt forward[MAX_LEN];
size_t forward_length;
panda_nt reverse[MAX_LEN];
size_t reverse_length;
bool skip;
double threshold;
};
bool hang_next(
panda_seq_identifier *id,
const panda_qual **forward,
size_t *forward_length,
const panda_qual **reverse,
size_t *reverse_length,
void *user_data) {
struct hang_data *data = (struct hang_data *) user_data;
while (data->next(id, forward, forward_length, reverse, reverse_length, data->next_data)) {
size_t offset;
if (data->forward_length > 0) {
offset = panda_compute_offset_qual(data->threshold, 0, true, *forward, *forward_length, data->forward, data->forward_length);
if (offset == 0) {
panda_log_proxy_write(data->logger, PANDA_CODE_NO_FORWARD_PRIMER, NULL, id, "OVERHANGING REJECT");
if (!data->skip)
continue;
} else {
*forward_length -= offset - 1;
}
}
if (data->reverse_length > 0) {
offset = panda_compute_offset_qual(data->threshold, 0, true, *reverse, *reverse_length, data->reverse, data->reverse_length);
if (offset == 0) {
panda_log_proxy_write(data->logger, PANDA_CODE_NO_REVERSE_PRIMER, NULL, id, "OVERHANGING REJECT");
if (!data->skip)
continue;
} else {
*reverse_length -= offset - 1;
}
}
return true;
}
return false;
}
void hang_free(
void *user_data) {
struct hang_data *hang_data = (struct hang_data *) user_data;
DESTROY_MEMBER(hang_data, next);
panda_log_proxy_unref(hang_data->logger);
free(hang_data);
}
PandaNextSeq panda_trim_overhangs(
PandaNextSeq inner,
void *inner_data,
PandaDestroy inner_destroy,
PandaLogProxy logger,
panda_nt *forward,
size_t forward_length,
panda_nt *reverse,
size_t reverse_length,
bool skip,
double threshold,
void **next_data,
PandaDestroy *next_destroy) {
struct hang_data *data = malloc(sizeof(struct hang_data));
size_t it;
data->next = inner;
data->next_data = inner_data;
data->next_destroy = inner_destroy;
data->skip = skip;
data->threshold = threshold;
for (it = 0; it < forward_length; it++)
data->forward[forward_length - it - 1] = forward[it];
for (it = 0; it < reverse_length; it++)
data->reverse[reverse_length - it - 1] = reverse[it];
data->forward_length = forward_length;
data->reverse_length = reverse_length;
data->logger = panda_log_proxy_ref(logger);
*next_data = data;
*next_destroy = hang_free;
return hang_next;
}