My Profile Photo My Profile Photo


A support website for Alevin-tool (part of Salmon). How Tos and FAQs

Spatial Alevin

Spatial Single-Cell Quantification with alevin

Quantify Spatial Single-Cell Data with alevin

Slide-seq V1-V2 (Rodriques, Samuel G., et al., 2019, Stickels, Robert R., et al., 2020) and 10x Genomics’ Visium Gene Expression has enable the transcriptome-wide measurements of the molecular signals in a tissue with spatial localization at single-cell level. From a quantification point of view, these spatial single-cell technologies requires the generation of a gene-count matrix for each spot on the tissue, which are identified by spatially marked cellular barcodes. Based on the size of a spot & other technological limitations,each spot potentially contains multiple cells and unlike single-cell sequencing a single barcode can contains multiple cells. In this tutorial we generate the spatially-resolved gene-count matrix for each spot using alevin and we visualize it using Seurat.

The sections below contain code chunks executed in different languages, indicated with different background colors. R code is represented by grey boxes and shell commands by blue boxes.

Step 1. Index the reference sequences

In order to quantify the abundances with alevin, we need to generate the index of the reference sequences. Here, we will use prebuild indices from refgenie but in case the index of a reference species is not available, follow the Setting Up Resources tutorial to generate the index.

Please note, based on the availability of the computational resources indexing of the reference sequences can be done at multiple level of accuracy, for more information please check our preprint. In this tutorial we are using sagital mouse brain data from 10X Genomics Visium technology and the selective alignment (SA) index of salmon for mouse reference. The following other options are also available for salmon mouse reference index, these are in the increasing order of their size but also in the improvement of the accuracy:

1.) cDNA index: 455.5MB.
2.) SA index: 806.1MB.
3.) SAF index: 12.1GB.

We start by downloading the SA salmon index from the refgenie website and unpacking the index.

wget --content-disposition  -nv

tar -xvzf salmon_partial_sa_index__default.tgz
## 2020-04-06 13:16:35 URL: [845304904/845304904] -> "salmon_partial_sa_index__default.tgz.1" [1]
## salmon_partial_sa_index/
## salmon_partial_sa_index/complete_ref_lens.bin
## salmon_partial_sa_index/mphf.bin
## salmon_partial_sa_index/rank.bin
## salmon_partial_sa_index/duplicate_clusters.tsv
## salmon_partial_sa_index/gentrome.fa
## salmon_partial_sa_index/mm10.gtf
## salmon_partial_sa_index/pre_indexing.log
## salmon_partial_sa_index/reflengths.bin
## salmon_partial_sa_index/seq.bin
## salmon_partial_sa_index/refAccumLengths.bin
## salmon_partial_sa_index/ctg_offsets.bin
## salmon_partial_sa_index/pos.bin
## salmon_partial_sa_index/decoys.txt
## salmon_partial_sa_index/eqtable.bin
## salmon_partial_sa_index/versionInfo.json
## salmon_partial_sa_index/refseq.bin
## salmon_partial_sa_index/info.json
## salmon_partial_sa_index/ctable.bin
## salmon_partial_sa_index/ref_indexing.log

We also need a tsv file that maps the transcript names to the gene names. The refgenie SA index already contains the reference file used for indexing and we can generate the map file from that as follows:

grep "^>" salmon_partial_sa_index/gentrome.fa | cut -d " " -f 1,7 --output-delimiter=$'\t' - | sed 's/[>"gene_symbol:"]//g' > txp2gene.tsv

Step 2. Download the raw spatial sequencing data

We download the fastq files for the Mouse Brain Serial Section 1 Visium experiment. The raw reads files are available on the website with the hyperlink FASTQ. However, since there is a registration requirements from the source, we are not providing the direct download link. Once downloaded the reads would look like the following:

tar -xvf V1_Mouse_Brain_Sagittal_Anterior_fastqs.tar
## V1_Mouse_Brain_Sagittal_Anterior_Section_1_fastqs/
## V1_Mouse_Brain_Sagittal_Anterior_Section_1_fastqs/V1_Mouse_Brain_Sagittal_Anterior_Section_1_S7_L002_R1_001.fastq.gz
## V1_Mouse_Brain_Sagittal_Anterior_Section_1_fastqs/V1_Mouse_Brain_Sagittal_Anterior_Section_1_S7_L001_I2_001.fastq.gz
## V1_Mouse_Brain_Sagittal_Anterior_Section_1_fastqs/V1_Mouse_Brain_Sagittal_Anterior_Section_1_S7_L002_R2_001.fastq.gz
## V1_Mouse_Brain_Sagittal_Anterior_Section_1_fastqs/V1_Mouse_Brain_Sagittal_Anterior_Section_1_S7_L001_I1_001.fastq.gz
## V1_Mouse_Brain_Sagittal_Anterior_Section_1_fastqs/V1_Mouse_Brain_Sagittal_Anterior_Section_1_S7_L001_R2_001.fastq.gz
## V1_Mouse_Brain_Sagittal_Anterior_Section_1_fastqs/V1_Mouse_Brain_Sagittal_Anterior_Section_1_S7_L002_I1_001.fastq.gz
## V1_Mouse_Brain_Sagittal_Anterior_Section_1_fastqs/V1_Mouse_Brain_Sagittal_Anterior_Section_1_S7_L001_R1_001.fastq.gz
## V1_Mouse_Brain_Sagittal_Anterior_Section_1_fastqs/V1_Mouse_Brain_Sagittal_Anterior_Section_1_S7_L002_I2_001.fastq.gz

We also need the spatial imaging data which contains the spatial coordinates for each cellular barcode on the tissue slide (similar data can be found in the Slides-seq V1-2). The data can be found on the same web link under the name Spatial imaging data. Once downloaded the content of the file looks as follows:

tar -xvzf V1_Mouse_Brain_Sagittal_Anterior_spatial.tar.gz
## spatial/
## spatial/tissue_lowres_image.png
## spatial/tissue_positions_list.csv
## spatial/tissue_hires_image.png
## spatial/scalefactors_json.json
## spatial/detected_tissue_image.jpg
## spatial/aligned_fiducials.jpg

Step 3. Quantify with alevin

we run alevin to quantify the spatial gene abundances based on the index above.
Note: Visium uses 16 length cellular barcode (cb) and 12 length UMI which requires --chorimiumV3 flag, however this should be swapped with either --chromium for 16 length cb, 10 length UMI or --end 5 --barcodeLength X --umiLength Y in case the technology uses different legnths for cb,UMI; where X is the cb length and Y is the UMI length

module load Salmon/1.1.0 && 
salmon alevin -l ISR -i salmon_partial_sa_index \
-1 V1_Mouse_Brain_Sagittal_Anterior_Section_1_S7_L001_R1_001.fastq.gz \
V1_Mouse_Brain_Sagittal_Anterior_Section_1_S7_L002_R1_001.fastq.gz \
-2 V1_Mouse_Brain_Sagittal_Anterior_Section_1_S7_L001_R2_001.fastq.gz \
V1_Mouse_Brain_Sagittal_Anterior_Section_1_S7_L002_R2_001.fastq.gz \
-o alevin_out -p 16 --tgMap txp2gene.tsv \
--chromiumV3 --dumpFeatures

Step 4. Loading data into R

We start by loading the required R packages.
Note: We need the spatial branch of Seurat package to support the spatial data processing.


    # use the below command to install spatial Seurat
    # devtools::install_github("satijalab/seurat", ref = "spatial")

We load the alevin generated spot-gene count matrix using tximport package and create a Seurat object.

files <- file.path("~/alevin_out/alevin/quants_mat.gz")
## [1] TRUE
# tximport loads the alevin data into R
txi <- tximport(files = files, type = "alevin")
## reading in alevin gene-level counts across cells with fishpond
# Creating a Seurat object with spatial assay
assay <- "Spatial"
brain <- CreateSeuratObject(counts = txi$counts, project = "SPATIAL", assay = assay)
## An object of class Seurat 
## 31460 features across 3728 samples within 1 assay 
## Active assay: Spatial (31460 features, 0 variable features)

We load the spatial image data to extract the spatial 2D coordinates of each cellular barcodes and add the metadata to the Seurat object.

# loading the 10x image data <- Read10X_Image("~/spatial/")

# Since the names of alevin cb is different from 10x
# we rename the cells and filter the image data
# to have the metadata for only quantified cells
rownames( <- gsub("-1", "", rownames(
common.cells <- intersect(Cells(x = brain), rownames( <-[common.cells]
brain <- subset(brain, cells = common.cells)

# adding image data to Seurat object
DefaultAssay(object = <- "Spatial"
brain[['slice']] <-

Step 5. Visualization

Once we have the Seurat object we can use all the exciting features made available through the Seurat package. We use the spatial vignette provided by the Seurat package for visualizing the Spatial data.

plot1 <- VlnPlot(brain, features = "nCount_Spatial", pt.size = 0.1) + NoLegend()
plot2 <- SpatialFeaturePlot(brain, features = "nCount_Spatial") + theme(legend.position = "right")
wrap_plots(plot1, plot2)

We can also perform the gene expression visualization after normalizing the data through scTransform.

brain <- SCTransform(brain, assay = "Spatial", verbose = FALSE)
SpatialFeaturePlot(brain, features = c("Hpca", "Ttr"))