Skip to content

Commit

Permalink
Merge pull request #2 from jpfeuffer/gui/proteintable
Browse files Browse the repository at this point in the history
Fixes, cleanups and todos
  • Loading branch information
dhanmoni authored Aug 12, 2021
2 parents 232f491 + a066019 commit ac65701
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 116 deletions.
2 changes: 1 addition & 1 deletion src/openms_gui/include/OpenMS/VISUAL/DataSelectionTabs.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace OpenMS
/// Tabs which have data to show are automatically enabled. Others are disabled.
/// If the currently visible tab would have to data to show, we pick the highest (rightmost) tab
/// which has data and show that instead
void update();
void callUpdateEntries();

/// invoked when user changes the active tab to @p tab_index
void currentTabChanged(int tab_index);
Expand Down
47 changes: 40 additions & 7 deletions src/openms_gui/include/OpenMS/VISUAL/SequenceVisualizer.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
// --------------------------------------------------------------------------
// OpenMS -- Open-Source Mass Spectrometry
// --------------------------------------------------------------------------
// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
// ETH Zurich, and Freie Universitaet Berlin 2002-2021.
//
// This software is released under a three-clause BSD license:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of any author or any participating institution
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
// For a full list of authors, refer to the file AUTHORS.
// --------------------------------------------------------------------------
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// --------------------------------------------------------------------------
// $Maintainer: Julianus Pfeuffer $
// $Authors: Dhanmoni Nath, Julianus Pfeuffer $
// --------------------------------------------------------------------------

#ifdef QT_WEBENGINEWIDGETS_LIB
#pragma once

// OpenMS_GUI config
Expand All @@ -6,9 +41,6 @@
#include <QWidget>
#include <QJsonObject>

#include <unordered_map>
#include <vector>

namespace Ui
{
class SequenceVisualizer;
Expand All @@ -23,15 +55,16 @@ namespace OpenMS
Q_PROPERTY(QJsonObject json_data_obj MEMBER m_json_data_obj)

public:
SequenceVisualizer(QWidget* parent = nullptr);
~SequenceVisualizer();
explicit SequenceVisualizer(QWidget* parent = nullptr);
~SequenceVisualizer() override;

public slots:

void setProteinPeptideDataToJsonObj(QString accession_num, QString pro_seq, QJsonArray peptides_data, QJsonArray pep_mod_data);
void setProteinPeptideDataToJsonObj(const QString& accession_num, const QString& pro_seq, const QJsonArray& peptides_data, const QJsonArray& pep_mod_data);

private:
Ui::SequenceVisualizer* ui;
QJsonObject m_json_data_obj;
};
}// namespace OpenMS
}// namespace OpenMS
#endif
11 changes: 4 additions & 7 deletions src/openms_gui/include/OpenMS/VISUAL/SpectraIDViewTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,20 @@ namespace OpenMS

private:
/// partially fill the bottom-most row
void fillRow_(const MSSpectrum& spectrum, const int spec_index, const QColor background_color);
void fillRow_(const MSSpectrum& spectrum, const int spec_index, const QColor& background_color);
// extract the required part of the accession
QString extractNumFromAccession_(QString listItem);
static static QString extractNumFromAccession_(const QString& listItem);
//open browser to navigate to uniport site with accession
void openUniProtSiteWithAccession_(QString accession);
void openUniProtSiteWithAccession_(const QString& accession);

LayerData* layer_ = nullptr;
QCheckBox* hide_no_identification_ = nullptr;
QCheckBox* create_rows_for_commmon_metavalue_ = nullptr;
TableView* table_widget_ = nullptr;
TableView* protein_table_widget_ = nullptr;
QTableWidget* fragment_window_ = nullptr;
QWidget* protein_window_ = nullptr;
QWidget* accession_window_ = nullptr;
bool is_ms1_shown_ = false;
bool is_first_time_loading = true;
std::unordered_map<String, std::vector<PeptideIdentification>> protein_to_peptide_id_map;
std::unordered_map<String, std::vector<const PeptideIdentification*>> protein_to_peptide_id_map;
private slots:
/// Saves the (potentially filtered) IDs as an idXML or mzIdentML file
void saveIDs_();
Expand Down
7 changes: 6 additions & 1 deletion src/openms_gui/include/OpenMS/VISUAL/SpectraTreeTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ namespace OpenMS
/// @param current_type Either DT_PEAK or DT_CHROMATOGRAM, depending on what is currently shown
bool getSelectedScan(MSExperiment& exp, LayerData::DataType& current_type) const;

/// received focus e.g. through tabswitching
void updateIndexFromCurrentLayer();

signals:
void spectrumSelected(int);
void chromsSelected(std::vector<int> indices);
Expand All @@ -92,13 +95,15 @@ namespace OpenMS
QLineEdit* spectra_search_box_ = nullptr;
QComboBox* spectra_combo_box_ = nullptr;
TreeView* spectra_treewidget_ = nullptr;
LayerData* layer_ = nullptr;
/// cache to store mapping of chromatogram precursors to chromatogram indices
std::map<size_t, std::map<Precursor, std::vector<Size>, Precursor::MZLess> > map_precursor_to_chrom_idx_cache_;
/// remember the last PeakMap that we used to fill the spectra list (and avoid rebuilding it)
const PeakMap* last_peakmap_ = nullptr;

private slots:
/// fill the search-combo-box with current column header names

/// fill the search-combo-box with current column header names
void populateSearchBox_();
/// searches for rows containing a search text (from spectra_search_box_); called when text search box is used
void spectrumSearchText_();
Expand Down
3 changes: 2 additions & 1 deletion src/openms_gui/source/VISUAL/APPLICATIONS/TOPPViewBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2022,7 +2022,8 @@ namespace OpenMS
{
return;
}
selection_view_->currentTabChanged(1); //switch to ID view
selection_view_->setCurrentIndex(DataSelectionTabs::IDENT_IDX); //switch to ID view
selection_view_->currentTabChanged(DataSelectionTabs::IDENT_IDX);
}

void TOPPViewBase::annotateWithOSW()
Expand Down
16 changes: 12 additions & 4 deletions src/openms_gui/source/VISUAL/DataSelectionTabs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace OpenMS

// called externally
// and internally by signals
void DataSelectionTabs::update()
void DataSelectionTabs::callUpdateEntries()
{
// prevent infinite loop when calling 'setTabEnabled' -> currentTabChanged() -> update()
this->blockSignals(true);
Expand Down Expand Up @@ -151,7 +151,6 @@ namespace OpenMS
Size current_index = currentIndex();
// update the currently visible tab (might be disabled if no data is shown)
tab_ptrs_[current_index]->updateEntries(layer_ptr);
this->update(); // not sure if necessary. Should update itself if changes occurred.
}

void DataSelectionTabs::currentTabChanged(int tab_index)
Expand All @@ -167,9 +166,13 @@ namespace OpenMS
case IDENT_IDX:
spectraview_controller_->deactivateBehavior();
diatab_controller_->deactivateBehavior();
if (tv_->getActive2DWidget()) // currently 2D window is open
std::cout << "trying to switch to Ident tab" << std::endl;
if (tv_->getActive2DWidget()) // currently, 2D window is open
{
std::cout << "2D was open" << std::endl;
idview_controller_->showSpectrumAsNew1D(0);
} else {
std::cout << "2D was NOT open" << std::endl;
}
idview_controller_->activateBehavior();
break;
Expand All @@ -182,7 +185,12 @@ namespace OpenMS
std::cerr << "Error: tab_index " << tab_index << " is invalid\n";
throw Exception::NotImplemented(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
}
update();
callUpdateEntries(); //TODO actually this is overkill. Why would you load the entire table again
// when you only switched tabs? The TabView should get notified when the layer data changes, so it only
// updates when necessary...
// The only thing that maybe needs to happen when switching tabs is to sync the index across the tables in the different tabs.
// which is the only reason why we need to actually use callUpdateEntries here.
// At least we reduced it to only updateEntries during tab switch, not EVERY update() [e.g. when resizing, refocussing...]
}

void DataSelectionTabs::showSpectrumAsNew1D(int index)
Expand Down
3 changes: 2 additions & 1 deletion src/openms_gui/source/VISUAL/ICONS/sequence_viz.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
length="${protlen}"
displaystart="1"
displayend="${protlen}"
numberofticks="0"
use-ctrl-to-zoom="true"
highlight-event="onmouseover"
/>
Expand All @@ -132,7 +133,7 @@
let modProtTrack = `
<protvista-track id="mod_track"
length="${protlen}"
displaystart="0"
displaystart="1"
displayend="${protlen}"
use-ctrl-to-zoom="true"
tooltip-event="mouseover"
Expand Down
5 changes: 3 additions & 2 deletions src/openms_gui/source/VISUAL/Plot1DCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ namespace OpenMS
}

// Warn if non-empty peak color array present but size doesn't match number of peaks
// This indicates a bug but we gracefuly just issue a warning
// This indicates a bug but we gracefully just issue a warning
if (!layer.peak_colors_1d.empty() &&
layer.peak_colors_1d.size() < spectrum.size())
{
Expand Down Expand Up @@ -996,7 +996,7 @@ namespace OpenMS
if (peak.peak >= spec.size())
{
// somehow the peak is invalid. This happens from time to time and should be tracked down elsewhere
// but its hard to reproduce (changing spectra in 1D view using arrow keys while hovering over the spectrum with the mouse?).
// but it's hard to reproduce (changing spectra in 1D view using arrow keys while hovering over the spectrum with the mouse?).
return;
}
const ExperimentType::PeakType& sel = spec[peak.peak];
Expand Down Expand Up @@ -2096,6 +2096,7 @@ namespace OpenMS
// be an in-memory representation in the peak data structure. Using
// setCurrentSpectrumIndex will select the appropriate spectrum and load it
// into memory.
std::cout << "Current nr. spec: " << getCurrentLayer().getPeakData()->size() << std::endl;
if (index < getCurrentLayer().getPeakData()->size())
{
getCurrentLayer().setCurrentSpectrumIndex(index);
Expand Down
55 changes: 43 additions & 12 deletions src/openms_gui/source/VISUAL/SequenceVisualizer.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
// --------------------------------------------------------------------------
// OpenMS -- Open-Source Mass Spectrometry
// --------------------------------------------------------------------------
// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
// ETH Zurich, and Freie Universitaet Berlin 2002-2021.
//
// This software is released under a three-clause BSD license:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of any author or any participating institution
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
// For a full list of authors, refer to the file AUTHORS.
// --------------------------------------------------------------------------
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// --------------------------------------------------------------------------
// $Maintainer: Julianus Pfeuffer $
// $Authors: Dhanmoni Nath, Julianus Pfeuffer $
// --------------------------------------------------------------------------

#ifdef QT_WEBENGINEWIDGETS_LIB
#include <OpenMS/VISUAL/SequenceVisualizer.h>
#include <ui_SequenceVisualizer.h>

#include <QLabel>
#include <QDebug>
#include <QWebChannel>
#include <QPushButton>
#include <QMessageBox>
#include <QJsonArray>
#include <QString>

#include <QtWebEngineWidgets/QWebEngineView>
Expand All @@ -18,8 +48,8 @@ namespace OpenMS
QWidget(parent), ui(new Ui::SequenceVisualizer)
{
ui->setupUi(this);
QWebEngineView* view = new QWebEngineView(parent);
QWebChannel* channel = new QWebChannel(this);
auto* view = new QWebEngineView(parent);
auto* channel = new QWebChannel(this);
view->page()->setWebChannel(channel);
channel->registerObject(QString("SequenceVisualizer"), this);
view->load(QUrl("qrc:/new/sequence_viz.html"));
Expand All @@ -31,14 +61,15 @@ namespace OpenMS
delete ui;
}

void SequenceVisualizer::setProteinPeptideDataToJsonObj(QString accession_num,
QString pro_seq,
QJsonArray pep_data,
QJsonArray pep_mod_data)
void SequenceVisualizer::setProteinPeptideDataToJsonObj(const QString& accession_num,
const QString& pro_seq,
const QJsonArray& pep_data,
const QJsonArray& pep_mod_data)
{
m_json_data_obj["accession_num"] = accession_num;
m_json_data_obj["protein_sequence_data"] = pro_seq;
m_json_data_obj["peptides_data"] = pep_data;
m_json_data_obj["peptides_mod_data"] = pep_mod_data;
}
}// namespace OpenMS
}// namespace OpenMS
#endif
Loading

0 comments on commit ac65701

Please sign in to comment.