set annotation draw function by type
authorDiane Trout <diane@caltech.edu>
Fri, 13 Apr 2007 23:38:43 +0000 (23:38 +0000)
committerDiane Trout <diane@caltech.edu>
Fri, 13 Apr 2007 23:38:43 +0000 (23:38 +0000)
Additionally, I renamed a couple of functions to reflect that we're looking for valid sequence
instead of Ns, and my draw functions now use the color set in the drawable.
(Which also means that I have to set the color for the drawable class).

alg/glseqbrowser.cpp
alg/glsequence.cpp
alg/glsequence.hpp
alg/seq_span.hpp
alg/test/test_glsequence.cpp

index 107099bd824105df653a994699472f3a122cf2fb..c3f5cb19a8f4199e7debd2892fd40615d63c1465 100644 (file)
@@ -354,7 +354,9 @@ void GlSeqBrowser::push_sequence(GlSequence gs)
 
 void GlSeqBrowser::push_sequence(GlSequenceRef gs)
 {
+  ColorRef default_color(new Color(0.0, 0.8, 0.0));
   GlSequenceRef new_gs(new GlSequence(gs));
+  new_gs->update_annotation_draw_function("gene", draw_narrow_track, default_color);
   // mark where the sequence is
   new_gs->add_annotations_for_defined_sequence(draw_track);
   
index c77c29b5369a4acf5ab72d2981c16e3f2d403d08..2e5bb756b03979448291da6c56982439a3281549 100644 (file)
@@ -68,18 +68,21 @@ DrawableRef GlSequence::copy_drawable(DrawableRef old_d)
   return d;
 }
 
-SeqSpanRef GlSequence::make_undefined_sequence_annotation(
+SeqSpanRef GlSequence::make_drawable_annotation(
   Drawable::draw_func_ptr draw,
+  std::string name, 
   size_type start,
-  size_type count)
+  size_type count,
+  ColorRef color)
 {
   // create all the components of our annotation
   // (should seq_i-start_i 
   SeqSpanRef empty_seq(seq->subseq(start, count)); 
-  AnnotationsRef empty_seq_annot(new Annotations("null"));
+  AnnotationsRef empty_seq_annot(new Annotations(name));
   DrawableRef drawable(default_drawable());
   // glue everything to gether
   drawable->setDrawFunction(draw);
+  drawable->setColor(color);
   empty_seq->setAnnotations(empty_seq_annot);
   empty_seq->setDrawable(drawable);
   return empty_seq;
@@ -87,6 +90,7 @@ SeqSpanRef GlSequence::make_undefined_sequence_annotation(
 
 void GlSequence::add_annotations_for_defined_sequence(Drawable::draw_func_ptr draw)
 {
+  ColorRef sequence_color(new Color(0.0, 0.0, 0.0));
   Sequence::const_iterator start_i = begin();
   Sequence::const_iterator seq_i = begin();
   Sequence::const_iterator end_i = end();
@@ -105,7 +109,10 @@ void GlSequence::add_annotations_for_defined_sequence(Drawable::draw_func_ptr dr
         size_type start = start_block_i - start_i;
         size_type count = seq_i - start_block_i;
         // add the annotation
-        add_annotation(make_undefined_sequence_annotation(draw, start, count));        
+        add_annotation(
+          make_drawable_annotation(draw, "sequence", start, count, 
+                                   sequence_color)
+        );        
         // reset our counter...
         start_block_i = end_i;
       }
@@ -115,10 +122,36 @@ void GlSequence::add_annotations_for_defined_sequence(Drawable::draw_func_ptr dr
   if( start_block_i != end_i ) {
     size_type start = start_block_i - start_i;
     size_type count = seq_i - start_block_i;
-    add_annotation(make_undefined_sequence_annotation(draw, start, count));        
+    add_annotation(make_drawable_annotation(draw, "sequence", start, count, 
+                                            sequence_color)
+                  );        
   }
 }
 
+void GlSequence::update_annotation_draw_function(
+       std::string type, 
+       Drawable::draw_func_ptr draw_func,
+       ColorRef color
+)
+{
+  for(SeqSpanRefList::iterator annot_i = annotation_list->begin();
+      annot_i != annotation_list->end();
+      ++annot_i)
+  {
+    AnnotationsRef metadata( (*annot_i)->annotations() );
+     
+    if (metadata->has_key("type") and metadata->get("type") == type) {
+      // we should update
+      DrawableRef d((*annot_i)->drawable());
+      if (!d) {
+        d = default_drawable();
+        (*annot_i)->setDrawable(d);
+      }
+      d->setDrawFunction(draw_func);
+      d->setColor(color);
+    }
+  }
+}
 
 void GlSequence::setX(float value)
 {
@@ -465,9 +498,10 @@ void draw_narrow_track(SeqSpanRef s, float left, float right)
   float y( (parent_draw) ? parent_draw->y() : 0);
   float z( (parent_draw) ? parent_draw->z() : 10 );
   float height( (parent_draw) ? parent_draw->height() : default_height ); 
-
-  glColor3f(0.0, 0.0, 0.0);
-  float hsmall = height * 0.5;
+  Color c( (s->drawable()) ? s->drawable()->color() : Color(0.0, 0.0, 0.0) );  
+  glColor3fv(c.get());
+  
+  float hsmall = height * 0.25;
   GlSequence::draw_box(left, right, x+s->start(), x+s->stop(), 
                        hsmall, y, z+10);
 }
@@ -480,8 +514,9 @@ void draw_track(SeqSpanRef s, float left, float right)
   float y( (parent_draw) ? parent_draw->y() : 0);
   float z( (parent_draw) ? parent_draw->z() : 10 );
   float height( (parent_draw) ? parent_draw->height() : default_height ); 
+  Color c( (s->drawable()) ? s->drawable()->color() : Color(0.0, 0.0, 0.0) );  
 
-  glColor3f(0.0, 0.0, 0.0);
+  glColor3fv( c.get() );
   GlSequence::draw_box(left, right, x+s->start(), x+s->stop(), 
                        height, y, z+10);
 }
\ No newline at end of file
index b772cd2fa75e77510e1c2128fd2f5af5db4f06d9..6f16a199e8c747cd89146316883a934ce8d51d42 100644 (file)
@@ -37,6 +37,14 @@ public:
   
   //! search through sequence and add an annotation highlighting all the non AGCT characters
   void add_annotations_for_defined_sequence(Drawable::draw_func_ptr draw=0);
+  /**!search through our annotations and set the draw function for a particular "type"
+   * this is really a temporary solution to configuring annotation display styles
+   */
+  void update_annotation_draw_function(
+         std::string type, 
+         Drawable::draw_func_ptr draw, 
+         ColorRef color
+       );
   //! set our starting x (horizontal) coordinate
   void setX(float x);
   //! get our starting x (horizontal) coordinate
@@ -116,10 +124,12 @@ protected:
   const GLfloat char_pix_per_world_unit;
 
   //! initalize a SeqSpanRef covering start, count
-  SeqSpanRef make_undefined_sequence_annotation(
+  SeqSpanRef make_drawable_annotation(
     Drawable::draw_func_ptr draw,
+    std::string name,
     size_type start,
-    size_type count);
+    size_type count,
+    ColorRef color);
 
   //! draw sequence as a bar
   void draw_track(GLfloat, GLfloat) const;
index cf2723ea928d7bfc80034bba4d3d811940b226bb..6635a10c9dfbd182f2dc0c50e70d01683b2041c9 100644 (file)
@@ -58,7 +58,6 @@ public:
   enum strand_type { UnknownStrand, MinusStrand, PlusStrand, 
                      BothStrand, SameStrand, OppositeStrand, SingleStrand };
 
-public:
   SeqSpan(const SeqSpan &);
   SeqSpan(const SeqSpan *);
   explicit SeqSpan(const std::string &, 
index 120a3f6d238a664a55678f08bee4a4aa029704f8..47621af4eac63fe11154339bdb39aaa69fd1bfd8 100644 (file)
@@ -91,6 +91,33 @@ BOOST_AUTO_TEST_CASE( glsequence_find_real_sequence )
   BOOST_CHECK_EQUAL(annot[2]->size(), 1);
 }
 
+void dummy_draw_func(SeqSpanRef ref, float l, float r)
+{
+}
+  
+BOOST_AUTO_TEST_CASE( glsequence_set_annotation_drawfunc_by_type )
+{
+  ColorRef default_color(new Color(1.0, 0.0, 0.0));
+  boost::shared_ptr<AnnotationColors> cm(new AnnotationColors);
+  GlSequence s("AAAAGGGGNNNNTTTTCCC", cm);
+  //            0123456789012345678
+  s.add_annotation("Aname", "value", 0, 4);
+  s.add_annotation("Gname", "value", 4, 4);
+  s.add_annotation("Tname", "gene", 12, 4);
+  s.update_annotation_draw_function("gene", dummy_draw_func, default_color);
+
+  BOOST_CHECK_EQUAL(s.annotations().size(), 3);
+  std::vector<SeqSpanRef> annot(s.annotations().begin(), s.annotations().end());
+  // the two not updated annotations shouldn't have a drawable attached to them yet 
+  BOOST_CHECK( not annot[0]->drawable());
+  BOOST_CHECK( not annot[1]->drawable());
+  // the annotation updated must be drawable
+  BOOST_REQUIRE(annot[2]->drawable());
+  // and it must have the right draw function
+  BOOST_CHECK_EQUAL(annot[2]->drawable()->drawFunction(), dummy_draw_func);
+  BOOST_CHECK_EQUAL(annot[2]->drawable()->color(), default_color);
+}
+
 BOOST_AUTO_TEST_CASE( glsequence_renderable )
 {
   boost::shared_ptr<AnnotationColors> cm(new AnnotationColors);