17 void AP_filter::init(
size_t size) {
18 filter_mask =
new bool[size];
25 filterpos_2_seqpos =
NULp;
27 #if defined(ASSERTION_USED)
28 checked_for_validity =
false;
32 void AP_filter::make_permeable(
size_t size) {
34 real_len = filter_len;
35 for (
size_t i = 0; i < size; i++) filter_mask[i] =
true;
38 void AP_filter::init_from_string(
const char *ifilter,
const char *zerobases,
size_t size) {
44 for (i = 0; i<256; ++i) char2mask[i] =
true;
46 for (i = 0; zerobases[i]; ++i) char2mask[
safeCharIndex(zerobases[i])] =
false;
49 char2mask[
'0'] =
false;
53 for (i = 0; i < size && ifilter[i]; ++i) {
56 for (; i < size; i++) {
57 filter_mask[i] =
true;
68 : filter_mask(new bool[other.filter_len]),
69 filter_len(other.filter_len),
70 real_len(other.real_len),
72 simplify_type(other.simplify_type),
74 filterpos_2_seqpos(
NULp)
76 memcpy(filter_mask, other.filter_mask, filter_len*
sizeof(*filter_mask));
77 memcpy(simplify, other.simplify,
sizeof(simplify)*
sizeof(*simplify));
78 if (other.bootstrap) {
79 bootstrap =
new size_t[real_len];
80 memcpy(bootstrap, other.bootstrap, real_len*
sizeof(*bootstrap));
82 if (other.filterpos_2_seqpos) {
83 filterpos_2_seqpos =
new size_t[real_len];
84 memcpy(filterpos_2_seqpos, other.filterpos_2_seqpos, real_len*
sizeof(*filterpos_2_seqpos));
86 #if defined(ASSERTION_USED)
87 checked_for_validity = other.checked_for_validity;
94 if (!ifilter || !*ifilter) {
98 init_from_string(ifilter, zerobases, size);
104 const bool *omask = other.filter_mask;
107 for (
size_t i = 0; i < size; i++) {
108 real_len += (filter_mask[i] = !omask[i]);
118 const bool *m1 = f1.filter_mask;
119 const bool *m2 = f2.filter_mask;
123 for (
size_t i = 0; i<size; ++i) {
124 real_len += (filter_mask[i] = (m1[i] && m2[i]));
128 for (
size_t i = 0; i<size; ++i) {
129 real_len += (filter_mask[i] = (m1[i] || m2[i]));
133 for (
size_t i = 0; i<size; ++i) {
134 real_len += (filter_mask[i] = (m1[i] ^ m2[i]));
142 delete [] filter_mask;
143 delete [] filterpos_2_seqpos;
149 char *data = ARB_alloc<char>(filter_len+1);
151 for (
size_t i=0; i<filter_len; ++i) {
152 data[i] =
"01"[filter_mask[i]];
154 data[filter_len] = 0;
161 if (type != simplify_type) {
163 for (i=0; i<32; i++) {
171 simplify[(
unsigned char)
'g'] =
'a';
172 simplify[(
unsigned char)
'G'] =
'A';
173 simplify[(
unsigned char)
'u'] =
'c';
174 simplify[(
unsigned char)
't'] =
'c';
175 simplify[(
unsigned char)
'U'] =
'C';
176 simplify[(
unsigned char)
'T'] =
'C';
188 simplify_type =
type;
192 void AP_filter::calc_filterpos_2_seqpos() {
196 delete [] filterpos_2_seqpos;
197 filterpos_2_seqpos =
new size_t[real_len];
199 for (i=j=0; i<filter_len; ++i) {
200 if (filter_mask[i]) {
201 filterpos_2_seqpos[j++] = i;
211 bootstrap =
new size_t[real_len];
215 for (
size_t i = 0; i<real_len; ++i) {
228 char *blownup = ARB_alloc<char>(filter_len+1);
231 for (
size_t i = 0; i<filter_len; ++i) {
232 blownup[i] =
use_position(i) ? filtered_string[f++] : fillChar;
234 blownup[filter_len] = 0;
245 char *filtered = ARB_alloc<char>(real_len+1);
249 for (
size_t i = 0; i<real_len; ++i) {
250 size_t p = filterpos_2_seqpos[i];
251 filtered[f++] = fulllen_string[p];
262 : len(fil->get_filtered_length()),
268 : len(fil->get_filtered_length()),
276 for (j=i=0; j<wlen; ++j) {
300 static long time = 0;
312 #define TEST_EXPECT_EQUAL_FILTERS(f1,f2) do{ \
313 TEST_EXPECT_NO_ERROR((f1).is_invalid()); \
314 TEST_EXPECT_NO_ERROR((f2).is_invalid()); \
315 char *m1 = (f1).to_string(); \
316 char *m2 = (f2).to_string(); \
317 TEST_EXPECT_EQUAL(m1, m2); \
324 const int MASK_BITCOUNT = 9;
325 const char *mask =
"01100001110000110011";
326 const char *mask_inv =
"10011110001111001100";
327 const char *mask_some =
"00100101100101011001";
328 const char *
seq =
"MSKTAYTKVLFDRGSALDGK";
329 const char *seq_masked =
"SK" "KVL" "SA""GK";
330 const char *blow_mask =
"_SK____KVL____SA__GK";
331 const char *seq_masked_inv =
"M""TAYT" "FDRG""LD";
332 const char *blow_mask_inv =
"M__TAYT___FDRG__LD__";
358 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(f1.to_string(),
"11111111111111111111");
359 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(f2.to_string(), mask);
360 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(f3.to_string(), mask_inv);
361 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(n2.to_string(), mask_inv);
362 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(n3.to_string(), mask);
364 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(f1.filter_string(seq),
seq);
365 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(f2.filter_string(seq), seq_masked);
366 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(f3.filter_string(seq), seq_masked_inv);
367 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(n2.filter_string(seq), seq_masked_inv);
368 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(n3.filter_string(seq), seq_masked);
370 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(f1.blowup_string(seq,
'_'),
seq);
371 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(f2.blowup_string(seq_masked,
'_'), blow_mask);
372 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(f3.blowup_string(seq_masked_inv,
'_'), blow_mask_inv);
378 TEST_EXPECT_EQUAL_FILTERS(i2, n2);
379 TEST_EXPECT_EQUAL_FILTERS(i3, n3);
397 TEST_EXPECT_EQUAL_FILTERS(o2223, f2);
403 TEST_EXPECT_EQUAL_FILTERS(x, xa1);
404 TEST_EXPECT_EQUAL_FILTERS(x, xa2);
406 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(x.to_string(), mask);
const size_t * get_filterpos_2_seqpos() const
char * blowup_string(const char *filtered_string, char insert) const
CONSTEXPR_INLINE unsigned char safeCharIndex(char c)
AP_weights(const AP_filter *fil)
char * filter_string(const char *fulllen_string) const
static int weights[MAX_BASETYPES][MAX_BASETYPES]
size_t get_length() const
size_t get_filtered_length() const
void enable_simplify(AWT_FILTER_SIMPLIFY type)
#define TEST_EXPECT_NO_ERROR(call)
#define TEST_EXPECT_ERROR_CONTAINS(call, part)
bool use_position(size_t pos) const
#define TEST_EXPECT_EQUAL(expr, want)
void ARB_alloc_aligned(TYPE *&tgt, size_t nelems)