Skip to content

Commit 72bc558

Browse files
last last error main commit
1 parent 8639b7e commit 72bc558

File tree

4 files changed

+292
-149
lines changed

4 files changed

+292
-149
lines changed

plankton/graph.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import pandas as pd
1515
from scipy.stats import binom
16-
from sklearn.decomposition import PCA
16+
from sklearn.decomposition import PCA, FastICA
1717

1818
from sklearn.neighbors import NearestNeighbors
1919

@@ -236,7 +236,7 @@ def kernel(x): return np.exp(-x**2/(2*bandwidth**2))
236236
] += kernel(self.distances[:, i])
237237
return counts
238238

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):
240240
"""run_umap: Creates a UMAP representation of recurring local contexts in the source data.
241241
242242
: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
254254
counts[np.arange(len(self.sdata)),
255255
self.sdata.gene_ids] += zero_weight-1
256256

257-
pca=PCA()
258-
facs = pca.fit_transform(counts)
257+
if cutoff is not None:
259258

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+
262276

263277
umap = UMAP(metric=metric, *args, **kwargs)
264-
self._umap = umap.fit_transform(facs_)
278+
self._umap = umap.fit_transform(counts)
265279

266280
def plot_umap(self, color_prop='genes', text_prop=None,
267281
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'):
350364

351365
n_bars = 20
352366

353-
if self.sdata.background is not None:
367+
if False:
354368
f_scatter = go.FigureWidget(px.imshow(np.repeat(self.sdata.background.data[:, :, None], 3, axis=-1,),
355369
x=np.linspace(
356370
self.sdata.background.extent[0], self.sdata.background.extent[1], self.sdata.background.data.shape[0]),

test/HDCA-lung/background.jpg

1.6 MB
Loading

test/HDCA-lung/demo.ipynb

Lines changed: 223 additions & 126 deletions
Large diffs are not rendered by default.

tutorials/exploration.ipynb

Lines changed: 47 additions & 15 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)