Skip to content

Vizgen MERSCOPE Starter Tutorial

Input Data

The input is a spatial gene expression (SGE) dataset from the adult mouse hippocampus, extracted by masking a coronal brain section (Slice Number: 2;Replicate Number: 1; file: detected_transcripts.csv) from Vizgen MERSCOPE Neuroscience Showcase.

File Format

The MERSCOPE input SGE includes one comma delimited text file with the following format:

CSV file format

1
2
3
4
,barcode_id,global_x,global_y,global_z,x,y,fov,gene
0,22,56.930107,3851.851,5.0,147.80061,1711.9067,0,Adgre1
1,22,183.60107,3874.0085,5.0,1320.6799,1917.0692,0,Adgre1
2,22,59.750736,3666.5576,5.0,132.66754,1844.2372,1,Adgre1
  • Column 1: Unique numeric index for each transcript within a field of view (non-consecutive, ascending).
  • barcode_id: Zero-based index of the transcript barcode in the codebook; forms a composite key with fov.
  • global_x: Transcript x coordinates (µm) in the experimental region; may be negative due to alignment.
  • global_y: Transcript y coordinates (µm) in the experimental region; may be negative due to alignment.
  • global_z: The index of the z-position. The position is a zero-indexed integer.
  • x: The x-coordinate of the transcript (µm), within the coordinate space of the field of view.
  • y: The y-coordinate of the transcript (µm), within the coordinate space of the field of view.
  • fov: Zero-based field of view index; forms a composite key with barcode_id.
  • gene: Gene name associated with the transcript.

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/merscope_starter.raw.tar.gz
tar --strip-components=1 -zxvf merscope_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
8
# Unique identifier for your dataset
DATA_ID="merscope_hippo"                # change this to reflect your dataset name
PLATFORM="vizgen_merscope"              # platform information
SCALE=1                                 # scale from coordinate to micrometer

# LDA parameters
train_width=12                           # 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 MERSCOPE?

The MERSCOPE example data currently used here provides SGE in micrometer units. Use define scaling factor from coordinate to micrometer as 1.

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
cartloader sge_convert \
  --makefn sge_convert.mk \
  --platform ${PLATFORM} \
  --in-csv ./input.tsv.gz \
  --units-per-um ${SCALE} \
  --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-csv required string Path to the input TSV/CSV file
--units-per-um required float Scale to convert coordinates to microns (default: 1.0)
--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)

FICTURE Analysis

Compute spatial factors using punkst (FICTURE2 mode). See more details in Reference page.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
cartloader run_ficture2 \
  --makefn run_ficture2.mk \
  --main \
  --in-transcript ./sge/transcripts.unsorted.tsv.gz \
  --in-feature ./sge/feature.clean.tsv.gz \
  --in-minmax ./sge/coordinate_minmax.tsv \
  --cmap-file ${cmap} \
  --exclude-feature-regex '^(mt-.*$|Gm\d+$)' \
  --out-dir ./ficture2 \
  --width ${train_width} \
  --n-factor ${n_factor} \
  --spatula ${spatula} \
  --ficture2 ${punkst} \
  --n-jobs ${n_jobs} \
  --threads ${n_jobs}
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 12, 12 factors, a fit width of 12, and an anchor resolution of 6.

FICTURE cmap

Factor RGB Weight PostUMI TopGene_pval TopGene_fc TopGene_weight
0 255,101,101 0.30225 799546 Slc17a7,Epha4,Amigo2,Kit,Syt4,Epha6,Anxa11,Npy2r,Nrp1,Adora1,Chrm3,Gpr26,Ackr1,Gpr158,Celsr2,Gabbr2,Gpr22,Chrm1,Adra1d,Epha5 Avpr1b,Blank-85,Kit,Amigo2,Blank-158,Hcrtr2,Npy6r,Blank-49,Oxtr,Npy2r,Gpr26,Hcrtr1,Blank-146,Cckbr,Adgrg7,Mrgprb1,Blank-28,Adgrf4,Blank-32,Blank-151 Slc17a7,Epha4,Cx3cl1,Epha6,Gabbr1,Gabbr2,Adora1,Baiap2,Celsr2,Grin2b,Chrm1,Syt4,Anxa11,Grm5,Epha7,Ntrk3,Adgrl1,Nrp1,Chrm3,Lmtk2
1 237,238,0 0.14118 373464 Grm2,Ntrk3,Baiap2,Epha7,Tmem108,Cxcl12,Adcyap1r1,Chrm1,Htr4,Mas1,Npy1r,Grm7,Anxa11,Grm1,Drd1,Epha4,Sstr2,Grin2b,Gprc5b,Grm5 Grm2,Ghsr,Drd1,Npy1r,Glp2r,Sstr2,Htr4,Igfbpl1,Gpr139,Mc4r,Rho,Sstr1,Lgr6,P2ry4,Tmem108,Mas1,Cxcl12,Blank-31,Epha1,Peg10 Slc17a7,Epha4,Ntrk3,Baiap2,Gabbr1,Epha7,Cx3cl1,Grin2b,Chrm1,Gabbr2,Grm5,Grm2,Gprc5b,Anxa11,Adgrl1,Celsr2,Grm7,Adcyap1r1,Epha6,Gad1
2 101,255,101 0.12849 339911 Sstr4,Gpr161,Cx3cl1,Chrm3,Grin2b,Epha6,Htr1a,Epha7,Man1a,Htr1b,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3,Ednrb,Fzd9,Erbb3,Sstr1,Mc5r,S1pr2,Calcrl Gpr17,Mki67,Pdgfra,Top2a,Pcdh15,Traf4,Blank-109,Ascl1,Olig1,Mc5r,Fzd9,S1pr2,Sox8,Sstr1,Prlhr,Prokr1,Blank-116,Plxnb3,Blank-72,Cspg5 Olig1,Cspg5,Gpr17,Pdgfra,Gpr37l1,Gjc3,Sox8,Traf4,Pcdh15,Ntrk2,Gfap,Ntrk3,Adcyap1r1,Adgrb1,Gabbr1,Ednrb,Adora1,Erbb4,Slc17a7,Adgrl1
11 255,153,204 0.01216 32170 Htr2c,Gpr182,Efemp1,Cxcl12,Myh11,Crhr2,Igfbpl1,Lmod1,Cxcr4,Fzd4,Gprc5c,Ptgdr,Ddr2,Arhgap29,Hcar1,Ror2,Dlk1,Sox9,Ddr1,Fzd2 Gpr55,Gpr182,Ptgdr,Lpar3,Hcar1,Htr2c,Cxcr3,Ror2,Mc3r,Crhr2,Lmod1,Musk,Slc47a1,Gpr20,Gpr88,Gpr132,Mrgprf,Efemp1,Igfbpl1,Dlk1 Cxcl12,Sox9,Ddr1,Ntrk2,Htr2c,Anxa11,Gprc5b,Igf1r,Arhgap29,Gfap,Gpr182,Efemp1,Myh11,Fgfr2,Smo,Pdgfra,Tmem108,Fzd4,Axl,Man1a

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.15824932.

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