Commit 11a88c98 authored by Mathieu Giraud's avatar Mathieu Giraud

tests: update unit tests to the de-templatized KmerAffectAnalyser

parent 68671cfd
......@@ -3,21 +3,22 @@
#include <core/kmerstore.h>
#include <core/kmeraffect.h>
template<template <class> class T, class KAffect>
template<template <class> class T>
void testAffectAnalyser1() {
const int k = 4;
const bool revcomp = false;
T<KAffect> *index = createIndex<T<KAffect> >(k, revcomp);
T<KmerAffect> *index = createIndex<T<KmerAffect> >(k, revcomp);
string sequence = "AAAACCCCCGGGGG";
KmerAffectAnalyser<KAffect> kaa(*index, sequence);
CountKmerAffectAnalyser<KAffect> ckaa(*index, sequence);
KmerAffectAnalyser kaa(*index, sequence);
CountKmerAffectAnalyser ckaa(*index, sequence);
TAP_TEST(ckaa.getAllowedOverlap() == 0, TEST_COUNT_AA_GET_OVERLAP, "");
ckaa.setAllowedOverlap(k-1);
set<KAffect> forbidden;
forbidden.insert(KAffect::getAmbiguous());
forbidden.insert(KAffect::getUnknown());
set<KmerAffect> forbidden;
forbidden.insert(KmerAffect::getAmbiguous());
forbidden.insert(KmerAffect::getUnknown());
TAP_TEST(ckaa.getAllowedOverlap() == k-1, TEST_COUNT_AA_GET_OVERLAP, "");
TAP_TEST(ckaa.getSequence() == "AAAACCCCCGGGGG", TEST_AA_GET_SEQUENCE, "actual: " << ckaa.getSequence());
......@@ -25,29 +26,29 @@ void testAffectAnalyser1() {
for (int i = 2; i < nb_seq-1; i++) {
// i starts at 2 because AAAA is not found: there is an ambiguity with
// AAAA coming from AAAACAAAACAAAAC or AAAAAAAAAAAAAAA
KAffect current_affect(seq[2*i+1], 1);
KmerAffect current_affect(seq[2*i+1], 1);
TAP_TEST(kaa.count(current_affect) == 0, TEST_AA_COUNT, "");
TAP_TEST(ckaa.count(current_affect) == 0, TEST_COUNT_AA_COUNT, ckaa.count(current_affect));
TAP_TEST(kaa.first(current_affect) == (int)string::npos, TEST_AA_FIRST, "");
TAP_TEST(kaa.last(current_affect) == (int)string::npos, TEST_AA_LAST, "");
}
for (int i = 0; i < 2; i++) {
KAffect current_affect(seq[2*i+1], 1);
KmerAffect current_affect(seq[2*i+1], 1);
TAP_TEST(kaa.count(current_affect) == 2, TEST_AA_COUNT, kaa.count(current_affect));
TAP_TEST(ckaa.count(current_affect) == 2, TEST_COUNT_AA_COUNT, ckaa.count(current_affect));
TAP_TEST(kaa.getAffectation(kaa.first(current_affect)) == current_affect, TEST_AA_GET_AFFECT, "");
TAP_TEST(kaa.getAffectation(kaa.last(current_affect)) == current_affect, TEST_AA_GET_AFFECT, "");
}
TAP_TEST(kaa.count(KAffect(seq[2*(nb_seq-1)+1], 1)) == 1, TEST_AA_COUNT, "");
TAP_TEST((kaa.first(KAffect(seq[2*(nb_seq-1)+1], 1))
== kaa.last(KAffect(seq[2*(nb_seq-1)+1], 1)))
TAP_TEST(kaa.count(KmerAffect(seq[2*(nb_seq-1)+1], 1)) == 1, TEST_AA_COUNT, "");
TAP_TEST((kaa.first(KmerAffect(seq[2*(nb_seq-1)+1], 1))
== kaa.last(KmerAffect(seq[2*(nb_seq-1)+1], 1)))
== 1, TEST_AA_FIRST, "");
TAP_TEST(ckaa.max(forbidden) == KAffect("C lots of", 1)
|| ckaa.max(forbidden) == KAffect("G lots of", 1),
TAP_TEST(ckaa.max(forbidden) == KmerAffect("C lots of", 1)
|| ckaa.max(forbidden) == KmerAffect("G lots of", 1),
TEST_COUNT_AA_MAX, "max is " << ckaa.max(forbidden));
TAP_TEST(ckaa.max() == KAffect::getUnknown(),
TAP_TEST(ckaa.max() == KmerAffect::getUnknown(),
TEST_COUNT_AA_MAX, "max is " << ckaa.max());
TAP_TEST(kaa.getAffectation(3).isUnknown(), TEST_AA_PREDICATES, "");
......@@ -56,8 +57,8 @@ void testAffectAnalyser1() {
TAP_TEST(kaa.getDistinctAffectations().size() == 5, TEST_AA_GET_DISTINCT_AFFECT, "");
KAffect cAffect = KAffect(seq[1], 1);
KAffect gAffect = KAffect(seq[3], 1);
KmerAffect cAffect = KmerAffect(seq[1], 1);
KmerAffect gAffect = KmerAffect(seq[3], 1);
TAP_TEST(ckaa.countBefore(cAffect, 0) == 0, TEST_COUNT_AA_COUNT_BEFORE, "");
TAP_TEST(ckaa.countBefore(gAffect, 0) == 0, TEST_COUNT_AA_COUNT_BEFORE, "");
TAP_TEST(ckaa.countAfter(cAffect, 10) == 0, TEST_COUNT_AA_COUNT_BEFORE, "");
......@@ -87,8 +88,8 @@ void testAffectAnalyser1() {
TAP_TEST(ckaa.lastMax(cAffect, gAffect) == 8, TEST_COUNT_AA_LAST_MAX, ckaa.lastMax(cAffect, gAffect));
// Test affectation with two affects that are not in the sequence
KAffect aAffect = KAffect(seq[5], 1);
KAffect tAffect = KAffect(seq[7], 1);
KmerAffect aAffect = KmerAffect(seq[5], 1);
KmerAffect tAffect = KmerAffect(seq[7], 1);
TAP_TEST(ckaa.firstMax(aAffect, tAffect) == -1, TEST_COUNT_AA_FIRST_MAX, "");
TAP_TEST(ckaa.lastMax(aAffect, tAffect) == - 1,
TEST_COUNT_AA_LAST_MAX, "");
......@@ -107,24 +108,24 @@ void testAffectAnalyser1() {
}
// Test with revcomp
template<template <class> class T, class KAffect>
template<template <class> class T>
void testAffectAnalyser2() {
const int k = 5;
const bool revcomp = true;
T<KAffect> *index = createIndex<T<KAffect> >(k, revcomp);
T<KmerAffect> *index = createIndex<T<KmerAffect> >(k, revcomp);
string sequence = "TTTTTGGGGG";
KmerAffectAnalyser<KAffect> kaa(*index, sequence);
CountKmerAffectAnalyser<KAffect> ckaa(*index, sequence);
KmerAffectAnalyser kaa(*index, sequence);
CountKmerAffectAnalyser ckaa(*index, sequence);
ckaa.setAllowedOverlap(k-1);
set<KAffect> forbidden;
forbidden.insert(KAffect::getAmbiguous());
forbidden.insert(KAffect::getUnknown());
set<KmerAffect> forbidden;
forbidden.insert(KmerAffect::getAmbiguous());
forbidden.insert(KmerAffect::getUnknown());
TAP_TEST(kaa.getSequence() == "TTTTTGGGGG", TEST_AA_GET_SEQUENCE, "actual: ");
TAP_TEST(ckaa.getSequence() == "TTTTTGGGGG", TEST_AA_GET_SEQUENCE, "actual: " << ckaa.getSequence());
TAP_TEST(kaa.getAffectation(1) == KAffect(seq[2*(nb_seq-1)+1], -1), TEST_AA_GET_AFFECT, "");
TAP_TEST(kaa.getAffectation(1) == KmerAffect(seq[2*(nb_seq-1)+1], -1), TEST_AA_GET_AFFECT, "");
TAP_TEST(kaa.count(kaa.getAffectation(1)) == 1, TEST_AA_GET_AFFECT, "");
TAP_TEST(ckaa.count(kaa.getAffectation(1)) == 1, TEST_COUNT_AA_COUNT, "");
TAP_TEST(kaa.getAffectation(0) == kaa.getAffectation(10 - k), TEST_AA_GET_AFFECT, "");
......@@ -135,10 +136,10 @@ void testAffectAnalyser2() {
TAP_TEST(kaa.getDistinctAffectations().size() == 3, TEST_AA_GET_DISTINCT_AFFECT, "");
TAP_TEST(ckaa.max(forbidden) == KAffect(seq[2*(nb_seq-1)+1], -1),
TAP_TEST(ckaa.max(forbidden) == KmerAffect(seq[2*(nb_seq-1)+1], -1),
TEST_COUNT_AA_MAX, "max is " << ckaa.max(forbidden));
TAP_TEST(ckaa.max() == KAffect::getUnknown(),
TAP_TEST(ckaa.max() == KmerAffect::getUnknown(),
TEST_COUNT_AA_MAX, "max is " << ckaa.max());
for (int i = 0; i < 10 - k; i++)
......@@ -164,7 +165,7 @@ void testGetMaximum() {
// J-J- _ _ _ _V-V-V- _ _ _J-J-
vector<KmerAffect> affectations(a, a+sizeof(a)/sizeof(KmerAffect));
KmerAffectAnalyser<KmerAffect> kaa(*index, "", affectations);
KmerAffectAnalyser kaa(*index, "", affectations);
TAP_TEST(kaa.getSequence() == "", TEST_AA_GET_SEQUENCE, "");
affect_infos results = kaa.getMaximum(AFFECT_J_BWD, AFFECT_V_BWD, 2., 0);
......@@ -201,7 +202,7 @@ void testGetMaximum() {
// 0 1 2 3 4 5 6 7 8 9 11 13 15
// V+V+V+V+V+V+V+V+V+V+J+J+J+V+V+V+
vector<KmerAffect> affectations2(a2, a2+sizeof(a2)/sizeof(KmerAffect));
KmerAffectAnalyser<KmerAffect> kaa2(*index, "", affectations2);
KmerAffectAnalyser kaa2(*index, "", affectations2);
results = kaa2.getMaximum(AFFECT_V, AFFECT_J, 2., 0);
TAP_TEST(! results.max_found,
TEST_AA_GET_MAXIMUM_MAX_FOUND, "(" << results.first_pos_max
......@@ -241,7 +242,7 @@ void testGetMaximum() {
// 0 1 2 3 4 5 6 7 8 9 11 13 15 17 19
// V+V+V+V+V+V+V+V+V+V+ _ _ _ _ _ _J-J-V+J-
vector<KmerAffect> affectations3(a3, a3+sizeof(a3)/sizeof(KmerAffect));
KmerAffectAnalyser<KmerAffect> kaa3(*index, "", affectations3);
KmerAffectAnalyser kaa3(*index, "", affectations3);
results = kaa3.getMaximum(AFFECT_V, AFFECT_J, 2., 0);
TAP_TEST(results.max_found, TEST_AA_GET_MAXIMUM_MAX_FOUND,
......@@ -266,13 +267,13 @@ void testGetMaximum() {
/**
* A sequence and its revcomp are not affected in the same way.
*/
template<template <class> class T, template <class> class AffectA, class KAffect>
template<template <class> class T>
void testBugAffectAnalyser() {
Fasta seqV("../../germline/IGHV.fa", 2);
Fasta seqJ("../../germline/IGHJ.fa", 2);
Fasta data("../../data/bug-revcomp.fa", 1, " ");
T<KAffect> index(9, true);
T<KmerAffect> index(9, true);
index.insert(seqV, "V");
index.insert(seqJ, "J");
......@@ -284,8 +285,8 @@ void testBugAffectAnalyser() {
TEST_FASTA_SEQUENCE,
"Sequences should be of same length: sequence and its revcomp");
AffectA<KAffect> fwdAffect(index, data.read(0).sequence);
AffectA<KAffect> bwdAffect(index, data.read(1).sequence);
KmerAffectAnalyser fwdAffect(index, data.read(0).sequence);
KmerAffectAnalyser bwdAffect(index, data.read(1).sequence);
int total = fwdAffect.count();
......@@ -299,8 +300,8 @@ void testBugAffectAnalyser() {
<< " for the bwd instead");
for (int i = 0; i < total; i++) {
const KAffect fwd = fwdAffect.getAffectation(i);
const KAffect bwd = bwdAffect.getAffectation(total - 1 - i);
const KmerAffect fwd = fwdAffect.getAffectation(i);
const KmerAffect bwd = bwdAffect.getAffectation(total - 1 - i);
if (fwd.isAmbiguous() || bwd.isAmbiguous()
|| fwd.isUnknown() || bwd.isUnknown()) {
......@@ -322,19 +323,13 @@ void testBugAffectAnalyser() {
}
void testAffectAnalyser() {
testAffectAnalyser1<MapKmerStore,KmerAffect>();
testAffectAnalyser2<MapKmerStore,KmerAffect>();
testAffectAnalyser1<MapKmerStore,KmerStringAffect>();
testAffectAnalyser2<MapKmerStore,KmerStringAffect>();
testBugAffectAnalyser<MapKmerStore, KmerAffectAnalyser, KmerAffect>();
testBugAffectAnalyser<MapKmerStore, KmerAffectAnalyser, KmerStringAffect>();
testAffectAnalyser1<MapKmerStore>();
testAffectAnalyser2<MapKmerStore>();
testBugAffectAnalyser<MapKmerStore>();
testGetMaximum<MapKmerStore>();
testAffectAnalyser1<ArrayKmerStore,KmerAffect>();
testAffectAnalyser2<ArrayKmerStore,KmerAffect>();
testAffectAnalyser1<ArrayKmerStore,KmerStringAffect>();
testAffectAnalyser2<ArrayKmerStore,KmerStringAffect>();
testBugAffectAnalyser<ArrayKmerStore, KmerAffectAnalyser, KmerAffect>();
testBugAffectAnalyser<ArrayKmerStore, KmerAffectAnalyser, KmerStringAffect>();
testAffectAnalyser1<ArrayKmerStore>();
testAffectAnalyser2<ArrayKmerStore>();
testBugAffectAnalyser<ArrayKmerStore>();
testGetMaximum<ArrayKmerStore>();
}
......@@ -26,7 +26,7 @@ void testSegmentationBug1(int delta_min, int delta_max) {
while (input.hasNext()) {
input.next();
KmerAffectAnalyser<KmerAffect> *kaa = new KmerAffectAnalyser<KmerAffect>(*(germline->index), input.getSequence().sequence);
KmerAffectAnalyser *kaa = new KmerAffectAnalyser(*(germline->index), input.getSequence().sequence);
set<KmerAffect> distinct_a = kaa->getDistinctAffectations();
int strand = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment