First compiled: November 11, 2017 by T. Callies.
| Gene_Exploration | Cluster_Visualization | Pseudotime |
|---|---|---|
In contrast to Scanpy's builtin visualization tools, the graph drawing tool SPRING of Weinreb et al. (2017) allows an interactive exploration of data.
Scanpy allows exporting SPRING projects via sc.export_to.spring_dir.
To start, clone (or download) https://github.com/AllonKleinLab/SPRING to your preferred destination directory, in the following referred to as SPRING_INSTALLATION. Here, we use the current working directory of this notebook.
git clone https://github.com/AllonKleinLab/SPRING.git
After exporting an AnnData object adata
sc.export_to.spring_project(adata)
in the terminal, type
python -m http.server 8000 &
or python3 if python defaults to a Python 2 installation.
Now, in a browser, open
http://localhost:8000/<SPRING_INSTALLATION>/springViewer.html?<Relative_Path_To_SPRING_PROJECT>
In [1]:
import scanpy.api as sc
import numpy as np
sc.settings.verbosity = 3 # verbosity = 3: errors, warnings, info, hints
sc.settings.set_figure_params(dpi=80) # dots (pixels) per inch determine size of inline figures
sc.logging.print_versions()
For background information, see here.
In [2]:
adata_krumsiek11 = sc.datasets.krumsiek11()
Let us add some computational analysis results.
In [3]:
sc.pp.neighbors(adata_krumsiek11)
In [4]:
sc.tl.louvain(adata_krumsiek11)
sc.tl.dpt(adata_krumsiek11, n_branchings=1)
The sc.tl.draw_graph function provides various graph drawing layouts, but not in an interactive way.
In [5]:
sc.tl.draw_graph(adata_krumsiek11)
Let's plot this.
In [6]:
sc.pl.draw_graph(adata_krumsiek11, color=['cell_type', 'louvain', 'dpt_groups', 'dpt_pseudotime', 'Gata1'])
In [7]:
adata_krumsiek11.write('./write/krumsiek11.h5')
Exporting the results to a SPRING project directory.
In [8]:
adata_krumsiek11 = sc.read('./write/krumsiek11.h5')
In [9]:
sc.export_to.spring_project(adata_krumsiek11, './spring_krumsiek11')
Now, after starting a server, open
http://localhost:8000/SPRING/springViewer.html?../spring_kurmsiek11
You might need to click 'center view' and 'deselect all' to see the data.
This starts from the standard clustering tutorial: https://github.com/theislab/scanpy_usage/tree/master/170505_seurat.
Selecting genes: It is recommended that - especially for large datasets - only a preselected number of genes of interest is used for SPRING, so that these genes can be found more easily (in the dataset below, searching for a certain gene in a dropdown list of ca. 13000 entries can be hard ).
In [10]:
adata = sc.read('../170505_seurat/write/pmbc3k.h5ad')
In [11]:
sc.tl.draw_graph(adata)
Plot the groups.
In [12]:
sc.pl.draw_graph(adata, color=['NKG7', 'louvain'])
In [13]:
# Rank genes in order to include only significant ones.
# Note that the ranking function by default ranks 100, not 20 as displayed below.
sc.tl.rank_genes_groups(adata, 'louvain')
sc.pl.rank_genes_groups(adata, n_genes=20)
In [14]:
# export some known marker genes
known_marker_genes = ['IL7R','CD14','LYZ', 'MS4A1', 'CD8A', 'FCGR3A', 'MS4A7',
'GNLY', 'NKG7', 'FCER1A', 'CST3', 'PPBP']
sc.export_to.spring_project(
adata, './spring_pbmc3k_known_markers',
use_genes=known_marker_genes)
In [16]:
# export the ranked genes
sc.export_to.spring_project(
adata, './spring_pbmc3k_ranked_genes',
use_genes='rank_genes_groups')