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);
43 analysisNameLabel->setWhatsThis("Meaningful name for your analysis ");
44 analysisNameLineEdit->setWhatsThis("Meaningful name for your analysis ");
47 windowEdit->setMinimum(1);
48 windowEdit->setValue(30);
49 windowEdit->setWhatsThis("Sliding window size to use in analysis.\n\nSee Mussagl Manual for more information by selecting the 'Help > Mussagl Manual' menu option. ");
50 QLabel *windowLabel = new QLabel(tr("Window (nt)"));
51 windowLabel->setBuddy(windowEdit);
52 windowLabel->setWhatsThis("Sliding window size to use in analysis.\n\nSee Mussagl Manual for more information by selecting the 'Help > Mussagl Manual' menu option. ");
55 thresholdEdit->setMinimum(1);
56 thresholdEdit->setMaximum(windowEdit->value());
57 thresholdEdit->setValue(21);
58 thresholdEdit->setWhatsThis("Threshold of minimum number of matches required in a window to be considered a match.\n\nSee Mussagl Manual for more information by selecting the 'Help > Mussagl Manual' menu option. ");
59 QLabel *thresholdLabel = new QLabel(tr("Threshold (nt)"));
60 thresholdLabel->setBuddy(thresholdEdit);
61 thresholdLabel->setWhatsThis("Threshold of minimum number of matches required in a window to be considered a match.\n\nSee Mussagl Manual for more information by selecting the 'Help > Mussagl Manual' menu option. ");
62 connect(windowEdit, SIGNAL(valueChanged(int)),
63 this, SLOT(updateThreshold(int)));
65 // Number of sequences
66 QLabel *numOfSequencesLabel = new QLabel(tr("Number of sequences"));
67 numOfSequencesLabel->setBuddy(numOfSequencesSpinBox);
68 numOfSequencesLabel->setWhatsThis("Number of sequences to include in analysis. ");
69 numOfSequencesSpinBox->setMinimum(1);
70 numOfSequencesSpinBox->setWhatsThis("Number of sequences to include in analysis. ");
72 //Sequence setup frame
73 seqSetupFrame = new SequenceSetupFrame;
75 connect(numOfSequencesSpinBox, SIGNAL(valueChanged(int)),
76 seqSetupFrame, SLOT(changeSequenceCount(int)));
78 numOfSequencesSpinBox->setValue(2);
80 // Create Experiment Button
81 connect(createPushButton, SIGNAL(pressed()),
82 this, SLOT(mussaCreatePushed()));
85 connect(cancelPushButton, SIGNAL(pressed()),
86 this, SLOT(mussaCancelPushed()));
89 QHBoxLayout *row1Layout = new QHBoxLayout;
90 QHBoxLayout *row2Layout = new QHBoxLayout;
91 QVBoxLayout *mainLayout = new QVBoxLayout;
92 QHBoxLayout *buttonLayout = new QHBoxLayout;
94 row1Layout->addWidget(analysisNameLabel);
95 row1Layout->addWidget(analysisNameLineEdit);
97 row2Layout->addWidget(thresholdLabel);
98 row2Layout->addWidget(thresholdEdit);
99 row2Layout->addWidget(windowLabel);
100 row2Layout->addWidget(windowEdit);
101 row2Layout->addWidget(numOfSequencesLabel);
102 row2Layout->addWidget(numOfSequencesSpinBox);
104 buttonLayout->addStretch(1);
105 buttonLayout->addWidget(createPushButton);
106 buttonLayout->addWidget(cancelPushButton);
108 mainLayout->addLayout(row1Layout);
109 mainLayout->addLayout(row2Layout);
110 mainLayout->addWidget(seqSetupFrame);
111 mainLayout->addLayout(buttonLayout);
112 setLayout(mainLayout);
115 void MussaSetupWidget::mussaCreatePushed()
117 emit createButtonPushed();
120 void MussaSetupWidget::mussaCancelPushed()
122 emit cancelButtonPushed();
125 void MussaSetupWidget::updateThreshold(int new_threshold)
127 thresholdEdit->setMaximum(new_threshold);
130 MussaRef MussaSetupWidget::getMussaObject()
132 MussaRef mussa = Mussa::init();
138 list<SetupInfo *> setupInfoList = seqSetupFrame->getSetupInfo();
140 for (list<SetupInfo *>::reverse_iterator setup_item = setupInfoList.rbegin();
141 setup_item != setupInfoList.rend();
144 std::string seqName = (*setup_item)->getName();
145 std::string seqNative = (*setup_item)->getSeqFile();
146 std::string annotNative = (*setup_item)->getAnnotFile();
147 fastaIndex = (*setup_item)->getFastaIndex();
148 start = (*setup_item)->getSubSeqStart();
149 end = (*setup_item)->getSubSeqEnd();
151 fs::path seqFile(seqNative, fs::native);
152 fs::path annotFile(annotNative, fs::native);
153 mussa->load_sequence(seqFile, annotFile, fastaIndex, start, end, &seqName);
155 setupInfoList.clear();
157 int win_size = windowEdit->value();
158 int threshold = thresholdEdit->value();
159 std::string name = analysisNameLineEdit->text().toStdString();
160 if (win_size == 0 or threshold == 0) {
161 throw mussa_load_error("must set analysis parameters");
163 mussa->set_name(name);
164 mussa->set_window(win_size);
165 mussa->set_threshold(threshold);
166 mussa->set_analysis_mode(Mussa::TransitiveNway);
167 //mussa->set_entropy(0); // might want to add this at some point