Python
Register projects and datasets from a script with import plexora: the same projects the app shows, with no server to start.
Everything Import Sample… and New dataset… do in the app is also a Python call. Use it to register a cohort in a loop, answer a project's open questions from a script, or open the viewer from a notebook. Registering a project writes to the same project list the app reads, so there is no server to start first.
import plexoraEvery function on this page is then plexora.<name>. Each has a full reference page under Python API.
Common tasks
Each section below is a separate task; use the ones you need.
Import a sample
Two calls register a sample. Use whichever matches what you know about your files:
import_sample is Import Sample… as a call: give it an image, a mask and a table (or a folder), and it works out which file is which, groups them into one sample and returns its name.
import plexora
name = plexora.import_sample("slide.ome.tif", "slide_mask.tif", "cells.csv", wait=True)
print(name)
print(plexora.project_manifest(name)["summary"])Pass wait=True in a script: without it the call returns while the mask is still being converted in the background.
Fill in what is still open
A project registered with only an image is complete, but a tool may later need a table or a column it does not have yet. configure_project answers with the same keywords and returns the project's manifest, so you can see what is still open.
import plexora
name = plexora.create_project("slide.ome.tif")
manifest = plexora.configure_project(name, data="cells.csv", cell_id="CellID")
print(manifest["manifest"]["table"]["status"])
print(manifest["manifest"]["role:cell_id"])A keyword outside the vocabulary (plexora.PROJECT_SPEC_KEYS) is refused by name, not ignored.
Group samples into a dataset
A dataset is a named group of projects: a cohort, a TMA series, one imaging run. images is the short form, one project per file; projects takes a dict per project with the same keys create_project takes.
import plexora
cohort = plexora.create_dataset("Melanoma Cohort", projects=[
{"image": "slide.ome.tif", "segmentation": "slide_mask.tif",
"data": "cells.csv", "cell_id": "CellID"},
{"image": "slide2.ome.tif"},
])
print(cohort.name, cohort.projects)Every path is checked before anything is registered, so a typo in the last entry fails before the first one starts converting.
Open the viewer
plexora.view(name) returns a viewer. In a notebook, make it the last line of a cell and it appears inline; it can also open what is already in memory. See Notebook.
plexora.view("tonsil_01", tool="gating")Tips
- The
Datasetobject is a snapshot. Its methods (add,remove,rename,describe,delete) return a fresh one, so writecohort = cohort.add("slide2"). Removing a project from a dataset, or deleting the dataset, never deletes the project. plexora.dataset("Melanoma Cohort")finds a dataset again by name;plexora.list_datasets()lists them all.plexora.add_layers(name, "slide2.ome.tif", wait=True)adds files to a project that already exists.- The same spec dict works in three places:
create_project(**spec), an entry increate_dataset(projects=[...]), and a JSON file forplexora project create --from spec.json.