Skip to content

10X VisiumHD Starter Tutorial

Input Data

The input data originates from the mouse hippocampus and is extracted from an official release of mouse brain spatial gene expression (SGE) data.

File Format

Visium HD slides use a 2×2 µm grid of barcoded squares (square_002um) for high-resolution spatial gene mapping. The SGE file format comprises several key files as below:

barcodes.tsv.gz – spatial barcode for tissue locations
1
2
3
s_002um_00639_00600-1
s_002um_00923_01639-1
s_002um_01050_01530-1
  • Column 1: spatial barcodes corresponding to specific locations on the tissue section.
features.tsv.gz – feature metadata
1
2
3
ENSMUSG00000051951  Xkr4    Gene Expression
ENSMUSG00000025900  Rp1     Gene Expression
ENSMUSG00000025902  Sox17   Gene Expression
  • Column 1: Feature ID
  • Column 2: Feature symbol
  • Column 3: Features types
matrix.mtx.gz – expression count matrix
1
2
3
4
5
6
%%MatrixMarket matrix coordinate integer general
%
19059 869411 11376563
3606 1 1
8957 1 1
9733 1 1
  • Header: Initial lines form the header, declaring the matrix's adherence to the Market Matrix (MTX) format, outlining its traits. This may include comments (lines beginning with %) for extra metadata, all marked by a “%”.
  • Dimensions: Following the header, the first line details the matrix dimensions: the count of rows (features), columns (barcodes), and non-zero entries.
  • Data Entries: Post-dimensions, subsequent lines enumerate non-zero entries in seven columns: row index (feature index), column index (barcode index), and one value presenting the expression count per barcode per feature.
tissue_positions.parquet – spatial barcode metadata
1
2
barcode                 in_tissue   array_row   array_col   pxl_row_in_fullres  pxl_col_in_fullres
s_002um_00434_01637-1   1           434         1637        3396.371014         9125.919898
  • barcode: Unique spatial barcode associated with each capture spot.
  • in_tissue: Binary flag (1 = in tissue, 0 = background) indicating whether the spot falls within the tissue boundary.
  • array_row, array_col: Integer indices representing the position of the spot on the capture array grid.
  • pxl_row_in_fullres, pxl_col_in_fullres: Floating point coordinates locating the spot in full-resolution tissue image pixels.
scalefactors_json.json – pixel-to-micrometer scaling factors
1
2
3
4
5
6
7
8
9
{
    "spot_diameter_fullres": 7.303953797779634,
    "bin_size_um": 2.0,
    "microns_per_pixel": 0.2738242950835738,
    "regist_target_img_scalef": 0.2505533,
    "tissue_lowres_scalef": 0.02505533,
    "fiducial_diameter_fullres": 1205.1523766336395,
    "tissue_hires_scalef": 0.2505533
}
  • spot_diameter_fullres: Estimated diameter of a barcoded spot in full-resolution pixels.
  • bin_size_um: Physical size (in micrometers) of the smallest bin, typically 2.0 µm for Visium HD.
  • microns_per_pixel: Resolution of the full-res image, used to convert pixel distances to micrometers.
  • regist_target_img_scalef: Scaling factor applied during image registration to the target image.
  • tissue_lowres_scalef: Downscaling factor from full-res to low-resolution tissue image.
  • fiducial_diameter_fullres: Diameter of fiducial markers in full-resolution pixels, useful for alignment.
  • tissue_hires_scalef: Downscaling factor from full-res to high-resolution tissue image.

Data Access

The example data is hosted on Zenedo ().

Follow the commands below to download the example data.

1
2
3
4
work_dir=/path/to/work/directory
cd $work_dir
wget  https://zenodo.org/records/15786632/files/visiumhd_starter.raw.tar.gz 
tar -zxvf visiumhd_starter.raw.tar.gz  

Set Up the Environment

Define paths to all required binaries and resources. Optionally, specify a fixed color map for consistent rendering.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# ====
# Replace each placeholder with the actual path on your system.  
# ====

work_dir=/path/to/work/directory        # path to work directory that contains the downloaded input data
cd $work_dir

# Define paths to required binaries and resources
spatula=/path/to/spatula/binary         # path to spatula executable
punkst=/path/to/punkst/binary           # path to FICTURE2/punkst executable
tippecanoe=/path/to/tippecanoe/binary   # path to tippecanoe executable
pmtiles=/path/to/pmtiles/binary         # path to pmtiles executable
aws=/path/to/aws/cli/binary             # path to AWS CLI binary

# (Optional) Define path to color map. 
cmap=/path/to/color/map                 # Path to the fixed color map for rendering. cartloader provides a fixed color map at cartloader/assets/fixed_color_map_256.tsv.

# Number of jobs
n_jobs=10                               # If not specify, the number of jobs defaults to 1.

# Activate the bioconda environment
conda activate ENV_NAME                 # replace BIOENV_NAME with your bioconda environment name

Define data ID and analysis parameters:

1
2
3
4
5
6
7
# Unique identifier for your dataset
DATA_ID="visiumhd_hippo"                 # change this to reflect your dataset name
PLATFORM="10x_visium_hd"                 # platform information

# LDA parameters
train_width=18                           # define LDA training hexagon width (comma-separated if multiple widths are applied)
n_factor=6,12                            # define number of factors in LDA training (comma-separated if multiple n-factor are applied)

How to Define Scaling Factors for Visium HD

10x Visium HD includes a scalefactors_json.json file that provides pixel-to-micrometer scaling information. cartloader can directly accept this file via the --scale-json option and will automatically compute the appropriate scaling factor, omitting manually calculate and specify --units-per-um.

Alternatively, users may bypass the JSON file by directly providing a value through the --units-per-um option.

SGE Format Conversion

Convert the raw input to the unified SGE format. See more details in Reference page.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
cartloader sge_convert \
  --makefn sge_convert.mk \
  --platform ${PLATFORM} \
  --in-mex ./raw \
  --in-parquet ./raw/tissue_positions.parquet \
  --scale-json ./raw/scalefactors_json.json \
  --out-dir ./sge \
  --exclude-feature-regex '^(BLANK|NegCon|NegPrb)' \
  --sge-visual \
  --spatula ${spatula} \
  --n-jobs ${n_jobs}
Parameter Required Type Description
--platform required string Platform (options: "10x_visium_hd", "seqscope", "10x_xenium", "bgi_stereoseq", "cosmx_smi", "vizgen_merscope", "pixel_seq", "generic")
--in-mex required string Path to the input MEX directory containing gene × barcode matrix
--in-parquet required string Path to the tissue_positions.parquet file with spatial barcode metadata
--scale-json required 1 string Path to the scalefactors_json.json file for coordinate scaling (or use --units-per-um to specify directly)
--out-dir required string Output directory for the converted SGE files
--makefn string File name for the generated Makefile (default: sge_convert.mk)
--exclude-feature-regex regex Pattern to exclude control features
--sge-visual flag Enable SGE visualization step (generates diagnostic image) (default: FALSE)
--spatula string Path to the spatula binary (default: spatula)
--n-jobs int Number of parallel jobs for processing (default: 1)

1: To define the scaling factor, cartloader requires either a JSON file (via --scale-json) or a direct scale value using --units-per-um. When using --scale-json, make sure the JSON file has microns_per_pixel information.

FICTURE Analysis

Parameter Required Type Description
--main required 1 flag Enable cartloader to run all five steps
--in-transcript required string Path to input transcript-level SGE file
--out-dir required string Path to output directory
--width required int or comma-separated list LDA training hexagon width(s)
--n-factor required int or comma-separated list Number of LDA factors
--makefn string File name for the generated Makefile (default: run_ficture2.mk )
--in-feature string Path to input feature file
--in-minmax string Path to input coordinate min/max file
--cmap-file string Path to color map file
--exclude-feature-regex regex Pattern to exclude features
--spatula string Path to the spatula binary (default: spatula)
--ficture2 string Path to the punkst directory (defaults to punkst repository within submodules directory of cartloader)
--n-jobs int Number of parallel jobs (default: 1)
--threads int Number of threads per job (default: 1)

1: cartloader requires the user to specify at least one action. Available actions includes: --tile to run tiling step; --segment to run segmentation step; --init-lda to run LDA training step; --decode to run decoding step; --summary to run summarization step; --main to run all above five actions.

cartloader Compilation

Generate pmtiles and web-compatible tile directories. See more details in Reference page.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
cartloader run_cartload2 \
  --makefn run_cartload2.mk \
  --fic-dir ./ficture2 \
  --out-dir ./cartload2 \
  --id ${DATA_ID} \
  --spatula ${spatula} \
  --pmtiles ${pmtiles} \
  --tippecanoe ${tippecanoe} \
  --n-jobs ${n_jobs} \
  --threads ${n_jobs}
Parameter Required Type Description
--fic-dir required string Path to the input directory containing FICTURE2 output
--out-dir required string Path to the output directory for PMTiles and web tiles
--id required string Dataset ID used for naming outputs and metadata
--makefn string File name for the generated Makefile (default: run_cartload2.mk)
--spatula string Path to the spatula binary (default: spatula)
--pmtiles string Path to the pmtiles binary (default: pmtiles)
--tippecanoe string Path to the tippecanoe binary (default: tippecanoe)
--n-jobs int Number of parallel jobs (default: 1)
--threads int Number of threads per job (default: 1)

Upload to Data Repository

Choose a data repository to host/share your output

cartloader supports two upload options (AWS and Zenodo) for storing PMTiles of SGE and spatial factors in a data repository.

Choose the one that best suits your needs.

AWS Uploads

Upload the generated cartloader outputs to your designated AWS S3 directory:

1
2
3
4
5
6
7
8
# AWS S3 target location for cartostore
AWS_BUCKET="EXAMPLE_AWS_BUCKET"         # replace EXAMPLE_AWS_BUCKET with your actual S3 bucket name

cartloader upload_aws \
  --in-dir ./cartload2 \
  --s3-dir "s3://${AWS_BUCKET}/${DATA_ID}" \
  --aws ${aws} \
  --n-jobs ${n_jobs}
Parameter Required Type Description
--in-dir required string Path to the input directory containing the cartloader compilation output
--s3-dir required string Path to the target S3 directory for uploading
--aws string Path to the AWS CLI binary
--n-jobs int Number of parallel jobs

Zenodo Uploads

Upload the generated cartloader outputs to your designated Zenodo deposition or a new deposition.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
zenodo_token=/path/to/zenodo/token/file    # replace /path/to/zenodo/token/file by path to your zenodo token file

cartloader upload_zenodo \
  --in-dir ./cartload2 \
  --upload-method catalog \
  --zenodo-token $zenodo_token \
  --create-new-deposition \
  --title  "Yur Title" \
  --creators "Your Name" \
  --description "This is an example description"
Parameter Required Type Description
--in-dir required string Path to the input directory containing the cartloader compilation output
--upload-method required string Method to determine which files to upload. Options: all to upload all files in --in-dir; catalog to upload files listed in a catalog YAML file, user_list to upload files explicitly listed via --in-list
--catalog-yaml string Required if --upload-method catalog. Path to the catalog.yaml file generated in run_cartload2. If absent, will use the catalog.yaml in the input directory specified by --in-dir.
--zenodo-token required string Path to your Zenodo access file
--create-new-deposition flag a new Zenodo deposition will be created.
--title required string Required if --create-new-deposition. Title for the new Zenodo deposition.
--creators required list of str List of creators in "Lastname, Firstname" format.

Output Data

See more details of output at the Reference pages for run_ficture2 and run_cartload2.

Spatial Factor Inference from FICTURE

Below is an example of spatial factor inference results produced by FICTURE using a training width of 18, 12 factors, a fit width of 18, and an anchor resolution of 6.

FICTURE cmap

Factor RGB Weight PostUMI TopGene_pval TopGene_fc TopGene_weight
0 255,101,101 0.20931 2920184 Atp2b1,Tmsb4x,Hpca,Wfs1,Cck,Plk2,Ptk2b,Rasgrp1,Scn3b,Cacng8,Ppp3r1,Kcnab1,Man1a,Epha6,Ppp3ca,Khdrbs3,Fibcd1,Prkcg,Rasd1,Itpka Lefty1,Stac,Grem1,Wnt11,Spink8,Wfs1,Fibcd1,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pm6a,Selenow,Eef1a2,Atp1b1,Kalrn,Ptms,Ppp3ca,Gria2,Snhg11,Map1b
10 178,101,255 8e-05 1124 Hbb-bs,Hba-a2,S100a9,S100a8,Hbb-bt,Anxa1,Atg9b,Paqr5,Rbl1,Tent5c,Lcn2,Ikzf1,Ifit3b,Cdh5,Tcf19,Klf5,Lrrc32,Rrm2,Mob3c,Ifi30 Hbb-bs,Hba-a2,S100a8,S100a9,Hbb-bt,Anxa1,Atg9b,Rbl1,Tent5c,Paqr5,Lcn2,Ifit3b,Tcf19,Klf5,Lrrc32,Mob3c,Rrm2,Ifi30,Cdh5,Rassf9 Hbb-bs,Hba-a2,S100a9,S100a8,Hbb-bt,Mbp,Ppp1r9b,Sparcl1,Fth1,Mt3,Atp1a2,Rgs5,Tmsb4x,Cpe,Atp1b1,Selenow,Ly6e,Calm1,Apoe,Atp6v0d1
9 101,178,255 0 10 Mcm3,Bche,Hmgcs2,Cped1,Vwc2l,Spata6,Sh3tc2,Sh2b2,Slc26a2,Hhip,Cd83,Mdk,Zfp524,Unc13c,Nfil3,Bmp6,Dkkl1,Gmppb,Rhbdd1,Fam189a2 Mcm3,Bche,Selenop,Kcnab2,Sptbn2,Rnf168,Fa2h,Sacs,Hid1,Cd83,Rhob,Nmral1,Hmgcs2,Fam163b,Gna12,Gfap,Akirin2,Cand1,Phactr1,Sema7a Mcm3,Sptbn2,Selenop,Kcnab2,Rhob,Gnao1,Aldoa_v1,Atp1b1,Gpm6a,Sept7,Calm1,Uqcrc1,Slc17a7,Vxn,Chchd2,Fam163b,Akirin2,Phactr1,Gfap,Cand1

Packed SGE and Spatial Factor Outputs from run_cartload2

The packed SGE data and spatial factor inferences generated by FICTURE are available in PMTile format on Zenodo: DOI:10.5281/zenodo.15824955.

These datasets can also be loaded directly using the following catalog YAML file:
https://zenodo.org/records/15824956/catalog.yaml