Skip to content

Commit adb72c7

Browse files
authored
♻️ Refactor vuecore library with an initial example for scatter plot
This structure would enable the support of various backend engines and separate the validation, style, and building logic for the plots. Here is a diagram of the proposed project structure: ``` vuecore/ ├── __init__.py ├── constants.py # Defines global enums and constants (e.g., plot types) ├── engines/ # Manages all plotting backends │ ├── __init__.py # Engine registry and loading logic │ ├── plotly/ │ │ ├── __init__.py # Registers Plotly engine components │ │ ├── saver.py # Functions to save Plotly figures │ │ ├── theming.py # Applies styles and themes to Plotly figures │ │ ├── scatter.py # Generates plotly scatter plots from data and config │ │ └── ... ├── plots/ # User-facing API │ ├── basic/ │ │ ├── scatter.py # Creates scatter plots using schemas and engines │ │ └── ... │ ├── .../ ├── schemas/ # Pydantic models for validating plot configurations │ ├── distribution/ │ │ ├── scatter.py │ │ └── ... ├── utils/ # Helper functions shared across the project │ ├── statistics.py │ ├── validation.py # Custom validation logic beyond Pydantic └── ... tests/ ├── test_scatter.py # Unit and integration tests for scatter plot generation └── ... ``` Also, here is the workflow: ``` User Code │ ▼ plots/distribution/scatter.py # "Create scatter plot" │ │ Uses ├──► schemas/distribution/scatter.py # Pydantic validation │ │ │ └──► utils/validation.py # Custom validation │ │ Uses ├──► constants.py # Access plot types, engine types, etc. │ │ Selects engine: ▼ engines/plotly/scatter.py # Generate Plotly scatter plot from data + config │ │ Uses ├──► engines/plotly/theming.py # Apply theming │ │ Uses ├──► utils/statistics.py # Support for transformations, etc │ │ Uses ▼ engines/plotly/saver.py # Save plot (e.g., as PNG/HTML/JSON) ```
2 parents c5b5609 + 275db81 commit adb72c7

File tree

21 files changed

+5282
-6
lines changed

21 files changed

+5282
-6
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,8 @@ cython_debug/
161161

162162
# VSCode
163163
*DS_Store
164+
165+
# Tests
166+
test_results/
167+
docs/api_examples/outputs/
168+
docs/api_examples/iframe_figures/

.readthedocs.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,19 @@ build:
1010
os: ubuntu-22.04
1111
tools:
1212
python: "3.12"
13-
# apt_packages:
14-
# - some-package
13+
apt_packages:
14+
- libnss3
15+
- libatk-bridge2.0-0
16+
- libcups2
17+
- libxcomposite1
18+
- libxdamage1
19+
- libxfixes3
20+
- libxrandr2
21+
- libgbm1
22+
- libxkbcommon0
23+
- libpango-1.0-0
24+
- libcairo2
25+
- libasound2
1526

1627
# Build documentation in the "docs/" directory with Sphinx
1728
sphinx:

docs/.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ reference
44
_build
55
jupyter_execute
66

7-
# VS Code
8-
.DS_Store
7+
# VsCode
8+
*.DS_Store

docs/api_examples/scatter_plot.ipynb

Lines changed: 4523 additions & 0 deletions
Large diffs are not rendered by default.

docs/api_examples/scatter_plot.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
"""
2+
Title: Scatter Plot Examples using VueCore
3+
Description:
4+
This script demonstrates how to generate scatter plots using VueCore — a Python package for creating
5+
interactive and static visualizations of multi-omics data. It is part of an ecosystem including ACore
6+
for data processing and VueGen for automated reporting.
7+
8+
We showcase basic and advanced plot configurations, highlighting customization options such as grouping,
9+
color mapping, annotations, and export to multiple formats.
10+
11+
Script Structure:
12+
0. Work environment setup
13+
1. Basic scatter plot
14+
2. Advanced scatter plot
15+
16+
Authors:
17+
Sebastián Ayala-Ruano
18+
Supervisors:
19+
Henry Webel, Alberto Santos (Multiomics Network Analytics Group, DTU Biosustain)
20+
21+
Institution:
22+
Multiomics Network Analytics Group (MoNA),
23+
Novo Nordisk Foundation Center for Biosustainability (DTU Biosustain)
24+
25+
Project Repository:
26+
https://github.com/Multiomics-Analytics-Group/vuecore
27+
28+
License:
29+
MIT License
30+
31+
Created: 2025-06-25
32+
Last Updated: 2025-06-25
33+
"""
34+
35+
# %%
36+
# 0. Work environment setup
37+
# 0.1. Installing libraries and creating global variables for platform and working directory
38+
# To run this notebook locally, you should create a virtual environment with the required libraries.
39+
# pip install vuecore
40+
41+
# 0.2. Importing libraries
42+
import os
43+
import pandas as pd
44+
import plotly.io as pio
45+
from vuecore.plots.basic.scatter import create_scatter_plot
46+
47+
# Set the Plotly renderer based on the environment, default to notebook, but you can change it
48+
# to "browser" if you do not want to use jupyter widgets.
49+
pio.renderers.default = "notebook"
50+
51+
# 0.3. Create a directory for outputs
52+
output_dir = "./outputs"
53+
os.makedirs(output_dir, exist_ok=True)
54+
55+
# %%
56+
# 1. Basic Scatter Plot
57+
# Created sample data
58+
sample_df = pd.DataFrame(
59+
{
60+
"gene_expression": [1.2, 2.5, 3.1, 4.5, 5.2, 6.8, 3.9, 2.1],
61+
"log_p_value": [0.5, 1.5, 2.0, 3.5, 4.0, 5.5, 1.8, 0.9],
62+
"regulation": ["Up", "Up", "None", "Down", "Down", "Down", "None", "Up"],
63+
"significance_score": [10, 20, 5, 40, 55, 80, 15, 25],
64+
"gene_name": [
65+
"GENE_A",
66+
"GENE_B",
67+
"GENE_C",
68+
"GENE_D",
69+
"GENE_E",
70+
"GENE_F",
71+
"GENE_G",
72+
"GENE_H",
73+
],
74+
"cell_type": ["A", "B", "A", "B", "A", "B", "A", "B"],
75+
}
76+
)
77+
78+
# Define output path
79+
file_path_png = os.path.join(output_dir, "scatter_basic.png")
80+
81+
# Generate basic plot
82+
fig = create_scatter_plot(
83+
data=sample_df,
84+
x="gene_expression",
85+
y="log_p_value",
86+
file_path=file_path_png,
87+
)
88+
89+
fig.show()
90+
91+
# %%
92+
# 2. Advanced Scatter Plot
93+
# Define output path
94+
file_path_adv_html = os.path.join(output_dir, "scatter_advanced.html")
95+
96+
# Generate advanced plot
97+
fig_advanced = create_scatter_plot(
98+
data=sample_df,
99+
x="gene_expression",
100+
y="log_p_value",
101+
group="regulation",
102+
size="significance_score",
103+
text="gene_name",
104+
title="Advanced Gene Expression Plot",
105+
x_title="Log2 Fold Change",
106+
y_title="-Log10(P-value)",
107+
colors={"Up": "#FF5733", "Down": "#3380FF", "None": "#33FF57"},
108+
marker_opacity=0.8,
109+
marker_line_width=1,
110+
marker_line_color="darkgray",
111+
width=900,
112+
height=600,
113+
file_path=file_path_adv_html,
114+
)
115+
116+
fig_advanced.show()

docs/index.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,24 @@
77
:relative-images:
88
```
99

10+
```{toctree}
11+
:maxdepth: 1
12+
:caption: API Usage Examples
13+
14+
api_examples/scatter_plot
15+
```
16+
1017
```{toctree}
1118
:maxdepth: 2
12-
:caption: Modules
19+
:caption: API Reference
1320
:hidden:
1421
1522
reference/vuecore
1623
```
1724

1825
```{toctree}
1926
:maxdepth: 1
20-
:caption: MISC:
27+
:caption: Extra Materials
2128
:hidden:
2229
2330
README.md

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ dependencies = [
3737
"webweb",
3838
"acore",
3939
"dash-cytoscape",
40+
"pydantic",
41+
"nbformat>=4.2.0",
4042
]
4143

4244
[project.optional-dependencies]

src/vuecore/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
import numpy as np
1818
import pandas as pd
1919

20+
from .constants import PlotType, EngineType
21+
22+
__all__ = ["PlotType", "EngineType"]
23+
2024
plt.rcParams["figure.figsize"] = [4.0, 3.0]
2125
plt.rcParams["pdf.fonttype"] = 42
2226
plt.rcParams["ps.fonttype"] = 42

src/vuecore/constants.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from enum import auto
2+
3+
try:
4+
from enum import StrEnum
5+
except ImportError:
6+
from strenum import StrEnum
7+
8+
9+
class PlotType(StrEnum):
10+
SCATTER = auto()
11+
LINE = auto()
12+
# Add other plot types as needed
13+
14+
15+
class EngineType(StrEnum):
16+
PLOTLY = auto()
17+
# Add other engines as needed

src/vuecore/engines/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from vuecore.engines.registry import get_builder, get_saver
2+
3+
# Import the engine modules to trigger their registration
4+
from . import plotly # noqa: F401, E402
5+
6+
# from . import matplotlib # This is where you'd add a new engine
7+
8+
__all__ = ["get_builder", "get_saver"]

0 commit comments

Comments
 (0)