Skip to content

Commit

Permalink
Using Gene expression proportion across sections if provided.
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonSong1995 authored and Ganten-Hornby committed Dec 3, 2024
1 parent f73a7c1 commit 9fd6705
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/gsMap/latent_to_gene.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def run_latent_to_gene(config: LatentToGeneConfig):

# Geometric mean across slices
gM = None
frac_whole = None
if config.gM_slices is not None:
logger.info('Geometrical mean across multiple slices is provided.')
gM_df = pd.read_parquet(config.gM_slices)
Expand All @@ -190,6 +191,7 @@ def run_latent_to_gene(config: LatentToGeneConfig):
common_genes = np.intersect1d(adata.var_names, gM_df.index)
gM_df = gM_df.loc[common_genes]
gM = gM_df['G_Mean'].values
frac_whole = gM_df['frac'].values
adata = adata[:, common_genes]
logger.info(f'{len(common_genes)} common genes retained after loading the cross slice geometric mean.')

Expand All @@ -211,12 +213,15 @@ def run_latent_to_gene(config: LatentToGeneConfig):
if gM is None:
gM = gmean(ranks, axis=0)

# Compute the fraction of each gene across cells
adata_X_bool = adata_X.astype(bool)
frac_whole = np.asarray(adata_X_bool.sum(axis=0)).flatten() / n_cells
if frac_whole is None:
# Compute the fraction of each gene across cells
frac_whole = np.asarray(adata_X_bool.sum(axis=0)).flatten() / n_cells
logger.info('Gene expression proportion of each gene across cells computed.')
else:
logger.info('Gene expression proportion of each gene across cells in all sections has been provided.')

frac_whole += 1e-12 # Avoid division by zero
logger.info('Gene expression proportion of each gene across cells computed.')

# Normalize the ranks
ranks /= gM

Expand Down

0 comments on commit 9fd6705

Please sign in to comment.