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(19, 30);
59 threshold.setThreshold(19);
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::setupActions()
76 // we really don't want to run this more than once.
77 assert (closeAction == 0);
79 // the ever popular about box
80 aboutAction = new QAction(tr("&About"), this);
81 connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
82 aboutAction->setIcon(QIcon("icons/info.png"));
85 closeAction = new QAction(tr("&Close"), this);
86 closeAction->setStatusTip(tr("Close this window"));
87 connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
88 closeAction->setIcon(QIcon("icons/exit.png"));
90 createNewAnalysisAction = new QAction(tr("Define Analysis"), this);
91 connect(createNewAnalysisAction, SIGNAL(triggered()),
92 this, SLOT(createNewAnalysis()));
93 createNewAnalysisAction->setIcon(QIcon("icons/filenew.png"));
95 createSubAnalysisAction = new QAction(tr("Define SubAnalysis"), this);
96 connect(createSubAnalysisAction, SIGNAL(triggered()),
97 this, SLOT(createSubAnalysis()));
99 editMotifsAction = new QAction(tr("Edit Motifs"), this);;
100 connect(editMotifsAction, SIGNAL(triggered()), this, SLOT(editMotifs()));
102 loadMotifListAction = new QAction(tr("Load Motif List"), this);
103 connect(loadMotifListAction, SIGNAL(triggered()),
104 this, SLOT(loadMotifList()));
105 loadMotifListAction->setIcon(QIcon("icons/fileopen.png"));
107 loadMupaAction = new QAction(tr("Load Mussa Parameters"), this);
108 connect(loadMupaAction, SIGNAL(triggered()),
109 this, SLOT(loadMupa()));
110 loadMupaAction->setIcon(QIcon("icons/fileopen.png"));
112 loadSavedAnalysisAction = new QAction(tr("Load &Analysis"), this);
113 connect(loadSavedAnalysisAction, SIGNAL(triggered()),
114 this, SLOT(loadSavedAnalysis()));
115 loadSavedAnalysisAction->setIcon(QIcon("icons/fileopen.png"));
117 saveMotifListAction = new QAction(tr("Save Motifs"), this);
118 connect(saveMotifListAction, SIGNAL(triggered()),
119 this, SLOT(saveMotifList()));
120 saveMotifListAction->setIcon(QIcon("icons/filesave.png"));
122 showMussaViewToolbarAction = new QAction(tr("Show Toolbar"), this);
123 connect(showMussaViewToolbarAction, SIGNAL(triggered()),
124 this, SLOT(showMussaToolbar()));
125 showMussaViewToolbarAction->setCheckable(true);
126 showMussaViewToolbarAction->setChecked(true);
128 toggleMotifsAction = new QAction(tr("Toggle Motifs"), this);
129 connect(toggleMotifsAction, SIGNAL(triggered()),
130 this, SLOT(toggleMotifs()));
131 toggleMotifsAction->setCheckable(true);
132 toggleMotifsAction->setIcon(QIcon("icons/motif_icon.png"));
133 toggleMotifsAction->setWhatsThis(tr("Toggle motif annotations on/off\n\n"
134 "You can load motif annotations via "
135 "'File->Load Motif List' menu option."));
137 //Save pixel map action
138 saveBrowserPixmapAction = new QAction(tr("Save to image..."), this);
139 connect(saveBrowserPixmapAction, (SIGNAL(triggered())),
140 &browser, SLOT(promptSaveBrowserPixmap()));
141 saveBrowserPixmapAction->setIcon(QIcon("icons/image2.png"));
143 viewMussaAlignmentAction = new QAction(tr("View mussa alignment"), this);
144 connect(viewMussaAlignmentAction, SIGNAL(triggered()),
145 this, SLOT(viewMussaAlignment() ));
146 viewMussaAlignmentAction->setWhatsThis(tr("Create a zoomed in window "
147 "showing alignment of the seqcomp "
150 whatsThisAction = QWhatsThis::createAction(this);
151 whatsThisAction->setIcon(QIcon("icons/help.png"));
155 void MussaWindow::setupMainMenu()
157 // we need to run setupActions first
158 assert (closeAction != 0);
161 newMenu = menuBar()->addMenu(tr("&File"));
162 newMenu->addAction(createNewAnalysisAction);
163 newMenu->addAction(loadMupaAction);
164 newMenu->addAction(loadSavedAnalysisAction);
165 //newMenu->addAction(createSubAnalysisAction);
166 newMenu->addSeparator();
167 newMenu->addAction(loadMotifListAction);
168 newMenu->addAction(saveMotifListAction);
169 newMenu->addSeparator();
170 newMenu->addAction(saveBrowserPixmapAction);
171 newMenu->addSeparator();
172 newMenu->addAction(closeAction);
174 newMenu = menuBar()->addMenu(tr("&View"));
175 newMenu->addAction(editMotifsAction);
176 newMenu->addAction(viewMussaAlignmentAction);
177 newMenu->addAction(showMussaViewToolbarAction);
179 newMenu = menuBar()->addMenu(tr("&Help"));
180 newMenu->addAction(whatsThisAction);
181 newMenu->addSeparator();
182 newMenu->addAction(aboutAction);
185 void MussaWindow::about()
187 QMessageBox::about(this, tr("About mussa"),
188 tr("Welcome to Multiple Species Sequence Analysis\n"
189 "(c) 2005-2006 California Institute of Technology\n"
190 "Tristan De Buysscher, Diane Trout\n"));
193 void MussaWindow::createNewAnalysis()
195 MussaSetupDialog *msd = new MussaSetupDialog(this);
198 std::cout << "New mussa exp. defined!\n";
202 std::cout << "New mussa exp. aborted!\n";
207 void MussaWindow::createSubAnalysis()
212 void MussaWindow::editMotifs()
214 if (motif_editor != 0) {
215 motif_editor->hide();
218 motif_editor = new MotifEditor(analysis);
219 connect(motif_editor, SIGNAL(changedMotifs()),
220 this, SLOT(updateAnnotations()));
221 motif_editor->show();
224 void MussaWindow::loadMotifList()
226 QString caption("Load a motif list");
227 QString filter("Motif list(*.txt *.mtl)");
228 QString path = QFileDialog::getOpenFileName(this,
235 // try to load safely
237 analysis->load_motifs(path.toStdString());
238 } catch (runtime_error e) {
239 QString msg("Unable to load ");
243 QMessageBox::warning(this, "Load Motifs", msg);
245 assert (analysis != 0);
248 void MussaWindow::saveMotifList()
253 void MussaWindow::loadMupa()
255 QString caption("Load a mussa parameter file");
256 QString filter("Mussa Parameters (*.mupa)");
257 QString mupa_path = QFileDialog::getOpenFileName(this,
262 if (mupa_path.isNull())
264 // try to load safely
266 Mussa *m = new Mussa;
267 m->load_mupa_file(mupa_path.toStdString());
268 m->analyze(0, 0, Mussa::TransitiveNway, 0.0);
269 // only switch mussas if we loaded without error
273 } catch (mussa_load_error e) {
274 QString msg("Unable to load ");
278 QMessageBox::warning(this, "Load Parameter", msg);
280 assert (analysis != 0);
283 void MussaWindow::loadSavedAnalysis()
285 QString caption("Load a previously run analysis");
286 QString muway_dir = QFileDialog::getExistingDirectory(this,
288 QDir::currentPath());
290 if (muway_dir.isNull())
292 // try to safely load
294 Mussa *m = new Mussa;
295 m->load(muway_dir.toStdString());
296 // only switch mussas if we loaded without error
300 } catch (mussa_load_error e) {
301 QString msg("Unable to load ");
305 QMessageBox::warning(this, "Load Parameter", msg);
307 assert (analysis != 0);
310 void MussaWindow::setSoftThreshold(int threshold)
312 if (analysis->get_soft_thres() != threshold) {
313 analysis->set_soft_thres(threshold);
320 void MussaWindow::showMussaToolbar()
322 if (mussaViewTB.isVisible())
328 void MussaWindow::toggleMotifs()
333 void MussaWindow::NotImplementedBox()
335 QMessageBox::warning(this, QObject::tr("mussa"), QObject::tr("Not implemented yet"));
338 void MussaWindow::viewMussaAlignment()
340 const set<int>& selected_paths = browser.selectedPaths();
341 if (selected_paths.size() == 0 ) {
342 QMessageBox::warning(this,
343 QObject::tr("mussa"),
344 QObject::tr("you should probably select some paths "
347 MussaAlignedWindow *ma_win = new MussaAlignedWindow(*analysis,
349 connect(this, SIGNAL(changedAnnotations()),
350 ma_win, SLOT(update()));
351 aligned_windows.push_back(ma_win);
356 void MussaWindow::updateAnalysis()
358 cout << "analysis updated" << endl;
359 for (list<MussaAlignedWindow *>::iterator maw_i = aligned_windows.begin();
360 maw_i != aligned_windows.end();
368 const vector<Sequence>& seqs = analysis->sequences();
369 browser.setSequences(seqs, analysis->colorMapper());
372 cout << "browser zoom " << browser.zoom() << endl;
373 zoomBox.setValue(browser.zoom());
376 void MussaWindow::updateAnnotations()
378 // motifs were changed in the sequences by
379 // Mussa::update_sequences_motifs
380 emit changedAnnotations();
384 void MussaWindow::updateLinks()
386 browser.clear_links();
387 bool reversed = false;
388 const NwayPaths& nway = analysis->paths();
390 typedef list<ExtendedConservedPath> conserved_paths;
391 typedef conserved_paths::const_iterator const_conserved_paths_itor;
392 for(const_conserved_paths_itor path_itor = nway.refined_pathz.begin();
393 path_itor != nway.refined_pathz.end();
396 // since we were drawing to the start of a window, and opengl lines
397 // are centered around the two connecting points our lines were slightly
398 // offset. the idea of window_offset is to adjust them to the
399 // right for forward compliment or left for reverse compliment
400 // FIXME: figure out how to unit test these computations
401 //GLfloat window_offset = (path_itor->window_size)/2.0;
403 size_t track_len = path_itor->track_indexes.size();
404 vector<int> normalized_path;
405 normalized_path.reserve(track_len);
406 vector<bool> rc_flags(false, track_len);
407 for (size_t track_i=0; track_i != track_len; ++track_i)
409 int x = path_itor->track_indexes[track_i];
410 // at some point when we modify the pathz data structure to keep
411 // track of the score we can put grab the depth here.
413 // are we reverse complimented?
418 x = -x; // make positive
420 normalized_path.push_back(x);
421 rc_flags.push_back(reversed);
423 browser.link(normalized_path, rc_flags, path_itor->window_size);