Allow MussaAlignedWindows to create subanalyses
authorDiane Trout <diane@caltech.edu>
Tue, 3 Oct 2006 01:14:56 +0000 (01:14 +0000)
committerDiane Trout <diane@caltech.edu>
Tue, 3 Oct 2006 01:14:56 +0000 (01:14 +0000)
I passed a shared_ptr reference for the subanalysis window
from MussaWindow to MussaAlignedWindow so either window can be used
to customize the same subanalysis.

qui/MussaAlignedWindow.cpp
qui/MussaAlignedWindow.hpp
qui/MussaWindow.cpp
qui/MussaWindow.hpp
qui/SubanalysisWindow.hpp

index 65e3d7bf27df26328a92692ab7efbb2ecc1055e8..4c917c45da40a8d653d72aba3c3d00b3695e7638 100644 (file)
@@ -14,9 +14,11 @@ using namespace std;
 
 MussaAlignedWindow::MussaAlignedWindow(MussaRef m, 
                                        const set<int>& sel_paths,
+                                       SubanalysisWindowRef window, 
                                        QWidget *parent)
   : QMainWindow(parent),
     analysis(m),
+    subanalysis_window(window),
     pick_align_menu(tr("Choose Alignment")),
     view_align_menu(tr("View Alignment")),
     zoom(0),
@@ -50,6 +52,11 @@ MussaAlignedWindow::MussaAlignedWindow(MussaRef m,
 
 void MussaAlignedWindow::setupActions()
 {
+  // more cut-n-paste from MussaWindow
+  createSubAnalysisAction = new QAction(tr("Add to Subanalysis"), this);
+  connect(createSubAnalysisAction, SIGNAL(triggered()), 
+          this, SLOT(createSubAnalysis()));
+            
   //Save pixel map action
   saveBrowserPixmapAction = new QAction(tr("Save to image..."), this);
   connect(saveBrowserPixmapAction, (SIGNAL(triggered())),
@@ -64,6 +71,13 @@ void MussaAlignedWindow::setupMenus()
 
   newMenu = menuBar()->addMenu(tr("&Edit"));
   newMenu->addAction(browser.getCopySelectedSequenceAsFastaAction());
+  newMenu->addAction(createSubAnalysisAction);
+  
+  // add some extra features to the context menu
+  QMenu *popupMenu = browser.getPopupMenu();
+  if (popupMenu) {
+    popupMenu->addAction(createSubAnalysisAction);
+  }  
 }
 
 void MussaAlignedWindow::setupAlignmentMenus()
@@ -137,6 +151,25 @@ void MussaAlignedWindow::setSelectedPaths(MussaRef m, const set<int>& sel_paths)
   }
 }
 
+// FIXME: this is a cut-n-paste from MussaWindow, perhaps they should be refactored to
+// some shared place
+void MussaAlignedWindow::createSubAnalysis()
+{
+  list<SequenceLocation> result;
+  SequenceLocationModel& model = subanalysis_window->getModel();
+  browser.copySelectedTracksAsSeqLocation(result);
+  for(list<SequenceLocation>::iterator result_itor = result.begin();
+      result_itor != result.end();
+      ++result_itor)
+  {
+    model.push_back(*result_itor);
+  }
+
+  if (not subanalysis_window->isVisible()) {
+    subanalysis_window->show();
+  }
+}
+
 void MussaAlignedWindow::setAlignment(int alignment_index)
 {
   if (selected_paths.size() > 0) {
index c4715f9106732cd9afc17d46a50e6532d9142ef0..452ac0e5bea391e48ba588a0a69d391833e8cd08 100644 (file)
@@ -12,6 +12,7 @@
 #include "qui/IntAction.hpp"
 #include "qui/ZoomWidget.hpp"
 #include "qui/seqbrowser/SequenceBrowserWidget.hpp"
+#include "qui/SubanalysisWindow.hpp"
 
 //! Show sequence alignments
 class MussaAlignedWindow : public QMainWindow
@@ -22,11 +23,16 @@ public:
   //! construct an aligned window for an analysis and selected paths
   /*! \param analysis is a shared_ptr to a mussa analysis 
    *  \param paths is a set of "paths" AKA integer offsets into the sequences stored in mussa
+   *  \param window points to a SubanalysisWindowRef, so we can pick interesting
+   *         sequence portions from both the mussa window and the sequence view window
    *  \param parent is the typical Qt pointer to a parent widget
    */ 
-  MussaAlignedWindow(MussaRef analysis, const std::set<int>& paths, QWidget *parent=0);
+  MussaAlignedWindow(MussaRef analysis, const std::set<int>& paths, 
+                     SubanalysisWindowRef window, QWidget *parent=0);
 
 public slots:
+  //! launch a sub analysis
+  void createSubAnalysis();
   //! use selected_paths[pathid] to set the starting position of our sequence
   void setAlignment(int pathid);
   //! toggle whether or not to show the aligned basepairs of a window
@@ -51,10 +57,12 @@ protected:
   //const std::set<int>& selected_paths;
   std::vector<ConservedPath> selected_paths;
   std::vector<bool> view_paths;
+  SubanalysisWindowRef subanalysis_window;
   SequenceBrowserWidget browser;
   QMenu pick_align_menu;
   QMenu view_align_menu;
 
+  QAction *createSubAnalysisAction;
   QAction *saveBrowserPixmapAction;
 
   std::vector <IntAction *> pick_actions;
@@ -62,4 +70,7 @@ protected:
   ZoomWidget *zoom;
   QToolBar *alignTB;
 };
+
+//! reference to a MussaAlignedWindow
+typedef boost::shared_ptr<MussaAlignedWindow> MussaAlignedWindowRef;
 #endif
index cb3c2ce9295bc09daec97e4878e8d4f41c377420..01702309e1938aaa0bedd697ab6ecf55c33640b0 100644 (file)
@@ -608,8 +608,8 @@ void MussaWindow::viewMussaAlignment()
                          QObject::tr("you should probably select some paths "
                                      "first"));
   } else {
-    boost::shared_ptr<MussaAlignedWindow> ma_win( 
-      new MussaAlignedWindow(analysis, selected_paths)
+    MussaAlignedWindowRef ma_win( 
+      new MussaAlignedWindow(analysis, selected_paths, subanalysis_window)
     );
 
     aligned_windows.push_back(ma_win);
index ed34adb5fe7647d5a219e6b688f9792bc2887b08..8371c66473823b2d64b5ae64944cb2815b24a74f 100644 (file)
@@ -102,7 +102,7 @@ protected:
   std::list<boost::shared_ptr<MussaAlignedWindow> > aligned_windows;
   MotifEditor *motif_editor;
   MussaSetupDialog *setup_analysis_dialog;
-  boost::shared_ptr<SubanalysisWindow> subanalysis_window;
+  SubanalysisWindowRef subanalysis_window;
 
   // display our wonderful mussa output
   SequenceBrowserWidget *browser;
index ce141e8f689b854d6b9844c0c56a0c207ab9ee95..0bf32949c8f489ce82c5857c164a7f4531bbd8b6 100644 (file)
@@ -36,4 +36,7 @@ private:
 
   SequenceLocationModel model;
 };
+
+//! reference to a subanalysis window
+typedef boost::shared_ptr<SubanalysisWindow> SubanalysisWindowRef;
 #endif