77import numpy as np
88from .. import utils
99from .. import logging as logg
10- from ..data_structs import DataGraph
10+ from ..data_structs .data_graph import add_graph_to_adata
11+
1112
1213def louvain (adata ,
1314 n_neighbors = 30 ,
@@ -43,28 +44,19 @@ def louvain(adata,
4344 - basic suggestion for single-cell: Levine et al., Cell 162, 184-197 (2015)
4445 - combination with "attachedness" matrix: Wolf et al., bioRxiv (2017)
4546 """
46- logg .m ('run Louvain clustering' , r = True )
47+ logg .m ('running Louvain clustering' , r = True )
4748 adata = adata .copy () if copy else adata
4849 if 'Ktilde' not in adata .add or recompute_graph :
49- graph = DataGraph (adata ,
50- k = n_neighbors ,
51- n_pcs = n_pcs ,
52- recompute_pca = recompute_pca ,
53- recompute_graph = recompute_graph ,
54- n_jobs = n_jobs )
55- # compute diffmap for later use although it's not needed here
56- # it does not cost much
57- graph .update_diffmap ()
58- adata .add ['distance' ] = graph .Dsq
59- adata .add ['Ktilde' ] = graph .Ktilde
60- adata .smp ['X_diffmap' ] = graph .rbasis [:, 1 :]
61- adata .smp ['X_diffmap0' ] = graph .rbasis [:, 0 ]
62- adata .add ['diffmap_evals' ] = graph .evals [1 :]
50+ add_graph_to_adata (
51+ adata ,
52+ n_neighbors = n_neighbors ,
53+ n_pcs = n_pcs ,
54+ recompute_pca = recompute_pca ,
55+ recompute_graph = recompute_graph ,
56+ n_jobs = n_jobs )
6357 else :
64- # do not use the undirected kernel Ktilde here, but the
65- # sparse distance matrix
6658 n_neighbors = adata .add ['distance' ][0 ].nonzero ()[0 ].size + 1
67- logg .info (' using precomputed graph with n_neighbors= {}'
59+ logg .info (' using stored graph with n_neighbors = {}'
6860 .format (n_neighbors ))
6961 adjacency = adata .add ['Ktilde' ]
7062 if flavor in {'vtraag' , 'igraph' }:
@@ -83,11 +75,10 @@ def louvain(adata,
8375 resolution_parameter = resolution )
8476 adata .add ['louvain_quality' ] = part .quality ()
8577 except AttributeError :
86- logg .warn ('Did not find louvain package >= 0.6 on your system, '
87- 'the result will therefore not be 100% reproducible, but '
88- 'is influenced by randomness in the community detection '
89- 'algorithm. Still you get very meaningful results!\n '
90- 'If you want 100% reproducible results, but 0.6 is not yet '
78+ logg .warn ('Did not find package louvain>=0.6, '
79+ 'the clustering result will therefore not be 100% reproducible, '
80+ 'but still meaningful! '
81+ 'If you want 100% reproducible results, but louvain 0.6 is not yet '
9182 'available via "pip install louvain", '
9283 'either get the latest (development) version from '
9384 'https://github.com/vtraag/louvain-igraph or use the option '
0 commit comments