Skip to content

Commit

Permalink
Move graph's titles with nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Shostina committed Jan 15, 2024
1 parent 38f8271 commit 04c0e46
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 88 deletions.
2 changes: 1 addition & 1 deletion command_line/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int handleImageCmd(QApplication *app,
}

g_assemblyGraph->clear();
g_assemblyGraph->append(new AssemblyGraph());
g_assemblyGraph->m_graphMap[1] = new AssemblyGraph();
bool loadSuccess = g_assemblyGraph->first()->loadGraphFromFile(cmd.m_graph.c_str());
if (!loadSuccess) {
outputText(("Bandage-NG error: could not load " + cmd.m_graph.native()).c_str(), &err); // FIXME
Expand Down
7 changes: 3 additions & 4 deletions graph/assemblygraphlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ QString AssemblyGraphList::generateNodesNotFoundErrorMessage(std::vector<QString
void AssemblyGraphList::recalculateAllNodeWidths(double averageNodeWidth,
double depthPower, double depthEffectOnWidth)
{
for (auto assemblyGraph : m_graphList)
for (auto assemblyGraph : m_graphMap.values())
assemblyGraph->recalculateAllNodeWidths(averageNodeWidth,depthPower, depthEffectOnWidth);
}

Expand All @@ -88,12 +88,11 @@ void AssemblyGraphList::changeNodeDepth(const std::vector<DeBruijnNode *> &nodes
}

for (auto node : nodes) {
auto graphIndex = node->getGraphId() - 1;

//If this graph does not already have a depthTag, give it a depthTag of KC
//so the depth info will be saved.
if (m_graphList[graphIndex]->m_depthTag == "")
m_graphList[graphIndex]->m_depthTag = "KC";
if (m_graphMap[node->getGraphId()]->m_depthTag == "")
m_graphMap[node->getGraphId()]->m_depthTag = "KC";
}
}

Expand Down
36 changes: 18 additions & 18 deletions graph/assemblygraphlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,56 @@ class AssemblyGraphList
AssemblyGraphList();

AssemblyGraph* first() {
if (m_graphList.isEmpty()) {
if (m_graphMap.isEmpty()) {
auto assemblyGraph = new AssemblyGraph();
m_graphList.append(assemblyGraph);
m_graphMap[1] = assemblyGraph;
}
return m_graphList.first();
return m_graphMap[1];
}
AssemblyGraph* last() { return m_graphList.last(); }
bool isEmpty() { return m_graphList.isEmpty(); }
auto begin() { return m_graphList.begin(); }
auto begin() const { return m_graphList.begin(); }
auto end() { return m_graphList.end(); }
auto end() const { return m_graphList.end(); }
void append(AssemblyGraph* graph) { m_graphList.append(graph); }
void clear() { m_graphList.clear(); }
size_t size() const { return m_graphList.size(); }
//AssemblyGraph* last() { return m_graphList.last(); }
bool isEmpty() { return m_graphMap.isEmpty(); }
//auto begin() { return m_graphList.begin(); }
//auto begin() const { return m_graphList.begin(); }
//auto end() { return m_graphList.end(); }
//auto end() const { return m_graphList.end(); }
//void append(AssemblyGraph* graph) { m_graphList.append(graph); }
void clear() { m_graphMap.clear(); }
size_t size() const { return m_graphMap.size(); }

QColor getCustomColourForDisplay(const DeBruijnNode *node) const;
QStringList getCustomLabelForDisplay(const DeBruijnNode *node) const;

int getNodeCount(){
int count = 0;
for (auto graph : m_graphList) {
for (auto graph : m_graphMap.values()) {
count += graph->m_nodeCount;
}
return count;
}
int getEdgeCount() {
int count = 0;
for (auto graph : m_graphList) {
for (auto graph : m_graphMap.values()) {
count += graph->m_edgeCount;
}
return count;
}
int getPathCount() {
int count = 0;
for (auto graph : m_graphList) {
for (auto graph : m_graphMap.values()) {
count += graph->m_pathCount;
}
return count;
}
int getTotalLength() {
int count = 0;
for (auto graph : m_graphList) {
for (auto graph : m_graphMap.values()) {
count += graph->m_totalLength;
}
return count;
}

void determineGraphInfo() {
for (auto graph : m_graphList) {
for (auto graph : m_graphMap.values()) {
graph -> determineGraphInfo();
}
}
Expand All @@ -73,7 +73,7 @@ class AssemblyGraphList
void changeNodeDepth(const std::vector<DeBruijnNode *> &nodes, double newDepth);
void recalculateAllNodeWidths(double averageNodeWidth, double depthPower, double depthEffectOnWidth);

QList<AssemblyGraph*> m_graphList;
QMap<int, AssemblyGraph*> m_graphMap;

private:

Expand Down
11 changes: 10 additions & 1 deletion graph/graphicsitemnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "assemblygraph.h"
#include "annotationsmanager.h"

#include "painting/textgraphicsitemnode.h"

#include "program/globals.h"
#include "program/memory.h"
#include "program/settings.h"
Expand Down Expand Up @@ -394,6 +396,13 @@ void GraphicsItemNode::mouseMoveEvent(QGraphicsSceneMouseEvent * event)

fixEdgePaths(&nodesToMove);
fixHiCEdgePaths(&nodesToMove);
if (g_settings->multyGraphMode && g_settings->moveGraphTitle) {
AssemblyGraph& currrentGraph = *g_assemblyGraph->m_graphMap[m_deBruijnNode->getGraphId()];
if (currrentGraph.hasTextGraphicsItem()) {
TextGraphicsItemNode * graphTitle = currrentGraph.getTextGraphicsItemNode();
graphTitle->mouseMoveEvent(event);
}
}
}
}

Expand Down Expand Up @@ -479,7 +488,7 @@ QStringList GraphicsItemNode::getNodeText() const
if (g_settings->displayNodeDepth)
nodeText << formatDepthForDisplay(m_deBruijnNode->getDepth());
if (g_settings->displayNodeCsvData) {
for (auto graph : g_assemblyGraph->m_graphList) {
for (auto graph : g_assemblyGraph->m_graphMap.values()) {
auto data = graph->getCsvLine(m_deBruijnNode, g_settings->displayNodeCsvDataCol);
if (data)
nodeText << *data;
Expand Down
16 changes: 5 additions & 11 deletions graph/nodecolorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ QColor GCNodeColorer::get(const GraphicsItemNode *node) {
QColor TagValueNodeColorer::get(const GraphicsItemNode *node) {
const DeBruijnNode *deBruijnNode = node->m_deBruijnNode;

for (auto graph : m_graphs.data()->m_graphList) {
for (auto graph : m_graphs.data()->m_graphMap.values()) {
auto tags = graph->m_nodeTags.find(deBruijnNode);
if (tags != graph->m_nodeTags.end()) {
if (auto tag = gfa::getTag(m_tagName.c_str(), tags->second)) {
Expand All @@ -354,7 +354,7 @@ void TagValueNodeColorer::reset() {
m_tagNames.clear();

// Collect all tags and their corresponding values
for (auto graph : m_graphs.data()->m_graphList) {
for (auto graph : m_graphs.data()->m_graphMap.values()) {
for (const auto &entry : graph->m_nodeTags) {
for (const auto &tag: entry.second) {
std::stringstream stream;
Expand Down Expand Up @@ -386,13 +386,7 @@ void TagValueNodeColorer::reset() {
QColor CSVNodeColorer::get(const GraphicsItemNode *node) {
const DeBruijnNode *deBruijnNode = node->m_deBruijnNode;

AssemblyGraph* graph;
for(auto currentGraph : m_graphs.data()->m_graphList) {
if (currentGraph->getGraphId() == deBruijnNode->getGraphId()) {
graph = currentGraph;
break;
}
}
AssemblyGraph* graph = m_graphs.data()->m_graphMap[deBruijnNode->getGraphId()];
auto val = graph->getCsvLine(deBruijnNode, m_colIdx);
if (!val || m_colIdx >= m_colors.size())
return m_graphs->getCustomColourForDisplay(deBruijnNode);
Expand All @@ -409,11 +403,11 @@ void CSVNodeColorer::reset() {
m_colors.clear();

size_t columns = 0;
for (auto graph : m_graphs.data()->m_graphList)
for (auto graph : m_graphs.data()->m_graphMap.values())
columns = std::max(columns, size_t(graph->m_csvHeaders.size()));
m_colors.resize(columns);
// Store all unique values into a map
for(auto graph : m_graphs.data()->m_graphList) {
for(auto graph : m_graphs.data()->m_graphMap.values()) {
for (const auto &entry : graph->m_nodeCSVData) {
const auto &row = entry.second;
for (size_t i = 0; i < row.size() && i < columns; ++i) {
Expand Down
6 changes: 3 additions & 3 deletions graphsearch/blast/blastsearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ QString BlastSearch::buildDatabase(QSharedPointer<AssemblyGraphList> graphList,

{
QTextStream out(&file);
for (AssemblyGraph* graph: graphList->m_graphList) {
for (AssemblyGraph* graph: graphList->m_graphMap.values()) {
for (const auto *node : graph->m_deBruijnGraphNodes) {
if (m_cancelBuildDatabase)
return (m_lastError = "Build cancelled.");
Expand All @@ -91,7 +91,7 @@ QString BlastSearch::buildDatabase(QSharedPointer<AssemblyGraphList> graphList,

// Make sure the graph has sequences
bool atLeastOneSequence = false;
for (AssemblyGraph* graph: graphList->m_graphList) {
for (AssemblyGraph* graph: graphList->m_graphMap.values()) {
for (const auto *node : graph->m_deBruijnGraphNodes) {
if (!node->sequenceIsMissing()) {
atLeastOneSequence = true;
Expand Down Expand Up @@ -341,7 +341,7 @@ buildHitsFromBlastOutput(QString blastOutput,

QStringList blastHitList = blastOutput.split("\n", Qt::SkipEmptyParts);

for(auto graph : g_assemblyGraph->m_graphList) {
for(auto graph : g_assemblyGraph->m_graphMap.values()) {
for (const auto &hitString : blastHitList) {
QStringList alignmentParts = hitString.split('\t');

Expand Down
4 changes: 2 additions & 2 deletions graphsearch/hmmer/hmmersearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ QString HmmerSearch::buildDatabase(QSharedPointer<AssemblyGraphList> graphList,
// in order to mitigate this, emit the largest (=more diverse) node first
const DeBruijnNode *longest = nullptr;
size_t length = 0;
for (AssemblyGraph* graph: graphList->m_graphList) {
for (AssemblyGraph* graph: graphList->m_graphMap.values()) {
for (const auto *node : graph->m_deBruijnGraphNodes) {
if (!node->sequenceIsMissing() && node->getLength() > length) {
length = node->getLength();
Expand Down Expand Up @@ -115,7 +115,7 @@ QString HmmerSearch::buildDatabase(QSharedPointer<AssemblyGraphList> graphList,

QTextStream out(&file);

for (AssemblyGraph* graph: graphList->m_graphList) {
for (AssemblyGraph* graph: graphList->m_graphMap.values()) {
for (const auto *node : graph->m_deBruijnGraphNodes) {
if (m_cancelBuildDatabase)
return (m_lastError = "Build cancelled.");
Expand Down
4 changes: 2 additions & 2 deletions graphsearch/minimap2/minimap2search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ QString Minimap2Search::buildDatabase(QSharedPointer<AssemblyGraphList> graphLis

{
QTextStream out(&file);
for (AssemblyGraph* graph: graphList->m_graphList) {
for (AssemblyGraph* graph: graphList->m_graphMap.values()) {
for (const auto *node : graph->m_deBruijnGraphNodes) {
if (m_cancelBuildDatabase)
return (m_lastError = "Build cancelled.");
Expand All @@ -81,7 +81,7 @@ QString Minimap2Search::buildDatabase(QSharedPointer<AssemblyGraphList> graphLis

// Make sure the graph has sequences
bool atLeastOneSequence = false;
for (AssemblyGraph* graph: graphList->m_graphList) {
for (AssemblyGraph* graph: graphList->m_graphMap.values()) {
for (const auto *node : graph->m_deBruijnGraphNodes) {
if (!node->sequenceIsMissing()) {
atLeastOneSequence = true;
Expand Down
12 changes: 8 additions & 4 deletions layout/graphlayoutworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ QList<GraphLayout*> GraphLayoutWorker::layoutGraph(QSharedPointer<AssemblyGraphL
double boardWidth = 1000;
qreal sumX = 0;
qreal oneMaxX = 0;
for(AssemblyGraph* graph : graphList->m_graphList) {
for(AssemblyGraph* graph : graphList->m_graphMap.values()) {
const AssemblyGraph& refGraph = std::cref(*graph);
ogdf::Graph G;
ogdf::EdgeArray<double> edgeLengths(G);
Expand Down Expand Up @@ -699,11 +699,15 @@ QList<GraphLayout*> GraphLayoutWorker::layoutGraph(QSharedPointer<AssemblyGraphL
qreal maxY = -boardWidth;
double textWidth = 0.0;

std::sort(graphList->m_graphList.begin(), graphList->m_graphList.end(), [](AssemblyGraph* a, AssemblyGraph* b)->bool{
return (layout::getMaxX(*a->m_layout) + layout::getMaxY(*a->m_layout)) > (layout::getMaxX(*b->m_layout) + layout::getMaxY(*b->m_layout));
QList<int> idGraphs = graphList->m_graphMap.keys();

std::sort(idGraphs.begin(), idGraphs.end(), [&](int a, int b)->bool{
return (layout::getMaxX(*(graphList->m_graphMap[a])->m_layout) + layout::getMaxY(*(graphList->m_graphMap[a])->m_layout)) >
(layout::getMaxX(*(graphList->m_graphMap[b])->m_layout) + layout::getMaxY(*(graphList->m_graphMap[b])->m_layout));
});

for(AssemblyGraph* graph : graphList->m_graphList) {
for(int id : idGraphs) {
AssemblyGraph* graph = graphList->m_graphMap[id];
if (maxX < boundX) {
maxX = std::max(maxX, prevX + textWidth) + boardWidth;
prevX = maxX;
Expand Down
14 changes: 5 additions & 9 deletions painting/textgraphicsitemnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ void TextGraphicsItemNode::paint(QPainter * painter, const QStyleOptionGraphicsI
painter->scale(zoomAdjustment, zoomAdjustment);
painter->translate(offset);

// painter->setBrush(Qt::NoBrush);
// painter->setPen(QPen(Qt::black, 1.0));
// painter->drawRect(boundingRect());

drawTextPathAtLocation(painter, textPath);
painter->translate(-offset);
painter->scale(inverseZoomAdjustment, inverseZoomAdjustment);
Expand Down Expand Up @@ -97,10 +93,10 @@ void TextGraphicsItemNode::mousePressEvent(QGraphicsSceneMouseEvent * event)
//graphics items will need to be adjusted accordingly.
void TextGraphicsItemNode::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
{
QPointF difference = event->pos() - event->lastPos();
auto *graphicsScene = dynamic_cast<BandageGraphicsScene *>(scene());

prepareGeometryChange();
QPointF difference = event->pos() - event->lastPos();
auto *graphicsScene = dynamic_cast<BandageGraphicsScene *>(scene());

m_centre += difference;
graphicsScene->possiblyExpandSceneRectangle(this);
m_centre = m_centre + difference;
graphicsScene->possiblyExpandSceneRectangle(this);
}
1 change: 1 addition & 0 deletions program/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ class Settings
FloatSetting hicEdgeLength;
bool roundMode = false;
bool multyGraphMode = false;
bool moveGraphTitle = true;
};

#endif // SETTINGS_H
Loading

0 comments on commit 04c0e46

Please sign in to comment.