Skip to content

Commit

Permalink
Dynamic implementation of proper range for depth node colorer
Browse files Browse the repository at this point in the history
resolves asl#161
  • Loading branch information
milenovic committed Jan 26, 2025
1 parent 94e08df commit 91f7cf2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
18 changes: 8 additions & 10 deletions graph/nodecolorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,10 @@

#include <QApplication>

graph::Scope DepthNodeColorer::m_Scope = graph::Scope::wholeGraph();

INodeColorer::INodeColorer(NodeColorScheme scheme)
: m_graph(g_assemblyGraph), m_scheme(scheme) {
}

void INodeColorer::saveScopeReference(graph::Scope& scope) {
DepthNodeColorer::getScope() = scope;
}

std::pair<QColor, QColor> INodeColorer::get(const GraphicsItemNode *node,
const GraphicsItemNode *rcNode) {
QColor posColor = this->get(node);
Expand Down Expand Up @@ -81,11 +75,11 @@ QColor DepthNodeColorer::get(const GraphicsItemNode *node) {
double depth = deBruijnNode->getDepth();

double lowValue = g_settings->lowDepthValue, highValue = g_settings->highDepthValue;
auto &scope = getScope();

if (g_settings->autoDepthValue) {
if (scope.graphScope() == DEPTH_RANGE) {
lowValue = scope.minDepth();
highValue = scope.maxDepth();
if (m_scope.graphScope() == DEPTH_RANGE) {
lowValue = m_scope.minDepth();
highValue = m_scope.maxDepth();
} else {
lowValue = m_graph->m_firstQuartileDepth;
highValue = m_graph->m_thirdQuartileDepth;
Expand All @@ -96,6 +90,10 @@ QColor DepthNodeColorer::get(const GraphicsItemNode *node) {
return tinycolormap::GetColor(fraction, colorMap(g_settings->colorMap)).ConvertToQColor();
}

void DepthNodeColorer::saveScopeReference(graph::Scope& scope) {
m_scope = scope;
}

QColor UniformNodeColorer::get(const GraphicsItemNode *node) {
const DeBruijnNode *deBruijnNode = node->m_deBruijnNode;

Expand Down
2 changes: 0 additions & 2 deletions graph/nodecolorer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ class INodeColorer {
static std::unique_ptr<INodeColorer> create(NodeColorScheme scheme);

[[nodiscard]] NodeColorScheme scheme() const { return m_scheme; }

virtual void saveScopeReference(graph::Scope& scope);

protected:
NodeColorScheme m_scheme;
Expand Down
13 changes: 7 additions & 6 deletions graph/nodecolorers.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@

class DepthNodeColorer : public INodeColorer {
public:
using INodeColorer::INodeColorer;

explicit DepthNodeColorer(NodeColorScheme scheme)
: INodeColorer(scheme),
m_scope(graph::Scope::wholeGraph())
{
}
QColor get(const GraphicsItemNode *node) override;
[[nodiscard]] const char* name() const override { return "Color by depth"; };

[[nodiscard]] static graph::Scope &getScope() {
return m_Scope;
}
void saveScopeReference(graph::Scope& scope);

private:
static graph::Scope m_Scope;
graph::Scope m_scope;
};

class UniformNodeColorer : public INodeColorer {
Expand Down
13 changes: 8 additions & 5 deletions ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ MainWindow::MainWindow(QString fileToLoadOnStartup, bool drawGraphAfterLoad) :
QMainWindow(nullptr),
ui(new Ui::MainWindow), m_imageFilter("PNG (*.png)"),
m_fileToLoadOnStartup(fileToLoadOnStartup), m_drawGraphAfterLoad(drawGraphAfterLoad),
m_uiState(NO_GRAPH_LOADED), m_blastSearchDialog(nullptr), m_alreadyShown(false)
m_uiState(NO_GRAPH_LOADED), m_blastSearchDialog(nullptr), m_alreadyShown(false),
m_scope(graph::Scope::wholeGraph())
{
ui->setupUi(this);

Expand Down Expand Up @@ -1004,7 +1005,7 @@ void MainWindow::drawGraph() {
QString errorMessage;
g_settings->doubleMode = ui->doubleNodesRadioButton->isChecked();

auto scope =
m_scope =
graph::scope(g_settings->graphScope,
ui->startingNodesLineEdit->text(),
ui->minDepthSpinBox->value(), ui->maxDepthSpinBox->value(),
Expand All @@ -1015,7 +1016,7 @@ void MainWindow::drawGraph() {
ui->nodeDistanceSpinBox->value());

auto startingNodes = graph::getStartingNodes(&errorTitle, &errorMessage,
*g_assemblyGraph, scope);
*g_assemblyGraph, m_scope);

if (!errorMessage.isEmpty()) {
QMessageBox::information(this, errorTitle, errorMessage);
Expand All @@ -1024,8 +1025,7 @@ void MainWindow::drawGraph() {

resetScene();
g_assemblyGraph->resetNodes();
g_assemblyGraph->markNodesToDraw(scope, startingNodes);
g_settings->nodeColorer->saveScopeReference(scope);
g_assemblyGraph->markNodesToDraw(m_scope, startingNodes);
layoutGraph();
}

Expand Down Expand Up @@ -1382,6 +1382,9 @@ void MainWindow::switchColourScheme(int idx) {
if (!g_assemblyGraph->m_csvHeaders.empty())
colorer->setColumnIdx(0);
ui->tagsComboBox->setVisible(true);
} else if (scheme == DEPTH_COLOUR) {
dynamic_cast<DepthNodeColorer*>(&*g_settings->nodeColorer)->saveScopeReference(m_scope);
ui->tagsComboBox->setVisible(false);
} else {
ui->tagsComboBox->setVisible(false);
}
Expand Down
1 change: 1 addition & 0 deletions ui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class MainWindow : public QMainWindow
bool m_drawGraphAfterLoad;
UiState m_uiState;
GraphSearchDialog * m_blastSearchDialog;
graph::Scope m_scope;

bool m_alreadyShown;

Expand Down

0 comments on commit 91f7cf2

Please sign in to comment.