Package: leidenalg
This package implements the Leiden algorithm inC++and exposes it topython.  It relies on(python-)igraphfor it to function. Besides the
relative flexibility of the implementation, it also scales well, and can be run
on graphs of millions of nodes (as long as they can fit in memory). The core
function isfind_partitionwhich finds the optimal partition using the
Leiden algorithm[1], which is an extension of the Louvain algorithm[2]for a
number of different methods. The methods currently implemented are (1)
modularity[3], (2) Reichardt and Bornholdt’s model using the configuration
null model and the Erdös-Rényi null model[4], (3) the Constant Potts model
(CPM)[5], (4) Significance[6], and finally (5) Surprise[7]. In addition,
it supports multiplex partition optimisation allowing community detection on for
example negative links[8]or multiple time slices[9]. There is the
possibility of only partially optimising a partition, so that some community
assignments remain fixed[10]. It also provides some support for community
detection on bipartite graphs. See thedocumentationfor more information.InstallationIn short:pip install leidenalg. All major platforms are supported on
Python>=3.6, earlier versions of Python are no longer supported. Alternatively,
you can install from Anaconda (channelconda-forge).For Unix like systems it is possible to install from source. For Windows this is
more complicated, and you are recommended to use the binary wheels. This Python
interface depends on the C++ packagelibleidenalgwhich in turn depends onigraph. You will need to build these packages yourself before you are able
to build this Python interface.Make sure you have all necessary tools for compilation. In Ubuntu this can be
installed usingsudoapt-getinstallbuild-essentialautoconf automake flex bison, please refer to the documentation for your specific system.  Make sure
that not onlygccis installed, but alsog++, as theleidenalgpackage is programmed inC++. Note that there are build scripts included in
thescripts/directory. These are also used to build the binary wheels.Compile (and install) the C core ofigraph(version >= 0.10). You can use
the filebuild_igraph.sh(on Unix-like systems) orbuild_igraph.bat(on Windows) in thescripts/directory to do this. For more details, seehttps://igraph.org/c/doc/igraph-Installation.html.Compile (and install) the C core oflibleidenalg(version >= 0.10). You
can use the filebuild_libleidenalg.sh(on Unix-like systems) orbuild_libleidenalg.bat(on Windows) in thescripts/directory to do
this. For more details, seehttps://github.com/vtraag/libleidenalg.Build the Python interface usingpython setup.py buildandpython setup.py install, or usepip install .You can check if all went well by running a variety of tests usingpython-munittest.TroubleshootingIn case of any problems, best to start over with a clean environment. Make sure
you remove theigraphandleidenalgpackage completely. Then, do a
complete reinstall starting frompip install leidenalg. In case you
installed from source, and built the C libraries ofigraphandlibleidenalgyourself, remove them completely and rebuild and reinstall
them.UsageThis is the Python interface for the C++ packagelibleidenalg. There are no
plans at the moment for developing an R interface to the package. However, there
have been various efforts to port the package to R. These typically do not offer
all available functionality or have some other limitations, but nonetheless may
be very useful. The available ports are:https://github.com/cole-trapnell-lab/leidenbasehttps://github.com/TomKellyGenetics/leidenhttps://github.com/kharchenkolab/leidenAlgPlease refer to the documentation for more details
on function calls and parameters.This implementation is made for flexibility, butigraphnowadays also
includes an implementation of the Leiden algorithm internally. That
implementation is less flexible: the implementation only works on undirected
graphs, and only CPM and modularity are supported. It is likely to be
substantially faster though.Just to get you started, below the essential parts.
To start, make sure to import the packages:>>> import leidenalg
>>> import igraph as igWe’ll create a random graph for testing purposes:>>> G = ig.Graph.Erdos_Renyi(100, 0.1);For simply finding a partition use:>>> part = leidenalg.find_partition(G, leidenalg.ModularityVertexPartition);ContributeSource code:https://github.com/vtraag/leidenalgIssue tracking:https://github.com/vtraag/leidenalg/issuesSee the documentation onImplementationfor more details on how to
contribute new methods.ReferencesPlease cite the references appropriately in case they are used.[1]Traag, V.A., Waltman. L., Van Eck, N.-J. (2018). From Louvain to
Leiden: guaranteeing well-connected communities. Scientific reports, 9(1), 5233.10.1038/s41598-019-41695-z[2]Blondel, V. D., Guillaume, J.-L., Lambiotte, R., & Lefebvre, E. (2008).
Fast unfolding of communities in large networks. Journal of Statistical
Mechanics: Theory and Experiment, 10008(10), 6.10.1088/1742-5468/2008/10/P10008[3]Newman, M. E. J., & Girvan, M. (2004). Finding and evaluating community
structure in networks. Physical Review E, 69(2), 026113.10.1103/PhysRevE.69.026113[4]Reichardt, J., & Bornholdt, S. (2006). Statistical mechanics of
community detection. Physical Review E, 74(1), 016110.10.1103/PhysRevE.74.016110[5]Traag, V. A., Van Dooren, P., & Nesterov, Y. (2011). Narrow scope for
resolution-limit-free community detection. Physical Review E, 84(1),
016114.10.1103/PhysRevE.84.016114[6]Traag, V. A., Krings, G., & Van Dooren, P. (2013). Significant scales in
community structure. Scientific Reports, 3, 2930.10.1038/srep02930[7]Traag, V. A., Aldecoa, R., & Delvenne, J.-C. (2015). Detecting
communities using asymptotical surprise. Physical Review E, 92(2),
022816.10.1103/PhysRevE.92.022816[8]Traag, V. A., & Bruggeman, J. (2009). Community detection in networks
with positive and negative links. Physical Review E, 80(3), 036115.10.1103/PhysRevE.80.036115[9]Mucha, P. J., Richardson, T., Macon, K., Porter, M. A., & Onnela, J.-P.
(2010). Community structure in time-dependent, multiscale, and multiplex
networks. Science, 328(5980), 876–8.10.1126/science.1184819[10]Zanini, F., Berghuis, B. A., Jones, R. C., Robilant, B. N. di,
Nong, R. Y., Norton, J., Clarke, Michael F., Quake, S. R. (2019).
northstar: leveraging cell atlases to identify healthy and neoplastic
cells in transcriptomes from human tumors. BioRxiv, 820928.10.1101/820928LicenceCopyright (C) 2020 V.A. TraagThis program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.  See the GNU General Public License for more details.You should have received a copy of the GNU General Public License along with
this program. If not, seehttp://www.gnu.org/licenses/.