You are a computational biologist performing spatial transcriptomics analysis on a 10x Genomics Visium dataset from a human brain tissue section (dorsolateral prefrontal cortex, DLPFC). ## Input Files - `input/filtered_feature_bc_matrix.h5` — 10x Genomics Space Ranger output: filtered feature-barcode count matrix in HDF5 format. Contains ~3,600 tissue spots and ~33,500 genes. - `input/spatial/` — Spatial metadata directory from the Space Ranger output: - `tissue_positions_list.csv` — Spot positions. No header row. Columns: barcode, in_tissue (0/1), array_row, array_col, pixel_row, pixel_col - `scalefactors_json.json` — Scale factors for image-coordinate alignment - `tissue_lowres_image.png` — Low-resolution H&E stained tissue image - `tissue_hires_image.png` — High-resolution H&E stained tissue image ## Software Environment Python 3 is available. You may install additional packages using pip. Recommended packages for spatial transcriptomics analysis: - scanpy (>=1.10.0) — single-cell/spatial analysis framework - anndata (>=0.10.0) — data container for omics data - squidpy (>=1.4.0) — spatial omics analysis (optional) - numpy, scipy, pandas, matplotlib — standard scientific computing ## Your Task Perform a complete spatial transcriptomics analysis to identify spatially coherent tissue domains in this brain tissue section. The DLPFC has a layered cortical architecture (cortical layers L1–L6 and white matter). Your clustering should aim to recover these tissue domains. The analysis must include: 1. **Data Loading**: Read the 10x h5 matrix and attach spatial coordinates from the tissue positions CSV. Only include in-tissue spots (in_tissue == 1). 2. **Quality Control**: Calculate and apply appropriate QC filters: - Filter spots by total counts, number of genes detected, and mitochondrial gene percentage (human mitochondrial genes start with "MT-") - Filter genes with very low expression - You must decide reasonable thresholds based on the data distribution 3. **Normalization & Feature Selection**: Normalize counts, log-transform, and select highly variable genes. 4. **Dimensionality Reduction & Clustering**: - Run PCA and store in `.obsm['X_pca']` - Build a neighbor graph and compute UMAP, store in `.obsm['X_umap']` - Perform Leiden clustering and store labels in `.obs['leiden']` - Choose a clustering resolution that produces a biologically reasonable number of clusters for cortical layer identification (typically 5–10 clusters) 5. **Marker Gene Analysis**: Find differentially expressed genes per cluster. Report top marker genes. 6. **Visualization**: Generate a UMAP plot colored by cluster assignment. 7. **Save all results** to the `output/` directory. ## Required Outputs (all in the `output/` directory) | File | Format | Description | |------|--------|-------------| | `qc_stats.txt` | Key-value text | QC summary. Must include at minimum: `spots_before`, `spots_after`, `genes_before`, `genes_after`. Use `key: value` or `key=value` format, one per line. | | `cell_clusters.csv` | CSV with header | Columns: `barcode`, `cluster`. One row per spot after QC. | | `marker_genes.csv` | CSV with header | Columns: `cluster`, `gene`, `score`, `pval_adj`. At least 5 marker genes per cluster. | | `umap_plot.png` | PNG image | UMAP plot colored by cluster. Must be a valid PNG > 2000 bytes. | | `results.h5ad` | AnnData HDF5 | Processed AnnData object containing `X_pca`, `X_umap`, and `leiden` in the appropriate slots (`.obsm` and `.obs`). | ## Important Notes - This is raw data from a 10x Visium experiment — you must handle data loading, QC, and all preprocessing yourself - The tissue_positions_list.csv has NO header row - Human mitochondrial genes start with "MT-" (uppercase) - You may write intermediate helper scripts as needed - The final clustering quality will be evaluated against expert-annotated cortical layer labels