HOME  ›   pipelines

# Running spaceranger count (FF)

## Learning objectives

In this tutorial you will:

## Prerequisites

For successful run of this tutorial, you must:

## Overview of Space Ranger's count pipeline

Spatial gene expression for fresh frozen (FF) tissue is determined using spaceranger count pipeline which takes microscope image of the visium slide (in either TIFF or JPEG formats) and sample FASTQ files as inputs. The pipeline performs alignment, tissue and fiducial detection as well as barcode/UMI counting. Outputs capture the feature-spot matrices, clustering and differential gene expression (DGE) which can be further analyzed and visualized in Loupe Browser.

## Example FF dataset

In this tutorial, we will run run spaceranger count pipeline on a mouse brain coronal section public dataset. Key dataset features are:

• Tissue section of 10 µm thickness
• H&E image acquired using a Nikon Ti2-E microscope
• Sequencing Depth: 115,569 read pairs per spot
• Sequencing Coverage: Read 1 - 28 bp (includes 16 bp Spatial Barcode, 12 bp UMI); Read 2 - 120 bp (transcript); i7 sample index - 10 bp; i5 sample index - 10 bp
• Visium Slide: V19L01-041
• Capture Area: C1

All the following commands will be run in the working directory spaceranger_tutorial that was use to setup spaceranger on a compatible compute platform.

### Example dataset

Both the raw sequencing files in FASTQ format, and the image in TIFF format, are available for batch download on the dataset page. For better organization, we will create a datasets folder prior to downloading the required file.

# Create datasets folder
mkdir datasets


% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
0 26.9G    0  135M    0     0  34.4M      0  0:13:22  0:00:03  0:13:19 34.4M


Alternatively, you can also use wget to download.

# Create datasets folder
mkdir datasets


Resolving s3-us-west-2.amazonaws.com (s3-us-west-2.amazonaws.com)... 52.218.217.16
Connecting to s3-us-west-2.amazonaws.com (s3-us-west-2.amazonaws.com)|52.218.217.16|:443...
connected.
HTTP request sent, awaiting response... 200 OK
Length: 28987985920 (27G) [application/x-tar]

10% [=======>                                                                         ] 3,179,419,763 36.2MB/s  eta 11m 35s


### Reference data

Since the example dataset is based on mouse tissue section, we can download the latest version of the mouse transcriptome reference available from the Downloads page. Here the curl download option is highlighted.

# Download mouse reference
curl -O https://cf.10xgenomics.com/supp/spatial-exp/refdata-gex-mm10-2020-A.tar.gz

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
1 9835M    1  158M    0     0  34.1M      0  0:04:48  0:00:04  0:04:44 34.1M


### Extract files

After successful download of the all the required files, the contents of the tar files need to be extracted before moving onto the next steps.

# Extract sample FASTQ files

# Extract mouse reference transcriptome
tar -xzvf refdata-gex-mm10-2020-A.tar.gz && rm refdata-gex-mm10-2020-A.tar.gz

# Sample FASTQ files
...

# Reference mouse transcriptome
refdata-gex-mm10-2020-A/
refdata-gex-mm10-2020-A/fasta/
refdata-gex-mm10-2020-A/fasta/genome.fa
...


Successful extraction will create two additional folders, highlighted in bold, within the working directory.

spaceranger_tutorial
├── datasets
├── refdata-gex-mm10-2020-A
└── spaceranger-2.0.0


## Set up the command for spaceranger count

We now have all the required inputs needed to run the spaceranger count pipeline. To obtain more information about the specifying inputs, print the pipeline specific usage statement.

# Print count usage statement
spaceranger count --help

spaceranger-count
Count gene expression and feature barcoding reads from a single capture area
USAGE:
spaceranger count [FLAGS] [OPTIONS] --id <ID> --transcriptome <PATH> --fastqs <PATH>... <--image <IMG>|--darkimage <IMG>...|--colorizedimage <IMG>>

FLAGS:
--no-bam             Do not generate a bam file
--nosecondary        Disable secondary analysis, e.g. clustering. Optional
--disable-ui         Do not serve the web UI
--noexit             Keep web UI running after pipestance completes or fails
--nopreflight        Skip preflight checks
-h, --help           Prints help information
...

OPTIONS:
--id <ID>                 A unique run id and output folder name [a-zA-Z0-9_-]+
--description <TEXT>      Sample description to embed in output files
--image <IMG>             Single H&E brightfield image in either TIFF or JPG format
--slide <TEXT>            Visium slide serial number, for example 'V10J25-015'
--area <TEXT>             Visium area identifier, for example 'A1'
--transcriptome <PATH>    Path of folder containing 10x-compatible reference
...


We can now build the spaceranger count command for the example dataset. We will running the pipeline in our working directory spaceranger_tutorial assuming the same directory structure as shown previously. The input folder paths below reflect this choice.

In case you have a different setup, amend the paths accordingly prior to running the pipeline to avoid any errors. The easiest method to customize would be to copy the code below in any text editor of your choice (e.g. notepad++), edit and paste it back to the terminal.

spaceranger count --id="V1_Adult_Mouse_Brain" \
--transcriptome=refdata-gex-mm10-2020-A \
--slide=V19L01-041 \
--area=C1 \
--localcores=16 \
--localmem=128

For compute platforms connected to the internet, spaceranger uses the value of the --slide argument to automatically download the slide layout file in gpr format.
spaceranger count --id="V1_Adult_Mouse_Brain" \
--transcriptome=refdata-gex-mm10-2020-A \
--slide=V19L01-041 \
--slidefile=V19L01-041.gpr \
--area=C1 \
--localcores=16 \
--localmem=128

In absence of internet connectivity to the compute platform, you can download this specific slide layout file in gpr format and provide it to spaceranger using the --slidefile argument.

Below are brief descriptions of the above command line options.

Option Description
--id The id must be unique string and will be used to name the resulting folder with all of the pipeline outputs. We choose to keep the original dataset name of V1_Adult_Mouse_Brain
--description This is sample description included in the output files (e.g. web_summary.html). We describe the sample as "Adult Mouse Brain (Coronal)"
--transcriptome The path to the species specific pre-compiled transcriptome files. Note that you can either provide the relative path as shown above or the absolute path to this folder. As the tissue sample was of mouse origin, we provide the path to the mouse reference transcriptome refdata-gex-mm10-2020-A
--fastqs The path to the folder containing sample sequencing files in FASTQ format. The path can be relative as shown above or absolute. The relative path is /datasets/V1_Adult_Mouse_Brain_fastqs
--image The path to a single brightfield image with H&E staining in either TIFF or JPEG formats. The path can be relative or absolute. Here we have a TIFF format image with the following relative path /datasets/V1_Adult_Mouse_Brain_image.tif
--slide The visium slide serial number of which the tissue sample was mounted and the value here is V19L01-041
--area The capture area identifier on the visium slide. It can be one of four values: A1, B1, C1 or D1. Here the tissue sample was mounted on C1 capture area.
--slidefile The slide layout file in gpr format which is provided when spaceranger does not have internet access. You can download the slide layout file and provide it as V19L01-041.gpr
--localcores The number of CPU cores available to run the spaceranger count pipeline. The maximum upper limit for your specific compute system is determined using the sitecheck subcommand. We will use 16 cores in this tutorial.
--localmem The max memory in GB available to run the spaceranger count pipeline. The maximum upper limit for your specific compute system is determined using the sitecheck subcommand. We will use 128 GB in this tutorial.

## Run spaceranger count

At the start of the pipeline, you should see the message about the preflight checks printed to the command line.

# Run spaceranger count
--transcriptome=refdata-gex-mm10-2020-A \
--slide=V19L01-041 \
--area=C1 \
--localcores=16 \
--localmem=128

# Run spaceranger count
--transcriptome=refdata-gex-mm10-2020-A \
--slide=V19L01-041 \
--slidefile=V19L01-041.gpr \
--area=C1 \
--localcores=16 \
--localmem=128

Martian Runtime - v4.0.5

Checking sample info...
Checking FASTQ folder...
Checking reference...
Checking reference_path...
Checking optional arguments...

...


Successful completion of the pipeline is indicated by summary of the output files generated.

Outputs:
- Outputs of spatial pipeline:
cytassist_image:                null
aligned_tissue_image:           null
barcode_fluorescence_intensity: null
- Correlation values between isotypes and Antibody features: null
- BAM CSI index:                                             null
- Filtered feature-barcode matrices MEX:                     /spaceranger_tutorial/V1_Adult_Mouse_Brain/outs/filtered_feature_bc_matrix
- Filtered feature-barcode matrices HDF5:                    /spaceranger_tutorial/V1_Adult_Mouse_Brain/outs/filtered_feature_bc_matrix.h5
- Unfiltered feature-barcode matrices MEX:                   /spaceranger_tutorial/V1_Adult_Mouse_Brain/outs/raw_feature_bc_matrix
- Unfiltered feature-barcode matrices HDF5:                  /spaceranger_tutorial/V1_Adult_Mouse_Brain/outs/raw_feature_bc_matrix.h5
- Secondary analysis output CSV:                             /spaceranger_tutorial/V1_Adult_Mouse_Brain/outs/analysis
- Feature Reference:                                         null
- Target Panel file:                                         null
- Probe Set file:                                            null

Waiting 6 seconds for UI to do final refresh.
Pipestance completed successfully!


## Explore the output of spaceranger count

After the run is completed, the working directory will have a new folder named V1_Adult_Mouse_Brain (value provided to --id argument) that contains all the metadata and outputs generated from the spaceranger count pipeline. We will highlight some key components of this folder (highlighted in bold):

V1_Adult_Mouse_Brain
├── _cmdline
├── _filelist
├── _finalstate
├── _invocation
├── _jobmode
├── _log
├── _mrosource
├── outs
├── _perf
├── _sitecheck
├── SPATIAL_RNA_COUNTER_CS
├── _tags
├── _timestamp
├── _uuid
├── _vdrkill
└── _versions

• outs contains all the final pipeline generated outputs
• V1_Adult_Mouse_Brain.mri.tgz contains diagnostic information helpful to 10x Genomics support to resolve any errors
• _sitecheck captures the system configuration similar to sitecheck subcommand
• _timestamp contains information on pipeline runtimes. The runtime for the example dataset with the above configuration was 1:26:17
• _cmdline captures the count command provided to run the pipeline
• _versions contains both the spaceranger and Martian versions used in the run

The outs folder contain all the calculated results.

You can further explore and understand these results by

• browsing the summary HTML file in any supported web browser. Note that the displayed color scheme for tissue and fiducials has flipped from the earlier version of spaceranger
• continuing further analysis by opening the .cloupe file in Loupe Browser
• referring to the Understanding Output section to explore individual files
• performing downstream analysis using community developed tools (e.g. Seurat, DropletUtils)

## FAQs

Q. I ran spaceranger count and got this error Could not retrieve spot layout data. What does this mean and how can I proceed ?

When you specify the visium slide id using the --slide argument, spaceranger count downloads the corresponding slide file layout file in gpr format. This step requires internet connectivity. However in some instances, compute platforms may not have internet access and hence the resulting error message. If you know the visium slide id, you can download the slide layout file and provide it to the pipeline using the --slidefile argument along with specifying the capture area with --area.

Q. I received visium dataset from my collaborator. However I do not have information about the visium slide id number and the capture area used in the experiment. What can I use instead ?

The spaceranger count pipeline can run in absence of knowledge of actual slide id or capture area information by providing --unknown-slide argument instead. This allows the pipeline to use a default slide layout file that comes bundled with the installation tarball. The typical per-spot difference between the default layout and a specific slide is under 10 microns.

Q. I ran into this error Tissue image incorrectly formatted: TinyImageError What does this mean ?

The spaceranger count pipelines expects an image with atleast 2000 pixels on one side. This error indicates that the provided image does not meet this requirement. You can address this by rescaling the image in any suitable tool (e.g. ImageJ/Fiji Image Magick) such that one of the image dimensions are greater than 2000 pixels. Read more about image requirements and accepted formats in Image Recommendations.