|  | 
|  | 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() | 
0 commit comments