[project @ 4]
[mussa.git] / mussa_gui_seq.cc
1 #include "mussa_gui_seq.hh"
2
3
4 void
5 SeqView::setup(string name, int sq_num, 
6                vector<Sequence> *some_seqs,
7                list<vector<int> > some_paths, vector<int> some_lens)
8 {
9   ana_name = name;
10   seq_num = sq_num;
11   S = some_seqs;
12   P = some_paths;
13   seq_lens = some_lens;
14
15   y_seq_incre = (y_max-10) / (seq_num - 1);
16
17   fl_font(FL_COURIER, 14);
18   cout << fl_width('A') << endl;
19
20   align_offsets(0);
21 }
22
23
24 void
25 SeqView::draw()
26 {
27   int seq_i;
28   Sequence a_seq;
29   int i, y_loc;
30   vector<int> a_path;
31   list<vector<int> >::iterator pathz_i;
32   int i2;
33   int x_start, y_start, x_end, y_end;
34   double ch_width;
35   int window_length, win_i;
36   int rc_1 = 0; 
37   int rc_2 = 0;
38   string sub_seq;
39   int offset1, offset2;
40   float center1, center2;
41
42
43   fl_font(FL_COURIER, 14);
44   fl_color(FL_BLACK);
45   //blatantly stolen from FR2
46   ch_width = fl_width('A');     // monospaced: all characters are same width
47
48   y_loc = 10;
49   for(seq_i = seq_num-1; seq_i >= 0; --seq_i)
50   {
51     sub_seq = (*S)[seq_i].seq();
52     sub_seq = sub_seq.substr(seq_align_offsets[seq_i]);
53     fl_draw(sub_seq.c_str(), 0+x(), y_loc+y()); 
54     y_loc += y_seq_incre;
55   }
56
57   fl_color(FL_RED);
58   fl_line_style(FL_SOLID, 1, NULL);
59
60   for(pathz_i = P.begin(); pathz_i != P.end(); ++pathz_i)
61   {
62     a_path = *pathz_i;
63     y_loc = 0;
64     window_length = a_path[0];
65     for(i2 = seq_num; i2 > 1; i2--)
66     {
67       // RC case handling
68
69       // ugh, and xor...only want rc coloring if just one of the nodes is rc
70       if ( ((a_path[i2] < 0) || (a_path[i2-1] < 0)) &&
71            !((a_path[i2] < 0) && (a_path[i2-1] < 0)) )
72         fl_color(FL_BLUE);
73
74       offset1 = seq_align_offsets[i2-1];
75       offset2 = seq_align_offsets[i2-2];
76       center1 = 0.5;
77       center2 = 0.5;
78
79       // no matter the case, any RC node needs an offset
80       if (a_path[i2] < 0)
81       {
82         rc_1 = window_length;        
83         offset1 = -offset1;
84         center1 = -center1;
85       }
86       if (a_path[i2-1] < 0)
87       {
88         rc_2 = window_length;        
89         offset2 = -offset2;
90         center2 = -center2;
91       }
92
93       // draw the line for each bp in this window that actually matches
94       for(win_i = 0; win_i < window_length; win_i++)
95       {
96         x_start = abs((int) (a_path[i2]-rc_1+win_i-offset1) );
97         x_end = abs((int) (a_path[i2-1]-rc_2+win_i-offset2) );
98         fl_line( (x_start+center1)*ch_width, y_loc + 10,
99                  (x_end+center2)*ch_width, y_loc+y_seq_incre );
100       }
101       y_loc += y_seq_incre;
102       fl_color(FL_RED);
103       rc_1 = 0;
104       rc_2 = 0;
105     }
106   }
107 }
108
109 void
110 SeqView::debug_draw()
111 {
112   int seq_i;
113   Sequence a_seq;
114   int i, y_loc;
115   vector<int> a_path;
116   list<vector<int> >::iterator pathz_i;
117   int i2;
118   int x_start, y_start, x_end, y_end;
119   double ch_width;
120   int window_length, win_i;
121   int rc_1 = 0; 
122   int rc_2 = 0;
123   string sub_seq;
124
125
126   cout << "debugging...\n";
127   y_loc = 10;
128   for(seq_i = seq_num-1; seq_i >= 0; --seq_i)
129   {
130     sub_seq = (*S)[seq_i].seq();
131     cout << sub_seq << endl;
132     sub_seq = sub_seq.substr(seq_align_offsets[seq_i]);
133     cout << sub_seq << endl;
134     //fl_draw(sub_seq.c_str(), 0+x(), y_loc+y());     
135     y_loc += y_seq_incre;
136   }
137 }
138
139 void
140 SeqView::align_offsets(int align_num)
141 {
142   list<vector<int> >::iterator pathz_i;
143   int i;
144
145
146   if (P.begin() == P.end())
147     cout << "crud....\n";
148   pathz_i = P.begin();
149   while(pathz_i != P.end())
150   {
151     //cout << (*pathz_i)[0] << endl;
152     ++pathz_i;
153   }
154
155   // find the path specified
156   i = 0;
157   pathz_i = P.begin();
158   cout << "fee\n";
159   while( (i < align_num) && (pathz_i != P.end()) )
160   {
161   cout << "fie\n";
162     ++i;
163     ++pathz_i;
164   }
165
166   cout << "foe\n";
167   // now set the alignment offsets - basically where the path starts
168   seq_align_offsets.clear();
169   for(i = 0; i < seq_num; i++)
170   {
171     cout << (*pathz_i)[i+1] << endl;
172     seq_align_offsets.push_back( (*pathz_i)[i+1] );
173   }
174   cout << "fum\n";
175 }
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194 /*
195       x_start = (int) ();
196       y_start = ;
197       x_end = (int) ();
198       y_end = ;
199       x_start,y_start,x_end,y_end
200 */
201
202
203 /*
204       if ((a_path[i2] >= 0) && (a_path[i2-1] >= 0))
205       {
206       }
207       else if ((a_path[i2] < 0) && (a_path[i2-1] < 0)) 
208       {
209         for(win_i = 0; win_i < window_length; win_i++)
210           fl_line(abs((int)((a_path[i2]+window_length+win_i+x())*ch_width)),
211                   y_loc + 10+y(),
212                   abs((int)((a_path[i2-1]+window_length+win_i+x())*ch_width)),
213                   y_loc+y_seq_incre+y());
214         
215       }
216       else 
217       {
218         fl_color(FL_BLACK);
219         for(win_i = 0; win_i < window_length; win_i++)
220           fl_line(abs((int)((a_path[i2]+window_length+win_i+x())*ch_width)),
221                   y_loc + 10+y(),
222                   abs((int)((a_path[i2-1]+win_i+x())*ch_width)),
223                   y_loc+y_seq_incre+y());
224         fl_color(FL_RED);
225       }
226       else //
227       {
228         fl_color(FL_BLACK);
229         for(win_i = 0; win_i < window_length; win_i++)
230           fl_line(abs((int)((a_path[i2]+win_i+x())*ch_width)),
231                   y_loc + 10+y(),
232                   abs((int)((a_path[i2-1]+window_length+win_i+x())*ch_width)),
233                   y_loc+y_seq_incre+y());
234         fl_color(FL_RED);
235       }
236 */