testFilter.cpp 19.5 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
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
#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;
  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();

  pair1 = buildACAutomatonToFilterBioReader(testedBioReader1, "####");
  pair2 = buildACAutomatonToFilterBioReader(testedBioReader2, "####");
  pair3 = buildACAutomatonToFilterBioReader(testedBioReader3, "####");

  /* 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;

  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();
  pair1 = buildACAutomatonToFilterBioReader(testedBioReader1, "####");
  pair2 = buildACAutomatonToFilterBioReader(testedBioReader2, "####");
  pair3 = buildACAutomatonToFilterBioReader(testedBioReader3, "####");


  filteredBioReader1 = filterBioReaderWithACAutomaton
                      (pair1, testedBioReader1, sequence1);
  filteredBioReader2 = filterBioReaderWithACAutomaton
                      (pair2, testedBioReader2, sequence2);
  filteredBioReader3 = filterBioReaderWithACAutomaton
                      (pair3, testedBioReader3, sequence3);

  //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();

351
  Germline germline("IGH", 'G', seqV, seqD, seqJ, "########", 0, true);
Cyprien Borée's avatar
Cyprien Borée committed
352
353
354
  germline.new_index(KMER_INDEX);
  germline.finish();

355
356
357
358
359
  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);
360
    filtered = filterBioReaderWithACAutomaton(germline.automaton_5, germline.rep_5, seq.sequence, 1);
361
362
363
364
    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
365
      }
366
      ++j;
Cyprien Borée's avatar
Cyprien Borée committed
367
    }
368
369
    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
370
  }
Cyprien Borée's avatar
Cyprien Borée committed
371
}
Cyprien Borée's avatar
Cyprien Borée committed
372

373
374
375
376
377
378
379
380
381
382
/*
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).
*/
383
384
385
386
387
void testExAequoKmersWhenSignificantParameter(){
  BioReader testedBioReader, filtered;
  seqtype seq;
  pair<vector<int>*, AbstractACAutomaton<KmerAffect>*>* p;
  string BIOREADER_EXAEQUO = "BioReader doesn't have ex-aequo";
388
  string SIZE_BIOREADER = "BioReader doesn't contain the good amount of sequences";
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
  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";
  p = buildACAutomatonToFilterBioReader(testedBioReader, "####");
409
410
411
  /* 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. */
412
  filtered = filterBioReaderWithACAutomaton(p, testedBioReader, seq, 2);
413
  /* Check that filtered BioReader contains sequence n°5 and sequence n°10 which are ex-aequo. */
414
415
416
417
418
419
420
421
  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;
  }
422
423
424
425
426
427
428
429
  /* 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);
430
431
  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);
432
  TAP_TEST(k < filtered.size(), TEST_FILTER_BIOREADER_WITH_AC_AUTOMATON, BIOREADER_EXAEQUO);
433
  /* Add a third ex-aequo: k-mer belonging to sequence n°12 appearing 29 times */
434
  seq += "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC";
Cyprien Borée's avatar
Cyprien Borée committed
435
  delete p->first; delete p->second; delete p;
436
437
  p = buildACAutomatonToFilterBioReader(testedBioReader, "####");
  filtered = filterBioReaderWithACAutomaton(p, testedBioReader, seq, 2);
438
439
440
441
442
443
444
445
446
447
448
449
450
  /* Check that BioReader contains previous sequences and n°12 */
  i = 0;
  while(i < filtered.size() && extractGeneName(filtered.label(i)) != extractGeneName(testedBioReader.label(5))){
    ++i;
  }
  j = 0;
  while(j < filtered.size() && extractGeneName(filtered.label(j)) != extractGeneName(testedBioReader.label(10))){
    ++j;
  }
  k = 0;
  while(k < filtered.size() && extractGeneName(filtered.label(k)) != extractGeneName(testedBioReader.label(11))){
    ++k;
  }
451
452
453
  int l = 0;
  while(l < filtered.size() && extractGeneName(filtered.label(l)) != extractGeneName(testedBioReader.label(12))){
    ++l;
454
  }
455
456
  /* 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);
457
458
459
  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);
460
  TAP_TEST(l < filtered.size(), TEST_FILTER_BIOREADER_WITH_AC_AUTOMATON, BIOREADER_EXAEQUO);
Cyprien Borée's avatar
Cyprien Borée committed
461
  delete p->first; delete p->second; delete p;
462
}
Cyprien Borée's avatar
Cyprien Borée committed
463

Cyprien Borée's avatar
Cyprien Borée committed
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
void testBehaviourWhenHugeBioReader(){
  BioReader hugeBioReader;
  hugeBioReader.add("../../germline/homo-sapiens/IGHV.fa");
  hugeBioReader.add("../../germline/homo-sapiens/IGLV.fa");
  pair<vector<int>*,AbstractACAutomaton<KmerAffect>*>* p;
  p = buildACAutomatonToFilterBioReader(hugeBioReader, "#########");
  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();
479
  testExAequoKmersWhenSignificantParameter();
Cyprien Borée's avatar
Cyprien Borée committed
480
}