The from_object shortcut
1. Import dependencies
Import the functions and classes that we will be using.
[ ]:
import os
from os.path import join
from urllib.request import urlretrieve
from anndata import read_h5ad
import scanpy as sc
from vitessce import (
VitessceConfig,
Component as cm,
CoordinationType as ct,
AnnDataWrapper,
)
2. Download the data
For this example, we need to download a dataset from the COVID-19 Cell Atlas https://www.covid19cellatlas.org/index.healthy.html#habib17.
[ ]:
os.makedirs("data", exist_ok=True)
adata_filepath = join("data", "habib17.processed.h5ad")
urlretrieve('https://covid19.cog.sanger.ac.uk/habib17.processed.h5ad', adata_filepath)
3. Load the data
[ ]:
adata = read_h5ad(join("data", "habib17.processed.h5ad"))
3.1. Preprocess the Data For Visualization
[ ]:
top_dispersion = adata.var["dispersions_norm"][
sorted(
range(len(adata.var["dispersions_norm"])),
key=lambda k: adata.var["dispersions_norm"][k],
)[-51:][0]
]
adata.var["top_highly_variable"] = (
adata.var["dispersions_norm"] > top_dispersion
)
With one line of code, you may create a Vitessce widget based on an automatically inferred configuration.
[ ]:
vw = VitessceConfig.from_object(AnnDataWrapper(
adata,
obs_embedding_paths=["obsm/X_umap"],
obs_embedding_names=["UMAP"],
obs_set_paths=["obs/CellType"],
obs_set_names=["Cell Type"],
obs_feature_matrix_path="X",
feature_filter_path="var/top_highly_variable"
), schema_version="1.0.15").widget(height=800)
vw