aboutsummaryrefslogtreecommitdiff
path: root/gnu/build/dbus-service.scm
blob: c5671396e2f7ec43e46c093ab5451414c44eb372 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2021, 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix 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.
;;;
;;; GNU Guix 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 GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:
;;;
;;; This module contains procedures to interact with D-Bus via the 'dbus-send'
;;; command line utility.  Before using any public procedure
;;;
;;; Code:

(define-module (gnu build dbus-service)
  #:use-module (ice-9 match)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-19)
  #:use-module (srfi srfi-26)
  #:autoload (d-bus protocol connections) (d-bus-conn?
                                           d-bus-conn-flush
                                           d-bus-connect
                                           d-bus-disconnect
                                           d-bus-session-bus-address
                                           d-bus-system-bus-address)
  #:autoload (d-bus protocol messages) (MESSAGE_TYPE_METHOD_CALL
                                        d-bus-headers-ref
                                        d-bus-message-body
                                        d-bus-message-headers
                                        d-bus-read-message
                                        d-bus-write-message
                                        header-PATH
                                        header-DESTINATION
                                        header-INTERFACE
                                        header-MEMBER
                                        header-SIGNATURE
                                        make-d-bus-message)
  #:export (%dbus-query-timeout

            initialize-dbus-connection!
            %current-dbus-connection
            send-dbus
            call-dbus-method

            dbus-available-services
            dbus-service-available?

            with-retries))

(define %dbus-query-timeout 2)          ;in seconds

;;; Use Fibers' sleep to enable cooperative scheduling in Shepherd >= 0.9.0,
;;; which is required at least for the Jami service.
(define sleep*
  (lambda ()                            ;delay execution
    (if (resolve-module '(fibers) #f)
        (module-ref (resolve-interface '(fibers)) 'sleep)
        (begin
          (format #f "fibers not available -- blocking 'sleep' in use")
          sleep))))

;;;
;;; Utilities.
;;;

(define-syntax-rule (with-retries n delay body ...)
  "Retry the code in BODY up to N times until it doesn't raise an exception nor
return #f, else raise an error.  A delay of DELAY seconds is inserted before
each retry."
  (let loop ((attempts 0))
    (catch #t
      (lambda ()
        (let ((result (begin body ...)))
          (if (not result)
              (error "failed attempt" attempts)
              result)))
      (lambda args
        (if (< attempts n)
            (begin
              ((sleep*) delay)            ;else wait and retry
              (loop (+ 1 attempts)))
            (error "maximum number of retry attempts reached"
                   body ... args))))))


;;;
;;; Low level wrappers above AC/D-Bus.
;;;

;; The active D-Bus connection (a parameter) used by the other procedures.
(define %current-dbus-connection (make-parameter #f))

(define* (initialize-dbus-connection!
          #:key (address (or (d-bus-session-bus-address)
                             (d-bus-system-bus-address))))
  "Initialize the D-Bus connection.  ADDRESS should be the address of the D-Bus
session, e.g. \"unix:path=/var/run/dbus/system_bus_socket\", the default value
if ADDRESS is not provided and DBUS_SESSION_BUS_ADDRESS is not set.  Return
the initialized D-Bus connection."
  ;; Clear current correction if already active.
  (when (d-bus-conn? (%current-dbus-connection))
    (d-bus-disconnect (%current-dbus-connection)))

  (let ((connection (d-bus-connect address)))
    (%current-dbus-connection connection) ;update connection parameter
    (call-dbus-method "Hello"))           ;initial handshake

  (%current-dbus-connection))

(define* (send-dbus message #:key
                    (connection (%current-dbus-connection))
                    timeout)
  "Send a D-Bus MESSAGE to CONNECTION and return the body of its reply.  Up to
READ-RETRIES replies are read until a matching reply is found, else an error
is raised.  MESSAGE is to be constructed with `make-d-bus-message'.  When the
body contains a single element, it is returned directly, else the body
elements are returned as a list.  TIMEOUT is a timeout value in seconds."
  (let ((serial     (d-bus-write-message connection message))
        (start-time (current-time time-monotonic))
        (timeout* (or timeout %dbus-query-timeout)))
    (d-bus-conn-flush connection)
    (let retry ()
      (when (> (time-second (time-difference (current-time time-monotonic)
                                             start-time))
               timeout*)
        (error 'dbus "fail to get reply in timeout" timeout*))
      (let* ((reply (d-bus-read-message connection))
             (reply-headers (d-bus-message-headers reply))
             (reply-serial (d-bus-headers-ref reply-headers 'REPLY_SERIAL))
             (error-name (d-bus-headers-ref reply-headers 'ERROR_NAME))
             (body (d-bus-message-body reply)))
        ;; Validate the reply matches the message.
        (when error-name
          (error 'dbus "method failed with error" error-name body))
        ;; Some replies do not include a serial header, such as the for the
        ;; org.freedesktop.DBus NameAcquired one.
        (if (and reply-serial (= serial reply-serial))
            (match body
              ((x x* ..1)               ;contains 2 ore more elements
               body)
              ((x)
               x)                       ;single element; return it directly
              (#f #f))
            (retry))))))

(define (argument->signature-type argument)
  "Infer the D-Bus signature type from ARGUMENT."
  ;; XXX: avoid ..1 when using vectors due to a bug (?) in (ice-9 match).
  (match argument
    ((? boolean?) "b")
    ((? string?) "s")
    (#((? string?) (? string?) ...) "as")
    (#(((? string?) . (? string?))
       ((? string?) . (? string?)) ...) "a{ss}")
    (_ (error 'dbus "no rule to infer type from argument" argument))))

(define* (call-dbus-method method
                           #:key
                           (path "/org/freedesktop/DBus")
                           (destination "org.freedesktop.DBus")
                           (interface "org.freedesktop.DBus")
                           (connection (%current-dbus-connection))
                           arguments
                           timeout)
  "Call the D-Bus method specified by METHOD, PATH, DESTINATION and INTERFACE.
The currently active D-Bus CONNECTION is used unless explicitly provided.
Method arguments may be provided via ARGUMENTS sent as the message body.
TIMEOUT limit the maximum time to allow for the reply.  Return the body of the
reply."
  (let ((message (make-d-bus-message
                  MESSAGE_TYPE_METHOD_CALL 0 #f '()
                  `#(,(header-PATH        path)
                     ,(header-DESTINATION destination)
                     ,(header-INTERFACE   interface)
                     ,(header-MEMBER      method)
                     ,@(if arguments
                           (list (header-SIGNATURE
                                  (string-join
                                   (map argument->signature-type arguments)
                                   "")))
                           '()))
                  arguments)))
    (send-dbus message #:connection connection #:timeout timeout)))


;;;
;;; Higher-level, D-Bus procedures.
;;;

(define (dbus-available-services)
  "Return the list of available (acquired) D-Bus services."
  (let ((names (vector->list (call-dbus-method "ListNames"))))
    ;; Remove entries such as ":1.7".
    (remove (cut string-prefix? ":" <>) names)))

(define (dbus-service-available? service)
  "Predicate to check for the D-Bus SERVICE availability."
  (member service (dbus-available-services)))

;; Local Variables:
;; eval: (put 'with-retries 'scheme-indent-function 2)
;; End:
age) as well as @code{SPREAD}.")
+ (license license:gpl3)))
+
(define-public imp
(package
(name "imp")
@@ -9895,7 +10017,7 @@ The following file formats are supported:
(inputs
`(("boost" ,boost)
("bzip2" ,bzip2)
- ("cereal" ,cereal)
+ ("cereal" ,cereal-1.3.0)
("curl" ,curl)
("eigen" ,eigen)
("jemalloc" ,jemalloc)
@@ -11262,7 +11384,7 @@ Thus the per-base error rate is similar to the raw input reads.")
(install-file "Bandage" (string-append out "/bin"))
#t))))))
(inputs
- (list qtbase-5 qtsvg))
+ (list qtbase-5 qtsvg-5))
(native-inputs
(list imagemagick))
(home-page "https://rrwick.github.io/Bandage/")
@@ -11413,6 +11535,123 @@ including:
dynamic cellular processes at single-cell resolution.")
(license license:expat))))
+;; Needed for r-liana
+(define-public r-omnipathr/devel
+ (let ((commit "679bb79e319af246a16968d27d64d8d6937a331a")
+ (revision "1"))
+ (package
+ (name "r-omnipathr")
+ (version (git-version "3.5.5" revision commit))
+ (source (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/saezlab/omnipathr")
+ (commit commit)))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32
+ "10h6lyapyx4ik8r4kx5z2dly46jlf2v57caq4g6i0hzifyz2vgjq"))))
+ (properties `((upstream-name . "OmnipathR")))
+ (build-system r-build-system)
+ (arguments
+ `(#:phases
+ (modify-phases %standard-phases
+ (add-after 'unpack 'set-HOME
+ (lambda _ (setenv "HOME" "/tmp"))))))
+ (propagated-inputs
+ (list r-checkmate
+ r-crayon
+ r-curl
+ r-digest
+ r-dplyr
+ r-httr
+ r-igraph
+ r-jsonlite
+ r-later
+ r-logger
+ r-magrittr
+ r-progress
+ r-purrr
+ r-rappdirs
+ r-readr
+ r-readxl
+ r-rlang
+ r-rvest
+ r-stringr
+ r-tibble
+ r-tidyr
+ r-tidyselect
+ r-withr
+ r-xml2
+ r-yaml))
+ (native-inputs (list r-knitr))
+ (home-page "https://github.com/saezlab/omnipathr")
+ (synopsis "OmniPath web service client and more")
+ (description
+ "This package provides a client for the OmniPath web service and many
+other resources. It also includes functions to transform and pretty print
+some of the downloaded data, functions to access a number of other resources
+such as BioPlex, ConsensusPathDB, EVEX, Gene Ontology, Guide to
+Pharmacology (IUPHAR/BPS), Harmonizome, HTRIdb, Human Phenotype Ontology,
+InWeb InBioMap, KEGG Pathway, Pathway Commons, Ramilowski et al. 2015,
+RegNetwork, ReMap, TF census, TRRUST and Vinayagam et al. 2011. Furthermore,
+OmnipathR features a close integration with the NicheNet method for ligand
+activity prediction from transcriptomics data, and its R implementation
+@code{nichenetr}.")
+ (license license:expat))))
+
+(define-public r-liana
+ (let ((commit "efb1249af46f576d1d620956053cfa93b2cee961")
+ (revision "1"))
+ (package
+ (name "r-liana")
+ (version (git-version "0.1.5" revision commit))
+ (source (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/saezlab/liana/")
+ (commit commit)))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32
+ "0z645k26kqrfj5f1s412vwclw1q47h1zfxxrh9ijr30pxhpv6cv0"))))
+ (properties `((upstream-name . "liana")))
+ (build-system r-build-system)
+ (arguments
+ (list
+ #:phases
+ `(modify-phases %standard-phases
+ ;; This is needed to find ~/.config/OmnipathR/omnipathr.yml
+ (add-after 'unpack 'set-HOME
+ (lambda _ (setenv "HOME" "/tmp"))))))
+ (propagated-inputs
+ (list r-complexheatmap
+ r-dplyr
+ r-ggplot2
+ r-magrittr
+ r-omnipathr/devel
+ r-purrr
+ r-rcolorbrewer
+ r-readr
+ r-reticulate
+ r-rlang
+ r-scater
+ r-scran
+ r-scuttle
+ r-seuratobject
+ r-singlecellexperiment
+ r-stringr
+ r-tibble
+ r-tidyr
+ r-tidyselect))
+ (native-inputs (list r-knitr))
+ (home-page "https://github.com/saezlab/liana/")
+ (synopsis "LIANA: a LIgand-receptor ANalysis frAmework")
+ (description
+ "LIANA provides a number of methods and resource for ligand-receptor
+interaction inference from scRNA-seq data.")
+ (license license:gpl3))))
+
(define-public r-circus
(package
(name "r-circus")
@@ -11842,19 +12081,23 @@ million cells.")
(define-public python-bbknn
(package
(name "python-bbknn")
- (version "1.3.6")
+ (version "1.5.1")
(source
(origin
(method url-fetch)
(uri (pypi-uri "bbknn" version))
(sha256
(base32
- "1jbsh01f57zj4bhvjr3jh4532zznqd6nccmgrl3qi9gnhkf7c4y0"))))
+ "0q11xdmjr2kf6f179a6kjizj3lllfrq743gslgw67qyzimvrrnhn"))))
(build-system python-build-system)
(arguments
`(#:tests? #f ; no tests are included
#:phases
(modify-phases %standard-phases
+ ;; Numba needs a writable dir to cache functions.
+ (add-before 'check 'set-numba-cache-dir
+ (lambda _
+ (setenv "NUMBA_CACHE_DIR" "/tmp")))
(add-after 'unpack 'do-not-fail-to-find-sklearn
(lambda _
;; XXX: I have no idea why it cannot seem to find sklearn.
@@ -11864,6 +12107,7 @@ million cells.")
(list python-annoy
python-cython
python-numpy
+ python-pandas
python-scikit-learn
python-scipy
python-umap-learn))
@@ -12060,14 +12304,14 @@ allowing the insertion of arbitrary types into the tree.")
(define-public python-intervaltree
(package
(name "python-intervaltree")
- (version "3.0.2")
+ (version "3.1.0")
(source
(origin
(method url-fetch)
(uri (pypi-uri "intervaltree" version))
(sha256
(base32
- "0wz234g6irlm4hivs2qzmnywk0ss06ckagwh15nflkyb3p462kyb"))))
+ "0bcm6c6r4ck9nfj9xwz4rm2swc5lrjvmw3lyl6rgj639jf41nawh"))))
(build-system python-build-system)
(arguments
`(#:phases
@@ -12433,6 +12677,35 @@ cooler). Both @code{hic} and @code{cool} files describe Hi-C contact
matrices.")
(license license:expat)))
+(define-public python-scanorama
+ (package
+ (name "python-scanorama")
+ (version "1.7.2")
+ (source (origin
+ (method url-fetch)
+ (uri (pypi-uri "scanorama" version))
+ (sha256
+ (base32
+ "0il7bf4c7vli2dm2jx7dskh3ymgv8nmk0y90jzgfrnqjzh250x5w"))))
+ (build-system python-build-system)
+ (propagated-inputs
+ (list python-annoy
+ python-fbpca
+ python-geosketch
+ python-intervaltree
+ python-matplotlib
+ python-numpy
+ python-scikit-learn
+ python-scipy))
+ (home-page "https://github.com/brianhie/scanorama")
+ (synopsis "Panoramic stitching of heterogeneous single cell transcriptomic data")
+ (description
+ "Scanorama enables batch-correction and integration of heterogeneous
+scRNA-seq datasets, which is described in the paper \"Efficient integration of
+heterogeneous single-cell transcriptomes using Scanorama\" by Brian Hie, Bryan
+Bryson, and Bonnie Berger.")
+ (license license:expat)))
+
(define-public r-pore
(package
(name "r-pore")