9 #include "qui/MussaAlignedWindow.hpp"
10 #include "alg/sequence.hpp"
15 MussaAlignedWindow::MussaAlignedWindow(MussaRef m,
16 const set<int>& sel_paths,
17 SubanalysisWindowRef window,
19 : QMainWindow(parent),
21 subanalysis_window(window),
22 pick_align_menu(tr("Choose Alignment")),
23 view_align_menu(tr("View Alignment")),
29 browser.setSequences(analysis->sequences(), analysis->colorMapper());
30 setSelectedPaths(analysis, sel_paths);
32 double zoom_level = browser.zoomToSequence();
34 zoom = new ZoomWidget();
35 connect(zoom, SIGNAL(valueChanged(double)),
36 &browser, SLOT(setZoom(double)));
37 zoom->setValue(zoom_level);
40 setupAlignmentMenus();
42 setCentralWidget(&browser);
44 // Add a threhold widget set to our current threshold and make it readonly
45 threshold_widget = new ThresholdWidget;
46 threshold_widget->setRange(analysis->get_threshold(),analysis->get_window());
47 threshold_widget->setBasepairThreshold(analysis->get_soft_threshold());
48 threshold_widget->setReadOnly(true);
50 alignTB = new QToolBar();
51 alignTB->addWidget(zoom);
52 alignTB->addWidget(threshold_widget);
55 ostringstream message;
56 message << "Selected " << selected_paths.size() << " paths";
57 statusBar()->showMessage(message.str().c_str(), 5000);
58 browser.updatePosition();
61 void MussaAlignedWindow::setupActions()
63 // more cut-n-paste from MussaWindow
64 createSubAnalysisAction = new QAction(tr("Add to Subanalysis"), this);
65 connect(createSubAnalysisAction, SIGNAL(triggered()),
66 this, SLOT(createSubAnalysis()));
68 //Save pixel map action
69 saveBrowserPixmapAction = new QAction(tr("Save to image..."), this);
70 connect(saveBrowserPixmapAction, (SIGNAL(triggered())),
71 &browser, SLOT(promptSaveBrowserPixmap()));
72 saveBrowserPixmapAction->setIcon(QIcon(":/icons/image2.png"));
75 void MussaAlignedWindow::setupMenus()
77 QMenu *newMenu = menuBar()->addMenu(tr("&File"));
78 newMenu->addAction(saveBrowserPixmapAction);
80 newMenu = menuBar()->addMenu(tr("&Edit"));
81 newMenu->addAction(browser.getCopySelectedSequenceAsFastaAction());
82 newMenu->addAction(createSubAnalysisAction);
84 // add some extra features to the context menu
85 QMenu *popupMenu = browser.getPopupMenu();
87 popupMenu->addAction(createSubAnalysisAction);
91 void MussaAlignedWindow::setupAlignmentMenus()
93 pick_align_menu.clear();
94 view_align_menu.clear();
98 for(vector<ConservedPath >::iterator pathz_i=selected_paths.begin();
99 pathz_i != selected_paths.end();
102 ConservedPath::path_type normalized_path = pathz_i->normalizedIndexes();
103 ostringstream menu_text;
104 menu_text << pathz_i->window_size << ":";
105 ConservedPath::iterator element_i = normalized_path.begin();
106 menu_text << *element_i++;
108 element_i != normalized_path.end();
112 menu_text << *element_i;
114 int index = pathz_i - selected_paths.begin();
115 IntAction *pick = new IntAction(QString(menu_text.str().c_str()), index, this);
116 connect(pick, SIGNAL(triggered(int)), this, SLOT(setAlignment(int)));
117 pick_actions.push_back(pick);
118 pick_align_menu.addAction(pick);
119 IntAction *view = new IntAction(QString(menu_text.str().c_str()), index, this);
120 connect(view, SIGNAL(triggered(int)), this, SLOT(toggleViewAlignment(int)));
121 view->setCheckable(true);
122 view->setChecked(true);
123 view_actions.push_back(view);
124 view_align_menu.addAction(view);
127 menuBar()->addMenu(&pick_align_menu);
128 menuBar()->addMenu(&view_align_menu);
132 void MussaAlignedWindow::setSelectedPaths(MussaRef m, const set<int>& sel_paths)
135 set<int>::iterator sel_i = sel_paths.begin();
136 list<ConservedPath>::const_iterator path_i = m->paths().refined_pathz.begin();
137 list<ConservedPath>::const_iterator path_end = m->paths().refined_pathz.end();
138 size_t path_size = m->paths().refined_pathz.size();
141 selected_paths.reserve(sel_paths.size());
142 view_paths.reserve(sel_paths.size());
143 while (pathid != path_size and sel_i != sel_paths.end())
145 assert (*sel_i >= 0);
146 size_t sel_pathid = (size_t)(*sel_i);
147 if (pathid == sel_pathid) {
148 selected_paths.push_back(*path_i);
149 view_paths.push_back(true);
153 } else if (pathid < sel_pathid) {
156 } else if (pathid > sel_pathid) {
162 // FIXME: this is a cut-n-paste from MussaWindow, perhaps they should be refactored to
164 void MussaAlignedWindow::createSubAnalysis()
166 list<SequenceLocation> result;
167 SequenceLocationModel& model = subanalysis_window->getModel();
168 browser.copySelectedTracksAsSeqLocation(result);
169 for(list<SequenceLocation>::iterator result_itor = result.begin();
170 result_itor != result.end();
173 model.push_back(*result_itor);
176 if (not subanalysis_window->isVisible()) {
177 subanalysis_window->show();
181 void MussaAlignedWindow::setAlignment(int alignment_index)
183 if (selected_paths.size() > 0) {
184 browser.centerOnPath(selected_paths[alignment_index].normalizedIndexes());
188 void MussaAlignedWindow::toggleViewAlignment(int alignment_index)
190 view_paths[alignment_index]= not view_paths[alignment_index];
191 // perhaps it'd be better if we could erase specific sets
192 // of matches instead of erasing them all and recomputing them all
193 // but this is easier
197 void MussaAlignedWindow::update()
202 void MussaAlignedWindow::computeMatchLines()
204 browser.clear_links();
206 // filter out conserved paths
207 list<ConservedPath> filtered_paths;
208 vector<ConservedPath>::iterator path_i = selected_paths.begin();
209 list<ConservedPath::path_type> result;
210 list<vector<bool> > reversed;
212 for(vector<ConservedPath>::size_type count = 0;
213 count != selected_paths.size();
216 if (view_paths[count])
217 filtered_paths.push_back(*path_i);
219 analysis->createLocalAlignment(filtered_paths.begin(),
220 filtered_paths.end(),
224 list<ConservedPath::path_type>::const_iterator result_i = result.begin();
225 list<vector<bool> >::const_iterator reversed_i = reversed.begin();
226 for(int i = 0; i != result.size(); ++i, ++result_i, ++reversed_i)
228 // make 1 base long links
229 browser.link(*result_i, *reversed_i, 1);