Skip to content

Commit

Permalink
last last error main commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiantiesmeyer committed Jul 25, 2022
1 parent 8639b7e commit 72bc558
Show file tree
Hide file tree
Showing 4 changed files with 292 additions and 149 deletions.
30 changes: 22 additions & 8 deletions plankton/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import pandas as pd
from scipy.stats import binom
from sklearn.decomposition import PCA
from sklearn.decomposition import PCA, FastICA

from sklearn.neighbors import NearestNeighbors

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

def run_umap(self, bandwidth=1, kernel=None, metric='euclidean', zero_weight=1.0, cutoff = 30, *args, **kwargs):
def run_umap(self, bandwidth=1, kernel=None, metric='euclidean', zero_weight=1.0, cutoff = None, *args, **kwargs):
"""run_umap: Creates a UMAP representation of recurring local contexts in the source data.
:param bandwidth: Bandwidth of the default Gaussian kernel used to build local environment models, defaults to 1
Expand All @@ -254,14 +254,28 @@ def run_umap(self, bandwidth=1, kernel=None, metric='euclidean', zero_weight=1.0
counts[np.arange(len(self.sdata)),
self.sdata.gene_ids] += zero_weight-1

pca=PCA()
facs = pca.fit_transform(counts)
if cutoff is not None:

facs_ = facs[:,:cutoff]
facs_[:,-1]=facs[:,cutoff:].sum(1)
# print(f'PCA redution to {cutoff} dimensions.')
# pca=PCA()
# facs = pca.fit_transform(counts)

# counts = np.zeros((counts.shape[0],cutoff+10))

# counts[:,:cutoff] = facs[:,:cutoff]

print(f'Reducing dimensions with FastICA')
ica = FastICA(n_components=cutoff)
counts = ica.fit_transform(counts)

# counts[:,cutoff:] = facs
# del facs,ica
print('Calculating UMAP embedding.')
# counts[:,-1]=facs[:,cutoff:].sum(1)


umap = UMAP(metric=metric, *args, **kwargs)
self._umap = umap.fit_transform(facs_)
self._umap = umap.fit_transform(counts)

def plot_umap(self, color_prop='genes', text_prop=None,
text_color_prop=None, c=None, color=None, color_dict=None, text_distance=1,
Expand Down Expand Up @@ -350,7 +364,7 @@ def umap_js(self, color_prop='c_genes'):

n_bars = 20

if self.sdata.background is not None:
if False:
f_scatter = go.FigureWidget(px.imshow(np.repeat(self.sdata.background.data[:, :, None], 3, axis=-1,),
x=np.linspace(
self.sdata.background.extent[0], self.sdata.background.extent[1], self.sdata.background.data.shape[0]),
Expand Down
Binary file added test/HDCA-lung/background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
349 changes: 223 additions & 126 deletions test/HDCA-lung/demo.ipynb

Large diffs are not rendered by default.

62 changes: 47 additions & 15 deletions tutorials/exploration.ipynb

Large diffs are not rendered by default.

0 comments on commit 72bc558

Please sign in to comment.