finish dialog box to setup an analysis
authorDiane Trout <diane@caltech.edu>
Wed, 22 Mar 2006 04:05:04 +0000 (04:05 +0000)
committerDiane Trout <diane@caltech.edu>
Wed, 22 Mar 2006 04:05:04 +0000 (04:05 +0000)
Closes ticket:5 (though I'm sure it'll introduce some new tickets).

this gets the dialog box brandon coded working so you can now setup an
analysis from the gui.

I think this finishes everything tristan's mussa had, and I think it took
5 weeks instead of the 3-4 estimated.

alg/sequence.cpp
qui/MussaWindow.cpp
qui/MussaWindow.hpp
qui/mussa_setup_dialog/MussaSetupDialog.cpp
qui/mussa_setup_dialog/MussaSetupWidget.cpp
qui/mussa_setup_dialog/MussaSetupWidget.hpp
qui/mussa_setup_dialog/SequenceSetupWidget.cpp
qui/mussa_setup_dialog/SequenceSetupWidget.hpp

index d7bf864bb984fc8abe712ed11d582a62d37b8896..4e0b4789e81784bbfbb7200ebda4d7e2078e846f 100644 (file)
@@ -116,6 +116,9 @@ Sequence::load_fasta(string file_path, int seq_num,
 
   data_file.open(file_path.c_str(), ios::in);
 
+  if (seq_num == 0) {
+    throw mussa_load_error("fasta sequence number is 1 based (can't be 0)");
+  }
   if (!data_file)
   {    
     throw mussa_load_error("Sequence File: " + file_path + " not found"); 
index b2c2a0811c8872c7d262a5de9067c7091384b13d..01b13ea974f565bd658310141fab049754f865ab 100644 (file)
@@ -71,6 +71,16 @@ MussaWindow::MussaWindow(Mussa *analysis_, QWidget *parent) :
   updateAnalysis();
 }
 
+void MussaWindow::setAnalysis(Mussa *new_analysis)
+{
+  if (new_analysis != 0) {
+    // only switch mussas if we loaded without error
+    delete analysis;
+    analysis = new_analysis;
+    updateAnalysis();
+  }
+}
+
 void MussaWindow::setupActions()
 {
   // we really don't want to run this more than once.
@@ -195,28 +205,22 @@ void MussaWindow::about()
    msg += (char *)glGetString(GL_VERSION);
    msg += "\n";
    QMessageBox::about(this, tr("About mussa"), msg);
-   /*
-                      tr("Welcome to Multiple Species Sequence Analysis\n"
-              "(c) 2005-2006 California Institute of Technology\n"
-              "Tristan De Buysscher, Diane Trout\n"));
-  */
-
 }
 
 void MussaWindow::createNewAnalysis()
 {
   MussaSetupDialog *msd = new MussaSetupDialog(this);
-  if (msd->exec())
-  {
-    std::cout << "New mussa exp. defined!\n";
-    Mussa *m = 0;
-    m = msd->getMussa();
-    std::cout << " Mussa Object at: " << m << "\n";
-    delete m;
-  }
-  else
-  {
-    std::cout << "New mussa exp. aborted!\n";
+  try {
+    if (msd->exec()) {
+      Mussa *m = 0;
+      m = msd->getMussa();
+      setAnalysis(m);
+    } else {
+      std::cout << "New mussa exp. aborted!\n";
+    }
+  } catch(mussa_error e) {
+    QString msg(e.what());
+    QMessageBox::warning(this, tr("Create New Analysis"), msg);
   }
   delete msd;
 }
@@ -283,10 +287,7 @@ void MussaWindow::loadMupa()
     Mussa *m = new Mussa;
     m->load_mupa_file(mupa_path.toStdString());
     m->analyze(0, 0, Mussa::TransitiveNway, 0.0);
-    // only switch mussas if we loaded without error
-    delete analysis;
-    analysis = m;
-    updateAnalysis();
+    setAnalysis(m);
   } catch (mussa_load_error e) {
     QString msg("Unable to load ");
     msg += mupa_path;
@@ -311,9 +312,7 @@ void MussaWindow::loadSavedAnalysis()
     Mussa *m = new Mussa;
     m->load(muway_dir.toStdString());
     // only switch mussas if we loaded without error
-    delete analysis;
-    analysis = m;
-    updateAnalysis();
+    setAnalysis(m);
   } catch (mussa_load_error e) {
     QString msg("Unable to load ");
     msg += muway_dir;
index 0d5f4127b2cc59a36ea3881987de043e5f4bf787..ac8282073d324c5e50438ce560625d0466206648 100644 (file)
@@ -24,6 +24,8 @@ class MussaWindow : public QMainWindow
 public: 
   MussaWindow(Mussa* analysis=0, QWidget *parent=0);
 
+  //! switch to a new analysis
+  void setAnalysis(Mussa *new_analysis);
 public slots:
   //! display an about box, contemplating the politics of the author list
   void about();
index 9bd234d100d053576b0ce8bc472ee4d681afcd5b..c4d5fbb774f7e3145a8a46e8ec5a3466f00b1c48 100644 (file)
@@ -17,7 +17,6 @@ MussaSetupDialog::MussaSetupDialog(QWidget *parent, Qt::WFlags f)
          this, SLOT(accept()));
   connect(setupWidget, SIGNAL(cancelButtonPushed()),
          this, SLOT(reject()));
-                             
 
   QVBoxLayout *layout = new QVBoxLayout;
   
index e896e538db653f748bc49b56e6808ae679df629d..79f05842d96290b4f933858d0aecca6446bc49e0 100644 (file)
@@ -8,61 +8,53 @@
 
 #include <list>
 
+using namespace std;
+
 //#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),
-    numOfSequencesSpinBox(0),
-    createPushButton(0),
-    cancelPushButton(0),
+    createPushButton(tr("Create")),
+    cancelPushButton(tr("Cancel")),
     seqSetupFrame(0)
 {
   
   // Analysis name
-  analysisNameLineEdit = new QLineEdit;
   QLabel *analysisNameLabel = new QLabel(tr("Analysis Name"));
-  analysisNameLabel->setBuddy(analysisNameLineEdit);
+  analysisNameLabel->setBuddy(&analysisNameLineEdit);
 
   // Window
-  windowLineEdit = new QLineEdit;
   QLabel *windowLabel = new QLabel(tr("Window"));
-  windowLabel->setBuddy(windowLineEdit);
+  windowLabel->setBuddy(&windowLineEdit);
 
   // Threshold
-  thresholdLineEdit = new QLineEdit;
   QLabel *thresholdLabel = new QLabel(tr("Threshold"));
-  thresholdLabel->setBuddy(thresholdLineEdit);
+  thresholdLabel->setBuddy(&thresholdLineEdit);
 
   // Number of sequences
-  numOfSequencesSpinBox = new QSpinBox;
   QLabel *numOfSequencesLabel = new QLabel(tr("Number of sequences"));
-  numOfSequencesLabel->setBuddy(numOfSequencesSpinBox);
-  numOfSequencesSpinBox->setMinimum(1);
-
+  numOfSequencesLabel->setBuddy(&numOfSequencesSpinBox);
+  numOfSequencesSpinBox.setMinimum(1);
 
   //Sequence setup frame
   seqSetupFrame = new SequenceSetupFrame;
 
-  connect(numOfSequencesSpinBox, SIGNAL(valueChanged(int)),
+  connect(&numOfSequencesSpinBox, SIGNAL(valueChanged(int)),
          seqSetupFrame, SLOT(changeSequenceCount(int)));
 
-  numOfSequencesSpinBox->setValue(1);
+  numOfSequencesSpinBox.setValue(2);
 
   // Create Experiment Button
-  createPushButton = new QPushButton(tr("Create"));
-  connect(createPushButton, SIGNAL(pressed()),
+  connect(&createPushButton, SIGNAL(pressed()),
          this, SLOT(mussaCreatePushed()));
   
   // Cancle Button
-  cancelPushButton = new QPushButton(tr("Cancel"));
-  connect(cancelPushButton, SIGNAL(pressed()),
+  connect(&cancelPushButton, SIGNAL(pressed()),
          this, SLOT(mussaCancelPushed()));
 
   // LAYOUT
@@ -72,17 +64,17 @@ MussaSetupWidget::MussaSetupWidget(QWidget *parent)
   QHBoxLayout *buttonLayout = new QHBoxLayout;
 
   row1Layout->addWidget(analysisNameLabel);
-  row1Layout->addWidget(analysisNameLineEdit);
+  row1Layout->addWidget(&analysisNameLineEdit);
 
   row2Layout->addWidget(windowLabel);
-  row2Layout->addWidget(windowLineEdit);
+  row2Layout->addWidget(&windowLineEdit);
   row2Layout->addWidget(thresholdLabel);
-  row2Layout->addWidget(thresholdLineEdit);
+  row2Layout->addWidget(&thresholdLineEdit);
   row2Layout->addWidget(numOfSequencesLabel);
-  row2Layout->addWidget(numOfSequencesSpinBox);
+  row2Layout->addWidget(&numOfSequencesSpinBox);
 
-  buttonLayout->addWidget(createPushButton);
-  buttonLayout->addWidget(cancelPushButton);
+  buttonLayout->addWidget(&createPushButton);
+  buttonLayout->addWidget(&cancelPushButton);
 
   mainLayout->addLayout(row1Layout);
   mainLayout->addLayout(row2Layout);
@@ -105,8 +97,6 @@ void MussaSetupWidget::mussaCancelPushed()
 Mussa* MussaSetupWidget::getMussaObject()
 {
   Mussa *mussa = new Mussa;
-  
-  
 
   std::string seqFile;
   std::string annotFile;
@@ -114,27 +104,29 @@ Mussa* MussaSetupWidget::getMussaObject()
   int start;
   int end;
 
-  std::list<SetupInfo *> setupInfoList = seqSetupFrame->getSetupInfo();
+  list<SetupInfo *> setupInfoList = seqSetupFrame->getSetupInfo();
   
-  const int count = setupInfoList.size();
-  
-  SetupInfo *setupInfo = 0;
-  for (int i=0; i < count; i++)
+  for (list<SetupInfo *>::iterator setup_item = setupInfoList.begin();
+       setup_item != setupInfoList.end();
+       ++setup_item)
   {
-    setupInfo = setupInfoList.back();
-    setupInfoList.pop_back();
-
-    seqFile = setupInfo->getSeqFile();
-    annotFile = setupInfo->getAnnotFile();
-    fastaIndex = setupInfo->getFastaIndex();
-    start = setupInfo->getSubSeqStart();
-    end = setupInfo->getSubSeqEnd();
-    
+    seqFile = (*setup_item)->getSeqFile();
+    annotFile = (*setup_item)->getAnnotFile();
+    fastaIndex = (*setup_item)->getFastaIndex();
+    start = (*setup_item)->getSubSeqStart();
+    end = (*setup_item)->getSubSeqEnd();
+   
     mussa->load_sequence(seqFile, annotFile, fastaIndex, start, end);
-    delete setupInfo;
   }
-
-  mussa->analyze(0, 0, Mussa::TransitiveNway, 0.0);
+  setupInfoList.clear();
+
+  int win_size = windowLineEdit.text().toInt();
+  int threshold = thresholdLineEdit.text().toInt();
+  if (win_size == 0 or threshold == 0) {
+    throw mussa_load_error("must set analysis parameters");
+  } else {
+    mussa->analyze(win_size, threshold, Mussa::TransitiveNway, 0.0);
+  }
 
   return mussa;
 }
index 4ced62bfdfd59ee5c20e32b4c5a56599e924b2fe..6244b20cf49a015fd4508848724e14d8649480fc 100644 (file)
@@ -2,11 +2,10 @@
 #define _MUSSA_SETUP_WIDGET_H_
 
 #include <QWidget>
+#include <QLineEdit>
+#include <QSpinBox>
+#include <QPushButton>
 
-//class QFrame;
-class QLineEdit;
-class QSpinBox;
-class QPushButton;
 class SequenceSetupFrame;
 
 class Mussa;
@@ -31,12 +30,12 @@ private slots:
 
 private:
 
-  QLineEdit *analysisNameLineEdit;
-  QLineEdit *windowLineEdit;
-  QLineEdit *thresholdLineEdit;
-  QSpinBox *numOfSequencesSpinBox;
-  QPushButton *createPushButton;
-  QPushButton *cancelPushButton;
+  QLineEdit analysisNameLineEdit;
+  QLineEdit windowLineEdit;
+  QLineEdit thresholdLineEdit;
+  QSpinBox numOfSequencesSpinBox;
+  QPushButton createPushButton;
+  QPushButton cancelPushButton;
 
   SequenceSetupFrame *seqSetupFrame;
 };
index 731b41b003d6513d2d7e036021767c1fc580cba0..524260f76de4a0f8f33c5ba4e2738bcdd3e3d89a 100644 (file)
@@ -97,6 +97,14 @@ SequenceSetupWidget::SequenceSetupWidget(QWidget *parent) :
 //{
 //}
 
+int SequenceSetupWidget::getFastaIndex() const
+{
+  if (fastaIndexLineEdit->text().size() == 0)
+    return 1;
+  else
+    return fastaIndexLineEdit->text().toInt(); 
+}
+
 void SequenceSetupWidget::promptForFastaFile()
 {
   QString fastaFilePath = QFileDialog::getOpenFileName(this,
index 0998c6621604c06e404db990bf066c78e93e6da0..2c99ba2fc29e806d945bad4fc31e3822cc613b0e 100644 (file)
@@ -13,11 +13,11 @@ public:
   SequenceSetupWidget(QWidget *parent = 0);
   //  SequenceSetupWidget(const SequenceSetupWidget&);
 
-  QString getSeqFile() { return sequenceLineEdit->text(); }
-  QString getAnnotFile() { return annotLineEdit->text(); }
-  int getFastaIndex() { return fastaIndexLineEdit->text().toInt(); }
-  int getStart() { return seqStartLineEdit->text().toInt(); }
-  int getEnd() { return seqStopLineEdit->text().toInt(); }
+  QString getSeqFile() const { return sequenceLineEdit->text(); }
+  QString getAnnotFile() const { return annotLineEdit->text(); }
+  int getFastaIndex() const;
+  int getStart() const { return seqStartLineEdit->text().toInt(); }
+  int getEnd() const { return seqStopLineEdit->text().toInt(); }
   
 
 public slots: