Skip to content

Commit 716c635

Browse files
author
niklasmueboe
committed
rename pca and umap objects
1 parent 6c8c4eb commit 716c635

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

ovrlpy/_ovrlp.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ class Ovrlp:
8484
The center of gravity of each celltype in the 2D embedding, used for UMAP annotation.
8585
celltype_assignments : numpy.ndarray
8686
The assignments of the cell types.
87-
pca_2d : sklearn.decomposition.PCA
88-
The PCA object used for the 2D embedding.
89-
embedder_2d : umap.UMAP
87+
pca : sklearn.decomposition.PCA
88+
The PCA object used for the 2D embedding and calculating the VSI score.
89+
umap_2d : umap.UMAP
9090
The UMAP object used for the 2D embedding.
91-
pca_3d : sklearn.decomposition.PCA
91+
pca_rgb : sklearn.decomposition.PCA
9292
The PCA object used for the 3D RGB embedding.
93-
embedder_3d : umap.UMAP
93+
umap_rgb : umap.UMAP
9494
The UMAP object used for the 3D RGB embedding.
9595
genes : list
9696
A list of genes to utilize in the model.
@@ -147,10 +147,10 @@ def __init__(
147147
n_jobs = n_workers if cumap_kwargs.get("random_state") is None else 1
148148
cumap_kwargs["n_jobs"] = n_jobs
149149

150-
self.pca_2d = PCA(n_components=n_components, random_state=random_state)
151-
self.embedder_2d = UMAP(**(umap_kwargs | {"n_components": 2}))
152-
self.pca_3d = PCA(n_components=3, random_state=random_state)
153-
self.embedder_3d = UMAP(**(cumap_kwargs | {"n_components": 3}))
150+
self.pca = PCA(n_components=n_components, random_state=random_state)
151+
self.umap_2d = UMAP(**(umap_kwargs | {"n_components": 2}))
152+
self.pca_rgb = PCA(n_components=3, random_state=random_state)
153+
self.umap_rgb = UMAP(**(cumap_kwargs | {"n_components": 3}))
154154

155155
def process_coordinates(self, gridsize: float = 1, **kwargs):
156156
"""
@@ -225,19 +225,19 @@ def fit_pseudocells(self, pseudocells: AnnData, *, fit_umap: bool = True):
225225

226226
self.pseudocells = pseudocells
227227
X = pseudocells[:, self.genes].X
228-
self.pca_2d.fit(X)
228+
self.pca.fit(X)
229229

230230
if fit_umap:
231-
factors = self.pca_2d.transform(X)
231+
factors = self.pca.transform(X)
232232

233233
print(f"Modeling {factors.shape[1]} pseudo-celltype clusters;")
234234

235-
self.pseudocells.obsm["2D_UMAP"] = self.embedder_2d.fit_transform(factors)
235+
self.pseudocells.obsm["2D_UMAP"] = self.umap_2d.fit_transform(factors)
236236

237-
embedding_color = self.embedder_3d.fit_transform(
237+
embedding_color = self.umap_rgb.fit_transform(
238238
factors / norm(factors, axis=1, keepdims=True)
239239
)
240-
embedding_color = _fill_color_axes(embedding_color, self.pca_3d, fit=True)
240+
embedding_color = _fill_color_axes(embedding_color, self.pca_rgb, fit=True)
241241

242242
self._colors_min_max = (
243243
embedding_color.min(axis=0),
@@ -405,7 +405,7 @@ def compute_VSI(self, *, min_transcripts: float = 2):
405405
_calculate_embedding,
406406
gene_queue,
407407
patch_mask,
408-
self.pca_2d.components_,
408+
self.pca.components_,
409409
bandwidth=self.KDE_bandwidth,
410410
dtype=self.dtype,
411411
)
@@ -602,11 +602,11 @@ def transform_pseudocells(
602602

603603
embedding, embedding_color = _transform_embeddings(
604604
pseudocells.to_numpy(),
605-
self.pca_2d,
606-
embedder_2d=self.embedder_2d,
607-
embedder_3d=self.embedder_3d,
605+
self.pca,
606+
umap_2d=self.umap_2d,
607+
umap_rgb=self.umap_rgb,
608608
)
609-
embedding_color = _fill_color_axes(embedding_color, self.pca_3d)
609+
embedding_color = _fill_color_axes(embedding_color, self.pca_rgb)
610610
color_min, color_max = self._colors_min_max
611611
embedding_color = (embedding_color - color_min) / (color_max - color_min)
612612
embedding_color = np.clip(embedding_color, 0, 1)

ovrlpy/_utils.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,12 @@ def _minmax_scaling(x: np.ndarray):
7878
return (x - x_min) / (x_max - x_min)
7979

8080

81-
def _transform_embeddings(expression, pca: PCA, embedder_2d: UMAP, embedder_3d: UMAP):
81+
def _transform_embeddings(expression, pca: PCA, umap_2d: UMAP, umap_rgb: UMAP):
8282
"""fit the expression data into the umap embeddings after PCA transformation"""
8383
factors = pca.transform(expression)
8484

85-
embedding = embedder_2d.transform(factors)
86-
embedding_color = embedder_3d.transform(
87-
factors / norm(factors, axis=1, keepdims=True)
88-
)
85+
embedding = umap_2d.transform(factors)
86+
embedding_color = umap_rgb.transform(factors / norm(factors, axis=1, keepdims=True))
8987

9088
return embedding, embedding_color
9189

0 commit comments

Comments
 (0)