Skip to content

CompBtBs/spFBA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spFBA - code repository

This repository includes ST datasets and the code for reproducing main results and figures presented in the manuscript D. Maspero, G. Marteletto, F. Lapi, et al. Spatial Flux Balance Analysis reveals tissue-of-origin and spatially-dependent metabolic rewiring in renal and colorectal cancer, npj Systems Biology and Applications (2026) DOI:10.1038/s41540-026-00654-x

To extract any tar.gz. archive, do the following:

mkdir scFBA; 
tar *.tar.gz -C spFBA

The workflow consists in the following steps:

  1. Preprocessing and Filtering

    In data/unprocessed directory are stored the scanpy objects for both stereo-seq (colorectal cancer) and visium (kidney tumor) datasets.

    In data/preprocessing_notebooks there are the corresponding jupyter notebooks to performed quality control, data normalization and, if needed, filtering of low quality spots. The notebooks are already computed and they include the visualization of quality metrics and clustering.

    Please note, visiumHD related notebooks will automatically download and generate the unprocessed objects.

    The resulting objects are stored in data/processed.

  2. Denoising, Sampling, and Computing Metabolic Flux Metrics

    The workflow uses the script/sampling_data.py to both denoise and compute the metabolic flux metrics. The denoising process is implemented using the MAGIC (Markov Affinity-based Graph Imputation of Cells) algorithm, which reduces noise and imputes missing values in the spatial transcriptomics data. After denoising, the script proceeds with the calculation of metabolic flux metrics.

    To run the script, simply use the following command:

    python sampling_data.py

    Denoised data will be saved in output/{input_file_name}/denoised, where {input_file_name} is dynamically replaced by the name of the input file. Computed metabolic flux metrics will be saved in output/{input_file_name}/sampling/CBS, where you will find:

    • All sampled fluxes for each cell/spot (not provided in this repository due to space limitation)
    • The value of the objective function

    Additionally, metrics are stored in an AnnData object named flux_statistics.h5ad. In this object:

    • The normalized mean fluxes are stored in .X
    • The mean fluxes and the confidence interval of the normalized mean are stored in .layers
  3. Visualizing the results

    In flux_distributions dir, you can find a jupyter notebook called plot_flux_distributions.ipynb. It includes the code for reading the processed scanpy objects and the metric computed in the previous step.

    Then, all the plots reported in the main text as well as in the supplemetary are generated and saved in plot subdir.

  4. Clustering and Comparison

    In the clustering_and_comparison dir, you can find a notebook called Figures_kidney.ipynb. This notebook includes code for the clustering analysis, V-measure computation, and cell-cycle score analysis. The notebook takes cell-cycle annotations from clustering_and_comparison/annotations/ and computes the cell-cycle score for each sample. All clustering results, including cell-cycle score analysis results, are saved as dictionaries in the clustering_and_comparison/annotations/ directory. The notebook uses RAS and performs pFBA. All clustering results are obtained using parameters that maximize the silhouette score in the Leiden clustering algorithm. After clustering analysis for all biological layers—namely RNA, RAS, pFBA, and spFBA—the V-measure is computed to compare the different layers. The distributions of the Biomass FES are visualized in violin plots and saved in clustering_and_comparison/plots/Biomass_FES_distributions. Finally, all spatial figures for each clustering layer are saved in clustering_and_comparison/plots/ in their respective directories.

Step 1 and 3 are based on the following main libraries:

Python      3.8.18
anndata     0.9.2
matplotlib  3.7.1
numpy       1.23.5
pandas      1.5.3

Step 2 is based on the following main libraries:

Python      3.12.2
anndata     0.10.8
matplotlib  3.8.4
numpy       1.26.4
pandas      2.2.1
scanpy      1.10.1
cobra       0.29.0
swiglpk     5.0.10
magic       3.0.0
scipy       1.12.0

We suggest to generate a conda environments for each step, if needed.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors