Skip to content

Markov screen plot functions and GRN regulon visualization - #78

Merged
WWXkenmo merged 70 commits into
theislab:mainfrom
emmaaer:markov_plot
Jul 17, 2026
Merged

Markov screen plot functions and GRN regulon visualization#78
WWXkenmo merged 70 commits into
theislab:mainfrom
emmaaer:markov_plot

Conversation

@emmaaer

@emmaaer emmaaer commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Created two new plot scripts to allow visualization of Markov density simulation screening and driver TF ranking.

_markov_screen.py: Previous plot functions (_visits_diff_per_tf, _plot_visits_dist) included in the script with new function (_plot_visits_dist_combined) to create a boxplot of TF density likelihood per terminal state for all screened TFs.

_driver_TF_ranking.py: Plot top TF hits for perturbation depletion/increase likelihood (plot_top_TF), compute donstream targets and upstream regulators per TF (compute_TF_regulon), compute regulatory weights for individual TF-target pairs (plot_grn_weight) and jointly plot regulon scores, GRN, and weight UMAPs for one TF and terminal states.(plot_GRN_per_TF)

emmaaer added 23 commits July 6, 2026 21:40
This file contains functions for visualizing visit differences per transcription factor (TF) and plotting their distributions across terminal states. It includes significance color mapping and boxplot generation.
This file contains functions for plotting transcription factor rankings and computing regulatory networks based on GRN weights. It includes functionality for visualizing top depletion and increase hits, as well as generating regulatory network diagrams.
Refactor TFscreening function to include new parameters and update logic for Markov simulations. Improved documentation and added plotting functionalities for density differences.
Updated import paths and added progress bar for TF screening. Added significance palette call from util.
Added a significance-level to color mapping for plots.
Removed hardcoded significance palette and imported it from _utils. Updated function parameters and docstring to reflect changes.
Removed local SIGNIFICANCE_PALETTE definition and imported it from _utils.
Refactor TF ranking function to remove output directory parameter and adjust coefficient handling.
Added device=cpu parameter to rgv.tl.inferred_grn to allow running on CPU
Removed saving of individual barplot SVG files and updated log message capitalization.
Removed saving of the Markov simulation barplot as SVG.
Added device parameter to specify the device (CPU/GPU) for GRN inference.
Added error handling for device specification when moving model.
Added fallback behavior for device selection in GRN inference.
Removed duplicate plt.show() call.
Added device parameter to specify the device for model inference.
@WWXkenmo
WWXkenmo self-requested a review July 8, 2026 20:14
emmaaer and others added 5 commits July 12, 2026 18:36
Implement tests for Markov screening and plotting functions, including training a model and simulating perturbations for transcription factors.
Added missing common variables for testing Markov functions.
Updated terminal states and starting points for the Markov test. Refactored data preprocessing and model training steps. Using zebrafish dataset as test set.
…ntly

test_markov.py was failing before it ever reached the screening/plotting
code it's meant to exercise: broken imports from a nonexistent tests/src
package, GPCCA macrostate splitting at n_states=10 (fixed to n_states=7,
matching the tutorial), and passing a live model object where the API
expects a saved model path. Running the fixed test end-to-end then
surfaced further real bugs, now fixed:

- compute_TF_regulon didn't normalize a string TF argument to a list
  (unlike in_silico_block_simulation), so a bare TF name was iterated
  character-by-character and crashed on a single-letter "gene" lookup.
- compute_TF_regulon declared n_states/n_samples parameters but silently
  hardcoded 7/50 internally, ignoring the caller's values.
- TFscreening's single-TF summary branch silently dropped n_step_to_use,
  falling back to a 100-step default regardless of what was requested,
  and used a copy-paste hardcoded plot title unrelated to the TF being run.
- plot_GRN_per_TF's device parameter never reached plot_grn_weight ->
  inferred_grn, so GRN inference always tried cuda:0 regardless of the
  caller's choice.
- test_markov.py called plot_GRN_per_TF with terminal_states= instead of
  the function's actual TERMINAL_STATES= parameter name.

Also moved compute_TF_regulon from plotting into tools (it computes, it
doesn't plot, added the missing _visits_diff_per_tf / _plot_visits_dist
exports to rgv.pl, and updated test_markov.py plus the zebrafish tutorial
notebook to call the public rgv.tl.X / rgv.pl.X API instead of importing
private submodules or calling a same-named-but-differently-signatured
function (TFscreening vs TFscreening_wrapper).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
EOF
)
@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

emmaaer and others added 28 commits July 15, 2026 12:00
- Fix theislab#1: Remove incomplete parameter declaration (depletion_likelihood)
- Fix theislab#2: Add missing return value (return both res_table and adata)
- Fix theislab#3: Fix function name calls - remove underscore prefixes
- Fix theislab#4: Add error checking for missing obs columns
- Fix theislab#5: Add zero-check before division for delta_success_rate
- Fix theislab#7: Remove unused variable (res_sort)
- Fix theislab#8: Remove unused import (Sequence)
- Fix theislab#10: Remove debug print statement in _visits_diff_per_TF.py
- Fix __init__.py: Update import for _plot_visits_dist_combined to use correct module

Addresses critical issues: function name mismatches, missing return value, unsafe operations, and code quality improvements."
Removed matrixplot visualization for TF hits.
Add new plotting module for GRN weight visualization.
Removed the plot_grn_weight function and its associated docstring. Removed plot_GRN_per_TF which will be added to tutorial
Removed plot_GRN_per_TF from imports and __all__.
- Added `coef` as a parameter to plot_regulon() function
- Updated docstring to document the new parameter
- Removed unused imports (os, scanpy, scvelo)
- Now uses the passed `coef` DataFrame directly instead of referencing undefined variables
- Maintains all existing functionality for plotting regulon edges and network visualization
Removed unused line with parameter tf_hits
Removed unused imports
- Rename tl.TFscreening -> tl.markov_density_screening (file _markov_density_screening.py):
  mute plots behind plot=False, silence CellRank logs and progress bars,
  store dd_score/visits/perturbation-rate tables in adata.uns and gate CSV
  saving behind save=False; move visits_diff_per_tf in as a local util.
- Rename pl.plot_top_TF -> pl.plot_TF_success_rate (file _plot_TF_success_rate.py):
  read results from adata.uns, add plt.show() and save=False-gated savefig,
  store tf_hits in adata.uns, use symmetric depletion filter (< -threshold),
  clarify success-rate docstring; drop the unused matrixplot/cluster_key.
- Make pl.plot_visits_dist / pl.plot_visits_dist_screen figure sizes adaptive
  with manual figsize override; screen plot reads df from adata.uns and keeps
  all significance levels by default.
- Remove pl.visits_diff_per_tf from the plotting module; update tests.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
- plot_TF_regulon: correct TF type (str, not list), accurate description of
  inferred/mixed GRN usage and plot_grn_weight calls, expand Returns.
- compute_TF_regulon: point Returns at plot_TF_regulon (plot_regulon removed).
- markov_density_screening: summary now reflects adata.uns storage, opt-in CSV
  (save), and plot-gated figures.
- plot_visits_dist / plot_visits_dist_screen: add Returns: None sections.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@WWXkenmo
WWXkenmo merged commit 0e882ce into theislab:main Jul 17, 2026
0 of 2 checks passed
@WWXkenmo WWXkenmo mentioned this pull request Jul 20, 2026
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.

2 participants