rs: Add section "Org-mode interaction".
This commit is contained in:
parent
a77261c424
commit
f16747d157
1 changed files with 33 additions and 1 deletions
34
rs.rkt
34
rs.rkt
|
@ -4,13 +4,16 @@
|
||||||
|
|
||||||
;;; Definitions for working with reaction systems.
|
;;; Definitions for working with reaction systems.
|
||||||
|
|
||||||
|
(require/typed "utils.rkt"
|
||||||
|
[string->any (String -> Any)])
|
||||||
|
|
||||||
(provide
|
(provide
|
||||||
;; Structures
|
;; Structures
|
||||||
reaction
|
reaction
|
||||||
;; Type names
|
;; Type names
|
||||||
Species ReactionSystem
|
Species ReactionSystem
|
||||||
;; Functions
|
;; Functions
|
||||||
enabled? list-enabled union-products apply-rs)
|
enabled? list-enabled union-products apply-rs ht-str-triples->rs)
|
||||||
|
|
||||||
;;; =================
|
;;; =================
|
||||||
;;; Basic definitions
|
;;; Basic definitions
|
||||||
|
@ -62,3 +65,32 @@
|
||||||
(define (apply-rs rs s)
|
(define (apply-rs rs s)
|
||||||
(let ([as (list-enabled rs s)])
|
(let ([as (list-enabled rs s)])
|
||||||
(union-products rs as)))
|
(union-products rs as)))
|
||||||
|
|
||||||
|
|
||||||
|
;;; ====================
|
||||||
|
;;; Org-mode interaction
|
||||||
|
;;; ====================
|
||||||
|
|
||||||
|
;;; This section contains some useful primitives for interoperating
|
||||||
|
;;; with org-mode.
|
||||||
|
|
||||||
|
;;; Reads a list of species from a string.
|
||||||
|
(: read-symbol-list (-> String (Listof Species)))
|
||||||
|
(define (read-symbol-list str)
|
||||||
|
(cast (string->any (string-append "(" str ")")) (Listof Species)))
|
||||||
|
|
||||||
|
;;; Converts a triple of strings to a reaction.
|
||||||
|
(: str-triple->reaction (-> (List String String String) reaction))
|
||||||
|
(define/match (str-triple->reaction lst)
|
||||||
|
[((list str-reactants str-inhibitors str-products))
|
||||||
|
(reaction (list->set (read-symbol-list str-reactants))
|
||||||
|
(list->set (read-symbol-list str-inhibitors))
|
||||||
|
(list->set (read-symbol-list str-products)))])
|
||||||
|
|
||||||
|
;;; Converts a hash table mapping reaction names to triples of strings
|
||||||
|
;;; to a reaction system.
|
||||||
|
(: ht-str-triples->rs (-> (HashTable Symbol (List String String String)) ReactionSystem))
|
||||||
|
(define (ht-str-triples->rs ht)
|
||||||
|
(for/hash : ReactionSystem
|
||||||
|
([(a triple) (in-hash ht)])
|
||||||
|
(values a (str-triple->reaction triple))))
|
||||||
|
|
Loading…
Reference in a new issue