13 #include "qui/MussaWindow.hpp"
14 #include "qui/mussa_setup_dialog/MussaSetupDialog.hpp"
15 #include "mussa_exceptions.hpp"
21 MussaWindow::MussaWindow(Mussa *analysis_, QWidget *parent) :
26 mussaViewTB("Path Views"),
30 closeAction(0) // initialize one of the pointers to null as a saftey flag
35 //This next setWhatsThis function prevents
36 // a segfault when using WhatsThis feature with
38 //scene->setWhatsThis(tr("Mussa in OpenGL!"));
39 setCentralWidget(&browser);
40 // well updatePosition isn't quite right as we really just need
42 connect(this, SIGNAL(changedAnnotations()), &browser, SLOT(update()));
44 mussaViewTB.addAction(toggleMotifsAction);
46 zoomLabel.setPixmap(QIcon("icons/viewmag.png").pixmap(16, 16));
47 zoomLabel.setToolTip(tr("Zoom"));
48 zoomLabel.setWhatsThis(tr("Zoom magnification factor"));
49 mussaViewTB.addWidget(&zoomLabel);
51 zoomBox.setToolTip(tr("Zoom"));
52 zoomBox.setWhatsThis(tr("Zoom magnification factor"));
53 zoomBox.setRange(1,10000000);
54 mussaViewTB.addWidget(&zoomBox);
55 connect(&zoomBox, SIGNAL(valueChanged(int)),
56 &browser, SLOT(setZoom(int)));
58 threshold.setRange(10,30);
59 threshold.setThreshold(20);
60 //scene->setClipPlane(20);
61 // FIXME: for when we get the paths drawn at the appropriate depth
62 //connect(&threshold, SIGNAL(thresholdChanged(int)),
63 // this, SLOT(setClipPlane(int)));
64 connect(&threshold, SIGNAL(thresholdChanged(int)),
65 this, SLOT(setSoftThreshold(int)));
66 mussaViewTB.addWidget(&threshold);
68 addToolBar(&mussaViewTB);
70 statusBar()->showMessage("Welcome to mussa", 2000);
74 void MussaWindow::setAnalysis(Mussa *new_analysis)
76 if (new_analysis != 0) {
77 // only switch mussas if we loaded without error
79 analysis = new_analysis;
84 void MussaWindow::setupActions()
86 // we really don't want to run this more than once.
87 assert (closeAction == 0);
89 // the ever popular about box
90 aboutAction = new QAction(tr("&About"), this);
91 connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
92 aboutAction->setIcon(QIcon("icons/info.png"));
95 closeAction = new QAction(tr("&Close"), this);
96 closeAction->setStatusTip(tr("Close this window"));
97 connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
98 closeAction->setIcon(QIcon("icons/exit.png"));
100 createNewAnalysisAction = new QAction(tr("Define Analysis"), this);
101 connect(createNewAnalysisAction, SIGNAL(triggered()),
102 this, SLOT(createNewAnalysis()));
103 createNewAnalysisAction->setIcon(QIcon("icons/filenew.png"));
105 createSubAnalysisAction = new QAction(tr("Define SubAnalysis"), this);
106 connect(createSubAnalysisAction, SIGNAL(triggered()),
107 this, SLOT(createSubAnalysis()));
109 editMotifsAction = new QAction(tr("Edit Motifs"), this);;
110 connect(editMotifsAction, SIGNAL(triggered()), this, SLOT(editMotifs()));
112 loadMotifListAction = new QAction(tr("Load Motif List"), this);
113 connect(loadMotifListAction, SIGNAL(triggered()),
114 this, SLOT(loadMotifList()));
115 loadMotifListAction->setIcon(QIcon("icons/fileopen.png"));
117 loadMupaAction = new QAction(tr("Load Mussa Parameters"), this);
118 connect(loadMupaAction, SIGNAL(triggered()),
119 this, SLOT(loadMupa()));
120 loadMupaAction->setIcon(QIcon("icons/fileopen.png"));
122 loadSavedAnalysisAction = new QAction(tr("Load &Analysis"), this);
123 connect(loadSavedAnalysisAction, SIGNAL(triggered()),
124 this, SLOT(loadSavedAnalysis()));
125 loadSavedAnalysisAction->setIcon(QIcon("icons/fileopen.png"));
127 saveMotifListAction = new QAction(tr("Save Motifs"), this);
128 connect(saveMotifListAction, SIGNAL(triggered()),
129 this, SLOT(saveMotifList()));
130 saveMotifListAction->setIcon(QIcon("icons/filesave.png"));
132 showMussaViewToolbarAction = new QAction(tr("Show Toolbar"), this);
133 connect(showMussaViewToolbarAction, SIGNAL(triggered()),
134 this, SLOT(showMussaToolbar()));
135 showMussaViewToolbarAction->setCheckable(true);
136 showMussaViewToolbarAction->setChecked(true);
138 toggleMotifsAction = new QAction(tr("Toggle Motifs"), this);
139 connect(toggleMotifsAction, SIGNAL(triggered()),
140 this, SLOT(toggleMotifs()));
141 toggleMotifsAction->setCheckable(true);
142 toggleMotifsAction->setIcon(QIcon("icons/motif_icon.png"));
143 toggleMotifsAction->setWhatsThis(tr("Toggle motif annotations on/off\n\n"
144 "You can load motif annotations via "
145 "'File->Load Motif List' menu option."));
147 //Save pixel map action
148 saveBrowserPixmapAction = new QAction(tr("Save to image..."), this);
149 connect(saveBrowserPixmapAction, (SIGNAL(triggered())),
150 &browser, SLOT(promptSaveBrowserPixmap()));
151 saveBrowserPixmapAction->setIcon(QIcon("icons/image2.png"));
153 viewMussaAlignmentAction = new QAction(tr("View mussa alignment"), this);
154 connect(viewMussaAlignmentAction, SIGNAL(triggered()),
155 this, SLOT(viewMussaAlignment() ));
156 viewMussaAlignmentAction->setWhatsThis(tr("Create a zoomed in window "
157 "showing alignment of the seqcomp "
160 whatsThisAction = QWhatsThis::createAction(this);
161 whatsThisAction->setIcon(QIcon("icons/help.png"));
165 void MussaWindow::setupMainMenu()
167 // we need to run setupActions first
168 assert (closeAction != 0);
171 newMenu = menuBar()->addMenu(tr("&File"));
172 newMenu->addAction(createNewAnalysisAction);
173 newMenu->addAction(loadMupaAction);
174 newMenu->addAction(loadSavedAnalysisAction);
175 //newMenu->addAction(createSubAnalysisAction);
176 newMenu->addSeparator();
177 newMenu->addAction(loadMotifListAction);
178 newMenu->addAction(saveMotifListAction);
179 newMenu->addSeparator();
180 newMenu->addAction(saveBrowserPixmapAction);
181 newMenu->addSeparator();
182 newMenu->addAction(closeAction);
184 newMenu = menuBar()->addMenu(tr("&View"));
185 newMenu->addAction(editMotifsAction);
186 newMenu->addAction(viewMussaAlignmentAction);
187 newMenu->addAction(showMussaViewToolbarAction);
189 newMenu = menuBar()->addMenu(tr("&Help"));
190 newMenu->addAction(whatsThisAction);
191 newMenu->addSeparator();
192 newMenu->addAction(aboutAction);
195 void MussaWindow::about()
197 QString msg("Welcome to Multiple Species Sequence Analysis\n"
198 "(c) 2005-2006 California Institute of Technology\n"
199 "Tristan De Buysscher, Diane Trout\n");
202 msg += QDir::currentPath();
205 msg += (char *)glGetString(GL_VERSION);
207 QMessageBox::about(this, tr("About mussa"), msg);
210 void MussaWindow::createNewAnalysis()
212 MussaSetupDialog *msd = new MussaSetupDialog(this);
219 std::cout << "New mussa exp. aborted!\n";
221 } catch(mussa_error e) {
222 QString msg(e.what());
223 QMessageBox::warning(this, tr("Create New Analysis"), msg);
228 void MussaWindow::createSubAnalysis()
233 void MussaWindow::editMotifs()
235 if (motif_editor != 0) {
236 motif_editor->hide();
239 motif_editor = new MotifEditor(analysis);
240 connect(motif_editor, SIGNAL(changedMotifs()),
241 this, SLOT(updateAnnotations()));
242 motif_editor->show();
245 void MussaWindow::loadMotifList()
247 QString caption("Load a motif list");
248 QString filter("Motif list(*.txt *.mtl)");
249 QString path = QFileDialog::getOpenFileName(this,
256 // try to load safely
258 analysis->load_motifs(path.toStdString());
259 } catch (runtime_error e) {
260 QString msg("Unable to load ");
264 QMessageBox::warning(this, "Load Motifs", msg);
266 assert (analysis != 0);
269 void MussaWindow::saveMotifList()
274 void MussaWindow::loadMupa()
276 QString caption("Load a mussa parameter file");
277 QString filter("Mussa Parameters (*.mupa)");
278 QString mupa_path = QFileDialog::getOpenFileName(this,
283 if (mupa_path.isNull())
285 // try to load safely
287 Mussa *m = new Mussa;
288 m->load_mupa_file(mupa_path.toStdString());
289 m->analyze(0, 0, Mussa::TransitiveNway, 0.0);
291 } catch (mussa_load_error e) {
292 QString msg("Unable to load ");
296 QMessageBox::warning(this, "Load Parameter", msg);
298 assert (analysis != 0);
301 void MussaWindow::loadSavedAnalysis()
303 QString caption("Load a previously run analysis");
304 QString muway_dir = QFileDialog::getExistingDirectory(this,
306 QDir::currentPath());
308 if (muway_dir.isNull())
310 // try to safely load
312 Mussa *m = new Mussa;
313 m->load(muway_dir.toStdString());
314 // only switch mussas if we loaded without error
316 } catch (mussa_load_error e) {
317 QString msg("Unable to load ");
321 QMessageBox::warning(this, "Load Parameter", msg);
323 assert (analysis != 0);
326 void MussaWindow::setSoftThreshold(int threshold)
328 if (analysis->get_soft_thres() != threshold) {
329 analysis->set_soft_thres(threshold);
336 void MussaWindow::showMussaToolbar()
338 if (mussaViewTB.isVisible())
344 void MussaWindow::toggleMotifs()
349 void MussaWindow::NotImplementedBox()
351 QMessageBox::warning(this, QObject::tr("mussa"), QObject::tr("Not implemented yet"));
354 void MussaWindow::viewMussaAlignment()
356 const set<int>& selected_paths = browser.selectedPaths();
357 if (selected_paths.size() == 0 ) {
358 QMessageBox::warning(this,
359 QObject::tr("mussa"),
360 QObject::tr("you should probably select some paths "
363 MussaAlignedWindow *ma_win = new MussaAlignedWindow(*analysis,
365 connect(this, SIGNAL(changedAnnotations()),
366 ma_win, SLOT(update()));
367 aligned_windows.push_back(ma_win);
372 void MussaWindow::updateAnalysis()
374 cout << "analysis updated" << endl;
375 for (list<MussaAlignedWindow *>::iterator maw_i = aligned_windows.begin();
376 maw_i != aligned_windows.end();
384 const vector<Sequence>& seqs = analysis->sequences();
385 browser.setSequences(seqs, analysis->colorMapper());
388 cout << "browser zoom " << browser.zoom() << endl;
389 zoomBox.setValue(browser.zoom());
392 void MussaWindow::updateAnnotations()
394 // motifs were changed in the sequences by
395 // Mussa::update_sequences_motifs
396 emit changedAnnotations();
400 void MussaWindow::updateLinks()
402 browser.clear_links();
403 bool reversed = false;
404 const NwayPaths& nway = analysis->paths();
406 typedef list<ExtendedConservedPath> conserved_paths;
407 typedef conserved_paths::const_iterator const_conserved_paths_itor;
408 for(const_conserved_paths_itor path_itor = nway.refined_pathz.begin();
409 path_itor != nway.refined_pathz.end();
412 // since we were drawing to the start of a window, and opengl lines
413 // are centered around the two connecting points our lines were slightly
414 // offset. the idea of window_offset is to adjust them to the
415 // right for forward compliment or left for reverse compliment
416 // FIXME: figure out how to unit test these computations
417 //GLfloat window_offset = (path_itor->window_size)/2.0;
419 size_t track_len = path_itor->track_indexes.size();
420 vector<int> normalized_path;
421 normalized_path.reserve(track_len);
422 vector<bool> rc_flags(false, track_len);
423 for (size_t track_i=0; track_i != track_len; ++track_i)
425 int x = path_itor->track_indexes[track_i];
426 // at some point when we modify the pathz data structure to keep
427 // track of the score we can put grab the depth here.
429 // are we reverse complimented?
434 x = -x; // make positive
436 normalized_path.push_back(x);
437 rc_flags.push_back(reversed);
439 browser.link(normalized_path, rc_flags, path_itor->window_size);