13 #include "qui/MussaWindow.hpp"
14 #include "mussa_exceptions.hpp"
18 #include <boost/filesystem/path.hpp>
19 namespace fs = boost::filesystem;
23 MussaWindow::MussaWindow(Mussa *analysis_, QWidget *parent) :
28 mussaViewTB("Path Views"),
31 closeAction(0) // initialize one of the pointers to null as a saftey flag
36 //This next setWhatsThis function prevents
37 // a segfault when using WhatsThis feature with
39 //scene->setWhatsThis(tr("Mussa in OpenGL!"));
40 setCentralWidget(&browser);
41 // well updatePosition isn't quite right as we really just need
43 connect(this, SIGNAL(changedAnnotations()), &browser, SLOT(update()));
45 mussaViewTB.addAction(toggleMotifsAction);
46 mussaViewTB.addWidget(&zoom);
48 connect(&zoom, SIGNAL(valueChanged(double)),
49 &browser, SLOT(setZoom(double)));
51 // threshold range is set in updateAnalysis
53 //scene->setClipPlane(20);
54 // FIXME: for when we get the paths drawn at the appropriate depth
55 //connect(&threshold, SIGNAL(thresholdChanged(int)),
56 // this, SLOT(setClipPlane(int)));
57 connect(&threshold, SIGNAL(thresholdChanged(int)),
58 this, SLOT(setSoftThreshold(int)));
59 mussaViewTB.addWidget(&threshold);
61 addToolBar(&mussaViewTB);
63 statusBar()->showMessage("Welcome to mussa", 2000);
67 void MussaWindow::setAnalysis(Mussa *new_analysis)
69 if (new_analysis != 0) {
70 // only switch mussas if we loaded without error
72 analysis = new_analysis;
77 void MussaWindow::setupActions()
79 // we really don't want to run this more than once.
80 assert (closeAction == 0);
82 // the ever popular about box
83 aboutAction = new QAction(tr("&About"), this);
84 connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
85 aboutAction->setIcon(QIcon(":/icons/info.png"));
88 closeAction = new QAction(tr("&Close"), this);
89 closeAction->setStatusTip(tr("Close this window"));
90 connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
91 closeAction->setIcon(QIcon(":/icons/exit.png"));
93 createNewAnalysisAction = new QAction(tr("Define Analysis"), this);
94 connect(createNewAnalysisAction, SIGNAL(triggered()),
95 this, SLOT(createNewAnalysis()));
96 createNewAnalysisAction->setIcon(QIcon(":/icons/filenew.png"));
98 createSubAnalysisAction = new QAction(tr("Define SubAnalysis"), this);
99 connect(createSubAnalysisAction, SIGNAL(triggered()),
100 this, SLOT(createSubAnalysis()));
102 editMotifsAction = new QAction(tr("Edit Motifs"), this);;
103 connect(editMotifsAction, SIGNAL(triggered()), this, SLOT(editMotifs()));
105 loadMotifListAction = new QAction(tr("Load Motif List"), this);
106 connect(loadMotifListAction, SIGNAL(triggered()),
107 this, SLOT(loadMotifList()));
108 loadMotifListAction->setIcon(QIcon(":/icons/fileopen.png"));
110 loadMupaAction = new QAction(tr("Load Mussa Parameters"), this);
111 connect(loadMupaAction, SIGNAL(triggered()),
112 this, SLOT(loadMupa()));
113 loadMupaAction->setIcon(QIcon(":/icons/fileopen.png"));
115 loadSavedAnalysisAction = new QAction(tr("Load &Analysis"), this);
116 connect(loadSavedAnalysisAction, SIGNAL(triggered()),
117 this, SLOT(loadSavedAnalysis()));
118 loadSavedAnalysisAction->setIcon(QIcon(":/icons/fileopen.png"));
120 saveMotifListAction = new QAction(tr("Save Motifs"), this);
121 connect(saveMotifListAction, SIGNAL(triggered()),
122 this, SLOT(saveMotifList()));
123 saveMotifListAction->setIcon(QIcon(":/icons/filesave.png"));
125 showMussaViewToolbarAction = new QAction(tr("Show Toolbar"), this);
126 connect(showMussaViewToolbarAction, SIGNAL(triggered()),
127 this, SLOT(showMussaToolbar()));
128 showMussaViewToolbarAction->setCheckable(true);
129 showMussaViewToolbarAction->setChecked(true);
131 toggleMotifsAction = new QAction(tr("Toggle Motifs"), this);
132 connect(toggleMotifsAction, SIGNAL(triggered()),
133 this, SLOT(toggleMotifs()));
134 toggleMotifsAction->setCheckable(true);
135 toggleMotifsAction->setIcon(QIcon(":/icons/motif_icon.png"));
136 toggleMotifsAction->setWhatsThis(tr("Toggle motif annotations on/off\n\n"
137 "You can load motif annotations via "
138 "'File->Load Motif List' menu option."));
140 //Save pixel map action
141 saveBrowserPixmapAction = new QAction(tr("Save to image..."), this);
142 connect(saveBrowserPixmapAction, (SIGNAL(triggered())),
143 &browser, SLOT(promptSaveBrowserPixmap()));
144 saveBrowserPixmapAction->setIcon(QIcon(":/icons/image2.png"));
146 viewMussaAlignmentAction = new QAction(tr("View mussa alignment"), this);
147 connect(viewMussaAlignmentAction, SIGNAL(triggered()),
148 this, SLOT(viewMussaAlignment() ));
149 viewMussaAlignmentAction->setWhatsThis(tr("Create a zoomed in window "
150 "showing alignment of the seqcomp "
153 whatsThisAction = QWhatsThis::createAction(this);
154 whatsThisAction->setIcon(QIcon(":/icons/help.png"));
158 void MussaWindow::setupMainMenu()
160 // we need to run setupActions first
161 assert (closeAction != 0);
164 newMenu = menuBar()->addMenu(tr("&File"));
165 newMenu->addAction(createNewAnalysisAction);
166 newMenu->addAction(loadMupaAction);
167 newMenu->addAction(loadSavedAnalysisAction);
168 //newMenu->addAction(createSubAnalysisAction);
169 newMenu->addSeparator();
170 newMenu->addAction(loadMotifListAction);
171 newMenu->addAction(saveMotifListAction);
172 newMenu->addSeparator();
173 newMenu->addAction(saveBrowserPixmapAction);
174 newMenu->addSeparator();
175 newMenu->addAction(closeAction);
177 newMenu = menuBar()->addMenu(tr("&View"));
178 newMenu->addAction(editMotifsAction);
179 newMenu->addAction(viewMussaAlignmentAction);
180 newMenu->addAction(showMussaViewToolbarAction);
182 newMenu = menuBar()->addMenu(tr("&Help"));
183 newMenu->addAction(whatsThisAction);
184 newMenu->addSeparator();
185 newMenu->addAction(aboutAction);
188 void MussaWindow::about()
190 QString msg("Welcome to Multiple Species Sequence Analysis\n"
191 "(c) 2005-2006 California Institute of Technology\n"
192 "Tristan De Buysscher, Diane Trout\n");
195 msg += QDir::currentPath();
198 msg += (char *)glGetString(GL_VERSION);
200 QMessageBox::about(this, tr("About mussa"), msg);
203 void MussaWindow::createNewAnalysis()
206 if (setup_analysis_dialog.exec()) {
208 m = setup_analysis_dialog.getMussa();
211 std::cout << "New mussa exp. aborted!\n";
213 } catch(mussa_error e) {
214 QString msg(e.what());
215 QMessageBox::warning(this, tr("Create New Analysis"), msg);
219 void MussaWindow::createSubAnalysis()
224 void MussaWindow::editMotifs()
226 if (motif_editor != 0) {
227 motif_editor->hide();
230 motif_editor = new MotifEditor(analysis);
231 connect(motif_editor, SIGNAL(changedMotifs()),
232 this, SLOT(updateAnnotations()));
233 motif_editor->show();
236 void MussaWindow::loadMotifList()
238 QString caption("Load a motif list");
239 QString filter("Motif list(*.txt *.mtl)");
240 QString path = QFileDialog::getOpenFileName(this,
247 // try to load safely
249 fs::path converted_path(path.toStdString(), fs::native);
250 analysis->load_motifs(converted_path);
251 } catch (runtime_error e) {
252 QString msg("Unable to load ");
256 QMessageBox::warning(this, "Load Motifs", msg);
258 assert (analysis != 0);
261 void MussaWindow::saveMotifList()
266 void MussaWindow::loadMupa()
268 QString caption("Load a mussa parameter file");
269 QString filter("Mussa Parameters (*.mupa)");
270 QString mupa_path = QFileDialog::getOpenFileName(this,
275 if (mupa_path.isNull())
277 // try to load safely
279 Mussa *m = new Mussa;
280 fs::path converted_path(mupa_path.toStdString(), fs::native);
281 m->load_mupa_file(converted_path);
282 m->analyze(0, 0, Mussa::TransitiveNway, 0.0);
284 } catch (mussa_load_error e) {
285 QString msg("Unable to load ");
289 QMessageBox::warning(this, "Load Parameter", msg);
291 assert (analysis != 0);
294 void MussaWindow::loadSavedAnalysis()
296 QString caption("Load a previously run analysis");
297 QString muway_dir = QFileDialog::getExistingDirectory(this,
299 QDir::currentPath());
301 if (muway_dir.isNull())
303 // try to safely load
305 Mussa *m = new Mussa;
306 fs::path converted_path(muway_dir.toStdString(), fs::native);
307 m->load(converted_path);
308 // only switch mussas if we loaded without error
310 } catch (mussa_load_error e) {
311 QString msg("Unable to load ");
315 QMessageBox::warning(this, "Load Parameter", msg);
317 assert (analysis != 0);
320 void MussaWindow::setSoftThreshold(int threshold)
322 if (analysis->get_soft_thres() != threshold) {
323 analysis->set_soft_thres(threshold);
330 void MussaWindow::showMussaToolbar()
332 if (mussaViewTB.isVisible())
338 void MussaWindow::toggleMotifs()
343 void MussaWindow::NotImplementedBox()
345 QMessageBox::warning(this, QObject::tr("mussa"), QObject::tr("Not implemented yet"));
348 void MussaWindow::viewMussaAlignment()
350 const set<int>& selected_paths = browser.selectedPaths();
351 if (selected_paths.size() == 0 ) {
352 QMessageBox::warning(this,
353 QObject::tr("mussa"),
354 QObject::tr("you should probably select some paths "
357 MussaAlignedWindow *ma_win = new MussaAlignedWindow(*analysis,
359 connect(this, SIGNAL(changedAnnotations()),
360 ma_win, SLOT(update()));
361 aligned_windows.push_back(ma_win);
366 void MussaWindow::updateAnalysis()
368 threshold.setRange(analysis->get_threshold(),analysis->get_window());
369 for (list<MussaAlignedWindow *>::iterator maw_i = aligned_windows.begin();
370 maw_i != aligned_windows.end();
378 const vector<Sequence>& seqs = analysis->sequences();
379 browser.setSequences(seqs, analysis->colorMapper());
382 zoom.setValue(browser.zoom());
385 void MussaWindow::updateAnnotations()
387 // motifs were changed in the sequences by
388 // Mussa::update_sequences_motifs
389 emit changedAnnotations();
393 void MussaWindow::updateLinks()
395 browser.clear_links();
396 bool reversed = false;
397 const NwayPaths& nway = analysis->paths();
399 typedef list<ExtendedConservedPath> conserved_paths;
400 typedef conserved_paths::const_iterator const_conserved_paths_itor;
401 for(const_conserved_paths_itor path_itor = nway.refined_pathz.begin();
402 path_itor != nway.refined_pathz.end();
405 // since we were drawing to the start of a window, and opengl lines
406 // are centered around the two connecting points our lines were slightly
407 // offset. the idea of window_offset is to adjust them to the
408 // right for forward compliment or left for reverse compliment
409 // FIXME: figure out how to unit test these computations
410 //GLfloat window_offset = (path_itor->window_size)/2.0;
412 size_t track_len = path_itor->track_indexes.size();
413 vector<int> normalized_path;
414 normalized_path.reserve(track_len);
415 vector<bool> rc_flags(false, track_len);
416 for (size_t track_i=0; track_i != track_len; ++track_i)
418 int x = path_itor->track_indexes[track_i];
419 // at some point when we modify the pathz data structure to keep
420 // track of the score we can put grab the depth here.
422 // are we reverse complimented?
430 normalized_path.push_back(x);
431 rc_flags.push_back(reversed);
433 browser.link(normalized_path, rc_flags, path_itor->window_size);