Human Cortex Multi‑Sample Spatial Factor Analysis Tutorial¶
Overview¶
This tutorial demonstrates how to run multi‑sample FICTURE analysis and package results using run_ficture2_multi and run_cartload2_multi.
Why use Multi‑Sample FICTURE Analysis?
CartLoader supports analyzing ≥2 samples in two ways:
- Multi‑sample FICTURE analysis (
run_ficture2_multi): Jointly learns spatial factors across all samples and writes per‑sample outputs in one parallelizable run. - SGE stitch + single‑sample analysis (
sge_stitch→run_ficture2): Stitch multiple SGEs into a single mosaic, then train one model on that mosaic.
What to expect
- Shared factors/comparability:
run_ficture2_multilearns a cohort‑wide latent basis and returns per‑sample decodes for direct comparison. The stitch approach yields a single model over the merged mosaic; useful when you need a unified coordinate system (e.g., tiling adjacent sections). - Efficiency and scale:
run_ficture2_multifits once for the cohort and decodes per sample, avoiding repeated runs and post‑hoc alignment. Stitching can be simpler for mosaics but often increases I/O and memory due to very large merged files.
Recommendation:
- Prefer
run_ficture2_multifor most cohorts for clean per‑sample outputs and better computational efficiency; use stitching when a single shared coordinate frame is required. - If you choose stitching, plan for higher resource usage (RAM, disk, and I/O). Large mosaics can be slow to generate and train on, and may require substantially more memory and temporary storage than per‑sample runs.
Input Data¶
This tutorial uses a series of four human cortex ST datasets from Walsh et al. Nature 2025, generated using MERFISH.
File Format
detected_transcripts.csv.gz
1 2 3 4 | |
- 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 withfov.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: Zero‑based z‑position index.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 withbarcode_id.gene: Gene name.transcript_id: Unique identifier for the transcript.cell_id: Unique identifier for cell.
Data Access
Follow the commands below to download the source data.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
Set Up the Environment¶
Pre-installed tools
Please ensure you have installed all required tools (See Installation).
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 | |
Define data ID and analysis parameters:
1 2 3 4 5 6 7 8 | |
Prepare a working directory:
1 2 | |
SGE Format Conversion¶
For each sample, convert its transcript‑indexed SGE file to be the CartLoader format.
Below use FB080_O1a as an example.
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Alternatively, if you don’t need SGE visualization or density/feature‑based filtering, you can directly generate a CartLoader‑compatible SGE with fixed column names (the raw SGE is already in micrometers):
1 2 3 4 | |
Prepare Input List¶
Create a tab‑separated TSV file (e.g., input.tsv) with one sample per line. The TSV should have no header and contain two to four columns.
Example Input List: input.tsv
1 2 3 4 | |
1st Column(required, str): Unique dataset identifier (avoid whitespace; prefer-to_).2nd Column(required, str): Path to the transcript‑indexed SGE file inCartLoaderformat, generated from SGE Format Conversion.3rd Column(optional, str): Dataset title. Quote the value when whitespace is involved.4th Column(optional, str): Dataset description. Quote the value when whitespace is involved.
Multi‑Sample FICTURE Analysis¶
Trains LDA models across samples for each parameter setting (width and n‑factor), decodes per sample, and writes per‑sample JSON manifests summarizing results.
Outputs are written under ficture2/<sample_id>/. See details in run_ficture2_multi.
1 2 3 4 5 6 7 8 9 10 11 | |
Multi‑Sample Asset Packaging¶
Package per‑sample outputs from ficture2/<sample_id>/ into web‑ready PMTiles and catalogs.
Outputs are written under cartload2/<sample_id>/. See details in run_cartload2_multi.
1 2 3 4 5 6 7 8 | |
Upload to AWS¶
Upload the generated CartLoader outputs from above to your designated AWS S3 directory — either the whole collection at once or each sample individually. For full details, see upload_aws.
1 2 3 4 5 6 | |
Below use FB080_O1a as an example.
1 2 3 4 5 | |
Output Summary¶
-
View/Explore¶
The output are available in both CartoScope.
See more details of output at the Reference pages for run_ficture2 and run_cartload2.