record selected track
authorDiane Trout <diane@caltech.edu>
Sun, 5 Mar 2006 20:27:25 +0000 (20:27 +0000)
committerDiane Trout <diane@caltech.edu>
Sun, 5 Mar 2006 20:27:25 +0000 (20:27 +0000)
Keep track of the lowest value selected track, so we know what to show
when people try to bring up the sequence view.

Also toss in some more Boost.Python code

py/getm.py [new file with mode: 0644]
py/gl.py [new file with mode: 0644]
py/glsequence.cxx [new file with mode: 0644]
py/module.cxx
py/module.mk
py/sequence.cxx [new file with mode: 0644]
qui/PathScene.cxx
qui/PathScene.h

diff --git a/py/getm.py b/py/getm.py
new file mode 100644 (file)
index 0000000..be5be65
--- /dev/null
@@ -0,0 +1,20 @@
+"""How many times does a large mussa analysis redraw the same line.
+"""
+import mussa
+m = mussa.Mussa()
+#m.load_mupa("examples/mck3test.mupa")
+#m.analyze(0, 0, mussa.analysis_modes.TransitiveNway, 0)
+m.load("../mussa_analyses/land/myogenin_w30_t21")
+path = m.paths()
+
+count = 0
+tracks = {}
+for rp in path.refinedPathz:
+  t0_id = rp.track_indexes[0]
+  t1_id = rp.track_indexes[1]
+  tid = (t0_id, t1_id)
+  tracks[tid] = tracks.setdefault(tid, 0) + 1
+  count += 1
+
+print "count", count
+print "tracks", len(tracks.keys())
diff --git a/py/gl.py b/py/gl.py
new file mode 100644 (file)
index 0000000..43d29f6
--- /dev/null
+++ b/py/gl.py
@@ -0,0 +1,18 @@
+"""Can we show a mussa gl object?
+"""
+from OpenGL.GLUT import *
+from OpenGL.GL import *
+import mussa
+
+def main():
+  seq = mussa.Sequence()
+  s = "AAGGCCTTAAGGCCTT" 
+  seq = mussa.Sequence(s)
+  assert s == seq.size() == len(seq)
+  glseq = mussa.GlSequence(seq)
+
+  glutInit(sys.argv)
+  
+  
+if __name__ == "__main__":
+  main()
diff --git a/py/glsequence.cxx b/py/glsequence.cxx
new file mode 100644 (file)
index 0000000..3c9cd36
--- /dev/null
@@ -0,0 +1,18 @@
+#include <boost/python.hpp>
+using namespace boost::python;
+
+#include "alg/glsequence.h"
+#include "alg/sequence.hh"
+
+void export_glsequence()
+{
+  class_<GlSequence>("GlSequence", init<Sequence &>())
+    .def(init<GlSequence &>())
+    .def("draw", &GlSequence::draw)
+    .def("sequence", &GlSequence::sequence, 
+                  return_internal_reference<>())
+    .add_property("x", &GlSequence::x, &GlSequence::setX)
+    .add_property("y", &GlSequence::y, &GlSequence::setY)
+    .add_property("width", &GlSequence::width, &GlSequence::setWidth)
+  ;
+}
index fbacede6189dacf02070aef9590784e37d7b3e03..1f6fd0280150cce15b0dbc2e7a31c7cf2860dd4c 100644 (file)
@@ -1,13 +1,17 @@
 #include <boost/python.hpp>
 using namespace boost::python;
 
+void export_conserved_path();
+void export_glsequence();
 void export_mussa();
 void export_nway_paths();
-void export_conserved_path();
+void export_sequence();
 
 BOOST_PYTHON_MODULE(mussa)
 {
+  export_conserved_path();
+  export_glsequence();
   export_mussa();
   export_nway_paths();
-  export_conserved_path();
+  export_sequence();
 }
index ba6336310238fab903527cecf1e927e53d722e8e..b122d73a78ba7d9188e3e4c30a9ad6dd1f4cb1f9 100644 (file)
@@ -2,9 +2,10 @@ CURDIR := $(BASEDIR)py/
 
 SOURCES.cxx := module.cxx \
                conserved_path.cxx \
+               glsequence.cxx \
                mussa.cxx \
-              nway_paths.cxx
-
+              nway_paths.cxx \
+              sequence.cxx
 
 MUSSA_PY_SRC := $(addprefix $(CURDIR), $(SOURCES.cxx))
 MUSSA_PY_OBJ := $(MUSSA_PY_SRC:.cxx=$(OBJEXT))
@@ -15,5 +16,5 @@ CXXFLAGS +=
 MUSSAPY := $(BASEDIR)/mussa.so
 TARGETBINS += $(MUSSAPY)
 
-$(MUSSAPY): $(MUSSA_PY_OBJ) $(MUSSA_ALG_OBJ)
-       g++ -shared $(CXXFLAGS) -lpython2.3 -lboost_python -o $@ $^
+$(MUSSAPY): $(MUSSA_PY_OBJ) $(MUSSA_ALG_OBJ) $(MUSSA_ALG_GL_OBJ)
+       g++ -shared $(CXXFLAGS) -lGL -lpython2.3 -lboost_python -o $@ $^
diff --git a/py/sequence.cxx b/py/sequence.cxx
new file mode 100644 (file)
index 0000000..39542fa
--- /dev/null
@@ -0,0 +1,16 @@
+#include <boost/python.hpp>
+using namespace boost::python;
+
+#include <string>
+#include "alg/glsequence.h"
+
+void export_sequence()
+{
+  class_<Sequence>("Sequence")
+    .def(init<std::string>())
+    //.add_property("seq", &Sequence::get_seq, &Sequence::set_seq)
+    .def("size", &Sequence::size)
+    .def("__len__", &Sequence::size)
+    //.add_property("header", &Sequence::get_header)
+  ;
+}
index 3203e72538e1232dda9321af5bffe1548f618602..759014ec6835ddcb5e61107d6f7833c8bf2c0846 100644 (file)
@@ -8,6 +8,7 @@
 #include <QRect>
 #include <QString>
 #include <iostream>
+#include <set>
 
 #include <GL/gl.h>
 #include <math.h>
@@ -23,7 +24,7 @@ PathScene::PathScene(Mussa* analysis, QWidget *parent) :
   zoom(0),
   maxOrtho2d(-50.0, -50, 3000000.0, 300.0),
   curOrtho2d(maxOrtho2d),
-  highlightMode(false),
+  selectedMode(false),
   rubberBand(0),
   drawingBand(false)
 { 
@@ -201,10 +202,11 @@ void PathScene::paintGL()
   mussaesque();
   glEnable(GL_BLEND);
   glDepthMask(GL_FALSE);
-  if (highlightMode && !drawingBand) {
+  if (selectedMode && !drawingBand) {
     glColor4f(0.4, 0.4, 0.4, 0.9);
     glRectf(previousBand.x(), previousBand.y(),
             previousBand.right(), previousBand.bottom());
+    cout << "x: " << previousBand.x() << " r:" << previousBand.right() << endl;
   }
   glDepthMask(GL_TRUE);
   glDisable(GL_BLEND);
@@ -249,12 +251,15 @@ void PathScene::processSelection(GLuint hits, GLuint buffer[], GLuint bufsize)
   GLuint objtype;
   GLuint objid;
 
-  highlightPaths.clear();
-  highlightPaths.reserve(pathz_count);
-  highlightPaths.insert(highlightPaths.begin(), pathz_count, false);
+  selectedPaths.clear();
+  selectedPaths.reserve(pathz_count);
+  selectedPaths.insert(selectedPaths.begin(), pathz_count, false);
+  selectedTrack = 0x7fffffff;
   
   std::cout << "hits = " << hits << " " << pathz_count << std::endl;
   ptr = (GLuint *) buffer;
+  if (hits > 0)
+    selectedMode = true;
   for (GLuint i=0; i < hits; ++i)
   {
     if ((i + 5) > bufsize) {
@@ -265,8 +270,6 @@ void PathScene::processSelection(GLuint hits, GLuint buffer[], GLuint bufsize)
       z2 = ((float)*ptr++)/0x7fffffff;
       objtype = *ptr++;
       objid = *ptr++;
-      //std::cout << "  z1 is " << z1 << std::endl
-      //          << "  z2 is " << z2 << std::endl;
       if (names != 2) {
         std::clog << "wrong number of glNames, selection is having trouble ";
         std::clog << " got " << names << std::endl;
@@ -277,16 +280,16 @@ void PathScene::processSelection(GLuint hits, GLuint buffer[], GLuint bufsize)
         std::clog << endl;
         return;
       } 
-      if (objtype == MussaPaths) {
-        highlightPaths[objid] = true;
-        // not sure i like this, but it means we'll only highlight if a 
-        // selection was made
-        highlightMode = true; 
+      switch (objtype) {
+        case MussaPaths:
+          selectedPaths[objid] = true;
+        break;
+        case MussaTracks:
+          if (objid < selectedTrack) {
+            selectedTrack = objid; 
+          }
+        break;
       }
-
-      //std::clog << ((objtype == MussaTracks) ? " track: " : " path: ")
-      //          << objid
-      //          << std::endl;
     }
   }
 }
@@ -296,7 +299,7 @@ void PathScene::mousePressEvent( QMouseEvent *e)
   drawingBand = true;
   std::cout << "x=" << e->x() << " y=" << e->y() << std::endl;
 
-  highlightMode = false;
+  selectedMode = false;
   bandOrigin = e->pos();
   if (!rubberBand)
     rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
@@ -434,7 +437,7 @@ void PathScene::draw_lines() const
       // the following boolean implements logical xor
       if ( (reversed || prevReversed) && (!reversed || !prevReversed)) { 
         // we have a different orientation
-        if (not highlightMode or highlightPaths[objid] == true) {
+        if (not selectedMode or selectedPaths[objid] == true) {
           // if we have nothing selected, or we're the highlight, be bright
           glColor3f(0.0, 0.0, 1.0);
         } else {
@@ -443,7 +446,7 @@ void PathScene::draw_lines() const
         }
       } else {
         // both current and previous path have the same orientation
-        if (not highlightMode or highlightPaths[objid] == true) {
+        if (not selectedMode or selectedPaths[objid] == true) {
           glColor3f(1.0, 0.0, 0.2);
         } else {
           glColor3f(1.0, 0.5, 0.5);
index 64997d60a030fa01a7e4a98a3901af171678b7ac..d836c1917e0cfb3fa06b092854bdead1b4ed5720 100644 (file)
@@ -49,8 +49,12 @@ protected:
   int zoom;
   QRectF maxOrtho2d;
   QRectF curOrtho2d;
-  bool highlightMode;
-  std::vector<bool> highlightPaths;
+  // true if we have a selection
+  bool selectedMode;
+  // indicate which paths are selected
+  std::vector<bool> selectedPaths;
+  // which track is selected (it only makes sense to have one track selected).
+  unsigned int selectedTrack;
 
   void initializeGL();
   void resizeGL(int width, int height);