13
13
14
14
import pandas as pd
15
15
from scipy .stats import binom
16
- from sklearn .decomposition import PCA
16
+ from sklearn .decomposition import PCA , FastICA
17
17
18
18
from sklearn .neighbors import NearestNeighbors
19
19
@@ -236,7 +236,7 @@ def kernel(x): return np.exp(-x**2/(2*bandwidth**2))
236
236
] += kernel (self .distances [:, i ])
237
237
return counts
238
238
239
- def run_umap (self , bandwidth = 1 , kernel = None , metric = 'euclidean' , zero_weight = 1.0 , cutoff = 30 , * args , ** kwargs ):
239
+ def run_umap (self , bandwidth = 1 , kernel = None , metric = 'euclidean' , zero_weight = 1.0 , cutoff = None , * args , ** kwargs ):
240
240
"""run_umap: Creates a UMAP representation of recurring local contexts in the source data.
241
241
242
242
:param bandwidth: Bandwidth of the default Gaussian kernel used to build local environment models, defaults to 1
@@ -254,14 +254,28 @@ def run_umap(self, bandwidth=1, kernel=None, metric='euclidean', zero_weight=1.0
254
254
counts [np .arange (len (self .sdata )),
255
255
self .sdata .gene_ids ] += zero_weight - 1
256
256
257
- pca = PCA ()
258
- facs = pca .fit_transform (counts )
257
+ if cutoff is not None :
259
258
260
- facs_ = facs [:,:cutoff ]
261
- facs_ [:,- 1 ]= facs [:,cutoff :].sum (1 )
259
+ # print(f'PCA redution to {cutoff} dimensions.')
260
+ # pca=PCA()
261
+ # facs = pca.fit_transform(counts)
262
+
263
+ # counts = np.zeros((counts.shape[0],cutoff+10))
264
+
265
+ # counts[:,:cutoff] = facs[:,:cutoff]
266
+
267
+ print (f'Reducing dimensions with FastICA' )
268
+ ica = FastICA (n_components = cutoff )
269
+ counts = ica .fit_transform (counts )
270
+
271
+ # counts[:,cutoff:] = facs
272
+ # del facs,ica
273
+ print ('Calculating UMAP embedding.' )
274
+ # counts[:,-1]=facs[:,cutoff:].sum(1)
275
+
262
276
263
277
umap = UMAP (metric = metric , * args , ** kwargs )
264
- self ._umap = umap .fit_transform (facs_ )
278
+ self ._umap = umap .fit_transform (counts )
265
279
266
280
def plot_umap (self , color_prop = 'genes' , text_prop = None ,
267
281
text_color_prop = None , c = None , color = None , color_dict = None , text_distance = 1 ,
@@ -350,7 +364,7 @@ def umap_js(self, color_prop='c_genes'):
350
364
351
365
n_bars = 20
352
366
353
- if self . sdata . background is not None :
367
+ if False :
354
368
f_scatter = go .FigureWidget (px .imshow (np .repeat (self .sdata .background .data [:, :, None ], 3 , axis = - 1 ,),
355
369
x = np .linspace (
356
370
self .sdata .background .extent [0 ], self .sdata .background .extent [1 ], self .sdata .background .data .shape [0 ]),
0 commit comments