1 #include "qui/subanalysis/SubanalysisWindow.hpp"
2 #include "qui/MussaWindow.hpp"
4 #include "mussa_exceptions.hpp"
5 #include "alg/mussa.hpp"
10 #include <QGridLayout>
12 SubanalysisWindow::SubanalysisWindow(MussaRef m, QWidget *parent)
24 parameterLayout = new QGridLayout;
26 thresholdLabel = new QLabel(tr("threshold (bp)"));
27 parameterLayout->addWidget(thresholdLabel, 0, 0);
28 threshold = new QSpinBox(this);
29 threshold->setValue(8);
30 parameterLayout->addWidget(threshold, 1, 0);
31 windowLabel = new QLabel(tr("window (bp)"));
32 parameterLayout->addWidget(windowLabel, 0, 1);
33 window = new QSpinBox(this);
35 parameterLayout->addWidget(window, 1, 1);
37 ok = new QPushButton(tr("&OK"), this);
38 ok->setEnabled( false );
39 connect(ok, SIGNAL(clicked()), this, SLOT(run()));
41 cancel = new QPushButton(tr("Cancel"), this);
42 connect(cancel, SIGNAL(clicked()), this, SLOT(abort()));
44 table = new QTableView(this);
45 table->setModel(&model);
48 QHBoxLayout *buttonLayout = new QHBoxLayout;
49 buttonLayout->addWidget(ok);
50 buttonLayout->addWidget(cancel);
52 // layout vertical space
53 QVBoxLayout *verticalLayout = new QVBoxLayout;
54 verticalLayout->addLayout(parameterLayout);
55 verticalLayout->addWidget(table);
56 verticalLayout->addLayout(buttonLayout);
57 setLayout(verticalLayout);
59 // now that we're all setup lets get notices when we're updated
60 connect(&model, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
61 this, SLOT(modelUpdated(const QModelIndex&, int, int)));
62 connect(&model, SIGNAL(rowsRemoved(const QModelIndex&, int, int)),
63 this, SLOT(modelUpdated(const QModelIndex&, int, int)));
68 SequenceLocationModel& SubanalysisWindow::getModel()
73 void SubanalysisWindow::abort()
79 void SubanalysisWindow::run()
81 if (window == 0 or threshold == 0) {
82 throw std::runtime_error("SubanalysisWindow misconstructed");
85 if (model.size() == 0) {
86 throw std::runtime_error("It shouldn't be possible to call run with an "
90 MussaRef new_m(new Mussa);
92 for(SequenceLocationModel::iterator itor = model.begin();
96 // append_sequence from a const Sequence & will make a copy
97 // for the shared pointer.
98 Sequence s = itor->getSelectedSequence();
100 new_m->append_sequence(s);
104 new_m->set_window(window->value());
105 new_m->set_threshold(threshold->value());
107 // FIXME: why isn't the nway_paths refined_pathz structure just initialized
108 // FIXME: with the contents of pathz?
109 new_m->set_soft_threshold(threshold->value());
111 std::vector<Sequence> motifs_copy;
112 std::vector<Color> color_copy;
113 const Mussa::motif_set motifs = analysis->motifs();
114 boost::shared_ptr<AnnotationColors> mapper = analysis->colorMapper();
115 for(Mussa::motif_set::const_iterator motif_i = motifs.begin();
116 motif_i != motifs.end();
119 motifs_copy.push_back(*motif_i);
120 color_copy.push_back(mapper->lookup("motif", motif_i->get_sequence()));
122 new_m->set_motifs(motifs_copy, color_copy);
123 MussaWindow *mw = new MussaWindow(new_m);
127 } catch(mussa_error e) {
128 QMessageBox::critical(this,
129 "Mussa Subanalysis Error",
131 QMessageBox::Ok, 0, 0);
135 void SubanalysisWindow::modelUpdated(const QModelIndex&, int, int )
137 // if the model is empty we shouldn't be able to click ok
138 if (ok) ok->setEnabled(not model.empty());
141 void SubanalysisWindow::updateTitle()
143 std::string title("Subanalysis: ");
145 title += analysis->get_title();
147 setWindowTitle(title.c_str());