Skip to content

25 restructure network page - #27

Merged
bastiennerehor merged 12 commits into
mainfrom
25-restructure-network-page
Sep 2, 2026
Merged

25 restructure network page#27
bastiennerehor merged 12 commits into
mainfrom
25-restructure-network-page

Conversation

@bastiennerehor

Copy link
Copy Markdown
Collaborator

Backend-Side to Frontend Changes to Restructure Network Page:

  • send the correct response to show node and edge details or error messages
  • add variable query to cache also for contexts (now that variables can be subsetted further than layers), both for overview/ context request that uses data_manager to get raw data as for typeahead query on the network page
  • resolve line plot bug when PRESERVE_PRIVACY is off
  • node and edge rankings are now computed on the backend to enable calculation on user defined pvalue threshold. Only top 10000 edges are send to frontend

Copilot AI lite review requested due to automatic review settings September 2, 2026 11:01
@bastiennerehor bastiennerehor linked an issue Sep 2, 2026 that may be closed by this pull request

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new significant-network truncation logic can return links that reference nodes omitted from points, and the edge ranking key doesn’t correctly treat NaN as “missing,” risking incorrect top-edge selection.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR updates the network-related backend APIs to better support the restructured Network Page UI, including context-aware caching, richer node metadata in responses, backend-side ranking/truncation of significant edges, and improved signaling of external enrichment API failures.

Changes:

  • Fix line-plot aggregation behavior when PRESERVE_PRIVACY is disabled by filtering the underlying DataFrame (not the GroupBy) before aggregation.
  • Add data_type to node/typeahead payloads and compute/return node/edge ranking metadata on the backend (including truncation to bounded result sets).
  • Add/adjust caching for context-scoped variable and context-node-id queries; surface g:Profiler/Reactome outage signals in community-annotation status responses.
File summaries
File Description
network/views/plotting.py Adjusts line-plot aggregation to avoid GroupBy misuse when privacy filtering is off.
network/views/network.py Extends typeahead response payload with data_type.
network/views/metagraph.py Adds backend ranking/truncation + node degree stats in Cosmograph/Metagraph responses; removes Cosmograph caching.
network/views/general.py Adds context-scoped caching for variables and refines availableLayers computation.
network/views/community_annotation.py Unwraps task result and exposes reactomeFailed / gprofilerFailed flags.
network/tasks.py Includes data_type/xrefs in moDiNA point shaping; propagates enrichment API failure states.
network/queries.py Adds data_type to node/typeahead queries; caches get_context_node_ids().
network/enrichment.py Distinguishes “API failure” (None) from “no significant results” (empty) for external enrichment calls.
network/contexts/contexts.py Clears context-related cache keys on context deletion to avoid ID reuse serving stale data.
Review details
  • Files reviewed: 9/9 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +432 to +444
candidate_links.sort(key=_edge_ranking_sort_key)
top_edges = candidate_links[:max_edges]
for rank, edge in enumerate(top_edges, start=1):
edge['rank'] = rank

ranked_node_ids = sorted(
weighted_degree.keys(),
key=lambda node_id: (-weighted_degree[node_id], -degree[node_id], node_id),
)
node_stats_by_id = {
node_id: {'degree': degree[node_id], 'weighted_degree': weighted_degree[node_id], 'rank': rank}
for rank, node_id in enumerate(ranked_node_ids[:max_nodes], start=1)
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem when truncated it's not used for the network. The current Networks ranking is calculated frontend side

Comment thread network/views/metagraph.py
@bastiennerehor bastiennerehor self-assigned this Sep 2, 2026
bastiennerehor and others added 3 commits September 2, 2026 15:27
shouldn't be None but fix just in case

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…backend_django into 25-restructure-network-page
@bastiennerehor
bastiennerehor requested a lite review from Copilot September 2, 2026 14:32
@bastiennerehor
bastiennerehor merged commit 8269dd9 into main Sep 2, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The full_network_stats response can return links whose endpoint nodes are missing from points, which can break graph consumers expecting all edge endpoints to be present.

Review details

Suppressed comments (3)

Previously missed (2) — in code that hasn't changed since the last review.

network/queries.py:142

  • The cache check uses cache_key in cache and then cache.get(cache_key), which causes two Redis round-trips on every cache hit (and this function is called on every keystroke in context-scoped typeahead). You can avoid the extra call by using a single cache.get with a None/sentinel check.
    network/views/general.py:82
  • This condition checks cache_key not in cache before settings.NO_CACHE, so when NO_CACHE is enabled it still performs a Redis membership check even though caching is effectively disabled. Reordering the condition avoids the unnecessary cache call.

network/views/metagraph.py:556

  • When full_network_stats is enabled, cohort_nodes is restricted to node_stats_by_id.keys() (top nodes by weighted-degree), but response_links is the (top) edge list ranked by p-value/effect size. These two truncations are independent, so the response can contain links whose source/target nodes are missing from points, which can break graph consumers expecting every endpoint to exist as a point. Consider including at least all endpoint node_ids from response_links in points (and filling degree/weighted_degree/rank appropriately), or alternatively filtering response_links down to edges whose endpoints are in the returned node set.
        if node_stats_by_id:
            cohort_nodes = node_model.objects.filter(node_id__in=node_stats_by_id.keys()).values(
                'node_id', 'display_name', 'node_group', 'node_subgroup', 'data_type', 'description', 'xrefs')
        else:
  • Files reviewed: 9/9 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restructure Network Page

2 participants