add function for marking 'N' regions
[mussa.git] / alg / glsequence.cpp
index 17fb561c830c5cf3fc241a01e8de2353c4cc8691..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);
@@ -256,18 +309,18 @@ void GlSequence::draw_annotations(GLfloat left, GLfloat right) const
 {
   // draw annotations
   GLfloat annotation_z = z() + 10.0;
-  const std::list<annot>& annots = Sequence::annotations();
-  const std::list<motif>& motifs = Sequence::motifs();
-  for (std::list<annot>::const_iterator annot_itor = annots.begin();
+  const SeqSpanRefList& annots = Sequence::annotations();
+  const MotifList& motifs = Sequence::motifs();
+  for (SeqSpanRefList::const_iterator annot_itor = annots.begin();
        annot_itor != annots.end();
        ++annot_itor)
   {
     glColor3f(0.0, 0.8, 0.0);
-    draw_box(left, right, x()+annot_itor->begin, x()+annot_itor->end
+    draw_box(left, right, x()+(*annot_itor)->start(), x()+(*annot_itor)->stop()
              height(), annotation_z);
   }
   // if motifs?
-  for (std::list<motif>::const_iterator motifs_itor = motifs.begin();
+  for (MotifList::const_iterator motifs_itor = motifs.begin();
        motifs_itor != motifs.end();
        ++motifs_itor)
   {
@@ -275,7 +328,6 @@ void GlSequence::draw_annotations(GLfloat left, GLfloat right) const
     draw_box(left, right, x()+motifs_itor->begin, x()+motifs_itor->end, 
              height(), annotation_z+1.0);
   }
-
 }
 
 // this way of drawing characters, came from the red open gl book