Skip to content

Commit

Permalink
fix error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
gagolews committed Nov 4, 2020
1 parent c8a52f7 commit a8c62f8
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
devel/data/pbmc3k_raw.h5ad
*.kate-swp
.vscode
.pytest_cache
Expand Down
65 changes: 65 additions & 0 deletions devel/sandbox_scanpy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Based on the code contributed by @gokceneraslan
# see https://github.com/gagolews/genieclust/issues/71


# pip install scanpy
# pip install louvain
# pip install scikit-misc


import scanpy as sc
sc.set_figure_params(dpi=100)
ad = sc.datasets.pbmc3k()
sc.pp.filter_genes(ad, min_cells=10)
ad.layers['counts'] = ad.X.copy()
sc.pp.normalize_total(ad, target_sum=10000)
sc.pp.log1p(ad)
sc.pp.highly_variable_genes(ad, n_top_genes=1000, flavor='seurat_v3', subset=True, layer='counts')
sc.pp.scale(ad, max_value=8)
sc.pp.pca(ad)
sc.pp.neighbors(ad)

sc.tl.umap(ad)

sc.tl.louvain(ad, resolution=0.2)

X_hidim = ad.X
X_lodim = ad.obsm['X_pca']


import genieclust
import numpy as np

g = genieclust.Genie(n_clusters=3, affinity='cosine')
labels = g.fit_predict(X_hidim)
ad.obs['genie_labels'] = labels.astype(str)
sc.pl.umap(ad, color='genie_labels')

g = genieclust.Genie(n_clusters=3, affinity='cosine')
labels = g.fit_predict(X_lodim)
ad.obs['genie_labels'] = labels.astype(str)
sc.pl.umap(ad, color='genie_labels')

sc.pl.umap(ad, color='louvain')


mst = genieclust.internal.mst_from_distance(X_hidim, 'cosine')
genieclust.plots.plot_segments(mst[1], ad.obsm["X_umap"])


X_hidim_std = (X_hidim-X_hidim.mean(axis=0))/(X_hidim.std(axis=0))
g = genieclust.Genie(n_clusters=3, affinity='cosine', M=5, postprocess="merge")
labels = g.fit_predict(X_hidim_std)
ad.obs['genie_labels_std'] = labels.astype(str)
sc.pl.umap(ad, color='genie_labels_std')


mst = genieclust.internal.mst_from_distance(X_hidim_std)
genieclust.plots.plot_segments(mst[1], ad.obsm["X_umap"])



mst = genieclust.internal.mst_from_distance(np.array(X_lodim, copy=True, order='C'))
#sc.pl.umap(ad, color='genie_labels')
genieclust.plots.plot_segments(mst[1], ad.obsm["X_umap"])

4 changes: 2 additions & 2 deletions genieclust/genie.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def _check_params(self, cur_state=None):
_postprocess_options = ("boundary", "none", "all")
cur_state["postprocess"] = str(self.postprocess).lower()
if cur_state["postprocess"] not in _postprocess_options:
raise ValueError("`postprocess` should be one of %r" % _postprocess_options)
raise ValueError("`postprocess` should be one of %s" % repr(_postprocess_options))

cur_state["affinity"] = str(self.affinity).lower()
if cur_state["affinity"] in ["euclidean", "lp:p=2"]:
Expand All @@ -227,7 +227,7 @@ def _check_params(self, cur_state=None):
_affinity_exact_options = (
"l2", "l1", "cosinesimil", "precomputed")
if cur_state["exact"] and cur_state["affinity"] not in _affinity_exact_options:
raise ValueError("`affinity` should be one of %r" % _affinity_exact_options)
raise ValueError("`affinity` should be one of %s" % repr(_affinity_exact_options))

if type(self.mlpack_enabled) is str:
cur_state["mlpack_enabled"] = str(self.mlpack_enabled).lower()
Expand Down
26 changes: 13 additions & 13 deletions src/c_mst.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,24 +315,24 @@ ssize_t Cmst_from_nn(

/*! Determine the first k nearest neighbours of each point.
*
* Exactly n*(n-1) distance computations are performed.
* Exactly n*(n-1)/2 distance computations are performed.
*
* It is assumed that each query point is not its own neighbour.
*
* Worst-case time complexity: O(n*(n-1)/2*d*k)
* Worst-case time complexity: O(n*(n-1)/2*d*k)
*
*
* @param D a callable CDistance object such that a call to
* <T*>D(j, <ssize_t*>M, ssize_t l) returns an n-ary array
* with the distances from the j-th point to l points whose indices
* are given in array M
* @param n number of points
* @param k number of nearest neighbours,
* @param dist [out] a c_contiguous array, shape (n,k),
* dist[i,j] gives the weight of the (undirected) edge {i, ind[i,j]}
* @param ind [out] a c_contiguous array, shape (n,k),
* (undirected) edge definition, interpreted as {i, ind[i,j]}
* @param verbose output diagnostic/progress messages?
* @param D a callable CDistance object such that a call to
* <T*>D(j, <ssize_t*>M, ssize_t l) returns an n-ary array
* with the distances from the j-th point to l points whose indices
* are given in array M
* @param n number of points
* @param k number of nearest neighbours,
* @param dist [out] a c_contiguous array, shape (n,k),
* dist[i,j] gives the weight of the (undirected) edge {i, ind[i,j]}
* @param ind [out] a c_contiguous array, shape (n,k),
* (undirected) edge definition, interpreted as {i, ind[i,j]}
* @param verbose output diagnostic/progress messages?
*/
template <class T>
void Cknn_from_complete(CDistance<T>* D, ssize_t n, ssize_t k,
Expand Down

0 comments on commit a8c62f8

Please sign in to comment.