13
13
14
14
import pandas as pd
15
15
from scipy .stats import binom
16
+ from sklearn .decomposition import PCA
16
17
17
18
from sklearn .neighbors import NearestNeighbors
18
19
@@ -235,7 +236,7 @@ def kernel(x): return np.exp(-x**2/(2*bandwidth**2))
235
236
] += kernel (self .distances [:, i ])
236
237
return counts
237
238
238
- def run_umap (self , bandwidth = 1 , kernel = None , metric = 'euclidean' , zero_weight = 1.0 , * args , ** kwargs ):
239
+ def run_umap (self , bandwidth = 1 , kernel = None , metric = 'euclidean' , zero_weight = 1.0 , cutoff = 30 , * args , ** kwargs ):
239
240
"""run_umap: Creates a UMAP representation of recurring local contexts in the source data.
240
241
241
242
:param bandwidth: Bandwidth of the default Gaussian kernel used to build local environment models, defaults to 1
@@ -252,9 +253,15 @@ def run_umap(self, bandwidth=1, kernel=None, metric='euclidean', zero_weight=1.0
252
253
assert (all (counts .sum (1 )) > 0 )
253
254
counts [np .arange (len (self .sdata )),
254
255
self .sdata .gene_ids ] += zero_weight - 1
255
-
256
+
257
+ pca = PCA ()
258
+ facs = pca .fit_transform (counts )
259
+
260
+ facs_ = facs [:,:cutoff ]
261
+ facs_ [:,- 1 ]= facs [:,cutoff :].sum (1 )
262
+
256
263
umap = UMAP (metric = metric , * args , ** kwargs )
257
- self ._umap = umap .fit_transform (counts )
264
+ self ._umap = umap .fit_transform (facs_ )
258
265
259
266
def plot_umap (self , color_prop = 'genes' , text_prop = None ,
260
267
text_color_prop = None , c = None , color = None , color_dict = None , text_distance = 1 ,
@@ -526,10 +533,10 @@ def map_and_umap(self, color_prop=None, scalebar=True, cmap='jet',
526
533
527
534
ax1 = plt .subplot2grid ((3 , 2 ), (0 , 0 ), 2 , 1 )
528
535
529
- sc2 , _ , _ = self .sdata .scatter (axd = ax1 ,scalebar = scalebar , ** kwargs )
536
+ sc2 , _ , _ = self .sdata .scatter (axd = ax1 ,scalebar = scalebar ,cmap = cmap , ** kwargs )
530
537
531
538
ax2 = plt .subplot2grid ((3 , 2 ), (0 , 1 ), 2 , 1 )
532
- self .sdata .graph .plot_umap (** kwargs )
539
+ self .sdata .graph .plot_umap (cmap = cmap , ** kwargs )
533
540
534
541
535
542
0 commit comments