1 #include "qui/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)
21 QGridLayout *parameterLayout = new QGridLayout;
23 QLabel *thresholdLabel = new QLabel(tr("threshold (bp)"));
24 parameterLayout->addWidget(thresholdLabel, 0, 0);
25 threshold = new QSpinBox(this);
26 threshold->setValue(8);
27 parameterLayout->addWidget(threshold, 1, 0);
28 QLabel *windowLabel = new QLabel(tr("window (bp)"));
29 parameterLayout->addWidget(windowLabel, 0, 1);
30 window = new QSpinBox(this);
32 parameterLayout->addWidget(window, 1, 1);
34 ok = new QPushButton(tr("&OK"), this);
35 ok->setEnabled( false );
36 connect(ok, SIGNAL(clicked()), this, SLOT(run()));
38 cancel = new QPushButton(tr("Cancel"), this);
39 connect(cancel, SIGNAL(clicked()), this, SLOT(abort()));
41 table = new QTableView(this);
42 table->setModel(&model);
45 QHBoxLayout *buttonLayout = new QHBoxLayout;
46 buttonLayout->addWidget(ok);
47 buttonLayout->addWidget(cancel);
49 // layout verticle space
50 QVBoxLayout *verticalLayout = new QVBoxLayout;
51 verticalLayout->addLayout(parameterLayout);
52 verticalLayout->addWidget(table);
53 verticalLayout->addLayout(buttonLayout);
54 setLayout(verticalLayout);
56 // now that we're all setup lets get notices when we're updated
57 connect(&model, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
58 this, SLOT(modelUpdated(const QModelIndex&, int, int)));
59 connect(&model, SIGNAL(rowsRemoved(const QModelIndex&, int, int)),
60 this, SLOT(modelUpdated(const QModelIndex&, int, int)));
65 SequenceLocationModel& SubanalysisWindow::getModel()
70 void SubanalysisWindow::abort()
76 void SubanalysisWindow::run()
78 if (window == 0 or threshold == 0) {
79 throw std::runtime_error("SubanalysisWindow misconstructed");
82 if (model.size() == 0) {
83 throw std::runtime_error("It shouldn't be possible to call run with an "
87 MussaRef new_m(new Mussa);
89 for(SequenceLocationModel::iterator itor = model.begin();
93 // append_sequence from a const Sequence & will make a copy
94 // for the shared pointer.
95 Sequence s = itor->getSelectedSequence();
97 new_m->append_sequence(s);
101 new_m->set_window(window->value());
102 new_m->set_threshold(threshold->value());
104 // FIXME: why isn't the nway_paths refined_pathz structure just initialized
105 // FIXME: with the contents of pathz?
106 new_m->set_soft_threshold(threshold->value());
108 std::vector<Sequence> motifs_copy;
109 std::vector<Color> color_copy;
110 const Mussa::motif_set motifs = analysis->motifs();
111 boost::shared_ptr<AnnotationColors> mapper = analysis->colorMapper();
112 for(Mussa::motif_set::const_iterator motif_i = motifs.begin();
113 motif_i != motifs.end();
116 motifs_copy.push_back(*motif_i);
117 color_copy.push_back(mapper->lookup("motif", motif_i->get_sequence()));
119 new_m->set_motifs(motifs_copy, color_copy);
120 MussaWindow *mw = new MussaWindow(new_m);
124 } catch(mussa_error e) {
125 QMessageBox::critical(this,
126 "Mussa Subanalysis Error",
128 QMessageBox::Ok, 0, 0);
132 void SubanalysisWindow::modelUpdated(const QModelIndex&, int, int )
134 // if the model is empty we shouldn't be able to click ok
135 if (ok) ok->setEnabled(not model.empty());
138 void SubanalysisWindow::updateTitle()
140 std::string title("Subanalysis: ");
142 title += analysis->get_title();
144 setWindowTitle(title.c_str());