Bootcamp / Session 6 / 6.3

Session 6.3 · Hands-on

Run a Xenium analysis on Foundry. You launch it.

The same pattern as 4.2, on spatial data. An AI agent sets up Foundry’s Xenium Spatial Analysis pipeline on public human lung data, you check every setting and press Run, and about fifteen minutes later you have a report with clusters and niches drawn on the tissue.

Go to the hands-on VS Code · Claude Code or Codex · Foundry Connect

Recordings

Alper’s part of the session, in six parts. Parts 3 and 4 run the hands-on below live.

Part 1: a tour of Foundry

What Foundry keeps for you. Datasets: added by hand, from GEO, from S3 or Google Cloud buckets, from the cluster, or from BaseSpace, or created by an agent. The Xenium pipeline for this session, which Claude built from a one-paragraph request. Pipelines are reusable processes with their inputs, outputs, scripts and containers recorded; a 2016 RNA-seq pipeline still runs today. The agent can explain every parameter, for example why miRNA reads don’t map with the default minimum length. Then a 2019 run, duplicated with all its settings to rerun on new data, and a question on why to use Foundry at all: a pipeline you can rerun or share without spending tokens again.

Alper Kucukural · Foundry tour · 25 minutes

Part 2: foundation models and safe setups

Foundation models such as scGPT are multiplying, and many need a GPU, so they run on the cluster rather than on your laptop. How to use AI agents without exposing private data: run in isolated containers, open only the folders you choose (read-only where you can), develop on public or fake data, and switch to the real data only once the code works. Then only error messages ever reach the model. A question on why to use a specialized model instead of Claude alone. The screen is blurred for part of this video because it showed internal servers; the audio is complete.

Alper Kucukural · models and safe setups · 11 minutes

Part 3: add Foundry to Claude

Settings, Connectors, Add custom connector, with the Foundry MCP address, then sign in with your Foundry account. The connector exposes 87 tools: datasets, runs, reports, processes and apps. For each tool you choose whether Claude must ask for approval first. Search tools are rate limited so one agent cannot overload the system.

Alper Kucukural · connecting Foundry · 9 minutes

Part 4: the Xenium run, live

The hands-on below, start to finish. Make the folder, trust only that folder in Claude (code versus Cowork), and paste the template-run prompt. Along the way: why a Singularity container keeps an analysis reproducible for years, and how the same request scales to many GEO datasets. The agent creates the project, duplicates the template run, and asks which environment and execution directory to use. Then you check the form, read the expected preflight warning, see how a missing required field blocks the run, and press Run.

Alper Kucukural · live run · 33 minutes

Part 5: the results

Pipeline versions belong to you, so you cannot break the shared pipeline. Then a tour of the Xenium report: QC violins, genes against UMIs, choosing the number of PCs, 27 clusters against 4 niches, the tissue view and the cluster markers. Clusters are a starting point to merge or split, not a final answer. Then the agent downloads the run’s RDS object, colors two genes on the tissue, builds an interactive HTML page for the top five genes, and uploads it back into the run’s reports, using about 10,000 tokens.

Alper Kucukural · results · 25 minutes

Part 6: what is coming, and closing

Features still in testing: model skills that download a model such as scGPT and run it on the cluster’s GPUs, knowledge bases attached to your projects, and a channel that lets the Claude on your laptop send work to the cluster without opening your other folders. The screen is blurred while it shows the test server; the audio is complete. Then the course wrap-up and thanks.

Alper Kucukural · what is coming · 7 minutes

The data

10x Genomics’ public Xenium human lung, 2 fields of view dataset (Xenium_V1_human_Lung_2fov, CC BY 4.0): a piece of a human lung section about 1.2 by 0.75 mm, measured with a 289 gene panel. The output bundle holds 11,898 segmented cells. It is small on purpose, so the run finishes during class.

We put it on the cluster where every account can read it, with the two sheets the pipeline takes:

/share/data/umw_biocore/genome_data/xenium/lung2fov/
  Lung2fov_outs/            the 10x output folder
  Lung2fov_cell_stats.csv   one row per cell: ID, transcripts, cell and nucleus area
  samplesheet.tsv           sample_name, xenium_path
  metadatasheet.tsv         sample_name, cell_stats_path, condition, replicate, tissue

The original download is a 278 MB ZIP from 10x, Xenium_V1_human_Lung_2fov_outs.zip. You do not need it today.

Two things we did to the bundle, and why
  • The pipeline expects a cell_feature_matrix/ folder. Newer 10x bundles ship it only as cell_feature_matrix.tar.gz, so we unpacked it.
  • The pipeline also wants a cell stats file of the kind Xenium Explorer exports. Public data has none, so we built one from cells.csv.gz. Leaving that column blank stops the run.
Fixing a pipeline’s input rather than its code is a normal workaround. Write it down, as here, so the next person knows.

What the pipeline does

Xenium Spatial Analysis Pipeline (version 1.0.4 on Foundry; version 1.0.3 gives the same results) runs two steps: it prepares the 10x folder, then renders one R Markdown report with Seurat.

  1. Load. Read the cell by gene counts, cell centroids, and control probe counts.
  2. QC. Drop cells with no transcripts, then keep cells between the 1st and 99th percentiles of transcripts per cell and of genes per cell.
  3. Normalize and reduce. SCTransform, then PCA, with the number of PCs picked from the PCA.
  4. Cluster. Cluster at 20 resolutions from 0.1 to 2.0 and pick one by how stable the clusters stay across resolutions.
  5. Niches. Group cells into 4 niches by the clusters of their 20 nearest neighbors, as in 6.2.
  6. Markers. Find marker genes for every cluster.

It writes two files: an HTML report and the Seurat object as an .rds file. You open both in 6.4.

Before you start

Foundry and the agent from 4.2

You need what you set up in Session 4.2: a Foundry run environment whose Test Connection is green, and an agent in VS Code with Foundry Connect. The agent works through Foundry Connect alone, so no browser automation is needed. Keep it in ask-first mode, as described in 4.2.

Make the folder and open it

macOS:

mkdir -p ~/Documents/bootcamp/session6/xenium

Windows PowerShell:

New-Item -ItemType Directory -Force (Join-Path ([Environment]::GetFolderPath('MyDocuments')) 'bootcamp\session6\xenium') | Out-Null

Then in VS Code choose File, Open Folder, and open Documents, bootcamp, session6, xenium. The agent saves its notes and the plot from step 4 here.

Hands-on: set up the run

1. Set it up by prompt

Using Foundry Connect only, copy template run 12369 into my project bootcamp_test (ask me before creating it) and name it "Xenium lung 2FOV". Set my run environment for the UMass cluster, ask me for the Execution Directory, and set the inputs samplesheet = /share/data/umw_biocore/genome_data/xenium/lung2fov/samplesheet.tsv and metadatasheet = /share/data/umw_biocore/genome_data/xenium/lung2fov/metadatasheet.tsv. Confirm Singularity uses quay.io/ummsbiocore/ubuntu-seurat:5.3.0, run preflight ("No sample dataset is attached" is expected), and do not launch. Give me the run ID, the run link and a table of what you set.

For the Execution Directory, give a folder you can write to on the cluster, such as /home/<your cluster username>/bootcamp/xenium. Approve each Foundry change only after you read it.

Write down the run ID (the number at the end of the run link). Steps 3 and 4 use it in place of <run ID>, because a search by name can find someone else’s run with the same name.

2. You check, you launch

Open the link in your browser, signed in to Foundry, and check: pipeline Xenium Spatial Analysis Pipeline 1.0.4, the two sheet paths exactly as above, your own run environment, Singularity on with the Seurat 5.3.0 image, and the Execution Directory you gave. Then press Run.

The rule The agent prepared the run. You launch it.

What did you observe?
  • Did the agent stop for the Execution Directory, and did it stop before Run?
  • Does the run page agree with its table?
  • The agent copied a template run instead of creating one from scratch. A new run of this pipeline gets a Space Ranger image with no R in it. What would that run have failed with? See If the run fails.

3. Watch it run

The cluster jobs take a few minutes; with queueing, expect about fifteen. Ask the agent to report instead of refreshing the page:

Using Foundry Connect, tell me the status of my run <run ID>. If it is still running, say which step it is on. If it failed, show me the last 30 lines of its log and explain the error in plain words. Do not change or relaunch anything.

Checkpoint The run ends as Completed, and its results list two files: HTML_Report/Lung2fov.analysis_report.html (about 5 MB) and Analysis_Results_RDS/Lung2fov.analysis.rds (about 40 MB).

4. Color two genes from your own run

The agent fetches the Seurat object your run made through Foundry Connect and plots two genes on the tissue. It needs R with Seurat 5, as in the 6.4 set up.

Using Foundry Connect, list the result files of my run <run ID>. Then use download_file on the Seurat .rds file. It is too big to come back in the chat, so Foundry answers with a download command and a link that expires in about 15 minutes: run that command right away to save the file in this folder. Do not open any app or viewer. Then write an R script that loads the file with Seurat, plots VWF and PDGFRA at their positions on the tissue with ImageFeaturePlot, and saves the plot as spatial_VWF_PDGFRA.png. Tell me how many cells have counts above zero for each gene, and the fraction of those cells in each niche.

Checkpoint A file of about 42 MB, with 11,486 cells and 289 genes. 495 cells express VWF, a vessel marker, and 194 express PDGFRA, a fibroblast marker. Both pile up in niche 3: 11.6% of its cells are VWF positive and 6.5% PDGFRA positive, against at most 3.9% and 1.1% in the other niches.

The download linkIt opens one file, for about 15 minutes, and needs no password. Treat it like a key for that time: do not paste it into a chat with anyone else. If it expires before you use it, ask the agent to call download_file again.

While it runs

Use the wait to question the agent about what you just launched. Make it say which parts it knows from a source and which it is inferring.

I launched a Xenium analysis on 10x's public human lung 2 field of view dataset, measured with a 289 gene panel. Explain what files a Xenium output folder contains and which ones a cell by gene analysis needs. Then explain what a negative control probe and a blank codeword are, and what rate of them would make me distrust a run.
The pipeline keeps cells between the 1st and 99th percentiles of transcripts and genes per cell. With a 289 gene panel, what kinds of cells could that remove for the wrong reason? Would you set the thresholds differently for spatial data than for single-cell?
The pipeline builds 4 niches from each cell's 20 nearest neighbors. What does a niche capture that a cluster does not, and what would change if I asked for 8 niches instead?

If the run fails

We hit each of these while preparing the session. Ask the agent to read the log with the prompt in step 3, then compare.

If your run cannot finish in class, nothing is lost: 6.4 uses course copies of the same two output files, from our own run of this setup.

After the session

Two minutes of feedback, so the next session is pitched better. It also records your attendance, so fill it in whether you were in the room, on Zoom, or catching up on the recording.

Session 6 feedback