Plot Layout

Latch Plots is currently in alpha release and confidential. Please do not share any details outside of your organization.

A Plot Layout consists of two components: Data Transformations and Visualizations. These components can be sequentially arranged from top to bottom, enabling the construction of a multi-step plot layout with multiple analysis and visualization steps.

Data Transformation

The Data Transformation component functions similarly to a Python cell in a Jupyter Notebook, allowing users to input, modify, and execute Python code interactively.

One key difference from the native Jupyter cell is that you can import the Latch Plots library and write single lines of Python code to define user-friendly and no-code widgets that get exposed to scientists.

Supported Widget Types

Below is a comprehensive list of supported widget types.

Each widget functions as a Python class and can be assigned to a variable. By calling .value on the variable, you can access the actual widget value.

File selector

from lplots.widgets.ldata import w_ldata_picker
import pandas as pd

# Select a CSV file using the widget
csv = w_ldata_picker(label="Condition CSV", default="latch:///welcome/deseq2/conditions.csv")

# Read the selected file into a Pandas DataFrame
df = pd.read_csv(csv.value.download())

In the example above, csv.value retrieves a remote LPath. The .download() method fetches the local file path as an absolute string, which is then used to load the data into a Pandas DataFrame.

Interface

Registry selector

If you store your tables in Latch Registry, you can create a widget to select from a list of Registry tables like so:

from lplots.widgets.registry import w_registry_table_picker
from latch.registry.table import Table

# Get the unique ID of the Registry table
table_id = w_registry_table_picker(label="Select a Registry table")

if table_id.value is not None:
  # Get a dataframe from the table ID
  df = Table(id=table_id.value).get_dataframe()

Interface:

Single Select

from lplots.widgets.select import w_select

options = w_select(label="Select an item from the dropdown", options=[1, 2, 3], default=1)

# Retrieve list of options
print(options.value)

Interface:

Checkbox

from lplots.widgets.checkbox import w_checkbox

for i in range(10):
    print(w_checkbox(label=f"Option {i}"))

Interface:

Text

from lplots.widgets.text import w_text_input, w_text_output

# Accept text input
name = w_text_input(label="Your name:", default="John Doe").value

# Display additional text on the interface
w_text_output(content=f"Hello, {name}!")

Interface:

Widgets Reactivity

Widgets are reactive, meaning that they automatically update in response to changes in upstream widgets they depend on. In other words, the downstream data transformation will just run, without you having to click the “Run” button explicitly.

For instance, consider a scenario where you use a file selector widget to load a file. If you have a subsequent dropdown widget designed to display values from a specific column in that file, it will dynamically update its list of options whenever the file in the file selector widget changes. This reactive behavior ensures that the widgets remain synchronized and relevant to the current data context.

Example:

# Data Transformation cell 1
from lplots.widgets.ldata import w_ldata_picker
import pandas as pd

# Select a CSV file using the widget
csv = w_ldata_picker(label="Condition CSV", default="latch:///welcome/deseq2/conditions.csv")
# Data Transformation cell 2

# Read the selected file into a Pandas DataFrame
df = pd.read_csv(csv.value.download())

options = w_select(label="Select the condition of interest:", options=list(df["Condition"]))
Important: To enforce the reactive behavior, observe how csv.value is used in the second data transformation block, rather than in the initial block. This setup is crucial because it allows changes in csv.value to trigger the automatic execution of the subsequent data transformation cell.

Visualization

In addition to Data Transformation blocks, scientists can also add Visualization blocks that plot from a file on Latch Data, a table in Registry, or an output table from a previous Data Transformation.

  • Plot types: Currently, scatter, line, bar, box, and violin plots are supported. Support for additional plot types can be rapidly added on a case-by-case basis. Please reach out to hannah@latch.bio if you have a new plot type in mind!
  • Interactivity: All plots are interactive, which means you can hover, zoom, pan, as well as adjust the limits for X and Y axes.
  • Faceting: Facilitate comparative analysis by creating multiple synchronized plots from a single dataset. Simply select a categorical variable, and the system will automatically generate a series of plots side by side, each representing a category from the selected variable.
  • Point labels: Check the desired columns to show specific data points as labels when you hover over any part of the plot.
  • Color by: Automatically change the color of various groups on the same plot by assigning a column to color by.