1 #ifndef TESTMOTIFEDITOR_HPP_
2 #define TESTMOTIFEDITOR_HPP_
5 #include <QtTest/QtTest>
6 #include <QtTest/QSignalSpy>
9 #include "alg/sequence.hpp"
11 #include "qui/motif_editor/MotifEditor.hpp"
12 #include "qui/motif_editor/MotifModel.hpp"
14 class TestMotifEditor : public QObject
20 void testSimpleConstructor() {
21 MussaRef m1(new Mussa);
22 MotifEditor *editor = new MotifEditor(m1);
24 QVERIFY(editor->get_analysis() == m1);
25 QVERIFY(editor->get_model() != 0);
28 // do we still have motifs in our sequences after hitting apply?
29 void testEditColorApply() {
30 std::vector<Sequence> motifs;
31 motifs.push_back("AAGG");
32 std::vector<Color> colors;
33 colors.push_back(Color(0.0, 0.0, 1.0));
35 MussaRef m(new Mussa);
36 m->append_sequence("AAAAGGGGTTTT");
37 m->append_sequence("AAAAAAAACCCC");
38 m->set_motifs(motifs, colors);
40 // do the sequences have the right motifs?
41 std::vector<SequenceRef> sequences1(m->sequences());
42 QVERIFY(sequences1[0]->motifs().size() == 1);
43 QVERIFY(sequences1[1]->motifs().size() == 0);
46 boost::shared_ptr<AnnotationColors> cm(m->colorMapper());
47 QVERIFY(cm->lookup("motif", "AAGG") == Color(0.0, 0.0, 1.0));
49 MotifEditor *editor(new MotifEditor(m));
50 MotifModel *model(editor->get_model());
51 // the AAGG motif and the emtpy motif
52 QVERIFY(model->size() == 2);
53 QModelIndex row0_color(model->index(0, MotifModel::ColorCell));
55 model->setData(row0_color, QVariant(QColor(0,255,0)));
56 // this is equivalent to pressing apply
57 editor->updateAnalysisMotifs();
59 std::vector<SequenceRef> sequences2(m->sequences());
60 QVERIFY(sequences2[0]->motifs().size() == 1);
61 QVERIFY(sequences2[1]->motifs().size() == 0);
62 QVERIFY(cm->lookup("motif", "AAGG") == Color(0.0, 1.0, 0.0));
63 QVERIFY(m->colorMapper()->lookup("motif", "AAGG") == Color(0.0, 1.0, 0.0));
65 QVERIFY(editor->get_analysis() == m);
66 QVERIFY(editor->get_model() == model);
67 QVERIFY(m->colorMapper() == cm);
70 void testEditMotifApply() {
71 std::vector<Sequence> motifs;
72 motifs.push_back("AAGG");
73 std::vector<Color> colors;
74 colors.push_back(Color(0.0, 0.0, 1.0));
76 MussaRef m(new Mussa);
77 m->append_sequence("AAAAGGGG");
78 m->append_sequence("AAAACCCC");
79 m->set_motifs(motifs, colors);
81 // do the sequences have the right motifs?
82 std::vector<SequenceRef> sequences1(m->sequences());
83 QVERIFY(sequences1[0]->get_sequence() == "AAAAGGGG");
84 QVERIFY(sequences1[1]->get_sequence() == "AAAACCCC");
85 QVERIFY(sequences1[0]->motifs().size() == 1);
86 QVERIFY(sequences1[1]->motifs().size() == 0);
89 boost::shared_ptr<AnnotationColors> cm(m->colorMapper());
90 QVERIFY(cm->lookup("motif", "AAGG") == Color(0.0, 0.0, 1.0));
92 MotifEditor *editor(new MotifEditor(m));
93 MotifModel *model(editor->get_model());
94 // the AATT motif and the empty motif
95 QVERIFY(model->size() == 2);
96 QModelIndex row0_color(model->index(0, MotifModel::ColorCell));
97 QModelIndex row0_sequence(model->index(0, MotifModel::SequenceCell));
98 QVERIFY(model->data(row0_sequence) == "AAGG");
100 // change contents of cell
101 model->setData(row0_sequence, QVariant("AACC"));
102 // this is equivalent to pressing apply
103 editor->updateAnalysisMotifs();
104 QVERIFY(model->data(row0_sequence) == "AACC");
106 // does the mussa analysis have the right data?
107 std::vector<SequenceRef> sequences2(m->sequences());
108 QVERIFY(sequences2[0]->motifs().size() == 0);
109 QVERIFY(sequences2[1]->motifs().size() == 1);
110 QVERIFY(cm->lookup("motif", "AACC") == Color(0.0, 0.0, 1.0));
111 QVERIFY(m->colorMapper()->lookup("motif", "AACC") == Color(0.0, 0.0, 1.0));
112 QVERIFY(cm->lookup("motif", "AAGG") == Color(0.0, 0.0, 0.0));
113 QVERIFY(m->colorMapper()->lookup("motif", "AAGG") == Color(0.0, 0.0, 0.0));
115 QVERIFY(editor->get_analysis() == m);
116 QVERIFY(editor->get_model() == model);
117 QVERIFY(m->colorMapper() == cm);
123 void updateAnalysisMotifs();
126 void changedMotifs();
129 #endif /*TESTMOTIFEDITOR_HPP_*/