image imagewidth (px) 576 1.92k |
|---|
YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Spatial Transcriptomics Atlas: Human Lymph Node Architecture and Immune Microenvironment
Integrated multi-modal analysis of spatial gene expression in human lymph node tissue. Panels depict high-resolution histology (A), annotated tissue domains (B), gene detection density (C), expression patterns of top spatially variable genes (D--F), and neighborhood enrichment statistics (G).
Abstract
This repository presents a reproducible computational framework for spatially resolved transcriptomic analysis of the human lymph node. Using 10x Genomics Visium spatial gene expression data, the pipeline performs end-to-end analysis spanning quality control, normalization, unsupervised domain identification, spatially variable gene discovery, and ligand-receptor-mediated intercellular communication inference. The analysis resolves six distinct tissue domains across 4,035 capture spots and 36,601 genes, identifies 136 spatially variable genes, and maps 36 statistically significant cell-cell interactions. All analyses are executable as a single, self-contained Jupyter notebook designed for full reproducibility on the Kaggle platform.
Scientific Background
The lymph node is a structurally compartmentalized organ in which spatial organization is not merely anatomical but functionally deterministic. B-cell follicles, germinal centers, the T-cell-rich paracortex, and medullary sinuses each constitute specialized microenvironments that coordinate distinct phases of adaptive immune activation. Conventional single-cell RNA sequencing dissociates tissue into individual cells, sacrificing the spatial context that governs intercellular signaling, niche-dependent gene regulation, and morphogenetic patterning.
Spatial transcriptomics technologies, particularly the 10x Genomics Visium platform, resolve this limitation by capturing polyadenylated mRNA from tissue sections while preserving two-dimensional positional information. Each capture spot (55 micrometers in diameter) samples between one and ten cells, enabling the reconstruction of gene expression topographies at near-cellular resolution and their direct overlay onto matched histological images.
This project applies a systems biology approach to a Visium dataset derived from a human lymph node specimen. The analytical framework extends beyond standard clustering by incorporating relative Z-score-based module scoring for immunological annotation, Moran's I spatial autocorrelation for spatially variable gene identification, permutation-based neighborhood enrichment testing for domain co-localization analysis, and OmniPath-sourced ligand-receptor interaction inference for mapping intercellular communication networks.
Dataset Summary
| Parameter | Value |
|---|---|
| Technology | 10x Genomics Visium Spatial Gene Expression |
| Tissue | Human lymph node |
| Capture spots | 4,035 |
| Genes profiled | 36,601 |
| Tissue domains identified | 6 |
| Median UMI counts per spot | 4,233 |
| Median genes detected per spot | 5,999 |
| Spatially variable genes | 136 (Moran's I, adjusted p < 0.05) |
| Significant cell-cell interactions | 36 |
| Top spatially variable genes | IGKC, IGHG4, IGHG1, FDCSP, CCL21 |
Repository Structure
Spatial_Transcriptomics_Atlas/
|-- README.md # This document
|-- LICENSE # MIT License
|-- requirements.txt # Python dependencies
|-- .gitignore # Git exclusion rules
|-- .gitattributes # Language detection and line endings
|-- spatial_systems_biology_lymph_node.ipynb # Primary analysis notebook (~43 MB)
|-- curation.py # Data ingestion, QC, normalization, clustering, annotation
|-- analysis_spatial.py # Spatial plotting and visualization generation
|-- final_map.py # Final annotated architecture and gradient maps
|-- download_atlas.py # Automated data download from 10x Genomics
|-- setup.sh # One-command environment setup and data download
|-- data/
| |-- README.md # Data documentation and download instructions
| `-- Human_Lymph_Node/
| |-- README.md # Placeholder for ignored large files
| |-- filtered_feature_bc_matrix.h5 # Gene expression matrix (~30 MB)
| `-- spatial/ # Visium spatial imaging files
| |-- README.md # Spatial data documentation
| |-- tissue_hires_image.png # High-resolution H&E image
| |-- tissue_lowres_image.png # Low-resolution H&E image
| |-- tissue_positions_list.csv # Spot coordinate mapping
| |-- scalefactors_json.json # Image scale factors
| |-- aligned_fiducials.jpg # Fiducial alignment reference
| `-- detected_tissue_image.jpg # Detected tissue boundary
|-- figures/ # Static and interactive visualizations
| |-- README.md # Figure index
| |-- analysis_summary.json # Quantitative analysis results
| |-- 01_quality_control.png # QC metrics panel
| |-- 02_tissue_architecture.png # Domain map overlaid on histology
| |-- 03_neighborhood_enrichment.png # Spatial enrichment heatmap
| |-- 04_spatially_variable_genes.png # SVG expression maps
| |-- 05_integrated_analysis.png # Multi-panel integrated view
| |-- 06_domain_metrics.png # Quantitative domain properties
| |-- show_QC_Map.png # QC spatial overlay
| |-- show_Immune_Architecture.png # B-cell and T-cell zone maps
| |-- show_Master_Architecture_Map.png # Annotated architecture map
| |-- show_Immune_Gradients.png # Immune marker intensity gradients
| |-- 07_3d_spatial_architecture.html # Interactive 3D tissue model
| |-- 08_3d_gene_expression.html # Interactive 3D expression surface
| |-- 09_gene_correlation.html # Interactive gene correlation heatmap
| |-- 10_communication_network.html # Interactive signaling network
| |-- 11_domain_markers.html # Interactive domain marker heatmap
| `-- 12_domain_metrics_interactive.html # Interactive metrics dashboard
|-- iframe_figures/ # Embeddable HTML visualizations
| |-- README.md # Iframe figure documentation
| |-- figure_9.html # Gene correlation heatmap (iframe)
| |-- figure_15.html # Domain marker heatmap (iframe)
| `-- figure_16.html # Domain metrics chart (iframe)
|-- results/ # Generated analysis outputs
| `-- README.md # Results documentation
|-- scripts/ # Utility scripts
| `-- README.md # Scripts documentation
`-- .github/
`-- workflows/
`-- ci.yml # CI: Python linting with flake8
Methodology
1. Data Acquisition and Curation
Raw spatial gene expression data is obtained from the 10x Genomics Visium platform. The automated download script (download_atlas.py) retrieves the filtered gene-barcode matrix and associated spatial imaging files, organizing them into the directory structure expected by Scanpy's read_visium() function.
Data curation (curation.py) proceeds through the following steps:
- Quality control filtering: Removal of low-quality spots based on minimum gene counts and mitochondrial content thresholds.
- Normalization: Library-size normalization to 10,000 counts per spot, followed by log1p transformation.
- Feature selection: Identification of highly variable genes using the cell-ranger flavor for downstream dimensionality reduction.
- Dimensionality reduction: Principal component analysis followed by UMAP embedding for visualization.
- Clustering: Leiden community detection on the k-nearest neighbor graph to partition spots into transcriptionally distinct groups.
- Biological annotation: Relative Z-score-based module scoring using curated gene sets for lymph node compartments, including B-cell follicle markers, T-cell zone markers, germinal center signatures, and medullary sinus markers. This scoring approach normalizes for differences in gene set size and background expression, enabling robust automated annotation even in the presence of dominant cell populations (such as plasma cells) that can skew absolute scoring methods.
The curated AnnData object is exported as human_lymph_node_master_atlas.h5ad for downstream spatial analysis.
2. Spatial Neighborhood Analysis
Spatial graph construction uses coordinate-based k-nearest neighbor computation (k = 6) to define the local neighborhood of each capture spot. Permutation-based neighborhood enrichment testing (n = 1,000 permutations) then quantifies whether pairs of tissue domains co-localize more or less frequently than expected by chance, yielding Z-scores and associated p-values for each domain pair.
3. Spatially Variable Gene Identification
Moran's I spatial autocorrelation statistic is computed for each gene across the spatial graph, with significance assessed via permutation testing (n = 500 permutations). Genes exhibiting statistically significant spatial structure (adjusted p < 0.05) are classified as spatially variable. This analysis identified 136 such genes, with top hits including immunoglobulin genes (IGKC, IGHG4, IGHG1), follicular dendritic cell markers (FDCSP), and chemokines directing lymphocyte trafficking (CCL21).
4. Intercellular Communication Inference
Ligand-receptor interaction analysis leverages the OmniPath database to identify potential signaling pathways operating between tissue domains. Domain-level mean expression of known ligands and receptors is computed, and interactions exceeding significance thresholds are retained. This analysis identified 36 significant interactions, capturing chemokine axes (CXCL13-CXCR5, CXCL12-CXCR4), cytokine signaling (IL7-IL7R), and adhesion molecule interactions (ICAM1-ITGAL) that reflect the known biology of lymph node microenvironments.
5. Visualization
The pipeline generates both static publication-quality figures and interactive HTML visualizations. Static figures are rendered using Matplotlib and Seaborn with spatial overlays powered by Scanpy's plotting functions. Interactive three-dimensional tissue models, gene expression surfaces, correlation heatmaps, and signaling network diagrams are built with Plotly and exported as self-contained HTML files.
Results
Quality Control
Quality control assessment. (A) Distribution of total UMI counts per spot. (B) Gene detection rates across spots. (C) Relationship between total counts and detected genes. (D) Spatial map of UMI density. (E) Spatial map of gene detection. (F) Gene prevalence across tissue spots.
Spatial Quality Control Maps
Spatial overlay of quality control metrics on the histological tissue section, demonstrating uniform sequencing depth and gene capture across the lymph node.
Tissue Architecture and Domain Annotation
Spatial organization of six identified tissue domains overlaid on high-resolution H&E histology (left) and corresponding molecular domain map (right). Domains were annotated using relative Z-score module scoring against curated immune compartment gene sets.
Annotated Architecture Map
Final annotated architecture map showing the spatial distribution of all identified tissue domains with semantic labels derived from biological module scoring.
Immune Cell Zone Architecture
Spatial expression of B-cell follicle markers (CR2, left) and T-cell zone markers (CD3D, right), delineating the canonical compartmentalization of adaptive immune cell populations within the lymph node.
Immune Marker Gradients
Intensity gradients of B-cell and T-cell module scores across the tissue, illustrating the continuous spatial transitions between immune compartments rather than sharp boundaries.
Neighborhood Enrichment Analysis
Permutation-based neighborhood enrichment analysis (n = 1,000 permutations) quantifying spatial co-localization patterns between tissue domains. Positive Z-scores indicate spatial attraction; negative Z-scores indicate spatial avoidance.
Spatially Variable Genes
Spatial expression patterns of the top spatially variable genes identified by Moran's I analysis. These genes exhibit statistically significant spatial autocorrelation (adjusted p < 0.05) and define zone-specific transcriptional programs.
Quantitative Domain Metrics
Quantitative characterization of tissue domains across four axes: domain size (number of spots), median gene detection, median expression depth (UMI counts), and spatial compactness.
Interactive Visualizations
The following interactive HTML visualizations are included in this repository. Because GitHub does not render HTML files directly, they must be downloaded and opened in a web browser, or hosted via GitHub Pages.
| Visualization | Description | File |
|---|---|---|
| 3D Spatial Architecture | Rotatable 3D tissue model colored by domain identity | 07_3d_spatial_architecture.html |
| 3D Gene Expression Surface | Interpolated gene expression landscape in three dimensions | 08_3d_gene_expression.html |
| Gene Correlation Heatmap | Co-expression patterns of top spatially variable genes | 09_gene_correlation.html |
| Communication Network | Ligand-receptor signaling graph with weighted edges | 10_communication_network.html |
| Domain Marker Heatmap | Domain-specific marker gene expression patterns | 11_domain_markers.html |
| Domain Metrics Dashboard | Dynamic quantitative domain property charts | 12_domain_metrics_interactive.html |
Installation
System Requirements
- Python 3.8 or higher
- 16 GB RAM minimum (32 GB recommended for full analysis)
- Linux, macOS, or Windows with WSL
Setup
# Clone the repository
git clone https://github.com/Qasim-Hussain-Code/Spatial_Transcriptomics_Atlas.git
cd Spatial_Transcriptomics_Atlas
# Option 1: Automated setup (creates venv, installs deps, downloads data)
chmod +x setup.sh
./setup.sh
# Option 2: Manual setup
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
Core Dependencies
The analysis relies on the following Python packages (see requirements.txt for version-pinned specifications):
- scanpy -- Single-cell and spatial transcriptomics analysis
- squidpy -- Spatial omics analysis framework
- anndata -- Annotated data matrix handling
- numpy, pandas, scipy -- Numerical computing
- matplotlib, seaborn -- Static visualization
- plotly, kaleido -- Interactive visualization and export
- scikit-learn -- Machine learning utilities
- networkx -- Graph-based analysis
Usage
Recommended: Run on Kaggle
The complete analysis is available as a Kaggle notebook with all data pre-attached:
- Open the notebook: Spatial Transcriptomics Atlas on Kaggle
- Click "Copy & Edit" to create your own copy
- Run all cells -- the notebook will automatically detect the Kaggle data path
- Interactive Plotly visualizations render directly within the Kaggle environment
Local Execution
# Download the spatial data (automated)
python download_atlas.py
# Launch the analysis notebook
jupyter notebook spatial_systems_biology_lymph_node.ipynb
Alternatively, individual pipeline stages can be executed as standalone scripts:
# Step 1: Data curation, QC, normalization, clustering, and annotation
python curation.py
# Step 2: Spatial visualization generation
python analysis_spatial.py
# Step 3: Final annotated architecture maps
python final_map.py
Expected Input Format
The pipeline operates on AnnData objects structured as follows:
AnnData object: n_obs x n_vars = 4035 x 36601
obs: 'Tissue_Architecture' -- domain annotation labels
var: gene-level metadata
obsm: 'spatial' -- (x, y) capture spot coordinates
uns: spatial imaging data (H&E histology, scale factors)
References
Software
Wolf, F. A., Angerer, P., & Theis, F. J. (2018). SCANPY: large-scale single-cell gene expression data analysis. Genome Biology, 19(1), 15. https://doi.org/10.1186/s13059-017-1382-0
Palla, G., Spitzer, H., Klein, M., et al. (2022). Squidpy: a scalable framework for spatial omics analysis. Nature Methods, 19(2), 171--178. https://doi.org/10.1038/s41592-021-01358-2
Virshup, I., Rybakov, S., Theis, F. J., et al. (2021). anndata: Annotated data. bioRxiv. https://doi.org/10.1101/2021.12.16.473007
Methods
Moran, P. A. (1950). Notes on continuous stochastic phenomena. Biometrika, 37(1/2), 17--23. https://doi.org/10.2307/2332142
Efremova, M., Vento-Tormo, M., Teichmann, S. A., & Vento-Tormo, R. (2020). CellPhoneDB: inferring cell-cell communication from combined expression of multi-subunit ligand-receptor complexes. Nature Protocols, 15(4), 1484--1506. https://doi.org/10.1038/s41596-020-0292-x
Stahl, P. L., Salmen, F., Vickovic, S., et al. (2016). Visualization and analysis of gene expression in tissue sections by spatial transcriptomics. Science, 353(6294), 78--82. https://doi.org/10.1126/science.aaf2403
Data Source
- 10x Genomics. (2020). Human Lymph Node -- Spatial Gene Expression Dataset. https://www.10xgenomics.com/datasets/human-lymph-node-1-standard-1-1-0
Contributing
Contributions are welcome. Please adhere to the following workflow:
- Fork the repository
- Create a feature branch (
git checkout -b feature/your-analysis) - Commit your changes with descriptive messages
- Push to your fork and open a pull request
All Python code should follow PEP 8 style conventions. New analysis modules should include docstrings and, where applicable, unit tests.
License
This project is licensed under the MIT License. See the LICENSE file for details.
- Downloads last month
- 70