add function for marking 'N' regions
authorDiane Trout <diane@caltech.edu>
Mon, 9 Apr 2007 21:01:46 +0000 (21:01 +0000)
committerDiane Trout <diane@caltech.edu>
Mon, 9 Apr 2007 21:01:46 +0000 (21:01 +0000)
with the right draw function add_annotations_for_undefined_sequence
should be able to highlight the regions with Ns in them.

alg/glsequence.cpp
alg/glsequence.hpp
alg/sequence.hpp
alg/test/test_glsequence.cpp

index 340a9ada0719b475753e9780fb082fbfe974a5d1..89150d3a0068aba3cf1d169cf6b322ab4c88bacf 100644 (file)
@@ -66,6 +66,59 @@ DrawableRef GlSequence::copy_drawable(DrawableRef old_d)
   return d;
 }
 
+SeqSpanRef GlSequence::make_undefined_sequence_annotation(
+  Drawable::draw_func_ptr draw,
+  size_type start,
+  size_type count)
+{
+  // 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"));
+  DrawableRef drawable(default_drawable());
+  // glue everything to gether
+  drawable->setDrawFunction(draw);
+  empty_seq->setAnnotations(empty_seq_annot);
+  empty_seq->setDrawable(drawable);
+  return empty_seq;
+}
+
+void GlSequence::add_annotations_for_undefined_sequence(Drawable::draw_func_ptr draw)
+{
+  Sequence::const_iterator start_i = begin();
+  Sequence::const_iterator seq_i = begin();
+  Sequence::const_iterator end_i = end();
+  
+  Sequence::const_iterator start_block_i = end();
+  
+  for(; seq_i != end_i; ++seq_i)
+  {
+    // need a better set of characters to serch for
+    if (*seq_i == 'N' or *seq_i == 'n') {
+      if (start_block_i == end_i) {
+        start_block_i = seq_i;
+      }
+    } else {
+      if (start_block_i != end_i) {
+        // we got one.
+        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));        
+        // reset our counter...
+        start_block_i = end_i;
+      }
+    }
+  }
+  // catch stuff at the end
+  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));        
+  }
+}
+
+
 void GlSequence::setX(float value)
 {
   seq->drawable()->setX(value);
index 4d93d15b66969aea13f3a51026352c58c9524a4a..7882d23a9340db77cbea53fdd2a3893726f46660 100644 (file)
@@ -35,6 +35,8 @@ public:
   static DrawableRef default_drawable();
   static DrawableRef copy_drawable(DrawableRef s);
   
+  //! search through sequence and add an annotation highlighting all the non AGCT characters
+  void add_annotations_for_undefined_sequence(Drawable::draw_func_ptr draw=0);
   //! set our starting x (horizontal) coordinate
   void setX(float x);
   //! get our starting x (horizontal) coordinate
@@ -105,6 +107,12 @@ protected:
   AnnotationColorsRef color_mapper;
   const GLfloat char_pix_per_world_unit;
 
+  //! initalize a SeqSpanRef covering start, count
+  SeqSpanRef GlSequence::make_undefined_sequence_annotation(
+    Drawable::draw_func_ptr draw,
+    size_type start,
+    size_type count);
+
   //! Return the pixel width of the opengl viewport.
   static int get_viewport_width_in_pixels();
   //! draw a from left to right +/- height/2
index c2de433fca1b9602f4c39065054c06f732047016..d476dfef2b9a3347a9706a57d295073c32c8f663 100644 (file)
@@ -215,6 +215,7 @@ public:
   //! create an initialized annotation with the "standard" types.
   SeqSpanRef make_annotation(std::string name, std::string type, size_type start, size_type stop) const;
   const SeqSpanRefList& annotations() const;
+  
   const MotifList& motifs() const;
 
   //! add a motif to our list of motifs
index bd528d30ffe75d5df7aff874ab24446bed8f8ff2..0c00fb1271857e79c631ad0ab445600eaeacee85 100644 (file)
@@ -74,6 +74,23 @@ BOOST_AUTO_TEST_CASE( glsequence_color )
   BOOST_CHECK_EQUAL( *(s.color()), *c );
 }
 
+BOOST_AUTO_TEST_CASE( glsequence_find_null_sequence )
+{
+  boost::shared_ptr<AnnotationColors> cm(new AnnotationColors);
+  GlSequence s("AAAAAAAAAANNNNNANAN", cm);
+  //            0123456789012345678
+  s.add_annotations_for_undefined_sequence();
+  
+  BOOST_CHECK_EQUAL(s.annotations().size(), 3);
+  std::vector<SeqSpanRef> annot(s.annotations().begin(), s.annotations().end());
+  BOOST_CHECK_EQUAL(annot[0]->start(), 10);
+  BOOST_CHECK_EQUAL(annot[0]->stop(), 15);
+  BOOST_CHECK_EQUAL(annot[1]->start(), 16);
+  BOOST_CHECK_EQUAL(annot[1]->size(), 1);
+  BOOST_CHECK_EQUAL(annot[2]->start(), 18);
+  BOOST_CHECK_EQUAL(annot[2]->size(), 1);
+}
+
 BOOST_AUTO_TEST_CASE( glsequence_renderable )
 {
   boost::shared_ptr<AnnotationColors> cm(new AnnotationColors);