aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMunyoki Kilyungi2024-02-08 17:13:27 +0300
committerMunyoki Kilyungi2024-02-08 17:13:27 +0300
commit6c686e0631823d747ce59de4bcd29513f9b30295 (patch)
tree7ee501390580fbaafbc6e806a3786d7c67c45f98 /examples
parent6f8321b34311ea2d17d75d53bbd46ea1d88699f0 (diff)
downloadgn-transform-databases-6c686e0631823d747ce59de4bcd29513f9b30295.tar.gz
Add a basic guile script to transform stored rtf data to files.
Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/dataset-metadata-git.scm76
1 files changed, 76 insertions, 0 deletions
diff --git a/examples/dataset-metadata-git.scm b/examples/dataset-metadata-git.scm
new file mode 100755
index 0000000..f2bde48
--- /dev/null
+++ b/examples/dataset-metadata-git.scm
@@ -0,0 +1,76 @@
+#! /usr/bin/env guile
+
+!#
+(use-modules
+ (ice-9 getopt-long)
+ (srfi srfi-26)
+ ((ice-9 regex) #:select (regexp-substitute/global))
+ ((transform strings) #:select (string-blank?))
+ ((transform sql) #:select (call-with-target-database sql-for-each))
+ ((transform triples) #:select (string->identifier)))
+
+(define (save-file file result)
+ (when result
+ (let ((dir-name (dirname file)))
+ (unless (file-exists? dir-name)
+ (mkdir dir-name))
+ (with-output-to-file file
+ (lambda ()
+ (format #t result))))))
+
+(define (infopages/sql->rtf result)
+ (let* ((get (cut assoc-ref result <>))
+ (get* (compose (lambda (str)
+ (if (string-blank? str)
+ #f
+ str))
+ get))
+ (identifier (string->identifier
+ ""
+ (regexp-substitute/global #f "[^A-Za-z0-9:]"
+ (get "InfoPageName")
+ 'pre "_" 'post)))
+ (dir-name (string-append "/export/data/genenetwork/data/"))
+ (file-name (cut string-append dir-name <>))
+ (summary (get* "Summary"))
+ (tissue (get* "AboutTissue"))
+ (specifics (get* "Specifics"))
+ (cases (get* "AboutCases"))
+ (platform (get* "AboutPlatform"))
+ (processing (get* "AboutDataProcessing"))
+ (notes (get* "Notes"))
+ (experiment-design (get* "ExperimentDesign"))
+ (acknowledgment (get* "Acknowledgment")))
+ (for-each (lambda (x)
+ (save-file (file-name (string-append dir-name (car x)))
+ (cdr x)))
+ `(("summary.rtf" . ,summary)
+ ("tissue.rtf" . ,tissue)
+ ("specifics.rtf" . ,specifics)
+ ("cases.rtf" . ,cases)
+ ("platform.rtf" . ,platform)
+ ("processing.rtf" . ,processing)
+ ("notes.rtf" . ,notes)
+ ("experiment-design.rtf" . ,experiment-design)
+ ("acknowledgement.rtf" . ,acknowledgement)))))
+
+(let* ((option-spec
+ '((settings (single-char #\s) (value #t))
+ (output (single-char #\o) (value #t))))
+ (options (getopt-long (command-line) option-spec))
+ (settings (option-ref options 'settings #f))
+ (output (option-ref options 'output #f))
+ (query "SELECT InfoPageName, Datasets.Summary, Datasets.AboutTissue, InfoFiles.Specifics,
+Datasets.AboutCases, Datasets.AboutPlatform, Datasets.AboutDataProcessing,
+Datasets.Notes, Datasets.ExperimentDesign, Datasets.Acknowledgment
+FROM InfoFiles LEFT JOIN Datasets USING (DatasetId) LIMIT 2")
+ (%connection-settings
+ (call-with-input-file settings
+ read)))
+ ;; TODO
+ (call-with-target-database
+ %connection-settings
+ (lambda (db)
+ (sql-for-each infopages/sql->rtf
+ db
+ query))))