mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-15 12:47:56 +08:00
236 lines
17 KiB
HTML
236 lines
17 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en-US">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
|
||
<!-- Begin Jekyll SEO tag v2.6.1 -->
|
||
<title>prepare | cellxgene</title>
|
||
<meta name="generator" content="Jekyll v3.8.7" />
|
||
<meta property="og:title" content="prepare" />
|
||
<meta property="og:locale" content="en_US" />
|
||
<meta name="description" content="Preparing your data" />
|
||
<meta property="og:description" content="Preparing your data" />
|
||
<link rel="canonical" href="https://chanzuckerberg.github.io/cellxgene/posts/prepare.html" />
|
||
<meta property="og:url" content="https://chanzuckerberg.github.io/cellxgene/posts/prepare.html" />
|
||
<meta property="og:site_name" content="cellxgene" />
|
||
<script type="application/ld+json">
|
||
{"publisher":{"@type":"Organization","logo":{"@type":"ImageObject","url":"https://chanzuckerberg.github.io/cellxgene/cellxgene-logo.png"}},"url":"https://chanzuckerberg.github.io/cellxgene/posts/prepare.html","headline":"prepare","description":"Preparing your data","@type":"WebPage","@context":"https://schema.org"}</script>
|
||
<!-- End Jekyll SEO tag -->
|
||
|
||
<link rel="stylesheet" href="/cellxgene/assets/css/style.css?v=2f67096579ad5dffe6ef2633dfbeda1e46b9fd16">
|
||
<!--[if lt IE 9]>
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script>
|
||
<![endif]-->
|
||
</head>
|
||
<body>
|
||
<div class="wrapper">
|
||
<header>
|
||
<img src="/cellxgene/cellxgene-logo.png" alt="cellxgene" />
|
||
|
||
<p>An interactive explorer for single-cell transcriptomics data</p>
|
||
<p>
|
||
|
||
|
||
<a href="/cellxgene/" class="btn">Quick start</a><br>
|
||
|
||
|
||
|
||
|
||
<a href="/cellxgene/posts/install" class="btn">Installation</a><br>
|
||
|
||
|
||
|
||
<a href="/cellxgene/posts/gallery" class="btn">Gallery</a><br>
|
||
|
||
|
||
|
||
<a href="/cellxgene/posts/demo-data" class="btn">Demo datasets</a><br>
|
||
|
||
|
||
|
||
<a href="/cellxgene/posts/prepare" class="btn"><b>Preparing your data</b></a><br>
|
||
|
||
|
||
|
||
<a href="/cellxgene/posts/launch" class="btn">Launching cellxgene</a><br>
|
||
|
||
|
||
|
||
<a href="/cellxgene/posts/hosted" class="btn">Hosting cellxgene</a><br>
|
||
|
||
|
||
|
||
<a href="/cellxgene/posts/annotations" class="btn">Annotating data</a><br>
|
||
|
||
|
||
|
||
<a href="/cellxgene/posts/methods" class="btn">Methods</a><br>
|
||
|
||
|
||
|
||
<a href="/cellxgene/posts/troubleshooting" class="btn">Troubleshooting</a><br>
|
||
|
||
|
||
|
||
<a href="/cellxgene/posts/roadmap" class="btn">Roadmap</a><br>
|
||
|
||
|
||
|
||
<a href="/cellxgene/posts/contribute" class="btn">Contributing (ideas or code)</a><br>
|
||
|
||
|
||
|
||
<a href="/cellxgene/posts/contact" class="btn">Contact & finding help</a><br>
|
||
|
||
|
||
|
||
<a href="/cellxgene/posts/cellxgene_cziscience_com" class="btn">cellxgene.cziscience.com</a><br>
|
||
|
||
|
||
|
||
<a href="https://github.com/chanzuckerberg/cellxgene" class="btn" target="_blank">Code</a>
|
||
</p>
|
||
</header>
|
||
|
||
<section>
|
||
<h1 id="data-format-requirements">Data format requirements</h1>
|
||
|
||
<p>If your data is in <code class="language-plaintext highlighter-rouge">h5ad</code> file (from the <a href="https://anndata.readthedocs.io/en/latest/index.html"><code class="language-plaintext highlighter-rouge">anndata</code></a> library) and meets the following requirements, you can go straight to <code class="language-plaintext highlighter-rouge">cellxgene launch</code>:</p>
|
||
|
||
<ul>
|
||
<li>Expression values (raw or normalized) in <code class="language-plaintext highlighter-rouge">anndata.X</code></li>
|
||
<li>At least one embedding (e.g., tSNE, UMAP) in <code class="language-plaintext highlighter-rouge">anndata.obsm</code>, specified with the prefix <code class="language-plaintext highlighter-rouge">X_</code> (e.g., by default scanpy stores UMAP coordinates in <code class="language-plaintext highlighter-rouge">anndata.obsm['X_umap']</code>)</li>
|
||
<li>A unique identifier is required for each cell, which by default will be pulled from the <code class="language-plaintext highlighter-rouge">obs</code> DataFrame index. If the index is not unique or does not contain the cell ID, an alternative column can be specified with <code class="language-plaintext highlighter-rouge">--obs-names</code></li>
|
||
<li>A unique identifier is required for each gene, which by default will be pulled from the <code class="language-plaintext highlighter-rouge">var</code> DataFrame index. If the index is not unique or does not contain the gene ID, an alternative column can be specified with <code class="language-plaintext highlighter-rouge">--var-names</code></li>
|
||
</ul>
|
||
|
||
<h4 id="what-about-r-objects-from-seurat--bioconductor">What about R objects from seurat / bioconductor!?</h4>
|
||
<p>We hear you! We’d also love to be able to ingest these files directly. This isn’t currently possible, but in the meantime, you can use <a href="https://bioconda.github.io/recipes/r-sceasy/README.html">sceasy</a> (<a href="https://cellgeni.readthedocs.io/en/latest/visualisations.html">docs</a>) to convert to <code class="language-plaintext highlighter-rouge">h5ad</code>. Seurat also has some <a href="https://satijalab.org/seurat/v3.0/conversion_vignette.html">handy conversion tools</a> that you can try out.</p>
|
||
|
||
<h4 id="can-i-use-data-hosted-on-the-web-somewhere">Can I use data hosted on the web somewhere?</h4>
|
||
<p>Yes! You can launch from a URL instead of a filepath. The same data format requirements apply. Please see <a href="launch">here</a> for more details.</p>
|
||
|
||
<h1 id="data-format-options">Data format options</h1>
|
||
|
||
<h4 id="category-colors">Category colors</h4>
|
||
<p><code class="language-plaintext highlighter-rouge">cellxgene</code> will display <a href="https://github.com/chanzuckerberg/cellxgene/issues/1152#issue-564361541">scanpy-style color
|
||
information</a>
|
||
for category-label pairs. An example of this format is shown below:</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>>>> category = "louvain"
|
||
>>> # colors stored in adata.uns must be matplotlib-compatible color information
|
||
>>> adata.uns[f"{category}_colors"]
|
||
array(['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#bcbd22'], dtype='<U7')
|
||
>>> # there must be a matching category in adata.obs
|
||
>>> category in adata.obs
|
||
True
|
||
</code></pre></div></div>
|
||
|
||
<p>To test that you’ve done this properly, check that for your given <code class="language-plaintext highlighter-rouge">category</code> the number of colors match the number of category values and that the second command below results in a mapping from categories to colors.</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>>>> len(adata.obs[category].cat.categories) == len(adata.uns[f"{category}_colors"])
|
||
True
|
||
>>> dict(zip(adata.obs[category].cat.categories, adata.uns[f"{category}_colors"]))
|
||
{'CD4 T cells': '#1f77b4', 'CD14+ Monocytes': '#ff7f0e', 'B cells': '#2ca02c', 'CD8 T cells': '#d62728', 'NK cells': '#9467bd', 'FCGR3A+ Monocytes': '#8c564b', 'Dendritic cells': '#e377c2', 'Megakaryocytes': '#bcbd22'}
|
||
</code></pre></div></div>
|
||
|
||
<p>You can disable this feature using the <code class="language-plaintext highlighter-rouge">--disable-custom-colors</code> flag for <code class="language-plaintext highlighter-rouge">cellxgene launch</code>. cellxgene will then chose colors from its standard color palettes.</p>
|
||
|
||
<h1 id="using-cellxgene-prepare">Using <code class="language-plaintext highlighter-rouge">cellxgene prepare</code></h1>
|
||
|
||
<p>If your data is in a different format, and/or you still need to perform dimensionality reduction and/or clustering, <code class="language-plaintext highlighter-rouge">cellxgene</code> can do that for you with the <code class="language-plaintext highlighter-rouge">prepare</code> command.</p>
|
||
|
||
<h2 id="what-is-cellxgene-prepare">What is <code class="language-plaintext highlighter-rouge">cellxgene prepare</code>?</h2>
|
||
|
||
<p><code class="language-plaintext highlighter-rouge">cellxgene prepare</code> offers an easy command line interface (CLI) to preliminarily wrangle your data into the required format for previewing it with cellxgene. It runs <code class="language-plaintext highlighter-rouge">scanpy</code> under the hood and can read in any format that is currently supported by <code class="language-plaintext highlighter-rouge">scanpy</code> (including mtx, loom, and more listed <a href="https://scanpy.readthedocs.io/en/latest/api/index.html#reading">in the scanpy documentation</a>).</p>
|
||
|
||
<p><code class="language-plaintext highlighter-rouge">prepare</code> uses scanpy to:</p>
|
||
|
||
<ul>
|
||
<li>Handle simple data normalization (from a <a href="https://www.pydoc.io/pypi/scanpy-0.2.3/autoapi/preprocessing/recipes/index.html">recipe</a>)</li>
|
||
<li>Do basic preprocessing to run PCA and compute the neighbor graph</li>
|
||
<li>Reduce dimensionality to generate embeddings</li>
|
||
<li>Infer clusters</li>
|
||
</ul>
|
||
|
||
<p>You can control which steps to run and their methods (when applicable), via the CLI. The CLI also includes options for computing QC metrics, enforcing matrix sparcity, specifying index names, and plotting output.</p>
|
||
|
||
<h2 id="what-is-cellxgene-prepare-not">What is cellxgene <code class="language-plaintext highlighter-rouge">prepare</code> <em>not</em>?</h2>
|
||
|
||
<p><code class="language-plaintext highlighter-rouge">cellxgene prepare</code> is not meant as a way to formally process or analyze your data. It’s simply a utility for quickly wrangling your data into cellxgene-compatible format and computing a “vanilla” embedding so you can try out <code class="language-plaintext highlighter-rouge">cellxgene</code> and get a general sense of a dataset.</p>
|
||
|
||
<h2 id="quickstart-for-cellxgene-prepare">Quickstart for <code class="language-plaintext highlighter-rouge">cellxgene prepare</code></h2>
|
||
<p>To add <code class="language-plaintext highlighter-rouge">cellxgene prepare</code> to your <a href="install">cellxgene installation</a>, run
|
||
<code class="language-plaintext highlighter-rouge">pip install cellxgene[prepare]</code></p>
|
||
|
||
<p>Then run <code class="language-plaintext highlighter-rouge">prepare</code> on your data with:</p>
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>cellxgene prepare dataset.h5ad --output=dataset-processed.h5ad
|
||
</code></pre></div></div>
|
||
|
||
<p>This will load the input data, perform PCA and nearest neighbor calculations, compute <code class="language-plaintext highlighter-rouge">UMAP</code> and <code class="language-plaintext highlighter-rouge">tSNE</code> embeddings and <code class="language-plaintext highlighter-rouge">louvain</code> cluster assignments, and save the results in a new file called <code class="language-plaintext highlighter-rouge">dataset-processed.h5ad</code> that can be loaded using <code class="language-plaintext highlighter-rouge">cellxgene launch</code>.</p>
|
||
|
||
<h2 id="example-usage">Example usage</h2>
|
||
|
||
<p>As a quick example, let’s construct a command to use <code class="language-plaintext highlighter-rouge">prepare</code> to take a raw expression matrix and generate a processed <code class="language-plaintext highlighter-rouge">h5ad</code> ready to visualize with cellxgene.</p>
|
||
|
||
<p>We’ll start off using the raw data from the pbmc3k dataset. This dataset is described <a href="https://icb-scanpy.readthedocs-hosted.com/en/stable/api/scanpy.datasets.pbmc3k.html">here</a>, and is available as part of the scanpy package. For this example, we’ll assume this raw data is stored in a file called <code class="language-plaintext highlighter-rouge">pbmc3k-raw.h5ad</code>.</p>
|
||
|
||
<p>Our <code class="language-plaintext highlighter-rouge">prepare</code> command looks like this:</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>cellxgene prepare pbmc3k-raw.h5ad \
|
||
--run-qc \ # (A)
|
||
--recipe seurat \ # (B)
|
||
--layout tsne --layout umap \ # (C)
|
||
--output pbmc3k-prepared.h5ad # (D)
|
||
</code></pre></div></div>
|
||
|
||
<p>Let’s look at what <code class="language-plaintext highlighter-rouge">prepare</code> is doing to our data, and how each step relates to the command above. You can see a walkthrough of what’s going on under the hood for this example in <a href="https://github.com/chanzuckerberg/cellxgene-vignettes/blob/master/dataset-processing/pbmc3k-prepare-example.ipynb">this notebook</a>.</p>
|
||
|
||
<p><strong>(A) - Compute quality control metrics and store this in our <code class="language-plaintext highlighter-rouge">AnnData</code> object for later inspection</strong>
|
||
<strong>(B) - Normalize the expression matrix using a basic preprocessing recipe</strong>
|
||
<strong>(auto) - Do some preprocessing to run PCA and compute the neighbor graph</strong>
|
||
<strong>(auto) - Infer clusters with the Louvain algorithm and store these labels to visualize later</strong>
|
||
<strong>(C) - Compute and store UMAP and tSNE embeddings</strong>
|
||
<strong>(D) - Write results to file</strong></p>
|
||
|
||
<h2 id="options-for-cellxgene-prepare">Options for cellxgene <code class="language-plaintext highlighter-rouge">prepare</code></h2>
|
||
|
||
<p><strong>For the most up-to-date and comprehensive list of options, run <code class="language-plaintext highlighter-rouge">cellxgene prepare --help</code></strong></p>
|
||
|
||
<p><code class="language-plaintext highlighter-rouge">--embedding</code> controls which dimensionality reduction algorithm is applies to your data.
|
||
Options are <code class="language-plaintext highlighter-rouge">umap</code> and/or <code class="language-plaintext highlighter-rouge">tsne</code>. Defaults to both.</p>
|
||
|
||
<p><code class="language-plaintext highlighter-rouge">--recipe</code> controls which normalization steps to apply to your data, based on one of the preprocessing <code class="language-plaintext highlighter-rouge">recipes</code> included with <code class="language-plaintext highlighter-rouge">scanpy</code>.
|
||
These recipes include steps like cell filtering and gene selection; see the <code class="language-plaintext highlighter-rouge">scanpy</code> <a href="https://scanpy.readthedocs.io/en/latest/api/index.html#recipes">documentation</a> for more details.
|
||
Options are <code class="language-plaintext highlighter-rouge">none</code>, <code class="language-plaintext highlighter-rouge">seurat</code>, or <code class="language-plaintext highlighter-rouge">zheng17</code>. Defaults to <code class="language-plaintext highlighter-rouge">none</code>.</p>
|
||
|
||
<p><code class="language-plaintext highlighter-rouge">--sparse</code> is a flag determines whether to enforce a sparse matrix. For large datasets, <code class="language-plaintext highlighter-rouge">prepare</code> can take a long time to run (a few minutes for datasets with 10-100k cells, up to an hour or more for datasets with >100k cells). If you want <code class="language-plaintext highlighter-rouge">prepare</code> to run faster we recommend using the <code class="language-plaintext highlighter-rouge">sparse</code> option.
|
||
If this flag is not included, default is <code class="language-plaintext highlighter-rouge">False</code></p>
|
||
|
||
<p><code class="language-plaintext highlighter-rouge">--skip-qc</code> by default, <code class="language-plaintext highlighter-rouge">cellxgene prepare</code> will compute quality control metrics (saved to <code class="language-plaintext highlighter-rouge">anndata.obs</code> and <code class="language-plaintext highlighter-rouge">anndata.var</code>) as described in the <code class="language-plaintext highlighter-rouge">scanpy</code> <a href="https://scanpy.readthedocs.io/en/stable/api/scanpy.pp.calculate_qc_metrics.html">documentation</a>. Pass this flag if you would like to skip this step.</p>
|
||
|
||
<p><code class="language-plaintext highlighter-rouge">--make-obs-names-unique</code> / <code class="language-plaintext highlighter-rouge">--make-var-names-unique</code> determine whether to rename <code class="language-plaintext highlighter-rouge">obs</code> (cell) / <code class="language-plaintext highlighter-rouge">var</code> (gene) names, respectively, to be unique.
|
||
Default is <code class="language-plaintext highlighter-rouge">True</code>.</p>
|
||
|
||
<p><code class="language-plaintext highlighter-rouge">--set-obs-names</code> controls which field in <code class="language-plaintext highlighter-rouge">anndata.obs</code> (cell metadata) is used as the <em>index</em> for cells (e.g., a cell ID column).
|
||
Default is <code class="language-plaintext highlighter-rouge">anndata.obs.names</code></p>
|
||
|
||
<p><code class="language-plaintext highlighter-rouge">--set-var-names</code> controls which field in <code class="language-plaintext highlighter-rouge">anndata.var</code> (gene metadata) is used as the <em>index</em> for genes.
|
||
Default is <code class="language-plaintext highlighter-rouge">anndata.var.names</code></p>
|
||
|
||
<p><code class="language-plaintext highlighter-rouge">--output</code> and <code class="language-plaintext highlighter-rouge">--overwrite</code> control where the processed data is saved.</p>
|
||
|
||
</section>
|
||
<footer>
|
||
|
||
<p>This project is maintained by <a href="https://github.com/chanzuckerberg">chanzuckerberg</a></p>
|
||
|
||
</footer>
|
||
</div>
|
||
<script src="/cellxgene/assets/js/scale.fix.js"></script>
|
||
|
||
</body>
|
||
</html>
|