13 #include <boost/filesystem/path.hpp>
14 namespace fs = boost::filesystem;
16 //#include "qui/mussa_setup_dialog/SequenceSetupWidget.hpp"
17 #include "qui/mussa_setup_dialog/SequenceSetupFrame.hpp"
18 #include "qui/mussa_setup_dialog/MussaSetupWidget.hpp"
19 #include "qui/mussa_setup_dialog/SetupInfo.hpp"
20 #include "alg/mussa.hpp"
21 #include "mussa_exceptions.hpp"
23 MussaSetupWidget::MussaSetupWidget(QWidget *parent)
25 analysisNameLineEdit(new QLineEdit),
26 windowEdit(new QSpinBox),
27 thresholdEdit(new QSpinBox),
28 numOfSequencesSpinBox(new QSpinBox),
29 createPushButton(new QPushButton(tr("Create"))),
30 cancelPushButton(new QPushButton(tr("Cancel"))),
33 analysisNameLineEdit = new QLineEdit;
34 windowEdit = new QSpinBox;
35 thresholdEdit = new QSpinBox;
36 numOfSequencesSpinBox = new QSpinBox;
37 createPushButton = new QPushButton(tr("Create"));
38 cancelPushButton = new QPushButton(tr("Cancel"));
41 QLabel *analysisNameLabel = new QLabel(tr("Analysis Name"));
42 analysisNameLabel->setBuddy(analysisNameLineEdit);
45 windowEdit->setMinimum(1);
46 windowEdit->setValue(30);
47 QLabel *windowLabel = new QLabel(tr("Window (nt)"));
48 windowLabel->setBuddy(windowEdit);
51 thresholdEdit->setMinimum(1);
52 thresholdEdit->setMaximum(windowEdit->value());
53 thresholdEdit->setValue(21);
54 QLabel *thresholdLabel = new QLabel(tr("Threshold (nt)"));
55 thresholdLabel->setBuddy(thresholdEdit);
56 connect(windowEdit, SIGNAL(valueChanged(int)),
57 this, SLOT(updateThreshold(int)));
59 // Number of sequences
60 QLabel *numOfSequencesLabel = new QLabel(tr("Number of sequences"));
61 numOfSequencesLabel->setBuddy(numOfSequencesSpinBox);
62 numOfSequencesSpinBox->setMinimum(1);
64 //Sequence setup frame
65 seqSetupFrame = new SequenceSetupFrame;
67 connect(numOfSequencesSpinBox, SIGNAL(valueChanged(int)),
68 seqSetupFrame, SLOT(changeSequenceCount(int)));
70 numOfSequencesSpinBox->setValue(2);
72 // Create Experiment Button
73 connect(createPushButton, SIGNAL(pressed()),
74 this, SLOT(mussaCreatePushed()));
77 connect(cancelPushButton, SIGNAL(pressed()),
78 this, SLOT(mussaCancelPushed()));
81 QHBoxLayout *row1Layout = new QHBoxLayout;
82 QHBoxLayout *row2Layout = new QHBoxLayout;
83 QVBoxLayout *mainLayout = new QVBoxLayout;
84 QHBoxLayout *buttonLayout = new QHBoxLayout;
86 row1Layout->addWidget(analysisNameLabel);
87 row1Layout->addWidget(analysisNameLineEdit);
89 row2Layout->addWidget(thresholdLabel);
90 row2Layout->addWidget(thresholdEdit);
91 row2Layout->addWidget(windowLabel);
92 row2Layout->addWidget(windowEdit);
93 row2Layout->addWidget(numOfSequencesLabel);
94 row2Layout->addWidget(numOfSequencesSpinBox);
96 buttonLayout->addStretch(1);
97 buttonLayout->addWidget(createPushButton);
98 buttonLayout->addWidget(cancelPushButton);
100 mainLayout->addLayout(row1Layout);
101 mainLayout->addLayout(row2Layout);
102 mainLayout->addWidget(seqSetupFrame);
103 mainLayout->addLayout(buttonLayout);
104 setLayout(mainLayout);
107 void MussaSetupWidget::mussaCreatePushed()
109 emit createButtonPushed();
112 void MussaSetupWidget::mussaCancelPushed()
114 emit cancelButtonPushed();
117 void MussaSetupWidget::updateThreshold(int new_threshold)
119 thresholdEdit->setMaximum(new_threshold);
122 MussaRef MussaSetupWidget::getMussaObject()
124 MussaRef mussa = Mussa::init();
130 list<SetupInfo *> setupInfoList = seqSetupFrame->getSetupInfo();
132 for (list<SetupInfo *>::reverse_iterator setup_item = setupInfoList.rbegin();
133 setup_item != setupInfoList.rend();
136 std::string seqName = (*setup_item)->getName();
137 std::string seqNative = (*setup_item)->getSeqFile();
138 std::string annotNative = (*setup_item)->getAnnotFile();
139 fastaIndex = (*setup_item)->getFastaIndex();
140 start = (*setup_item)->getSubSeqStart();
141 end = (*setup_item)->getSubSeqEnd();
143 fs::path seqFile(seqNative, fs::native);
144 fs::path annotFile(annotNative, fs::native);
145 mussa->load_sequence(seqFile, annotFile, fastaIndex, start, end, &seqName);
147 setupInfoList.clear();
149 int win_size = windowEdit->value();
150 int threshold = thresholdEdit->value();
151 std::string name = analysisNameLineEdit->text().toStdString();
152 if (win_size == 0 or threshold == 0) {
153 throw mussa_load_error("must set analysis parameters");
155 mussa->set_name(name);
156 mussa->set_window(win_size);
157 mussa->set_threshold(threshold);
158 mussa->set_analysis_mode(Mussa::TransitiveNway);
159 //mussa->set_entropy(0); // might want to add this at some point