From 0c4b689c8f8540a6ab60d98c67637cdb13996ba2 Mon Sep 17 00:00:00 2001 From: Brandon King Date: Fri, 20 Apr 2007 00:29:17 +0000 Subject: [PATCH] Load saved muway and set to muways soft threshold. * Fix for ticket:257 * Updated nway code to save the soft threshold when saving. * Updated nway code to load the soft threshold when saving. * Updated MussaWindow.load code to use soft threshold loaded from muway file. * Upadted MussaWindow.load code to load properly when the window is empty to start with. * Added a reset() function to the ThresholdWidget to avoid emits * This actually didn't fix the problem (see ticket:262) * Broke the SIGNAL/SLOT loop causing multiple nways to be run, by breaking the connection from MussaWindow to ThresholdWidget while the ThresholdWidget.reset() function is called. --- alg/mussa.cpp | 2 +- alg/nway_paths.cpp | 20 ++++++++++++++++++-- qui/MussaWindow.cpp | 19 +++++++++++++++++++ qui/ThresholdWidget.cpp | 19 +++++++++++++++++-- qui/ThresholdWidget.hpp | 2 ++ 5 files changed, 57 insertions(+), 5 deletions(-) diff --git a/alg/mussa.cpp b/alg/mussa.cpp index 2fb639b..1911c5d 100644 --- a/alg/mussa.cpp +++ b/alg/mussa.cpp @@ -668,7 +668,7 @@ Mussa::load(fs::path ana_file) // us know what our threshold and window sizes were when we load a muway window = the_paths.get_window(); threshold = the_paths.get_threshold(); - soft_thres = threshold; + soft_thres = the_paths.get_soft_threshold(); //-------------------------------------------------------- diff --git a/alg/nway_paths.cpp b/alg/nway_paths.cpp index e7a8474..85ae007 100644 --- a/alg/nway_paths.cpp +++ b/alg/nway_paths.cpp @@ -173,7 +173,7 @@ NwayPaths::save(fs::path save_file_path) // add a function para new_thres defaults to -1 to later deal with // reanalysis with higher thres - if statement whether to record base thres // or new thres (ie if -1, then base) - save_file << " thres=" << threshold << " >\n"; + save_file << " thres=" << threshold << " soft_thres=" << soft_thres << " >\n"; path_i = refined_pathz.begin(); paths_end = refined_pathz.end(); @@ -258,7 +258,23 @@ NwayPaths::load(fs::path load_file_path) data = file_data_line.substr(equal_split_i+1); threshold = atoi (data.c_str()); file_data_line = file_data_line.substr(space_split_i+1); - + // get cur_threshold + //std::cout << "file_data_line: " << file_data_line << "\n"; + //std::cout << "find(\">\"): " << file_data_line.find(">") << "\n"; + if (file_data_line.find(">") != 0) + { + space_split_i = file_data_line.find(" "); + header_data = file_data_line.substr(0,space_split_i); + equal_split_i = header_data.find("="); + data = file_data_line.substr(equal_split_i+1); + soft_thres = atoi (data.c_str()); + file_data_line = file_data_line.substr(space_split_i+1); + } + else + { + soft_thres = threshold; + } + //std::cout << "nway_soft_thres: " << soft_thres << "\n"; //cout << "seq_num=" << species_num << " win=" << win_size; //cout << " thres=" << threshold << endl; diff --git a/qui/MussaWindow.cpp b/qui/MussaWindow.cpp index 2427816..80d855d 100644 --- a/qui/MussaWindow.cpp +++ b/qui/MussaWindow.cpp @@ -115,7 +115,18 @@ void MussaWindow::setAnalysis(MussaRef new_analysis) if (new_analysis != 0) { // only switch mussas if we loaded without error clear(); + //std::cout << "analysis soft: " << analysis->get_soft_threshold() + // << " new analysis soft: " << new_analysis->get_soft_threshold() + // << "\n"; analysis.swap(new_analysis); + //std::cout << "after swap soft thres: " << analysis->get_soft_threshold() + // << "\n"; + threshold->disconnect(this); + threshold->reset(analysis->get_threshold(), + analysis->get_window(), + analysis->get_soft_threshold()); + connect(threshold, SIGNAL(thresholdChanged(int)), + this, SLOT(setSoftThreshold(int))); updateTitle(); updateAnalysis(); } @@ -631,14 +642,21 @@ void MussaWindow::newMussaWindow() void MussaWindow::setSoftThreshold(int value) { + //std::cout << "Soft: " << analysis->get_soft_threshold() + // << " Value: " << value << "\n"; if (analysis->get_soft_threshold() != value) { threshold->setEnabled( false ); + //std::cout << "Updating!!!!\n"; analysis->set_soft_threshold(value); analysis->nway(); updateLinks(); update(); threshold->setEnabled( true ); } + //else + //{ + // std::cout << "NOT Updating!!!!\n"; + //} } void MussaWindow::showMussaToolbar() @@ -733,6 +751,7 @@ void MussaWindow::updateAnalysis() // but it's possible for us to not have had a chance to set out sequences // yet. threshold->setRange(analysis->get_threshold(),analysis->get_window()); + threshold->setBasepairThreshold(analysis->get_soft_threshold()); updateLinks(); browser->zoomOut(); zoom->setValue(browser->zoom()); diff --git a/qui/ThresholdWidget.cpp b/qui/ThresholdWidget.cpp index 5c85696..20fdbeb 100644 --- a/qui/ThresholdWidget.cpp +++ b/qui/ThresholdWidget.cpp @@ -10,6 +10,7 @@ ThresholdWidget::ThresholdWidget(QWidget *parent, int min, int max) : QWidget(parent), layout(0), + cur_bp_threshold(0), basepair_spinner(0), window_size_label(0), percent_label(0) @@ -43,8 +44,11 @@ void ThresholdWidget::setupWidgets() void ThresholdWidget::setRange(int min, int max) { basepair_spinner->setRange(min, max); - cur_bp_threshold = min; - basepair_spinner->setValue(min); + if (cur_bp_threshold < min || cur_bp_threshold > max) + { + cur_bp_threshold = min; + basepair_spinner->setValue(min); + } QString num; num.setNum(max); @@ -100,3 +104,14 @@ int ThresholdWidget::threshold() const { return cur_bp_threshold; } + +void ThresholdWidget::reset(int min, int max, int threshold) +{ + + cur_bp_threshold = threshold; + cur_percent_threshold = (int)(roundl(ratio() * 100)); + setRange(min, max); + basepair_spinner->setValue(threshold); + updatePercentThreshold(); + +} diff --git a/qui/ThresholdWidget.hpp b/qui/ThresholdWidget.hpp index 47a7778..42d4e3b 100644 --- a/qui/ThresholdWidget.hpp +++ b/qui/ThresholdWidget.hpp @@ -26,6 +26,8 @@ public: int threshold() const; //! update percent threshold void updatePercentThreshold(); + + void reset(int min, int max, int threshold); public slots: void setBasepairThreshold(int threshold); -- 2.30.2