HACKISH: Display chipseq peak window track
[mussa.git] / alg / glsequence.hpp
1 #ifndef _GL_SEQUENCE_H_
2 #define _GL_SEQUENCE_H_
3
4 #include <boost/shared_ptr.hpp>
5
6 #include "alg/annotation_colors.hpp"
7 #include "alg/sequence.hpp"
8 #include "alg/color.hpp"
9 // isn't it lovely how the header file can live in different places?
10 #ifdef __APPLE__
11 #include <OpenGL/gl.h>
12 #else
13 #include <GL/gl.h>
14 #endif
15
16 class GlSequence;
17 typedef boost::shared_ptr<GlSequence> GlSequenceRef;
18
19 //! Manage rendering a mussa sequence track
20 /*! The idea is this will keep track of the location of where the sequence
21  *  is being rendered, and handle displaying annotations on that track
22  */
23 class GlSequence : public Sequence
24 {
25 public: 
26   GlSequence(const Sequence & s,
27              boost::shared_ptr<AnnotationColors> cm);
28   GlSequence(const GlSequence & s);
29   GlSequence(const GlSequence *);
30   //! Make a new GlSequence, using a copy of SeqSpan
31   GlSequence(const GlSequenceRef);
32   
33   GlSequence &operator=(const GlSequence &s);
34
35   static DrawableRef default_drawable();
36   static DrawableRef copy_drawable(DrawableRef s);
37   
38   //! search through sequence and add an annotation highlighting all the non AGCT characters
39   void add_annotations_for_defined_sequence(Drawable::draw_func_ptr draw=0);
40   /**!search through our annotations and set the draw function for a particular "type"
41    * this is really a temporary solution to configuring annotation display styles
42    */
43   void update_annotation_draw_function(
44          std::string type, 
45          Drawable::draw_func_ptr draw, 
46          ColorRef color
47        );
48   //! set our starting x (horizontal) coordinate
49   void setX(float x);
50   //! get our starting x (horizontal) coordinate
51   float x() const;
52   //! set our current y (vertical) position
53   void setY(float y);
54   //! get our current y (vertical) position
55   float y() const;
56   //! get our current z (depth) position
57   float z() const;
58   //! how thick (high) the track we're drawing is
59   float height() const;
60
61   //! set our default draw color
62   void setColor(ColorRef &c );
63   //! return our draw color
64   const ColorRef color() const;
65   //! return our draw color
66   ColorRef color();
67   //! return default gene color
68   static ColorRef default_gene_color();
69   //! return default track color
70   static ColorRef default_track_color();
71   //! return default chipseq color
72   static ColorRef default_chipseq_color();
73   
74   //! return our annotation color mapper
75   AnnotationColorsRef colorMapper() { return color_mapper; }
76
77   //! draw a from left to right +/- height/2
78   static
79   void draw_box(GLfloat world_left, GLfloat world_right, 
80                 GLfloat left, GLfloat right, GLfloat height,
81                 GLfloat y, GLfloat z,
82                 GLint primitive=GL_QUADS);
83   //! draw a track 
84   /*! left and right are the edges of the current viewport
85    */
86   void draw(GLfloat left, GLfloat right) const;
87
88   //! get our right (horizontal) coordinate (size-x)
89   float right() const;
90   //! how long is our sequence track? (computed from the sequence)
91   Sequence::size_type size() const;
92  
93   //! return the left (lowest) base index that is fully visible
94   Sequence::size_type leftbase(GLfloat left) const;
95   //! return one past rightmost (highest ) base index that is fully visible
96   //! done mostly so all the iterator logic continues to work correctly.
97   Sequence::size_type rightbase(GLfloat right) const;
98
99   //! provide an iterator to the sequence starting at world coordinate left
100   Sequence::const_iterator region_begin(GLfloat left, GLfloat right) const;
101   //! provide an iterator to the sequence ending at world coordinate right
102   Sequence::const_iterator region_end(GLfloat left, GLfloat right) const;
103
104   //! return a subsequence as a GlSequence (instead of a Sequence subsequence)
105   GlSequence subseq(size_type start, size_type count) const;
106   
107   //! Return the pixel width of the opengl viewport.
108   static int get_viewport_width_in_pixels();
109   //! how big is a pixel in world coordinats
110   static GLfloat pixelWidth(GLfloat, GLfloat);
111   //! how big is a pixel in world coordinats (specifying viewport size)
112   static GLfloat pixelWidth(GLfloat, GLfloat, int);
113
114   //! are we close enough that it would make sense to view the base pairs?
115   static bool is_sequence_renderable(GLfloat left, GLfloat right);
116   //! are we close enough that it would make sense to view the base pairs?
117   /*! though we don't actually check to see if there's sequence in our
118    *  view, just that there's enough pixels to render something if 
119    *  there were.
120    *  \param[in] left the left edge of the viewable region in world coordinates
121    *  \param[in] right the right edge of the viewable region in world 
122    *             coordinates
123    *  \param[in] pixel_width allow setting the current viewport pixel width
124    */
125   static bool is_sequence_renderable(GLfloat, GLfloat, int);
126
127   friend bool operator==(const GlSequence &left, const GlSequence &right);
128
129 protected:
130   AnnotationColorsRef color_mapper;
131
132   //! initalize a SeqSpanRef covering start, count
133   SeqSpanRef make_drawable_annotation(
134     Drawable::draw_func_ptr draw,
135     std::string name,
136     size_type start,
137     size_type count,
138     ColorRef color);
139
140   //! draw sequence as a bar
141   void draw_track(GLfloat, GLfloat) const;
142   void draw_annotations(GLfloat, GLfloat) const;
143   //! render a sequence as ATGC
144   /*! left and right are the current edges of the viewable world
145    */
146   void draw_sequence(GLfloat, GLfloat) const;
147 };
148
149 //! draw sequence track when we're far enough out not to see the AGCTs. 
150 void draw_summarized_track(SeqSpanRef ref, float left, float right);
151 //! draw a 1/4 width centered track 
152 void draw_narrow_track(SeqSpanRef ref, float left, float right);
153 //! draw a chipseq peak window track 
154 void draw_chipseq_window(SeqSpanRef ref, float left, float right);
155 #endif