<jupyter_start><jupyter_text>Vitessce Widget Tutorial  Visualization of single-cell RNA seq data  1. Import dependenciesWe need to import the classes and functions that we will be using from the corresponding packages.<jupyter_code>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,
)<jupyter_output><empty_output><jupyter_text>2. Download the dataFor this example, we need to download a dataset from the COVID-19 Cell Atlas https://www.covid19cellatlas.org/index.healthy.htmlhabib17.<jupyter_code>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)<jupyter_output><empty_output><jupyter_text>3. Load the dataNote: this function may print a `FutureWarning`<jupyter_code>adata = read_h5ad(adata_filepath)<jupyter_output><empty_output><jupyter_text>3.1. Optionally, preprocess the datasetThis dataset contains 25,587 genes. Here, we select the top 200 highly variable genes for visualization.<jupyter_code>sc.pp.highly_variable_genes(adata, n_top_genes=50)<jupyter_output><empty_output><jupyter_text>4. Create the Vitessce widget configurationVitessce needs to know which pieces of data we are interested in visualizing, the visualization types we would like to use, and how we want to coordinate (or link) the views.  4.1. Instantiate a `VitessceConfig` objectUse the `VitessceConfig(name, description)` constructor to create an instance.<jupyter_code>vc = VitessceConfig(name='Habib et al', description='COVID-19 Healthy Donor Brain')<jupyter_output><empty_output><jupyter_text>4.2. Add a dataset to the `VitessceConfig` instanceIn Vitessce, a dataset is a container for one file per data type. The `.add_dataset(name)` method on the `vc` instance sets up and returns a new dataset instance.Then, we can call the dataset's `.add_object(wrapper_object)` method to attach a "data wrapper" instance to our new dataset. For example, the `AnnDataWrapper` class knows how to convert AnnData objects to the corresponding Vitessce data types.Dataset wrapper classes may require additional parameters to resolve ambiguities. For instance, `AnnData` objects may store multiple clusterings or cell type annotation columns in the `adata.obs` dataframe. We can use the parameter `cell_set_obs_cols` to tell Vitessce which columns of the `obs` dataframe correspond to cell sets.<jupyter_code>dataset = vc.add_dataset(name='Brain').add_object(AnnDataWrapper(adata, cell_set_obs_cols=["CellType"]))<jupyter_output><empty_output><jupyter_text>4.3. Add visualizations to the `VitessceConfig` instanceNow that we have added a dataset, we can configure visualizations. The `.add_view(dataset, component_type)` method adds a view (i.e. visualization or controller component) to the configuration.The `Component` enum class (which we have imported as `cm` here) can be used to fill in the `component_type` parameter.For convenience, the `SCATTERPLOT` component type takes the extra `mapping` keyword argument, which specifies which embedding should be used for mapping cells to (x,y) points on the plot.<jupyter_code>scatterplot = vc.add_view(dataset, cm.SCATTERPLOT, mapping="X_umap")
cell_sets = vc.add_view(dataset, cm.CELL_SETS)
genes = vc.add_view(dataset, cm.GENES)
heatmap = vc.add_view(dataset, cm.HEATMAP)<jupyter_output><empty_output><jupyter_text>4.4. Define the visualization layoutThe `vc.layout(view_concat)` method allows us to specify how our views will be arranged in the layout grid in the widget. The `|` and `/` characters are magic syntax for `hconcat(v1, v2)` and `vconcat(v1, v2)`, respectively.<jupyter_code>vc.layout((scatterplot | cell_sets) / (heatmap | genes));<jupyter_output><empty_output><jupyter_text>5. Create the widgetThe `vc.widget()` method returns the configured widget instance.<jupyter_code>vw = vc.widget()
vw<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08525798525798525, 'fraction_numerical': 0.011547911547911549, 'mean_word_length': 6.566914498141264, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '632890', 'license': 'MIT', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1240, 'n_words': 420, 'path': 'docs/notebooks/widget_brain.ipynb', 'repo_name': 'sehilyi/vitessce-python', 'size': '4070'}