Skip to content

Viz Module API Reference

Widget Classes

Module for visualization

Landscape

Bases: AnyWidget

A widget for interactive visualization of spatial omics data. This widget currently supports iST (Xenium and MERSCOPE) and sST (Visium HD data)

Parameters:

Name Type Description Default
ini_x float

The initial x-coordinate of the view.

required
ini_y float

The initial y-coordinate of the view.

required
ini_zoom float

The initial zoom level of the view.

required
token str

The token traitlet.

required
base_url str

The base URL for the widget.

required
dataset_name str

The name of the dataset to visualize. This will show up in the user interface bar.

required

Attributes:

Name Type Description
component str

The name of the component.

technology str

The technology used.

base_url str

The base URL for the widget.

token str

The token traitlet.

ini_x float

The initial x-coordinate of the view.

ini_y float

The initial y-coordinate of the view.

ini_z float

The initial z-coordinate of the view.

ini_zoom float

The initial zoom level of the view.

dataset_name str

The name of the dataset to visualize.

update_trigger dict

The dictionary to trigger updates.

cell_clusters dict

The dictionary containing cell cluster information.

Returns:

Name Type Description
Landscape

A widget for visualizing a 'landscape' view of spatial omics data.

Source code in src/celldega/viz/widget.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class Landscape(anywidget.AnyWidget):
    """
    A widget for interactive visualization of spatial omics data. This widget
    currently supports iST (Xenium and MERSCOPE) and sST (Visium HD data)

    Args:
        ini_x (float): The initial x-coordinate of the view.
        ini_y (float): The initial y-coordinate of the view.
        ini_zoom (float): The initial zoom level of the view.
        token (str): The token traitlet.
        base_url (str): The base URL for the widget.
        dataset_name (str, optional): The name of the dataset to visualize. This will show up in the user interface bar.

    Attributes:
        component (str): The name of the component.
        technology (str): The technology used.
        base_url (str): The base URL for the widget.
        token (str): The token traitlet.
        ini_x (float): The initial x-coordinate of the view.
        ini_y (float): The initial y-coordinate of the view.
        ini_z (float): The initial z-coordinate of the view.
        ini_zoom (float): The initial zoom level of the view.
        dataset_name (str): The name of the dataset to visualize.
        update_trigger (dict): The dictionary to trigger updates.
        cell_clusters (dict): The dictionary containing cell cluster information.

    Returns:
        Landscape: A widget for visualizing a 'landscape' view of spatial omics data.
    """
    _esm = pathlib.Path(__file__).parent / "../static" / "widget.js"
    _css = pathlib.Path(__file__).parent / "../static" / "widget.css"
    component = traitlets.Unicode("Landscape").tag(sync=True)

    technology = traitlets.Unicode("sst").tag(sync=True)
    base_url = traitlets.Unicode("").tag(sync=True)
    token = traitlets.Unicode("").tag(sync=True)
    ini_x = traitlets.Float(1000).tag(sync=True)
    ini_y = traitlets.Float(1000).tag(sync=True)
    ini_z = traitlets.Float(0).tag(sync=True)
    ini_zoom = traitlets.Float(0).tag(sync=True)
    square_tile_size = traitlets.Float(1.4).tag(sync=True)
    dataset_name = traitlets.Unicode("").tag(sync=True)
    region = traitlets.Dict({}).tag(sync=True)
    nbhd = traitlets.Dict({}).tag(sync=True)

    update_trigger = traitlets.Dict().tag(sync=True)
    cell_clusters = traitlets.Dict().tag(sync=True)

    width = traitlets.Int(0).tag(sync=True)
    height = traitlets.Int(800).tag(sync=True)

    def trigger_update(self, new_value):
        # This method updates the update_trigger traitlet with a new value
        # You can pass any information necessary for the update, or just a timestamp
        self.update_trigger = new_value

    def update_cell_clusters(self, new_clusters):
        # Convert the new_clusters to a JSON serializable format if necessary
        self.cell_clusters = new_clusters

Matrix

Bases: AnyWidget

A widget for interactive visualization of a hierarchically clustered matrix.

Parameters:

Name Type Description Default
value int

The value traitlet.

required
component str

The component traitlet.

required
network dict

The network traitlet.

required
click_info dict

The click_info traitlet.

required

Attributes:

Name Type Description
component str

The name of the component.

network dict

The network dictionary.

click_info dict

The click_info dictionary.

Returns:

Name Type Description
Matrix

A widget for visualizing a hierarchically clustered matrix.

Source code in src/celldega/viz/widget.py
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
class Matrix(anywidget.AnyWidget):
    """
    A widget for interactive visualization of a hierarchically clustered matrix.

    Args:
        value (int): The value traitlet.
        component (str): The component traitlet.
        network (dict): The network traitlet.
        click_info (dict): The click_info traitlet.

    Attributes:
        component (str): The name of the component.
        network (dict): The network dictionary.
        click_info (dict): The click_info dictionary.

    Returns:
        Matrix: A widget for visualizing a hierarchically clustered matrix.
    """

    _esm = pathlib.Path(__file__).parent / "../static" / "widget.js"
    _css = pathlib.Path(__file__).parent / "../static" / "widget.css"
    value = traitlets.Int(0).tag(sync=True)
    component = traitlets.Unicode("Matrix").tag(sync=True)

    network = traitlets.Dict({}).tag(sync=True)

    width = traitlets.Int(600).tag(sync=True)
    height = traitlets.Int(600).tag(sync=True)
    click_info = traitlets.Dict({}).tag(sync=True)

landscape_matrix(landscape, mat, width='600px', height='700px')

Display a Landscape widget and a Matrix widget side by side.

Parameters:

Name Type Description Default
landscape Landscape

A Landscape widget.

required
mat Matrix

A Matrix widget.

required
width str

The width of the widgets.

'600px'
height str

The height of the widgets.

'700px'

Returns:

Type Description

Visualization display

Example: See example Landscape-Matrix_Xenium notebook

Source code in src/celldega/viz/__init__.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def landscape_matrix(landscape, mat, width='600px', height='700px'):
    """
    Display a `Landscape` widget and a `Matrix` widget side by side.

    Args:
        landscape (Landscape): A `Landscape` widget.
        mat (Matrix): A `Matrix` widget.
        width (str): The width of the widgets.
        height (str): The height of the widgets.

    Returns:
        Visualization display

    Example:
    See example [Landscape-Matrix_Xenium](../../../examples/brief_notebooks/Landscape-Matrix_Xenium) notebook
    """

    # Use `jslink` to directly link `click_info` from `mat` to `trigger_value` in `landscape_ist`
    jslink((mat, 'click_info'), (landscape, 'update_trigger'))

    # Set layouts for the widgets
    mat.layout = Layout(width=width)  # Adjust as needed
    landscape.layout = Layout(width=width, height=height)  # Adjust as needed

    # Display widgets side by side
    widgets_side_by_side = HBox([landscape, mat])

    display(widgets_side_by_side)