9 #include "qui/MussaAlignedWindow.hpp"
10 #include "alg/sequence.hpp"
15 MussaAlignedWindow::MussaAlignedWindow(Mussa& m,
16 const set<int>& sel_paths,
18 : QMainWindow(parent),
20 pick_align_menu(tr("Choose Alignment")),
21 view_align_menu(tr("View Alignment"))
23 browser.setSequences(analysis.sequences(), analysis.colorMapper());
24 setSelectedPaths(m, sel_paths);
26 double zoom_level = browser.zoomToSequence();
27 zoom.setValue(zoom_level);
32 alignTB.addWidget(&zoom);
34 connect(&zoom, SIGNAL(valueChanged(double)),
35 &browser, SLOT(setZoom(double)));
37 setCentralWidget(&browser);
38 menuBar()->addMenu(&pick_align_menu);
39 menuBar()->addMenu(&view_align_menu);
41 ostringstream message;
42 message << "Selected " << selected_paths.size() << " paths";
43 statusBar()->showMessage(message.str().c_str(), 5000);
44 browser.updatePosition();
48 void MussaAlignedWindow::setSelectedPaths(Mussa &m, const set<int>& sel_paths)
51 set<int>::iterator sel_i = sel_paths.begin();
52 list<ExtendedConservedPath>::const_iterator path_i = m.paths().rpbegin();
53 list<ExtendedConservedPath>::const_iterator path_end = m.paths().rpend();
54 size_t path_size = m.paths().refined_pathz.size();
57 selected_paths.reserve(sel_paths.size());
58 view_paths.reserve(sel_paths.size());
59 while (pathid != path_size and sel_i != sel_paths.end())
62 size_t sel_pathid = (size_t)(*sel_i);
63 if (pathid == sel_pathid) {
64 selected_paths.push_back(*path_i);
65 view_paths.push_back(true);
69 } else if (pathid < sel_pathid) {
72 } else if (pathid > sel_pathid) {
78 void MussaAlignedWindow::setupMenus()
80 pick_align_menu.clear();
81 view_align_menu.clear();
85 for(vector<ExtendedConservedPath >::iterator pathz_i=selected_paths.begin();
86 pathz_i != selected_paths.end();
89 ConservedPath::path_type normalized_path = pathz_i->normalizedIndexes();
90 ostringstream menu_text;
91 menu_text << pathz_i->window_size << ":";
92 ConservedPath::iterator element_i = normalized_path.begin();
93 menu_text << *element_i++;
95 element_i != normalized_path.end();
99 menu_text << *element_i;
101 int index = pathz_i - selected_paths.begin();
102 IntAction *pick = new IntAction(QString(menu_text.str().c_str()), index, this);
103 connect(pick, SIGNAL(triggered(int)), this, SLOT(setAlignment(int)));
104 pick_actions.push_back(pick);
105 pick_align_menu.addAction(pick);
106 IntAction *view = new IntAction(QString(menu_text.str().c_str()), index, this);
107 connect(view, SIGNAL(triggered(int)), this, SLOT(toggleViewAlignment(int)));
108 view->setCheckable(true);
109 view->setChecked(true);
110 view_actions.push_back(view);
111 view_align_menu.addAction(view);
115 void MussaAlignedWindow::setAlignment(int alignment_index)
117 if (selected_paths.size() > 0) {
118 browser.centerOnPath(selected_paths[alignment_index].normalizedIndexes());
122 void MussaAlignedWindow::toggleViewAlignment(int alignment_index)
124 view_paths[alignment_index]= not view_paths[alignment_index];
125 // perhaps it'd be better if we could erase specific sets
126 // of matches instead of erasing them all and recomputing them all
127 // but this is easier
131 void MussaAlignedWindow::update()
136 void MussaAlignedWindow::computeMatchLines()
138 const vector<Sequence>& raw_seq = analysis.sequences();
139 vector<int> aligned_path;
142 int window_length, win_i;
145 vector<bool> rc_list;
147 vector<bool> matched;
150 browser.clear_links();
152 for(vector<ExtendedConservedPath >::iterator pathz_i=selected_paths.begin();
153 pathz_i != selected_paths.end();
156 if (view_paths[align_counter])
158 ExtendedConservedPath& a_path = *pathz_i;
159 window_length = a_path.window_size;
160 // determine which parts of the path are RC relative to first species
161 rc_list = a_path.reverseComplimented();
163 // loop over each bp in the conserved region for all sequences
164 for(win_i = 0; win_i < window_length; win_i++)
166 aligned_path.clear();
167 // determine which exact base pairs match between the sequences
169 for(i2 = 0; i2 < a_path.size()-1; i2++)
171 // assume not rc as most likely, adjust below
174 // no matter the case, any RC node needs adjustments
176 rc_1 = window_length-1;
177 if (a_path[i2+1] < 0)
178 rc_2 = window_length-1;
180 x_start = (abs(a_path[i2]-rc_1+win_i));
181 x_end = (abs(a_path[i2+1]-rc_2+win_i));
184 // ugh, and xor...only want rc coloring if just one of the nodes is rc
185 // if both nodes are rc, then they are 'normal' relative to each other
186 if((rc_list[i2] || rc_list[i2+1] )&&!(rc_list[i2] && rc_list[i2+1]))
187 { //the hideous rc matching logic - not complex, but annoying
188 if(!(( (raw_seq[i2][x_start]=='A')&&(raw_seq[i2+1][x_end]=='T')) ||
189 ((raw_seq[i2][x_start]=='T')&&(raw_seq[i2+1][x_end]=='A')) ||
190 ((raw_seq[i2][x_start]=='G')&&(raw_seq[i2+1][x_end]=='C')) ||
191 ((raw_seq[i2][x_start]=='C')&&(raw_seq[i2+1][x_end]=='G'))) )
196 if (!( (raw_seq[i2][x_start] == raw_seq[i2+1][x_end]) &&
197 (raw_seq[i2][x_start] != 'N') &&
198 (raw_seq[i2+1][x_end] != 'N') ) )
203 // draw for matches stretching across all sequences
206 // now can draw the line for each bp in this window that matches
207 // grrr, need to ask if anyone cares if I switch the seq
211 for(i2 = 0; i2 < a_path.size()-1; i2++)
213 // assume not rc as most likely, adjust below
216 // no matter the case, any RC node needs adjustments
219 rc_1 = window_length;
223 rc_2 = window_length;
226 // maybe shouldn't recalc these, but store values from first loop
227 x_start = (abs((int) (a_path[i2]-rc_1+win_i)));
228 x_end = (abs((int) (a_path[i2+1]-rc_2+win_i)));
229 aligned_path.push_back(x_start);
230 // if we're on the last time through the loop, save x_end too
231 if (i2 == a_path.size()-2) {
232 aligned_path.push_back(x_end);
236 if (aligned_path.size() > 0) {
237 browser.link(aligned_path, rc_list,1);