efed5de9526f6e8441a6de9702628c81f273665d
[mussa.git] / qui / SubanalysisWindow.cpp
1 #include "qui/SubanalysisWindow.hpp"
2 #include "qui/MussaWindow.hpp"
3
4 #include "mussa_exceptions.hpp"
5 #include "alg/mussa.hpp"
6
7 #include <QVBoxLayout>
8 #include <QHBoxLayout>
9 #include <QGridLayout>
10
11 SubanalysisWindow::SubanalysisWindow(QWidget *parent)
12   : QWidget(parent),
13     window(0),
14     threshold(0),
15     table(0),
16     ok(0),
17     cancel(0)
18 {
19   QGridLayout *parameterLayout = new QGridLayout;
20
21   QLabel *thresholdLabel = new QLabel(tr("threshold (bp)"));
22   parameterLayout->addWidget(thresholdLabel, 0, 0);
23   threshold = new QSpinBox(this);
24   threshold->setValue(8);
25   parameterLayout->addWidget(threshold, 1, 0);
26   QLabel *windowLabel = new QLabel(tr("window (bp)"));
27   parameterLayout->addWidget(windowLabel, 0, 1);
28   window = new QSpinBox(this);
29   window->setValue(10);
30   parameterLayout->addWidget(window, 1, 1);
31
32   ok = new QPushButton(tr("&OK"), this);
33   connect(ok, SIGNAL(clicked()), this, SLOT(run()));
34   cancel = new QPushButton(tr("Cancel"), this);
35   connect(cancel, SIGNAL(clicked()), this, SLOT(abort()));
36   table = new QTableView(this);
37   table->setModel(&model);
38
39   // layout buttons
40   QHBoxLayout *buttonLayout = new QHBoxLayout;
41   buttonLayout->addWidget(ok);
42   buttonLayout->addWidget(cancel);
43
44   // layout verticle space
45   QVBoxLayout *verticalLayout = new QVBoxLayout;
46   verticalLayout->addLayout(parameterLayout);
47   verticalLayout->addWidget(table);
48   verticalLayout->addLayout(buttonLayout);
49   setLayout(verticalLayout);
50 }
51
52 SequenceLocationModel& SubanalysisWindow::getModel()
53 {
54   return model;
55 }
56
57 void SubanalysisWindow::abort()
58 {
59   model.clear();
60   hide();
61 }
62
63 void SubanalysisWindow::run()
64 {
65   if (window == 0 or threshold == 0) 
66     throw std::runtime_error("SubanalysisWindow misconstructed");
67
68   std::auto_ptr<Mussa> m(new Mussa);
69
70   for(SequenceLocationModel::iterator itor = model.begin();
71       itor != model.end();
72       ++itor)
73   {
74     m->append_sequence(itor->getSelectedSequence());
75   }
76
77   m->set_window(window->value());
78   m->set_threshold(threshold->value());
79   m->analyze();
80   MussaWindow *mw = new MussaWindow(m.get());
81   mw->show();
82   model.clear();
83   hide();
84 }
85