WhatsThis update
[mussa.git] / qui / mussa_setup_dialog / MussaSetupWidget.cpp
index 02a92eb50b84712ed6ee3c1447a6b3d74ba1a2f5..c116a9a2e12fc6e9983760a6f80f83906cd69961 100644 (file)
 #include <QFrame>
 #include <QLabel>
 #include <QLineEdit>
+#include <QSpinBox>
 #include <QVBoxLayout>
 #include <QHBoxLayout>
+#include <QPushButton>
+
+#include <list>
+
+using namespace std;
+
+#include <boost/filesystem/path.hpp>
+namespace fs = boost::filesystem;
 
 //#include "qui/mussa_setup_dialog/SequenceSetupWidget.hpp"
 #include "qui/mussa_setup_dialog/SequenceSetupFrame.hpp"
 #include "qui/mussa_setup_dialog/MussaSetupWidget.hpp"
+#include "qui/mussa_setup_dialog/SetupInfo.hpp"
+#include "alg/mussa.hpp"
+#include "mussa_exceptions.hpp"
 
 MussaSetupWidget::MussaSetupWidget(QWidget *parent)
   : QWidget(parent),
-    analysisNameLineEdit(0),
-    windowLineEdit(0),
-    thresholdLineEdit(0),
-    numOfSequencesLineEdit(0),
+    analysisNameLineEdit(new QLineEdit),
+    windowEdit(new QSpinBox),
+    thresholdEdit(new QSpinBox),
+    numOfSequencesSpinBox(new QSpinBox),
+    createPushButton(new QPushButton(tr("Create"))),
+    cancelPushButton(new QPushButton(tr("Cancel"))),
     seqSetupFrame(0)
 {
-  
-  // Analysis name
   analysisNameLineEdit = new QLineEdit;
+  windowEdit = new QSpinBox;
+  thresholdEdit = new QSpinBox;
+  numOfSequencesSpinBox = new QSpinBox;
+  createPushButton = new QPushButton(tr("Create"));
+  cancelPushButton = new QPushButton(tr("Cancel"));
+    
+  // Analysis name
   QLabel *analysisNameLabel = new QLabel(tr("Analysis Name"));
   analysisNameLabel->setBuddy(analysisNameLineEdit);
+  analysisNameLabel->setWhatsThis("Meaningful name for your analysis ");
+  analysisNameLineEdit->setWhatsThis("Meaningful name for your analysis ");
 
   // Window
-  windowLineEdit = new QLineEdit;
-  QLabel *windowLabel = new QLabel(tr("Window"));
-  windowLabel->setBuddy(windowLineEdit);
+  windowEdit->setMinimum(1);
+  windowEdit->setValue(30);
+  windowEdit->setWhatsThis("Sliding window size to use in analysis.\n\nSee Mussagl Manual for more information by selecting the 'Help > Mussagl Manual' menu option. ");
+  QLabel *windowLabel = new QLabel(tr("Window (nt)"));
+  windowLabel->setBuddy(windowEdit);
+  windowLabel->setWhatsThis("Sliding window size to use in analysis.\n\nSee Mussagl Manual for more information by selecting the 'Help > Mussagl Manual' menu option. ");
 
   // Threshold
-  thresholdLineEdit = new QLineEdit;
-  QLabel *thresholdLabel = new QLabel(tr("Threshold"));
-  thresholdLabel->setBuddy(thresholdLineEdit);
+  thresholdEdit->setMinimum(1);
+  thresholdEdit->setMaximum(windowEdit->value());
+  thresholdEdit->setValue(21);
+  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. ");
+  QLabel *thresholdLabel = new QLabel(tr("Threshold (nt)"));
+  thresholdLabel->setBuddy(thresholdEdit);
+  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. ");
+  connect(windowEdit, SIGNAL(valueChanged(int)),
+          this, SLOT(updateThreshold(int)));
 
   // Number of sequences
-  numOfSequencesLineEdit = new QLineEdit;
   QLabel *numOfSequencesLabel = new QLabel(tr("Number of sequences"));
-  numOfSequencesLabel->setBuddy(numOfSequencesLineEdit);
-
-  // frame
-  //sequenceFrame = new QFrame;
-  //sequenceFrame->setFrameStyle(QFrame::Panel | QFrame::Sunken);
-  //
-  //QVBoxLayout *sequenceLayout = new QVBoxLayout;
-  //
-  //SequenceSetupWidget *seq1 = new SequenceSetupWidget;
-  //sequenceLayout->addWidget(seq1);
-  //
-  //SequenceSetupWidget *seq2 = new SequenceSetupWidget;
-  //sequenceLayout->addWidget(seq2);
-  //
-  //sequenceFrame->setLayout(sequenceLayout);
+  numOfSequencesLabel->setBuddy(numOfSequencesSpinBox);
+  numOfSequencesLabel->setWhatsThis("Number of sequences to include in analysis. ");
+  numOfSequencesSpinBox->setMinimum(1);
+  numOfSequencesSpinBox->setWhatsThis("Number of sequences to include in analysis. ");
+
+  //Sequence setup frame
   seqSetupFrame = new SequenceSetupFrame;
-  seqSetupFrame->changeSequenceCount(3);
-  seqSetupFrame->changeSequenceCount(2);
 
-  //connect(numOfSequencesLineEdit, SIGNAL(changed,
-  //     seqSetupFrame, SLOT(changeSequenceCount(int)));
+  connect(numOfSequencesSpinBox, SIGNAL(valueChanged(int)),
+         seqSetupFrame, SLOT(changeSequenceCount(int)));
+
+  numOfSequencesSpinBox->setValue(2);
+
+  // Create Experiment Button
+  connect(createPushButton, SIGNAL(pressed()),
+         this, SLOT(mussaCreatePushed()));
+  
+  // Cancle Button
+  connect(cancelPushButton, SIGNAL(pressed()),
+         this, SLOT(mussaCancelPushed()));
 
   // LAYOUT
   QHBoxLayout *row1Layout = new QHBoxLayout;
   QHBoxLayout *row2Layout = new QHBoxLayout;
   QVBoxLayout *mainLayout = new QVBoxLayout;
+  QHBoxLayout *buttonLayout = new QHBoxLayout;
 
   row1Layout->addWidget(analysisNameLabel);
   row1Layout->addWidget(analysisNameLineEdit);
 
-  row2Layout->addWidget(windowLabel);
-  row2Layout->addWidget(windowLineEdit);
   row2Layout->addWidget(thresholdLabel);
-  row2Layout->addWidget(thresholdLineEdit);
+  row2Layout->addWidget(thresholdEdit);
+  row2Layout->addWidget(windowLabel);
+  row2Layout->addWidget(windowEdit);
   row2Layout->addWidget(numOfSequencesLabel);
-  row2Layout->addWidget(numOfSequencesLineEdit);
+  row2Layout->addWidget(numOfSequencesSpinBox);
+
+  buttonLayout->addStretch(1);
+  buttonLayout->addWidget(createPushButton);
+  buttonLayout->addWidget(cancelPushButton);
 
   mainLayout->addLayout(row1Layout);
   mainLayout->addLayout(row2Layout);
   mainLayout->addWidget(seqSetupFrame);
+  mainLayout->addLayout(buttonLayout);
   setLayout(mainLayout);
+}
 
+void MussaSetupWidget::mussaCreatePushed()
+{
+  emit createButtonPushed();
+}
+
+void MussaSetupWidget::mussaCancelPushed()
+{
+  emit cancelButtonPushed();
+}
+
+void MussaSetupWidget::updateThreshold(int new_threshold)
+{
+  thresholdEdit->setMaximum(new_threshold);
 }
 
-MussaSetupWidget::MussaSetupWidget(const MussaSetupWidget& msw)
-  : analysisNameLineEdit(msw.analysisNameLineEdit),
-    windowLineEdit(msw.windowLineEdit),
-    thresholdLineEdit(msw.thresholdLineEdit),
-    numOfSequencesLineEdit(msw.numOfSequencesLineEdit),
-    seqSetupFrame(msw.seqSetupFrame)
+MussaRef MussaSetupWidget::getMussaObject()
 {
+  MussaRef mussa = Mussa::init();
+
+  int fastaIndex;
+  int start;
+  int end;
+
+  list<SetupInfo *> setupInfoList = seqSetupFrame->getSetupInfo();
+  
+  for (list<SetupInfo *>::reverse_iterator setup_item = setupInfoList.rbegin();
+       setup_item != setupInfoList.rend();
+       ++setup_item)
+  {
+    std::string seqName = (*setup_item)->getName();
+    std::string seqNative = (*setup_item)->getSeqFile();
+    std::string annotNative = (*setup_item)->getAnnotFile();
+    fastaIndex = (*setup_item)->getFastaIndex();
+    start = (*setup_item)->getSubSeqStart();
+    end = (*setup_item)->getSubSeqEnd();
+  
+    fs::path seqFile(seqNative, fs::native);
+    fs::path annotFile(annotNative, fs::native);
+    mussa->load_sequence(seqFile, annotFile, fastaIndex, start, end, &seqName);
+  }
+  setupInfoList.clear();
+
+  int win_size = windowEdit->value();
+  int threshold = thresholdEdit->value();
+  std::string name = analysisNameLineEdit->text().toStdString();
+  if (win_size == 0 or threshold == 0) {
+    throw mussa_load_error("must set analysis parameters");
+  } else {
+    mussa->set_name(name);
+    mussa->set_window(win_size);
+    mussa->set_threshold(threshold);
+    mussa->set_analysis_mode(Mussa::TransitiveNway);
+    //mussa->set_entropy(0); // might want to add this at some point
+    mussa->analyze();
+  }
+
+  return mussa;
 }
+