test motif editor
authorDiane Trout <diane@caltech.edu>
Sat, 31 Mar 2007 01:44:41 +0000 (01:44 +0000)
committerDiane Trout <diane@caltech.edu>
Sat, 31 Mar 2007 01:44:41 +0000 (01:44 +0000)
I was thinking this is where the source of my motifs disappearing
might have been, but aparently the motif editor does still work
correctly.

alg/mussa.cpp
qui/motif_editor/MotifEditor.cpp
qui/motif_editor/MotifEditor.hpp
qui/motif_editor/test/CMakeLists.txt
qui/motif_editor/test/TestMotifEditor.cpp [new file with mode: 0644]
qui/motif_editor/test/TestMotifEditor.hpp [new file with mode: 0644]

index 52d0dce6006b7371ee8dbf2771233ed246c32169..4b96d1b4d115a6f12915d1b3fd5a1d082d43212e 100644 (file)
@@ -328,7 +328,7 @@ void Mussa::append_sequence(boost::shared_ptr<Sequence> a_seq)
 }
 
 
-const vector<boost::shared_ptr<Sequence> >& 
+const vector<SequenceRef>& 
 Mussa::sequences() const
 {
   return the_seqs;
index 8166e37cbca86fa16092717ea12e2146aa085ac5..acde2d3af74c8a756bb9e05f4855748215f69138 100644 (file)
@@ -51,6 +51,8 @@ void MotifEditor::updateModel()
   // if our current analysis doesn't match the one in our
   // model, we probalby changed the analysis.
   // so delete and restart
+  // DET 2007mar30 (can this if statement ever be true? it doesn't look 
+  //                like there's a way to change the analysis?)
   if (model and model->getAnalysis() != analysis) {
     delete model;
   }
index aaff9a729a9cc59d3f01f9ed3c8d38e7dc8760d9..1cc8a2fff846e16050d77371550b2c5b622fc37b 100644 (file)
@@ -24,6 +24,12 @@ public:
   //! resize cells
   void updateView();
   
+  //! return the analysis, intended for testing
+  MussaRef get_analysis() { return analysis; }
+  //! return the internal model used by the editor
+  //! this is mostly intended for testing
+  MotifModel *get_model() { return model; }
+   
 public slots:
   //! create model and attach it to the table view  
   void updateModel();
index 18cfc0c7b7d088798f3dd5e9abb83b97af14d588..9f3770870c60c1f345c17bb0488c936600519179 100644 (file)
@@ -1,4 +1,5 @@
 INCLUDE( TestMacros )
 
+MAKE_QUI_UNITTEST( TestMotifEditor )
 MAKE_QUI_UNITTEST( TestMotifElement )
 MAKE_QUI_UNITTEST( TestMotifModel )
\ No newline at end of file
diff --git a/qui/motif_editor/test/TestMotifEditor.cpp b/qui/motif_editor/test/TestMotifEditor.cpp
new file mode 100644 (file)
index 0000000..515c122
--- /dev/null
@@ -0,0 +1,3 @@
+#include "TestMotifEditor.hpp"
+
+QTEST_MAIN(TestMotifEditor)
diff --git a/qui/motif_editor/test/TestMotifEditor.hpp b/qui/motif_editor/test/TestMotifEditor.hpp
new file mode 100644 (file)
index 0000000..1e29ccc
--- /dev/null
@@ -0,0 +1,74 @@
+#ifndef TESTMOTIFEDITOR_HPP_
+#define TESTMOTIFEDITOR_HPP_
+#include <QtGui>
+#include <QVariant>
+#include <QtTest/QtTest>
+#include <QtTest/QSignalSpy>
+
+#include <vector>
+#include "alg/sequence.hpp"
+
+#include "qui/motif_editor/MotifEditor.hpp"
+#include "qui/motif_editor/MotifModel.hpp"
+
+class TestMotifEditor : public QObject
+{
+  Q_OBJECT
+
+private slots:
+
+  void testSimpleConstructor() {
+    MussaRef m1(new Mussa);
+    MotifEditor *editor = new MotifEditor(m1);
+    
+    QVERIFY(editor->get_analysis() == m1);
+    QVERIFY(editor->get_model() != 0);
+  }
+
+  // do we still have motifs in our sequences after hitting apply?
+  void testEditColorApply() {
+    std::vector<Sequence> motifs;
+    motifs.push_back("AAGG");
+    std::vector<Color> colors;
+    colors.push_back(Color(0.0, 0.0, 1.0));
+        
+    MussaRef m(new Mussa);
+    m->append_sequence("AAAAGGGGTTTT");
+    m->append_sequence("AAAAAAAACCCC");
+    m->set_motifs(motifs, colors);
+    
+    // do the sequences have the right motifs?
+    std::vector<SequenceRef> sequences1(m->sequences());
+    QVERIFY(sequences1[0]->motifs().size() == 1);
+    QVERIFY(sequences1[1]->motifs().size() == 0);
+    
+    // get color
+    boost::shared_ptr<AnnotationColors> cm(m->colorMapper());
+    QVERIFY(cm->lookup("motif", "AAGG") == Color(0.0, 0.0, 1.0));
+        
+    MotifEditor *editor(new MotifEditor(m));
+    MotifModel *model(editor->get_model());
+    // the AAGG motif and the emtpy motif
+    QVERIFY(model->size() == 2);
+    QModelIndex row0_color(model->index(0, MotifModel::ColorCell));
+    
+    model->setData(row0_color, QVariant(QColor(0,255,0)));
+    // this is equivalent to pressing apply
+    editor->updateAnalysisMotifs();
+
+    std::vector<SequenceRef> sequences2(m->sequences());
+    QVERIFY(sequences2[0]->motifs().size() == 1);
+    QVERIFY(sequences2[1]->motifs().size() == 0);
+    QVERIFY(cm->lookup("motif", "AAGG") == Color(0.0, 1.0, 0.0));
+  }
+/*
+  
+public slots:
+  void updateModel();
+  void updateAnalysisMotifs();
+
+signals:
+  void changedMotifs();
+  */
+};
+#endif /*TESTMOTIFEDITOR_HPP_*/