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);
39 //Save pixel map action
40 saveBrowserPixmapAction = new QAction(tr("Save to image..."), this);
41 connect(saveBrowserPixmapAction, (SIGNAL(triggered())),
42 &browser, SLOT(promptSaveBrowserPixmap()));
43 saveBrowserPixmapAction->setIcon(QIcon(":/icons/image2.png"));
45 QMenu *newMenu = menuBar()->addMenu(tr("&File"));
46 newMenu->addAction(saveBrowserPixmapAction);
47 menuBar()->addMenu(&pick_align_menu);
48 menuBar()->addMenu(&view_align_menu);
50 ostringstream message;
51 message << "Selected " << selected_paths.size() << " paths";
52 statusBar()->showMessage(message.str().c_str(), 5000);
53 browser.updatePosition();
57 void MussaAlignedWindow::setSelectedPaths(Mussa &m, const set<int>& sel_paths)
60 set<int>::iterator sel_i = sel_paths.begin();
61 list<ExtendedConservedPath>::const_iterator path_i = m.paths().refined_pathz.begin();
62 list<ExtendedConservedPath>::const_iterator path_end = m.paths().refined_pathz.end();
63 size_t path_size = m.paths().refined_pathz.size();
66 selected_paths.reserve(sel_paths.size());
67 view_paths.reserve(sel_paths.size());
68 while (pathid != path_size and sel_i != sel_paths.end())
71 size_t sel_pathid = (size_t)(*sel_i);
72 if (pathid == sel_pathid) {
73 selected_paths.push_back(*path_i);
74 view_paths.push_back(true);
78 } else if (pathid < sel_pathid) {
81 } else if (pathid > sel_pathid) {
87 void MussaAlignedWindow::setupMenus()
89 pick_align_menu.clear();
90 view_align_menu.clear();
94 for(vector<ExtendedConservedPath >::iterator pathz_i=selected_paths.begin();
95 pathz_i != selected_paths.end();
98 ConservedPath::path_type normalized_path = pathz_i->normalizedIndexes();
99 ostringstream menu_text;
100 menu_text << pathz_i->window_size << ":";
101 ConservedPath::iterator element_i = normalized_path.begin();
102 menu_text << *element_i++;
104 element_i != normalized_path.end();
108 menu_text << *element_i;
110 int index = pathz_i - selected_paths.begin();
111 IntAction *pick = new IntAction(QString(menu_text.str().c_str()), index, this);
112 connect(pick, SIGNAL(triggered(int)), this, SLOT(setAlignment(int)));
113 pick_actions.push_back(pick);
114 pick_align_menu.addAction(pick);
115 IntAction *view = new IntAction(QString(menu_text.str().c_str()), index, this);
116 connect(view, SIGNAL(triggered(int)), this, SLOT(toggleViewAlignment(int)));
117 view->setCheckable(true);
118 view->setChecked(true);
119 view_actions.push_back(view);
120 view_align_menu.addAction(view);
124 void MussaAlignedWindow::setAlignment(int alignment_index)
126 if (selected_paths.size() > 0) {
127 browser.centerOnPath(selected_paths[alignment_index].normalizedIndexes());
131 void MussaAlignedWindow::toggleViewAlignment(int alignment_index)
133 view_paths[alignment_index]= not view_paths[alignment_index];
134 // perhaps it'd be better if we could erase specific sets
135 // of matches instead of erasing them all and recomputing them all
136 // but this is easier
140 void MussaAlignedWindow::update()
145 void MussaAlignedWindow::computeMatchLines()
147 const vector<Sequence>& raw_seq = analysis.sequences();
148 vector<int> aligned_path;
151 int window_length, win_i;
154 vector<bool> rc_list;
156 vector<bool> matched;
159 browser.clear_links();
161 for(vector<ExtendedConservedPath >::iterator pathz_i=selected_paths.begin();
162 pathz_i != selected_paths.end();
165 if (view_paths[align_counter])
167 ExtendedConservedPath& a_path = *pathz_i;
168 window_length = a_path.window_size;
169 // determine which parts of the path are RC relative to first species
170 rc_list = a_path.reverseComplimented();
172 // loop over each bp in the conserved region for all sequences
173 for(win_i = 0; win_i < window_length; win_i++)
175 aligned_path.clear();
176 // determine which exact base pairs match between the sequences
178 for(i2 = 0; i2 < a_path.size()-1; i2++)
180 // assume not rc as most likely, adjust below
183 // no matter the case, any RC node needs adjustments
185 rc_1 = window_length-1;
186 if (a_path[i2+1] < 0)
187 rc_2 = window_length-1;
189 x_start = (abs(a_path[i2]-rc_1+win_i));
190 x_end = (abs(a_path[i2+1]-rc_2+win_i));
193 // ugh, and xor...only want rc coloring if just one of the nodes is rc
194 // if both nodes are rc, then they are 'normal' relative to each other
195 if((rc_list[i2] || rc_list[i2+1] )&&!(rc_list[i2] && rc_list[i2+1]))
196 { //the hideous rc matching logic - not complex, but annoying
197 if(!(( (raw_seq[i2][x_start]=='A')&&(raw_seq[i2+1][x_end]=='T')) ||
198 ((raw_seq[i2][x_start]=='T')&&(raw_seq[i2+1][x_end]=='A')) ||
199 ((raw_seq[i2][x_start]=='G')&&(raw_seq[i2+1][x_end]=='C')) ||
200 ((raw_seq[i2][x_start]=='C')&&(raw_seq[i2+1][x_end]=='G'))) )
205 if (!( (raw_seq[i2][x_start] == raw_seq[i2+1][x_end]) &&
206 (raw_seq[i2][x_start] != 'N') &&
207 (raw_seq[i2+1][x_end] != 'N') ) )
212 // draw for matches stretching across all sequences
215 // now can draw the line for each bp in this window that matches
216 // grrr, need to ask if anyone cares if I switch the seq
220 for(i2 = 0; i2 < a_path.size()-1; i2++)
222 // assume not rc as most likely, adjust below
225 // no matter the case, any RC node needs adjustments
228 rc_1 = window_length;
232 rc_2 = window_length;
235 // maybe shouldn't recalc these, but store values from first loop
236 x_start = (abs((int) (a_path[i2]-rc_1+win_i)));
237 x_end = (abs((int) (a_path[i2+1]-rc_2+win_i)));
238 aligned_path.push_back(x_start);
239 // if we're on the last time through the loop, save x_end too
240 if (i2 == a_path.size()-2) {
241 aligned_path.push_back(x_end);
245 if (aligned_path.size() > 0) {
246 browser.link(aligned_path, rc_list,1);