threshold widget shows both base pair and percents
authorDiane Trout <diane@caltech.edu>
Tue, 28 Mar 2006 06:10:14 +0000 (06:10 +0000)
committerDiane Trout <diane@caltech.edu>
Tue, 28 Mar 2006 06:10:14 +0000 (06:10 +0000)
ticket:31 also mentioned reporting the current threshold as both
number of basepairs out of the window size and the current percentage.

alg/glseqbrowser.cpp
qui/MussaWindow.cpp
qui/ThresholdWidget.cpp
qui/ThresholdWidget.hpp

index a523ebbae6121bacd48c818b4e9dda23c520b66f..36ab95e4ada3dd4dfe902a932c391692884e0149 100644 (file)
@@ -328,7 +328,7 @@ GlSeqBrowser::link(const vector<int>& path, const vector<bool>& rc, int )
     // should i throw an error instead?
     return;
   }
-  if (path.size() != track_container.size()-1 ) {
+  if (path.size() != track_container.size() ) {
     stringstream msg;
     msg << "Path size [" << path.size() << "] and track size [" 
         << track_container.size() << "] don't match" << endl;
index 4e11f474d4418ca65e1c51f309a19a7269e250d0..6565aefbf4522b9bc1601e7b7895305c12f6748d 100644 (file)
@@ -369,7 +369,6 @@ void MussaWindow::viewMussaAlignment()
 void MussaWindow::updateAnalysis()
 {
   threshold.setRange(analysis->get_threshold(),analysis->get_window());
-  threshold.setThreshold(analysis->get_threshold());
   for (list<MussaAlignedWindow *>::iterator maw_i = aligned_windows.begin();
        maw_i != aligned_windows.end();
        ++maw_i)
index 72e5e6816d1850a0cb83ec8e1e9c700e7c2278b3..2779a208251dba075ba598875b11e23bcf6da505 100644 (file)
@@ -1,67 +1,92 @@
 #include <QHBoxLayout>
 #include <QSlider>
+#include <QString>
 
 #include "qui/ThresholdWidget.hpp"
+#include <iostream>
+#include <math.h>
 
 // This is completely and totally derived from the Qt example
 // LCDRange.cpp
 ThresholdWidget::ThresholdWidget(QWidget *parent, int min, int max) 
   : QWidget(parent)
 {
-  basepair_spinner.setRange(min, max);
+  basepair_spinner.setWhatsThis("How many base pairs need to be conserved in the window size");
+
+  setRange(min, max);
 
   connect(&basepair_spinner, SIGNAL(valueChanged(int)), 
-          this, SIGNAL(thresholdChanged(int)));
+          this, SLOT(setBasepairThreshold(int)));
+  connect(&percent_spinner, SIGNAL(valueChanged(int)),
+          this, SLOT(setPercentThreshold(int)));
 
   basepair_spinner.setValue(min);
 
   QHBoxLayout *layout = new QHBoxLayout;
   layout->addWidget(&basepair_spinner);
+  layout->addWidget(&window_size_label);
+  layout->addWidget(&percent_spinner);
+  layout->addWidget(new QLabel("%"));
   setLayout(layout);
 }
-/*
-void ThresholdWidget::setMinimumThreshold(int min)
-{
-  basepair_spinner->setMinimum(min);
-}
 
-int ThresholdWidget::getMinimumThreshold()
+void ThresholdWidget::setRange(int min, int max)
 {
-  return basepair_spinner->minimum();
-}
+  basepair_spinner.setRange(min, max);
+  cur_bp_threshold = min;
+  basepair_spinner.setValue(min);
 
-void ThresholdWidget::setMaximumThreshold(int max)
-{
-  basepair_spinner->setMaximum(max);
+  QString num;
+  num.setNum(max);
+  window_size_label.setText("/"+num);
+  int min_percent =(int)fmaxl(0.0, roundl(min_ratio()*100));
+  cur_percent_threshold = min_percent;
+  percent_spinner.setRange( min_percent, 100);
+  if (min_percent != 0.0) {
+    percent_spinner.setSingleStep((int)(roundl(1.0/(double)(max)*100.0)));
+  }
+  percent_spinner.setValue(min_percent);
 }
 
-int ThresholdWidget::getMaximumThreshold()
-{
-  return basepair_spinner->maximum();
-}
-*/
-void ThresholdWidget::setRange(int min, int max)
+double ThresholdWidget::min_ratio() const
 {
-  basepair_spinner.setRange(min, max);
+  double ratio=((double)basepair_spinner.minimum()/
+                (double)basepair_spinner.maximum());
+
+  return ratio;
 }
 
-float ThresholdWidget::percent() const
+double ThresholdWidget::ratio() const
 {
   return ((float)threshold())/((float)basepair_spinner.maximum()); 
 }
 
-void ThresholdWidget::setThreshold(int threshold)
+void ThresholdWidget::setBasepairThreshold(int threshold)
 {
 if (basepair_spinner.value() != threshold)
if (cur_bp_threshold!= threshold)
   {
+    cur_bp_threshold = threshold;
+    cur_percent_threshold = (int)(roundl(ratio() * 100));
     basepair_spinner.setValue(threshold);
+    percent_spinner.setValue(cur_percent_threshold);
     emit thresholdChanged(threshold);
   }
 }
 
-int ThresholdWidget::threshold() const
+void ThresholdWidget::setPercentThreshold(int percent_threshold)
 {
-  return basepair_spinner.value();
+  if (cur_percent_threshold != percent_threshold)
+  {
+    cur_percent_threshold = percent_threshold;
+    long t=roundl(basepair_spinner.maximum()*((float)percent_threshold/100.0));
+    cur_bp_threshold = (int)t;
+    percent_spinner.setValue(percent_threshold);
+    basepair_spinner.setValue(cur_bp_threshold);
+    emit thresholdChanged(cur_bp_threshold);
+  }
 }
 
-
+int ThresholdWidget::threshold() const
+{
+  return cur_bp_threshold;
+}
index eed7ee812adf2fe12f279785ccb0597730b07461..1e00c12b8dd4c0ed734e7c8a00d7702efeaf6750 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef _THRESHOLD_WIDGET_H_ 
 #define _THRESHOLD_WIDGET_H_
 
+#include <QLabel>
 #include <QSpinBox>
 #include <QWidget>
 
@@ -9,23 +10,32 @@ class ThresholdWidget : public QWidget
   Q_OBJECT 
 
 public: 
-  ThresholdWidget(QWidget *parent = 0, int min=21, int max=30);
+  ThresholdWidget(QWidget *parent = 0, int min=20, int max=30);
 
-  //! return what percent of our maximum threshold we are.
-  float percent() const;
+  //! return min_threshold/max_threshold
+  double min_ratio() const;
+  //! return current_threshold/maximum_threshold
+  double ratio() const;
   //! return our current threshold
   int threshold() const;
 
 public slots:
-  void setThreshold(int threshold);
+  void setBasepairThreshold(int threshold);
+  void setPercentThreshold(int percent_threshold);
+  //! set the min and max base pair range
   void setRange(int min, int max);
 
 signals:
+  //! the current number of base pairs needed for a window of conservation
   void thresholdChanged(int new_threshold);
 
 protected:
   QSpinBox basepair_spinner;
+  QLabel window_size_label;
+  QSpinBox percent_spinner;
 
+  int cur_bp_threshold;
+  int cur_percent_threshold;
 };
 const int threshold_max_display_digits = 2;