Progress towards MussaSetupDialog (Currently will cause crash! Be warned!)
[mussa.git] / qui / mussa_setup_dialog / MussaSetupWidget.cpp
1 #include <QFrame>
2 #include <QLabel>
3 #include <QLineEdit>
4 #include <QSpinBox>
5 #include <QVBoxLayout>
6 #include <QHBoxLayout>
7 #include <QPushButton>
8
9 #include <list>
10
11 //#include "qui/mussa_setup_dialog/SequenceSetupWidget.hpp"
12 #include "qui/mussa_setup_dialog/SequenceSetupFrame.hpp"
13 #include "qui/mussa_setup_dialog/MussaSetupWidget.hpp"
14 #include "qui/mussa_setup_dialog/SetupInfo.hpp"
15 #include "alg/mussa.hpp"
16
17 MussaSetupWidget::MussaSetupWidget(QWidget *parent)
18   : QWidget(parent),
19     analysisNameLineEdit(0),
20     windowLineEdit(0),
21     thresholdLineEdit(0),
22     numOfSequencesSpinBox(0),
23     createPushButton(0),
24     cancelPushButton(0),
25     seqSetupFrame(0)
26 {
27   
28   // Analysis name
29   analysisNameLineEdit = new QLineEdit;
30   QLabel *analysisNameLabel = new QLabel(tr("Analysis Name"));
31   analysisNameLabel->setBuddy(analysisNameLineEdit);
32
33   // Window
34   windowLineEdit = new QLineEdit;
35   QLabel *windowLabel = new QLabel(tr("Window"));
36   windowLabel->setBuddy(windowLineEdit);
37
38   // Threshold
39   thresholdLineEdit = new QLineEdit;
40   QLabel *thresholdLabel = new QLabel(tr("Threshold"));
41   thresholdLabel->setBuddy(thresholdLineEdit);
42
43   // Number of sequences
44   numOfSequencesSpinBox = new QSpinBox;
45   QLabel *numOfSequencesLabel = new QLabel(tr("Number of sequences"));
46   numOfSequencesLabel->setBuddy(numOfSequencesSpinBox);
47   numOfSequencesSpinBox->setMinimum(1);
48
49
50   //Sequence setup frame
51   seqSetupFrame = new SequenceSetupFrame;
52
53   connect(numOfSequencesSpinBox, SIGNAL(valueChanged(int)),
54           seqSetupFrame, SLOT(changeSequenceCount(int)));
55
56   numOfSequencesSpinBox->setValue(1);
57
58   // Create Experiment Button
59   createPushButton = new QPushButton(tr("Create"));
60   connect(createPushButton, SIGNAL(pressed()),
61           this, SLOT(mussaCreatePushed()));
62   
63   // Cancle Button
64   cancelPushButton = new QPushButton(tr("Cancel"));
65   connect(cancelPushButton, SIGNAL(pressed()),
66           this, SLOT(mussaCancelPushed()));
67
68   // LAYOUT
69   QHBoxLayout *row1Layout = new QHBoxLayout;
70   QHBoxLayout *row2Layout = new QHBoxLayout;
71   QVBoxLayout *mainLayout = new QVBoxLayout;
72   QHBoxLayout *buttonLayout = new QHBoxLayout;
73
74   row1Layout->addWidget(analysisNameLabel);
75   row1Layout->addWidget(analysisNameLineEdit);
76
77   row2Layout->addWidget(windowLabel);
78   row2Layout->addWidget(windowLineEdit);
79   row2Layout->addWidget(thresholdLabel);
80   row2Layout->addWidget(thresholdLineEdit);
81   row2Layout->addWidget(numOfSequencesLabel);
82   row2Layout->addWidget(numOfSequencesSpinBox);
83
84   buttonLayout->addWidget(createPushButton);
85   buttonLayout->addWidget(cancelPushButton);
86
87   mainLayout->addLayout(row1Layout);
88   mainLayout->addLayout(row2Layout);
89   mainLayout->addWidget(seqSetupFrame);
90   mainLayout->addLayout(buttonLayout);
91   setLayout(mainLayout);
92
93 }
94
95 void MussaSetupWidget::mussaCreatePushed()
96 {
97   emit createButtonPushed();
98 }
99
100 void MussaSetupWidget::mussaCancelPushed()
101 {
102   emit cancelButtonPushed();
103 }
104
105 Mussa* MussaSetupWidget::getMussaObject()
106 {
107   Mussa *mussa = new Mussa;
108   
109   
110
111   std::string seqFile;
112   std::string annotFile;
113   int fastaIndex;
114   int start;
115   int end;
116
117   std::list<SetupInfo *> setupInfoList = seqSetupFrame->getSetupInfo();
118   
119   const int count = setupInfoList.size();
120   
121   SetupInfo *setupInfo = 0;
122   for (int i=0; i < count; i++)
123   {
124     setupInfo = setupInfoList.back();
125     setupInfoList.pop_back();
126
127     seqFile = setupInfo->getSeqFile();
128     annotFile = setupInfo->getAnnotFile();
129     fastaIndex = setupInfo->getFastaIndex();
130     start = setupInfo->getSubSeqStart();
131     end = setupInfo->getSubSeqEnd();
132     
133     mussa->load_sequence(seqFile, annotFile, fastaIndex, start, end);
134     delete setupInfo;
135   }
136
137   mussa->analyze(0, 0, Mussa::TransitiveNway, 0.0);
138
139   return mussa;
140 }
141
142 //MussaSetupWidget::MussaSetupWidget(const MussaSetupWidget& msw)
143 //  : analysisNameLineEdit(msw.analysisNameLineEdit),
144 //    windowLineEdit(msw.windowLineEdit),
145 //    thresholdLineEdit(msw.thresholdLineEdit),
146 //    numOfSequencesLineEdit(msw.numOfSequencesLineEdit),
147 //    seqSetupFrame(msw.seqSetupFrame)
148 //{
149 //}