Skip to content

Commit

Permalink
add option to export gene by spot matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahOuologuem committed Jan 28, 2025
1 parent a72fbcb commit 86fd9d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Cell2Location:

# -------------------------------
save_models: False # Default False; whether to save the reference and spatial mapping models
export_gene_by_spot: False # Default False; whether to save a gene by spot matrix for each cell type in a layer



Expand Down
16 changes: 16 additions & 0 deletions panpipes/python_scripts/run_cell2location.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
parser.add_argument("--save_models",
default=False,
help="whether to save the reference & spatial mapping models")
parser.add_argument("--export_gene_by_spot",
default=False,
help="whether to save a gene by spot matrix for each cell type in a layer")


# parameters for feature selection:
Expand Down Expand Up @@ -148,6 +151,11 @@
save_models = False
else:
save_models = True

if (args.export_gene_by_spot is False) or (args.export_gene_by_spot == "False"):
export_gene_by_spot = False
else:
export_gene_by_spot = True

if (args.remove_mt is True) or (args.remove_mt == "True"):
remove_mt = True
Expand Down Expand Up @@ -320,6 +328,14 @@
L.info("Plotting QC plots")
cell2loc_plot_QC_reconstr(model_spatial, figdir + "/QC_spatial_reconstruction_accuracy.png")

# export a gene by spot matrix for each cell type
if export_gene_by_spot:
# Compute expected expression per cell type
expected_dict = model_spatial.module.model.compute_expected_per_cell_type(model_spatial.samples["post_sample_q05"], model_spatial.adata_manager)
# Add to anndata layers
for i, n in enumerate(model_spatial.factor_names_):
sdata_st["table"].layers[n] = expected_dict['mu'][i]


#plot output
L.info("Plotting spatial embedding plot coloured by 'q05_cell_abundance_w_sf'")
Expand Down

0 comments on commit 86fd9d4

Please sign in to comment.