testFilter.cpp 19.4 KB
Newer Older
Cyprien Borée's avatar
Cyprien Borée committed
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include "core/automaton.h"
#include "core/filter.h"
#include "core/germline.h"
#include "core/tools.h"

/*
  Create an artificial BioReader to experiment tests.
  This BioReader behave as a regular BioReader.
  The only noticeable characteristic is the presence of
  a sequence where its shorten name doesn't contain a star.
  (sequence n°10)
*/
BioReader getDebugBioReader1(){
  BioReader result;
  Sequence sequences[13];
  sequences[0] = {"seq1-full_name", "seq-01*01", "AGCTGC","", NULL, 0};
  sequences[1] = {"seq1-full_name", "seq-01*02", "AGCTGA", "", NULL, 0};
  sequences[2] = {"seq1-full_name", "seq-01*03", "AGCTGT", "", NULL, 0};
  sequences[3] = {"seq2_full_name", "seq-02*01", "TCAA", "", NULL, 0};
  sequences[4] = {"seq2_full_name", "seq-02*02", "TCCA", "", NULL, 0};
  sequences[5] = {"seq3_full_name", "seq-03*01", "GGGG", "", NULL, 0};
  sequences[6] = {"seq4_full_name", "seq-04*01", "CCAATG", "", NULL, 0};
  sequences[7] = {"seq4_full_name", "seq-04*02", "CCAATT", "", NULL, 0};
  sequences[8] = {"seq4_full_name", "seq-04*03", "CCAATA", "", NULL, 0};
  sequences[9] = {"seq4_full_name", "seq-04*04", "CCAATC", "", NULL, 0};
  sequences[10] = {"seq5_full_name", "seq-05", "TTTT", "", NULL, 0};
  sequences[11] = {"seq6_full_name", "seq-06*01", "AAAT", "", NULL, 0};
  sequences[12] = {"seq6_full_name", "seq-06*02", "AAAA", "", NULL, 0};
  for(int i = 0;i < 13; ++i){
    result.add(sequences[i]);
  }
  return result;
}

/*
  Create an artificial BioReader to experiment tests.
  This BioReader behave as a regular BioReader.
  Its characteristic is to have the first group of gene
  containing only one sequence.
  (sequence n°0)
*/
BioReader getDebugBioReader2(){
  BioReader result;
  Sequence sequences[11];
  sequences[0] = {"seq1-full_name", "seq-01*01", "AGCTGC","", NULL, 0};
  sequences[1] = {"seq2_full_name", "seq-02*01", "TCAA", "", NULL, 0};
  sequences[2] = {"seq2_full_name", "seq-02*02", "TCCA", "", NULL, 0};
  sequences[3] = {"seq3_full_name", "seq-03*01", "GGGG", "", NULL, 0};
  sequences[4] = {"seq4_full_name", "seq-04*01", "CCAATG", "", NULL, 0};
  sequences[5] = {"seq4_full_name", "seq-04*02", "CCAATT", "", NULL, 0};
  sequences[6] = {"seq4_full_name", "seq-04*03", "CCAATA", "", NULL, 0};
  sequences[7] = {"seq4_full_name", "seq-04*04", "CCAATC", "", NULL, 0};
  sequences[8] = {"seq5_full_name", "seq-05*01", "TTTT", "", NULL, 0};
  sequences[9] = {"seq6_full_name", "seq-06*01", "AAAT", "", NULL, 0};
  sequences[10] = {"seq6_full_name", "seq-06*02", "AAAA", "", NULL, 0};
  for(int i = 0;i < 11; ++i){
    result.add(sequences[i]);
  }
  return result;
}

/*
  Create an artifical BioReader to experiment tests.
  This BioReader behave as a regular BioReader.
  Its characteristic is to have only one sequences in the
  last groupe of genes.
*/
BioReader getDebugBioReader3(){
  BioReader result;
  Sequence sequences[12];
  sequences[0] = {"seq1-full_name", "seq-01*01", "AGCTGC","", NULL, 0};
  sequences[1] = {"seq1-full_name", "seq-01*02", "AGCTGA", "", NULL, 0};
  sequences[2] = {"seq1-full_name", "seq-01*03", "AGCTGT", "", NULL, 0};
  sequences[3] = {"seq2_full_name", "seq-02*01", "TCAA", "", NULL, 0};
  sequences[4] = {"seq2_full_name", "seq-02*02", "TCCA", "", NULL, 0};
  sequences[5] = {"seq3_full_name", "seq-03*01", "GGGG", "", NULL, 0};
  sequences[6] = {"seq4_full_name", "seq-04*01", "CCAATG", "", NULL, 0};
  sequences[7] = {"seq4_full_name", "seq-04*02", "CCAATT", "", NULL, 0};
  sequences[8] = {"seq4_full_name", "seq-04*03", "CCAATA", "", NULL, 0};
  sequences[9] = {"seq4_full_name", "seq-04*04", "CCAATC", "", NULL, 0};
  sequences[10] = {"seq5_full_name", "seq-05*01", "TTTT", "", NULL, 0};
  sequences[11] = {"seq6_full_name", "seq-06*01", "AAAT", "", NULL, 0};
  for(int i = 0;i < 12; ++i){
    result.add(sequences[i]);
  }
  return result;
}

/*
  Create a vector of int corresponding to the
  sequences indexes in the BioReader build in
  the getDebugBioReader1 function.
  Read documentation in segment.cpp to learn
  more on the index elements and their structure.
*/
vector<int> getDebugIndexes1(){
  vector<int> indexes;
  indexes.push_back(0);
  indexes.push_back(3);
  indexes.push_back(5);
  indexes.push_back(6);
  indexes.push_back(10);
  indexes.push_back(11);
  indexes.push_back(13);
  return indexes;
}

/*
  Create a vector of int corresponding to the
  sequences indexes in the BioReader build in
  the getDebugBioReader2 function.
  Read documentation in segment.cpp to learn
  more on the index elements and their structure.
*/
vector<int> getDebugIndexes2(){
  vector<int> indexes;
  indexes.push_back(0);
  indexes.push_back(1);
  indexes.push_back(3);
  indexes.push_back(4);
  indexes.push_back(8);
  indexes.push_back(9);
  indexes.push_back(11);
  return indexes;
}

/*
  Create a vector of int corresponding to the
  sequences indexes in the BioReader build in
  the getDebugBioReader3 function.
  Read documentation in segment.cpp to learn
  more on the index elements and their structure.
*/
vector<int> getDebugIndexes3(){
  vector<int> indexes;
  indexes.push_back(0);
  indexes.push_back(3);
  indexes.push_back(5);
  indexes.push_back(6);
  indexes.push_back(10);
  indexes.push_back(11);
  indexes.push_back(12);
  return indexes;
}

/*
  Check the integrity of the automatonBuilderFilteringBioReader
  function. This test is separe in two parts. The first one
  will check if the vector of indexes received is accurate
  while the second part will check that every KmerAffect inside
  the revceivedAutomaton wear the good label.
*/
void testAutomatonBuilderFilteringBioReader(){
  pair<vector<int>*, AbstractACAutomaton<KmerAffect>*> *pair1, *pair2, *pair3;
  KmerAffect tmpKmer;
  seqtype tmpSeq;
  BioReader testedBioReader1;
  BioReader testedBioReader2;
  BioReader testedBioReader3;
  vector<int> expectedIndexes1;
  vector<int> expectedIndexes2;
  vector<int> expectedIndexes3;
163
  FilterWithACAutomaton *f1, *f2, *f3;
Cyprien Borée's avatar
Cyprien Borée committed
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
  seqtype seq;
  KmerAffect k;
  char asciiChar;
  unsigned int asciiNum;

  const string TEST_SIZE_ERROR =
                            "The expected vector doesn't have the good size";
  const string TEST_CONTENT_ERROR =
                            "The expected vector doesn't have the good content";
  const string TEST_LABEL_ERROR =
                            "The KmerAffect doesn't have the good label";

  testedBioReader1 = getDebugBioReader1();
  testedBioReader2 = getDebugBioReader2();
  testedBioReader3 = getDebugBioReader3();
  expectedIndexes1 = getDebugIndexes1();
  expectedIndexes2 = getDebugIndexes2();
  expectedIndexes3 = getDebugIndexes3();

183
184
185
186
187
188
189
  f1 = new FilterWithACAutomaton(testedBioReader1,"####");
  f2 = new FilterWithACAutomaton(testedBioReader2,"####");
  f3 = new FilterWithACAutomaton(testedBioReader3,"####");

  pair1 = f1->getPair();
  pair2 = f2->getPair();
  pair3 = f3->getPair();
Cyprien Borée's avatar
Cyprien Borée committed
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260

  /* test indexes size */
    TAP_TEST_EQUAL(pair1->first->size(), expectedIndexes1.size(),
      TEST_AUTOMATON_BUILDER_TO_FILTER_BIOREADER,
      TEST_SIZE_ERROR);
    TAP_TEST_EQUAL(pair2->first->size(), expectedIndexes2.size(),
      TEST_AUTOMATON_BUILDER_TO_FILTER_BIOREADER,
      TEST_SIZE_ERROR);
    TAP_TEST_EQUAL(pair3->first->size(), expectedIndexes3.size(),
      TEST_AUTOMATON_BUILDER_TO_FILTER_BIOREADER,
      TEST_SIZE_ERROR);

  /* test indexes content */
  for(unsigned int i = 0; i < pair1->first->size(); ++i){
    TAP_TEST_EQUAL(pair1->first->at(i), expectedIndexes1[i],
    TEST_AUTOMATON_BUILDER_TO_FILTER_BIOREADER,
    TEST_CONTENT_ERROR);
  }
  for(unsigned int i = 0; i < pair2->first->size(); ++i){
    TAP_TEST_EQUAL(pair2->first->at(i), expectedIndexes2[i],
    TEST_AUTOMATON_BUILDER_TO_FILTER_BIOREADER,
    TEST_CONTENT_ERROR);
  }
  for(unsigned int i = 0; i < pair3->first->size(); ++i){
    TAP_TEST_EQUAL(pair3->first->at(i), expectedIndexes3[i],
    TEST_AUTOMATON_BUILDER_TO_FILTER_BIOREADER,
    TEST_CONTENT_ERROR);
  }

  /* test automaton KmerAffect label */
  for(unsigned int i = 0;i < expectedIndexes1.size() - 1; ++i){
    for(int j = expectedIndexes1[i]; j < expectedIndexes1[i + 1]; ++j){
      seq = testedBioReader1.sequence(j);
      k = pair1->second->get(seq);
      asciiChar = k.getLabel().at(0);
      asciiNum = int(asciiChar);
      TAP_TEST_EQUAL(asciiNum, i + 1, TEST_AUTOMATON_BUILDER_TO_FILTER_BIOREADER,
      TEST_LABEL_ERROR);
    }
  }
  for(unsigned int i = 0;i < expectedIndexes2.size() - 1; ++i){
    for(int j = expectedIndexes2[i]; j < expectedIndexes2[i + 1]; ++j){
      seq = testedBioReader2.sequence(j);
      k = pair2->second->get(seq);
      asciiChar = k.getLabel().at(0);
      asciiNum = int(asciiChar);
      TAP_TEST_EQUAL(asciiNum, i + 1, TEST_AUTOMATON_BUILDER_TO_FILTER_BIOREADER,
      TEST_LABEL_ERROR);
    }
  }
  for(unsigned int i = 0;i < expectedIndexes3.size() - 1; ++i){
    for(int j = expectedIndexes3[i]; j < expectedIndexes3[i + 1]; ++j){
      seq = testedBioReader3.sequence(j);
      k = pair3->second->get(seq);
      asciiChar = k.getLabel().at(0);
      asciiNum = int(asciiChar);
      TAP_TEST_EQUAL(asciiNum, i + 1, TEST_AUTOMATON_BUILDER_TO_FILTER_BIOREADER,
      TEST_LABEL_ERROR);
    }
  }
  delete pair1->first; delete pair1->second; delete pair1;
  delete pair2->first; delete pair2->second; delete pair2;
  delete pair3->first; delete pair3->second; delete pair3;
}

void testFilterBioReaderWithACAutomaton(){
  pair<vector<int>*, AbstractACAutomaton<KmerAffect>*> *pair1, *pair2, *pair3;
  KmerAffect tmpKmer;
  seqtype sequence1, sequence2, sequence3;
  BioReader testedBioReader1, testedBioReader2, testedBioReader3;
  BioReader filteredBioReader1, filteredBioReader2, filteredBioReader3;
261
  FilterWithACAutomaton *f1, *f2, *f3;
Cyprien Borée's avatar
Cyprien Borée committed
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277

  const string SIZE_ERROR =
      "The BioReader size must be less or equal than the original's size";

  const string GENES_ERROR =
      "The BioReader doesn't contain the correct genes";

  const string MIN_ERROR =
      "The BioReader contains less sequences than the constant BIOREADER_MIN";

  sequence1 = "AAAAATTCCAATCCAATTTTTT";
  sequence2 = "AGCTGCAGCTGCGGGGAGCTGCAAAA";
  sequence3 = "AAATTTTTAAATTCCATGTGCAAATAAAAAGCTGT";
  testedBioReader1 = getDebugBioReader1();
  testedBioReader2 = getDebugBioReader2();
  testedBioReader3 = getDebugBioReader3();
278
279
280
281
282
283
  f1 = new FilterWithACAutomaton(testedBioReader1, "####");
  f2 = new FilterWithACAutomaton(testedBioReader2, "####");
  f3 = new FilterWithACAutomaton(testedBioReader3, "####");
  pair1 = f1->getPair();
  pair2 = f2->getPair();
  pair3 = f3->getPair();
Cyprien Borée's avatar
Cyprien Borée committed
284

285
286
287
  filteredBioReader1 = f1->filterBioReaderWithACAutomaton(testedBioReader1, sequence1);
  filteredBioReader2 = f2->filterBioReaderWithACAutomaton(testedBioReader2, sequence2);
  filteredBioReader3 = f3->filterBioReaderWithACAutomaton(testedBioReader3, sequence3);
Cyprien Borée's avatar
Cyprien Borée committed
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355

  //check filteredBioReader size
  TAP_TEST(filteredBioReader1.size() <= testedBioReader1.size(),
    TEST_FILTER_BIOREADER_WITH_AC_AUTOMATON, SIZE_ERROR);
  TAP_TEST(filteredBioReader2.size() <= testedBioReader2.size(),
    TEST_FILTER_BIOREADER_WITH_AC_AUTOMATON, SIZE_ERROR);
  TAP_TEST(filteredBioReader3.size() <= testedBioReader3.size(),
    TEST_FILTER_BIOREADER_WITH_AC_AUTOMATON, SIZE_ERROR);

  //check filtered BioReaders content
  vector<int>* v1 = pair1->first;
  map<KmerAffect, int> m1 = pair1->second->getMultiResults(sequence1);
  list<Sequence> l1 = filteredBioReader1.getAll();
  for(auto const m : m1){
    KmerAffect tmpKmer = m.first;
    if(tmpKmer.isNull() || tmpKmer.isUnknown() || tmpKmer.isAmbiguous()){
      continue;
    }
    unsigned int asciiNumber = int(tmpKmer.getLabel().at(0));
    for(int i = v1->at(asciiNumber-1); i < v1->at(asciiNumber); ++i){
      TAP_TEST(find(l1.begin(), l1.end(), testedBioReader1.read(i)) != l1.end(),
              TEST_FILTER_BIOREADER_WITH_AC_AUTOMATON, GENES_ERROR);
    }
  }
  vector<int>* v2 = pair2->first;
  map<KmerAffect, int> m2 = pair2->second->getMultiResults(sequence2);
  list<Sequence> l2 = filteredBioReader2.getAll();
  for(auto const m : m2){
    KmerAffect tmpKmer = m.first;
    if(tmpKmer.isNull() || tmpKmer.isUnknown() || tmpKmer.isAmbiguous()){
      continue;
    }
    unsigned int asciiNumber = int(tmpKmer.getLabel().at(0));
    for(int i = v2->at(asciiNumber-1); i < v2->at(asciiNumber); ++i){
      TAP_TEST(find(l2.begin(), l2.end(), testedBioReader2.read(i)) != l2.end(),
              TEST_FILTER_BIOREADER_WITH_AC_AUTOMATON, GENES_ERROR);
    }
  }
  vector<int>* v3 = pair3->first;
  map<KmerAffect, int> m3 = pair3->second->getMultiResults(sequence3);
  list<Sequence> l3 = filteredBioReader3.getAll();
  for(auto const m : m3){
    KmerAffect tmpKmer = m.first;
    if(tmpKmer.isNull() || tmpKmer.isUnknown() || tmpKmer.isAmbiguous()){
      continue;
    }
    unsigned int asciiNumber = int(tmpKmer.getLabel().at(0));
    for(int i = v3->at(asciiNumber-1); i < v3->at(asciiNumber); ++i){
      TAP_TEST(find(l3.begin(), l3.end(), testedBioReader3.read(i)) != l3.end(),
              TEST_FILTER_BIOREADER_WITH_AC_AUTOMATON, GENES_ERROR);
    }
  }

  delete pair1->first, delete pair1->second; delete pair1;
  delete pair2->first; delete pair2->second; delete pair2;
  delete pair3->first; delete pair3->second; delete pair3;
}

void testGetNSignicativeKmers(){
  BioReader filtered;
  BioReader seqV("../../germline/homo-sapiens/IGHV.fa", 2);
  BioReader seqD("../../germline/homo-sapiens/IGHD.fa", 2);
  BioReader seqJ("../../germline/homo-sapiens/IGHJ.fa", 2);

  OnlineFasta data("data/Stanford_S22.fasta", 1, " ");
  data.next();
  data.next();

356
  Germline germline("IGH", 'G', seqV, seqD, seqJ, "########", 0, true);
Cyprien Borée's avatar
Cyprien Borée committed
357
358
359
  germline.new_index(KMER_INDEX);
  germline.finish();

360
361
362
363
364
  string SIZE_ERROR = "Filtered size must be less than original one";
  string GENE_NOT_FOUND = "Filtering sequence not found after filter";

  for(int i = 0; i < germline.rep_5.size(); ++i){
    Sequence seq = germline.rep_5.read(i);
365
366
    FilterWithACAutomaton *f = germline.getFilter();
    filtered = f->filterBioReaderWithACAutomaton(germline.rep_5, seq.sequence, 1);
367
368
369
370
    int j = 0;
    while(j < filtered.size()){
      if(extractGeneName(filtered.label(j)) == extractGeneName(seq.label)){
        break;
Cyprien Borée's avatar
Cyprien Borée committed
371
      }
372
      ++j;
Cyprien Borée's avatar
Cyprien Borée committed
373
    }
374
375
    TAP_TEST(j < filtered.size(), TEST_FILTER_BIOREADER_WITH_AC_AUTOMATON, GENE_NOT_FOUND);
    TAP_TEST(filtered.size() < germline.rep_5.size(), TEST_FILTER_BIOREADER_WITH_AC_AUTOMATON, SIZE_ERROR);
Cyprien Borée's avatar
Cyprien Borée committed
376
  }
Cyprien Borée's avatar
Cyprien Borée committed
377
}
Cyprien Borée's avatar
Cyprien Borée committed
378

379
380
381
382
383
384
385
386
387
388
/*
Check if the filter method use the ex-aequo K-mers if a significant
parameter is provided.
For example if the parameter is N = 5 and the method get the following
K-mers occurences: 10, 10, 5, 5, 4, 3, 2 we want to filter using the K-mers with
the occurences 10, 10, 5, 5 and 4.
However if the K-mers occurences are 10, 10, 5, 5, 4, 4, 2 we want to filter using
the K-mers with occurences 10, 10, 5, 5, 4, and 4 (The last one is ex-aequo so
we take both).
*/
389
390
void testExAequoKmersWhenSignificantParameter(){
  BioReader testedBioReader, filtered;
391
  FilterWithACAutomaton *f;
392
393
394
  seqtype seq;
  pair<vector<int>*, AbstractACAutomaton<KmerAffect>*>* p;
  string BIOREADER_EXAEQUO = "BioReader doesn't have ex-aequo";
395
  string SIZE_BIOREADER = "BioReader doesn't contain the good amount of sequences";
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
  Sequence sequences[13];
  sequences[0] = {"seq1-full_name", "seq-01*01", "AGCTAGCTA","", NULL, 0};
  sequences[1] = {"seq1-full_name", "seq-01*02", "AGCTAGCTT", "", NULL, 0};
  sequences[2] = {"seq1-full_name", "seq-01*03", "AGCTAGCTC", "", NULL, 0};
  sequences[3] = {"seq2_full_name", "seq-02*01", "TCAATCAA", "", NULL, 0};
  sequences[4] = {"seq2_full_name", "seq-02*02", "TCCATCAA", "", NULL, 0};
  sequences[5] = {"seq3_full_name", "seq-03*01", "GGGGGGGG", "", NULL, 0};
  sequences[6] = {"seq4_full_name", "seq-04*01", "CCAATGCC", "", NULL, 0};
  sequences[7] = {"seq4_full_name", "seq-04*02", "CCAATTCC", "", NULL, 0};
  sequences[8] = {"seq4_full_name", "seq-04*03", "CCAATACC", "", NULL, 0};
  sequences[9] = {"seq4_full_name", "seq-04*04", "CCAATCCC", "", NULL, 0};
  sequences[10] = {"seq5_full_name", "seq-05*01", "TTTTTTTT", "", NULL, 0};
  sequences[11] = {"seq6_full_name", "seq-06*01", "AAATAAAT", "", NULL, 0};
  sequences[12] = {"seq7_full_name", "seq-07*01", "CCCCCCCC", "", NULL, 0};
  for(int i = 0;i < 13; ++i){
    testedBioReader.add(sequences[i]);
  }
  seq = "AAATAAATAAATAAATAAATAAATAAATAAATAAATAAATAAATAAATAAATAAATAAATAAAT";
  seq += "GGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTT";
415
416
  f = new FilterWithACAutomaton(testedBioReader, "####");
  p = f->getPair();
417
418
419
  /* Filter using the 2 most significant K-mers, the first one is belonging to
     sequence n°11 (with more than 60 occurences) and second one is sequence n°5
     and n°10 appearing 29 times both. */
420
  filtered = f->filterBioReaderWithACAutomaton(testedBioReader, seq, 2);
421
  /* Check that filtered BioReader contains sequence n°5 and sequence n°10 which are ex-aequo. */
422
423
424
425
426
427
428
429
  int i = 0;
  while(i < filtered.size() && extractGeneName(filtered.label(i)) != extractGeneName(testedBioReader.label(5))){
    ++i;
  }
  int j = 0;
  while(j < filtered.size() && extractGeneName(filtered.label(j)) != extractGeneName(testedBioReader.label(10))){
    ++j;
  }
430
431
432
433
434
435
436
437
  /* Check that filtered BioReader contains sequence n°11 which is the most present in the sequence. */
  int k = 0;
  while(k < filtered.size() && extractGeneName(filtered.label(k)) != extractGeneName(testedBioReader.label(11))){
    ++k;
  }

  /* Even though the filtered function got 2 as a parameter, since there are two ex-aequo the size is 3 */
  TAP_TEST(filtered.size() == 3, TEST_FILTER_BIOREADER_WITH_AC_AUTOMATON, SIZE_BIOREADER);
438
439
  TAP_TEST(i < filtered.size(), TEST_FILTER_BIOREADER_WITH_AC_AUTOMATON, BIOREADER_EXAEQUO);
  TAP_TEST(j < filtered.size(), TEST_FILTER_BIOREADER_WITH_AC_AUTOMATON, BIOREADER_EXAEQUO);
440
  TAP_TEST(k < filtered.size(), TEST_FILTER_BIOREADER_WITH_AC_AUTOMATON, BIOREADER_EXAEQUO);
441
  /* Add a third ex-aequo: k-mer belonging to sequence n°12 appearing 29 times */
442
  seq += "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC";
443
444
445
446
447
  delete f;
  f = new FilterWithACAutomaton(testedBioReader, "####");
  filtered = f->filterBioReaderWithACAutomaton(testedBioReader, seq, 2);
  int k = 0;
  while(k < filtered.size() && extractGeneName(filtered.label(k)) != extractGeneName(testedBioReader.label(12))){
448
449
    ++k;
  }
450
451
452
  int l = 0;
  while(l < filtered.size() && extractGeneName(filtered.label(l)) != extractGeneName(testedBioReader.label(12))){
    ++l;
453
  }
454
455
  /* Even though the filtered function got 2 as a parameter, since there are three ex-aequo the size is 4 */
  TAP_TEST(filtered.size() == 4, TEST_FILTER_BIOREADER_WITH_AC_AUTOMATON, SIZE_BIOREADER);
456
457
458
  TAP_TEST(i < filtered.size(), TEST_FILTER_BIOREADER_WITH_AC_AUTOMATON, BIOREADER_EXAEQUO);
  TAP_TEST(j < filtered.size(), TEST_FILTER_BIOREADER_WITH_AC_AUTOMATON, BIOREADER_EXAEQUO);
  TAP_TEST(k < filtered.size(), TEST_FILTER_BIOREADER_WITH_AC_AUTOMATON, BIOREADER_EXAEQUO);
459
  TAP_TEST(l < filtered.size(), TEST_FILTER_BIOREADER_WITH_AC_AUTOMATON, BIOREADER_EXAEQUO);
Cyprien Borée's avatar
Cyprien Borée committed
460
  delete p->first; delete p->second; delete p;
461
}
Cyprien Borée's avatar
Cyprien Borée committed
462

Cyprien Borée's avatar
Cyprien Borée committed
463
464
void testBehaviourWhenHugeBioReader(){
  BioReader hugeBioReader;
465
  FilterWithACAutomaton *f;
Cyprien Borée's avatar
Cyprien Borée committed
466
467
468
  hugeBioReader.add("../../germline/homo-sapiens/IGHV.fa");
  hugeBioReader.add("../../germline/homo-sapiens/IGLV.fa");
  pair<vector<int>*,AbstractACAutomaton<KmerAffect>*>* p;
469
470
  f = new FilterWithACAutomaton(hugeBioReader, "#########");
  p = f->getPair();
Cyprien Borée's avatar
Cyprien Borée committed
471
472
473
474
475
476
477
478
479
  TAP_TEST(!p, TEST_FILTER_BIOREADER_WITH_AC_AUTOMATON,
    "Automaton should not be constructed on a BioReader containing more than 127 sequences.");
}

void testFilter(){
  testAutomatonBuilderFilteringBioReader();
  testFilterBioReaderWithACAutomaton();
  testBehaviourWhenHugeBioReader();
  testGetNSignicativeKmers();
480
  testExAequoKmersWhenSignificantParameter();
Cyprien Borée's avatar
Cyprien Borée committed
481
}