gnu: r-rgraphviz: Build reproducibly.
[jackhill/guix/guix.git] / gnu / packages / graph.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017, 2018, 2019, 2020 Ricardo Wurmus <rekado@elephly.net>
3 ;;; Copyright © 2018 Joshua Sierles, Nextjournal <joshua@nextjournal.com>
4 ;;; Copyright © 2018, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
5 ;;; Copyright © 2019 Efraim Flashner <efraim@flashner.co.il>
6 ;;; Copyright © 2019 Andreas Enge <andreas@enge.fr>
7 ;;; Copyright © 2020 Alexander Krotov <krotov@iitp.ru>
8 ;;; Copyright © 2020 Pierre Langlois <pierre.langlos@gmx.com>
9 ;;;
10 ;;; This file is part of GNU Guix.
11 ;;;
12 ;;; GNU Guix is free software; you can redistribute it and/or modify it
13 ;;; under the terms of the GNU General Public License as published by
14 ;;; the Free Software Foundation; either version 3 of the License, or (at
15 ;;; your option) any later version.
16 ;;;
17 ;;; GNU Guix is distributed in the hope that it will be useful, but
18 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;;; GNU General Public License for more details.
21 ;;;
22 ;;; You should have received a copy of the GNU General Public License
23 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
24
25 (define-module (gnu packages graph)
26 #:use-module (guix download)
27 #:use-module (guix git-download)
28 #:use-module (guix packages)
29 #:use-module (guix utils)
30 #:use-module (guix build-system cmake)
31 #:use-module (guix build-system gnu)
32 #:use-module (guix build-system python)
33 #:use-module (guix build-system r)
34 #:use-module ((guix licenses) #:prefix license:)
35 #:use-module (gnu packages)
36 #:use-module (gnu packages gcc)
37 #:use-module (gnu packages autotools)
38 #:use-module (gnu packages bioconductor)
39 #:use-module (gnu packages bioinformatics)
40 #:use-module (gnu packages check)
41 #:use-module (gnu packages compression)
42 #:use-module (gnu packages cran)
43 #:use-module (gnu packages gd)
44 #:use-module (gnu packages graphviz)
45 #:use-module (gnu packages maths)
46 #:use-module (gnu packages multiprecision)
47 #:use-module (gnu packages pkg-config)
48 #:use-module (gnu packages python)
49 #:use-module (gnu packages python-science)
50 #:use-module (gnu packages python-web)
51 #:use-module (gnu packages python-xyz)
52 #:use-module (gnu packages statistics)
53 #:use-module (gnu packages swig)
54 #:use-module (gnu packages time)
55 #:use-module (gnu packages xml))
56
57 (define-public igraph
58 (package
59 (name "igraph")
60 (version "0.8.2")
61 (source
62 (origin
63 (method url-fetch)
64 (uri (string-append "https://github.com/igraph/igraph/releases/"
65 "download/" version "/igraph-" version ".tar.gz"))
66 (sha256
67 (base32 "158flvl80qh1l1ikfa04p1dzh8kapsvm6q80x3ih5gwcgcg4g2ki"))))
68 (build-system gnu-build-system)
69 (arguments
70 `(#:configure-flags
71 (list "--with-external-glpk"
72 "--with-external-blas"
73 "--with-external-lapack")))
74 (inputs
75 `(("gmp" ,gmp)
76 ("glpk" ,glpk)
77 ("libxml2" ,libxml2)
78 ("lapack" ,lapack)
79 ("openblas" ,openblas)
80 ("zlib" ,zlib)))
81 (home-page "https://igraph.org")
82 (synopsis "Network analysis and visualization")
83 (description
84 "This package provides a library for the analysis of networks and graphs.
85 It can handle large graphs very well and provides functions for generating
86 random and regular graphs, graph visualization, centrality methods and much
87 more.")
88 (license license:gpl2+)))
89
90 (define-public python-igraph
91 (package (inherit igraph)
92 (name "python-igraph")
93 (version "0.8.2")
94 (source
95 (origin
96 (method url-fetch)
97 (uri (pypi-uri "python-igraph" version))
98 (sha256
99 (base32 "0wkxrs28qdvnrz7d4jzcf2bh6v2yqzx3wyfziihfgsi2gn6n60a6"))))
100 (build-system python-build-system)
101 (arguments
102 '(#:configure-flags
103 (list "--use-pkg-config")
104 #:phases
105 (modify-phases %standard-phases
106 (replace 'build
107 (lambda _
108 (invoke "python" "./setup.py" "build" "--use-pkg-config")))
109 (delete 'check)
110 (add-after 'install 'check
111 (lambda* (#:key inputs outputs #:allow-other-keys)
112 (add-installed-pythonpath inputs outputs)
113 (invoke "pytest" "-v"))))))
114 (inputs
115 `(("igraph" ,igraph)))
116 (propagated-inputs
117 `(("python-texttable" ,python-texttable)))
118 (native-inputs
119 `(("pkg-config" ,pkg-config)
120 ("python-pytest" ,python-pytest)))
121 (home-page "https://pypi.org/project/python-igraph/")
122 (synopsis "Python bindings for the igraph network analysis library")))
123
124 (define-public r-rgraphviz
125 (package
126 (name "r-rgraphviz")
127 (version "2.32.0")
128 (source
129 (origin
130 (method url-fetch)
131 (uri (bioconductor-uri "Rgraphviz" version))
132 (sha256
133 (base32
134 "1calpvzgcz6v7s4x6bf35kj83sga95zjp7x87p5d3qnbv7q2wz5y"))))
135 (properties `((upstream-name . "Rgraphviz")))
136 (build-system r-build-system)
137 (arguments
138 `(#:phases
139 (modify-phases %standard-phases
140 (add-after 'unpack 'make-reproducible
141 (lambda _
142 ;; The replacement value is taken from src/graphviz/builddate.h
143 (substitute* "src/graphviz/configure"
144 (("VERSION_DATE=.*")
145 "VERSION_DATE=20200427.2341\n"))
146 #t)))))
147 ;; FIXME: Rgraphviz bundles the sources of an older variant of
148 ;; graphviz. It does not build with the latest version of graphviz, so
149 ;; we do not add graphviz to the inputs.
150 (inputs `(("zlib" ,zlib)))
151 (propagated-inputs
152 `(("r-graph" ,r-graph)))
153 (native-inputs
154 `(("pkg-config" ,pkg-config)))
155 (home-page "https://bioconductor.org/packages/Rgraphviz")
156 (synopsis "Plotting capabilities for R graph objects")
157 (description
158 "This package interfaces R with the graphviz library for plotting R graph
159 objects from the @code{graph} package.")
160 (license license:epl1.0)))
161
162 (define-public r-rbiofabric
163 (let ((commit "666c2ae8b0a537c006592d067fac6285f71890ac")
164 (revision "1"))
165 (package
166 (name "r-rbiofabric")
167 (version (string-append "0.3-" revision "." (string-take commit 7)))
168 (source (origin
169 (method git-fetch)
170 (uri (git-reference
171 (url "https://github.com/wjrl/RBioFabric")
172 (commit commit)))
173 (file-name (string-append name "-" version "-checkout"))
174 (sha256
175 (base32
176 "1yahqrcrqpbcywv73y9rlmyz8apdnp08afialibrr93ch0p06f8z"))))
177 (build-system r-build-system)
178 (propagated-inputs
179 `(("r-igraph" ,r-igraph)))
180 (home-page "http://www.biofabric.org/")
181 (synopsis "BioFabric network visualization")
182 (description "This package provides an implementation of the function
183 @code{bioFabric} for creating scalable network digrams where nodes are
184 represented by horizontal lines, and edges are represented by vertical
185 lines.")
186 (license license:expat))))
187
188 (define-public python-plotly
189 (package
190 (name "python-plotly")
191 (version "4.8.1")
192 (source (origin
193 (method git-fetch)
194 (uri (git-reference
195 (url "https://github.com/plotly/plotly.py")
196 (commit (string-append "v" version))))
197 (file-name (git-file-name name version))
198 (sha256
199 (base32
200 "08ab677gr85m10zhixr6dnmlfws8q6sra7nhyb8nf3r8dx1ffqhz"))))
201 (build-system python-build-system)
202 (arguments
203 `(#:phases
204 (modify-phases %standard-phases
205 (add-after 'unpack 'chdir
206 (lambda _
207 (chdir "packages/python/plotly")
208 #t))
209 (replace 'check
210 (lambda _
211 (invoke "pytest" "-x" "plotly/tests/test_core")
212 (invoke "pytest" "-x" "plotly/tests/test_io")
213 ;; FIXME: Add optional dependencies and enable their tests.
214 ;; (invoke "pytest" "-x" "plotly/tests/test_optional")
215 (invoke "pytest" "_plotly_utils/tests")))
216 (add-before 'reset-gzip-timestamps 'make-files-writable
217 (lambda* (#:key outputs #:allow-other-keys)
218 (let ((out (assoc-ref outputs "out")))
219 (for-each (lambda (file) (chmod file #o644))
220 (find-files out "\\.gz"))
221 #t))))))
222 (native-inputs
223 `(("python-pytest" ,python-pytest)))
224 (propagated-inputs
225 `(("python-decorator" ,python-decorator)
226 ("python-ipywidgets" ,python-ipywidgets)
227 ("python-pandas" ,python-pandas)
228 ("python-requests" ,python-requests)
229 ("python-retrying" ,python-retrying)
230 ("python-six" ,python-six)
231 ("python-statsmodels" ,python-statsmodels)
232 ("python-xarray" ,python-xarray)))
233 (home-page "https://plotly.com/python/")
234 (synopsis "Interactive plotting library for Python")
235 (description "Plotly's Python graphing library makes interactive,
236 publication-quality graphs online. Examples of how to make line plots, scatter
237 plots, area charts, bar charts, error bars, box plots, histograms, heatmaps,
238 subplots, multiple-axes, polar charts, and bubble charts. ")
239 (license license:expat)))
240
241 (define-public python-plotly-2.4.1
242 (package (inherit python-plotly)
243 (version "2.4.1")
244 (source
245 (origin
246 (method url-fetch)
247 (uri (pypi-uri "plotly" version))
248 (sha256
249 (base32
250 "0s9gk2fl53x8wwncs3fwii1vzfngr0sskv15v3mpshqmrqfrk27m"))))
251 (native-inputs '())
252 (propagated-inputs
253 `(("python-decorator" ,python-decorator)
254 ("python-nbformat" ,python-nbformat)
255 ("python-pandas" ,python-pandas)
256 ("python-pytz" ,python-pytz)
257 ("python-requests" ,python-requests)
258 ("python-six" ,python-six)))
259 (arguments
260 '(#:tests? #f)))) ; The tests are not distributed in the release
261
262 (define-public python2-plotly
263 (package-with-python2 python-plotly-2.4.1))
264
265 (define-public python-louvain
266 (package
267 (name "python-louvain")
268 (version "0.6.1")
269 ;; The tarball on Pypi does not include the tests.
270 (source (origin
271 (method git-fetch)
272 (uri (git-reference
273 (url "https://github.com/vtraag/louvain-igraph")
274 (commit version)))
275 (file-name (git-file-name name version))
276 (sha256
277 (base32
278 "0w31537sifkf65sck1iaip5i6d8g64pa3wdwad83d6p9jwkck57k"))))
279 (build-system python-build-system)
280 (propagated-inputs
281 `(("python-ddt" ,python-ddt)
282 ("python-igraph" ,python-igraph)))
283 (inputs
284 `(("igraph" ,igraph)))
285 (native-inputs
286 `(("pkg-config" ,pkg-config)
287 ("python-pytest" ,python-pytest)))
288 (home-page "https://github.com/vtraag/louvain-igraph")
289 (synopsis "Algorithm for methods of community detection in large networks")
290 (description
291 "This package provides an implementation of the Louvain algorithm for use
292 with igraph. Louvain is a general algorithm for methods of community
293 detection in large networks.
294
295 This package has been superseded by the @code{leidenalg} package and should
296 not be used for new projects.")
297 (license license:gpl3+)))
298
299 (define-public faiss
300 (package
301 (name "faiss")
302 (version "1.5.0")
303 (source (origin
304 (method git-fetch)
305 (uri (git-reference
306 (url "https://github.com/facebookresearch/faiss")
307 (commit (string-append "v" version))))
308 (file-name (git-file-name name version))
309 (sha256
310 (base32
311 "0pk15jfa775cy2pqmzq62nhd6zfjxmpvz5h731197c28aq3zw39w"))
312 (modules '((guix build utils)))
313 (snippet
314 '(begin
315 (substitute* "utils.cpp"
316 (("#include <immintrin.h>")
317 "#ifdef __SSE__\n#include <immintrin.h>\n#endif"))
318 #t))))
319 (build-system cmake-build-system)
320 (arguments
321 `(#:configure-flags
322 (list "-DBUILD_WITH_GPU=OFF" ; thanks, but no thanks, CUDA.
323 "-DBUILD_TUTORIAL=OFF") ; we don't need those
324 #:phases
325 (modify-phases %standard-phases
326 (add-after 'unpack 'prepare-build
327 (lambda _
328 (let ((features (list ,@(let ((system (or (%current-target-system)
329 (%current-system))))
330 (cond
331 ((string-prefix? "x86_64" system)
332 '("-mavx" "-msse2" "-mpopcnt"))
333 ((string-prefix? "i686" system)
334 '("-msse2" "-mpopcnt"))
335 (else
336 '()))))))
337 (substitute* "CMakeLists.txt"
338 (("-m64") "")
339 (("-mpopcnt") "") ; only some architectures
340 (("-msse4")
341 (string-append
342 (string-join features)
343 " -I" (getcwd)))
344 ;; Build also the shared library
345 (("ARCHIVE DESTINATION lib")
346 "LIBRARY DESTINATION lib")
347 (("add_library.*" m)
348 "\
349 add_library(objlib OBJECT ${faiss_cpu_headers} ${faiss_cpu_cpp})
350 set_property(TARGET objlib PROPERTY POSITION_INDEPENDENT_CODE 1)
351 add_library(${faiss_lib}_static STATIC $<TARGET_OBJECTS:objlib>)
352 add_library(${faiss_lib} SHARED $<TARGET_OBJECTS:objlib>)
353 install(TARGETS ${faiss_lib}_static ARCHIVE DESTINATION lib)
354 \n")))
355
356 ;; See https://github.com/facebookresearch/faiss/issues/520
357 (substitute* "IndexScalarQuantizer.cpp"
358 (("#define USE_AVX") ""))
359
360 ;; Make header files available for compiling tests.
361 (mkdir-p "faiss")
362 (for-each (lambda (file)
363 (mkdir-p (string-append "faiss/" (dirname file)))
364 (copy-file file (string-append "faiss/" file)))
365 (find-files "." "\\.h$"))
366 #t))
367 (replace 'check
368 (lambda _
369 (invoke "make" "-C" "tests"
370 (format #f "-j~a" (parallel-job-count)))))
371 (add-after 'install 'remove-tests
372 (lambda* (#:key outputs #:allow-other-keys)
373 (delete-file-recursively
374 (string-append (assoc-ref outputs "out")
375 "/test"))
376 #t)))))
377 (inputs
378 `(("openblas" ,openblas)))
379 (native-inputs
380 `(("googletest" ,googletest)))
381 (home-page "https://github.com/facebookresearch/faiss")
382 (synopsis "Efficient similarity search and clustering of dense vectors")
383 (description "Faiss is a library for efficient similarity search and
384 clustering of dense vectors. It contains algorithms that search in sets of
385 vectors of any size, up to ones that possibly do not fit in RAM. It also
386 contains supporting code for evaluation and parameter tuning.")
387 (license license:bsd-3)))
388
389 (define-public python-faiss
390 (package (inherit faiss)
391 (name "python-faiss")
392 (build-system python-build-system)
393 (arguments
394 `(#:phases
395 (modify-phases %standard-phases
396 (add-after 'unpack 'chdir
397 (lambda _ (chdir "python") #t))
398 (add-after 'chdir 'build-swig
399 (lambda* (#:key inputs #:allow-other-keys)
400 (with-output-to-file "../makefile.inc"
401 (lambda ()
402 (let ((python-version ,(version-major+minor (package-version python))))
403 (format #t "\
404 PYTHONCFLAGS =-I~a/include/python~am/ -I~a/lib/python~a/site-packages/numpy/core/include
405 LIBS = -lpython~am -lfaiss
406 SHAREDFLAGS = -shared -fopenmp
407 CXXFLAGS = -fpermissive -fopenmp -fPIC
408 CPUFLAGS = ~{~a ~}~%"
409 (assoc-ref inputs "python*") python-version
410 (assoc-ref inputs "python-numpy") python-version
411 python-version
412 (list ,@(let ((system (or (%current-target-system)
413 (%current-system))))
414 (cond
415 ((string-prefix? "x86_64" system)
416 '("-mavx" "-msse2" "-mpopcnt"))
417 ((string-prefix? "i686" system)
418 '("-msse2" "-mpopcnt"))
419 (else
420 '()))))))))
421 (substitute* "Makefile"
422 (("../libfaiss.a") ""))
423 (invoke "make" "cpu"))))))
424 (inputs
425 `(("faiss" ,faiss)
426 ("openblas" ,openblas)
427 ("python*" ,python)
428 ("swig" ,swig)))
429 (propagated-inputs
430 `(("python-matplotlib" ,python-matplotlib)
431 ("python-numpy" ,python-numpy)))
432 (description "Faiss is a library for efficient similarity search and
433 clustering of dense vectors. This package provides Python bindings to the
434 Faiss library.")))
435
436 (define-public python-leidenalg
437 (package
438 (name "python-leidenalg")
439 (version "0.7.0")
440 (source
441 (origin
442 (method url-fetch)
443 (uri (pypi-uri "leidenalg" version))
444 (sha256
445 (base32
446 "15fwld9hdw357rd026mzcwpah5liy4f33vc9x9kwy37g71b2rjf1"))))
447 (build-system python-build-system)
448 (arguments '(#:tests? #f)) ; tests are not included
449 (native-inputs
450 `(("pkg-config" ,pkg-config)))
451 (inputs
452 `(("igraph" ,igraph)))
453 (propagated-inputs
454 `(("python-igraph" ,python-igraph)))
455 (home-page "https://github.com/vtraag/leidenalg")
456 (synopsis "Community detection in large networks")
457 (description
458 "Leiden is a general algorithm for methods of community detection in
459 large networks. This package implements the Leiden algorithm in C++ and
460 exposes it to Python. Besides the relative flexibility of the implementation,
461 it also scales well, and can be run on graphs of millions of nodes (as long as
462 they can fit in memory). The core function is @code{find_partition} which
463 finds the optimal partition using the Leiden algorithm, which is an extension
464 of the Louvain algorithm, for a number of different methods.")
465 (license license:gpl3+)))
466
467 (define-public edge-addition-planarity-suite
468 (package
469 (name "edge-addition-planarity-suite")
470 (version "3.0.0.5")
471 (source
472 (origin
473 (method git-fetch)
474 (uri (git-reference
475 (url (string-append "https://github.com/graph-algorithms/"
476 name))
477 (commit (string-append "Version_" version))))
478 (file-name (git-file-name name version))
479 (sha256
480 (base32
481 "01cm7ay1njkfsdnmnvh5zwc7wg7x189hq1vbfhh9p3ihrbnmqzh8"))))
482 (build-system gnu-build-system)
483 (native-inputs
484 `(("autoconf" ,autoconf)
485 ("automake" ,automake)
486 ("libtool" ,libtool)))
487 (synopsis "Embedding of planar graphs")
488 (description "The package provides a reference implementation of the
489 linear time edge addition algorithm for embedding planar graphs and
490 isolating planarity obstructions.")
491 (license license:bsd-3)
492 (home-page
493 "https://github.com/graph-algorithms/edge-addition-planarity-suite")))
494
495 (define-public rw
496 (package
497 (name "rw")
498 ;; There is a version 0.8, but the tarball is broken with symlinks
499 ;; to /usr/share.
500 (version "0.7")
501 (source (origin
502 (method url-fetch)
503 (uri (string-append "mirror://sourceforge/rankwidth/"
504 "rw-" version ".tar.gz"))
505 (sha256
506 (base32
507 "1rv2v42x2506x7f10349m1wpmmfxrv9l032bkminni2gbip9cjg0"))))
508 (build-system gnu-build-system)
509 (native-inputs
510 `(("pkg-config" ,pkg-config)))
511 (inputs
512 `(("igraph" ,igraph)))
513 (home-page "https://sourceforge.net/projects/rankwidth/")
514 (synopsis "Rank-width and rank-decomposition of graphs")
515 (description "rw computes rank-width and rank-decompositions
516 of graphs.")
517 (license license:gpl2+)))
518
519 (define-public mscgen
520 (package
521 (name "mscgen")
522 (version "0.20")
523 (source
524 (origin
525 (method url-fetch)
526 (uri (string-append "http://www.mcternan.me.uk/mscgen/software/mscgen-src-"
527 version ".tar.gz"))
528 (sha256
529 (base32
530 "08yw3maxhn5fl1lff81gmcrpa4j9aas4mmby1g9w5qcr0np82d1w"))))
531 (build-system gnu-build-system)
532 (native-inputs
533 `(("pkg-config" ,pkg-config)))
534 (inputs
535 `(("gd" ,gd)))
536 (home-page "http://www.mcternan.me.uk/mscgen/")
537 (synopsis "Message Sequence Chart Generator")
538 (description "Mscgen is a small program that parses Message Sequence Chart
539 descriptions and produces PNG, SVG, EPS or server side image maps (ismaps) as
540 the output. Message Sequence Charts (MSCs) are a way of representing entities
541 and interactions over some time period and are often used in combination with
542 SDL. MSCs are popular in Telecoms to specify how protocols operate although
543 MSCs need not be complicated to create or use. Mscgen aims to provide a simple
544 text language that is clear to create, edit and understand, which can also be
545 transformed into common image formats for display or printing.")
546 (license license:gpl2+)))