Update mussa to build on ubuntu 10.04 with qt 4.6.2 +boost 1.40.0.1
[mussa.git] / qui / MussaAlignedWindow.cpp
index f418b02e8e7626e088030e4ff513153a90a0b8f4..7e4246dfb79509db70a90d15dd275605d9e4646e 100644 (file)
 #include <iostream>
 using namespace std;
 
-MussaAlignedWindow::MussaAlignedWindow(Mussa& m, 
-                                       const set<int>& sel_paths, 
+MussaAlignedWindow::MussaAlignedWindow(MussaRef m,
+                                       boost::shared_ptr<QDir> default_dir_,
+                                       const set<int>& sel_paths,
+                                       SubanalysisWindowRef window, 
                                        QWidget *parent)
   : QMainWindow(parent),
     analysis(m),
+    default_dir(default_dir_),
+    subanalysis_window(window),
+    browser(default_dir),
     pick_align_menu(tr("Choose Alignment")),
     view_align_menu(tr("View Alignment")),
+    threshold_widget(0),
     zoom(0),
     alignTB(0)
 {
   setupActions();
-  browser.setSequences(analysis.sequences(), analysis.colorMapper());
-  setSelectedPaths(m, sel_paths);
+  connect(&browser, SIGNAL(basepairsCopied(size_t)), 
+          this, SLOT(showBasePairsCopied(size_t)));
+  browser.setSequences(analysis->sequences(), analysis->colorMapper());
+  setSelectedPaths(analysis, sel_paths);
   setAlignment(0);
   double zoom_level = browser.zoomToSequence();
 
@@ -32,24 +40,43 @@ MussaAlignedWindow::MussaAlignedWindow(Mussa& m,
   connect(zoom, SIGNAL(valueChanged(double)), 
           &browser, SLOT(setZoom(double)));
   zoom->setValue(zoom_level);
+  
+  // Mouse scroll wheel zooming!
+  connect(&browser, SIGNAL(mouseWheelZoom(double)),
+                 zoom, SLOT(setValue(double)));
+  
   computeMatchLines();
   setupMenus();
   setupAlignmentMenus();
   
   setCentralWidget(&browser);
 
+  // Add a threhold widget set to our current threshold and make it readonly 
+  threshold_widget = new ThresholdWidget;
+  threshold_widget->setRange(analysis->get_threshold(),analysis->get_window());
+  threshold_widget->setBasepairThreshold(analysis->get_soft_threshold());
+  threshold_widget->setReadOnly(true);
+  
   alignTB = new QToolBar();
   alignTB->addWidget(zoom);
+  alignTB->addWidget(threshold_widget);
   addToolBar(alignTB);
   
   ostringstream message;
   message << "Selected " << selected_paths.size() << " paths";
   statusBar()->showMessage(message.str().c_str(), 5000);
   browser.updatePosition();
+  
+  updateTitle();
 }
 
 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())),
@@ -63,7 +90,15 @@ void MussaAlignedWindow::setupMenus()
   newMenu->addAction(saveBrowserPixmapAction);
 
   newMenu = menuBar()->addMenu(tr("&Edit"));
+  newMenu->addAction(browser.getCopySelectedSequenceAsStringAction());
   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()
@@ -107,13 +142,13 @@ void MussaAlignedWindow::setupAlignmentMenus()
 }
 
 
-void MussaAlignedWindow::setSelectedPaths(Mussa &m, const set<int>& sel_paths)
+void MussaAlignedWindow::setSelectedPaths(MussaRef m, const set<int>& sel_paths)
 {
   // sets are sorted
   set<int>::iterator sel_i = sel_paths.begin();
-  list<ConservedPath>::const_iterator path_i = m.paths().refined_pathz.begin();
-  list<ConservedPath>::const_iterator path_end = m.paths().refined_pathz.end();
-  size_t path_size = m.paths().refined_pathz.size();
+  list<ConservedPath>::const_iterator path_i = m->paths().refined_pathz.begin();
+  list<ConservedPath>::const_iterator path_end = m->paths().refined_pathz.end();
+  size_t path_size = m->paths().refined_pathz.size();
   size_t pathid=0;
 
   selected_paths.reserve(sel_paths.size());
@@ -137,6 +172,25 @@ void MussaAlignedWindow::setSelectedPaths(Mussa &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) {
@@ -144,6 +198,15 @@ void MussaAlignedWindow::setAlignment(int alignment_index)
   }
 }
 
+void MussaAlignedWindow::showBasePairsCopied(size_t bp_copied)
+{
+  QString msg("Copied ");
+  QString num;
+  num.setNum(bp_copied);
+  msg += num + " base pairs";
+  statusBar()->showMessage(msg, 5000);
+}
+
 void MussaAlignedWindow::toggleViewAlignment(int alignment_index)
 {
   view_paths[alignment_index]= not view_paths[alignment_index]; 
@@ -158,6 +221,15 @@ void MussaAlignedWindow::update()
   browser.update();
 }
 
+void MussaAlignedWindow::updateTitle()
+{
+  std::string title("Sequence View: ");
+  if (analysis) {
+    title += analysis->get_title();
+  }
+  setWindowTitle(title.c_str());
+}
+
 void MussaAlignedWindow::computeMatchLines()
 {
   browser.clear_links();
@@ -175,10 +247,10 @@ void MussaAlignedWindow::computeMatchLines()
     if (view_paths[count]) 
       filtered_paths.push_back(*path_i);
   }
-  analysis.createLocalAlignment(filtered_paths.begin(), 
-                                filtered_paths.end(),
-                                result, 
-                                reversed);
+  analysis->createLocalAlignment(filtered_paths.begin(), 
+                                 filtered_paths.end(),
+                                 result, 
+                                 reversed);
 
   list<ConservedPath::path_type>::const_iterator result_i = result.begin();
   list<vector<bool> >::const_iterator reversed_i = reversed.begin();