9 #include "qui/MussaAlignedWindow.hpp"
10 #include "alg/sequence.hpp"
14 MussaAlignedWindow::MussaAlignedWindow(Mussa& m,
15 const set<int>& sel_paths,
17 : QMainWindow(parent),
19 pick_align_menu(tr("Choose Alignment")),
20 view_align_menu(tr("View Alignment"))
22 browser.setSequences(analysis.sequences(), analysis.colorMapper());
23 setSelectedPaths(m, sel_paths);
25 browser.zoomToSequence();
29 setCentralWidget(&browser);
30 menuBar()->addMenu(&pick_align_menu);
31 menuBar()->addMenu(&view_align_menu);
33 ostringstream message;
34 message << "Selected " << selected_paths.size() << " paths";
35 statusBar()->showMessage(message.str().c_str(), 5000);
39 void MussaAlignedWindow::setSelectedPaths(Mussa &m, const set<int>& sel_paths)
42 set<int>::iterator sel_i = sel_paths.begin();
43 list<ExtendedConservedPath>::const_iterator path_i = m.paths().rpbegin();
44 list<ExtendedConservedPath>::const_iterator path_end = m.paths().rpend();
45 size_t path_size = m.paths().refined_pathz.size();
48 selected_paths.reserve(sel_paths.size());
49 view_paths.reserve(sel_paths.size());
50 while (pathid != path_size and sel_i != sel_paths.end())
53 size_t sel_pathid = (size_t)(*sel_i);
54 if (pathid == sel_pathid) {
55 selected_paths.push_back(*path_i);
56 view_paths.push_back(true);
60 } else if (pathid < sel_pathid) {
63 } else if (pathid > sel_pathid) {
69 void MussaAlignedWindow::setupMenus()
71 pick_align_menu.clear();
72 view_align_menu.clear();
76 for(vector<ExtendedConservedPath >::iterator pathz_i=selected_paths.begin();
77 pathz_i != selected_paths.end();
80 ConservedPath::path_type normalized_path = pathz_i->normalizedIndexes();
81 ostringstream menu_text;
82 menu_text << pathz_i->window_size << ":";
83 ConservedPath::iterator element_i = normalized_path.begin();
84 menu_text << *element_i++;
86 element_i != normalized_path.end();
90 menu_text << *element_i;
92 int index = pathz_i - selected_paths.begin();
93 IntAction *pick = new IntAction(QString(menu_text.str().c_str()), index, this);
94 connect(pick, SIGNAL(triggered(int)), this, SLOT(setAlignment(size_t)));
95 pick_actions.push_back(pick);
96 pick_align_menu.addAction(pick);
97 IntAction *view = new IntAction(QString(menu_text.str().c_str()), index, this);
98 connect(view, SIGNAL(triggered(int)), this, SLOT(toggleViewAlignment(size_t)));
99 view->setCheckable(true);
100 view->setChecked(true);
101 view_actions.push_back(view);
102 view_align_menu.addAction(view);
106 void MussaAlignedWindow::setAlignment(size_t alignment_index)
108 if (selected_paths.size() > 0) {
109 browser.centerOnPath(selected_paths[alignment_index].normalizedIndexes());
113 void MussaAlignedWindow::toggleViewAlignment(size_t alignment_index)
115 view_paths[alignment_index]= not view_paths[alignment_index];
116 // perhaps it'd be better if we could erase specific sets
117 // of matches instead of erasing them all and recomputing them all
118 // but this is easier
122 void MussaAlignedWindow::computeMatchLines()
124 const vector<Sequence>& raw_sequence = analysis.sequences();
125 vector<int> aligned_path;
128 int window_length, win_i;
132 vector<bool> rc_list;
134 vector<bool> matched;
137 browser.clear_links();
139 for(vector<ExtendedConservedPath >::iterator pathz_i=selected_paths.begin();
140 pathz_i != selected_paths.end();
143 if (view_paths[align_counter])
145 ExtendedConservedPath& a_path = *pathz_i;
146 window_length = a_path.window_size;
147 // determine which parts of the path are RC relative to first species
148 rc_list = a_path.reverseComplimented();
150 // loop over each bp in the conserved region for all sequences
151 for(win_i = 0; win_i < window_length; win_i++)
153 aligned_path.clear();
154 // determine which exact base pairs match between the sequences
156 for(i2 = 0; i2 < a_path.size()-1; i2++)
158 // assume not rc as most likely, adjust below
161 // no matter the case, any RC node needs adjustments
163 rc_1 = window_length-1;
164 if (a_path[i2+1] < 0)
165 rc_2 = window_length-1;
167 x_start = (abs(a_path[i2]-rc_1+win_i));
168 x_end = (abs(a_path[i2+1]-rc_2+win_i));
171 // ugh, and xor...only want rc coloring if just one of the nodes is rc
172 // if both nodes are rc, then they are 'normal' relative to each other
173 if ( ( rc_list[i2] || rc_list[i2+1] ) &&
174 !(rc_list[i2] && rc_list[i2+1] ) )
175 { //the hideous rc matching logic - not complex, but annoying
176 if ( !( ( (raw_sequence[i2][x_start] == 'A') &&
177 (raw_sequence[i2+1][x_end] == 'T') ) ||
178 ( (raw_sequence[i2][x_start] == 'T') &&
179 (raw_sequence[i2+1][x_end] == 'A') ) ||
180 ( (raw_sequence[i2][x_start] == 'G') &&
181 (raw_sequence[i2+1][x_end] == 'C') ) ||
182 ( (raw_sequence[i2][x_start] == 'C') &&
183 (raw_sequence[i2+1][x_end] == 'G') ) ) )
188 if (!( (raw_sequence[i2][x_start] == raw_sequence[i2+1][x_end]) &&
189 (raw_sequence[i2][x_start] != 'N') &&
190 (raw_sequence[i2+1][x_end] != 'N') ) )
195 // draw for matches stretching across all sequences
198 // now can draw the line for each bp in this window that matches
199 // grrr, need to ask if anyone cares if I switch the seq
203 for(i2 = 0; i2 < a_path.size()-1; i2++)
205 // assume not rc as most likely, adjust below
208 // no matter the case, any RC node needs adjustments
211 rc_1 = window_length;
215 rc_2 = window_length;
218 // maybe shouldn't recalc these, but store values from first loop
219 x_start = (abs((int) (a_path[i2]-rc_1+win_i)));
220 x_end = (abs((int) (a_path[i2+1]-rc_2+win_i)));
221 aligned_path.push_back(x_start);
222 // if we're on the last time through the loop, save x_end too
223 if (i2 == a_path.size()-2) {
224 aligned_path.push_back(x_end);
228 if (aligned_path.size() > 0) {
229 browser.link(aligned_path, rc_list,1);