@platforma-open/milaboratories.mixcr-shm-trees.workflow 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,78 @@
1
+ ll := import("@platforma-sdk/workflow-tengo:ll")
2
+ smart := import("@platforma-sdk/workflow-tengo:smart")
3
+
4
+ json := import("json")
5
+
6
+ _P_COLUMN_DATA_RESOURCE_MAP := { Name: "PColumnData/ResourceMap", Version: "1" }
7
+
8
+ groupDataByDonorId := func(donorColumn, datasets) {
9
+ // we need to form a pColumn with two axes:
10
+ // axes[0]: donorId
11
+ // axes[1]: sampleId
12
+ // axes[2]: mixcrBlockId
13
+ // value: fileRef resource
14
+
15
+ // we have:
16
+ // column of donorIds:
17
+ // axes[0]: sampleId
18
+ // value: donorId
19
+ // several columns of clns:
20
+ // axes[0]: sampleId
21
+ // value: fileRef resource
22
+
23
+ donorColumnSpec := donorColumn.get("spec").getDataAsJson()
24
+
25
+ resultSpec := {
26
+ // annotations and domain could differ between datasets
27
+ "axesSpec": [
28
+ {
29
+ "annotations": donorColumnSpec["annotations"],
30
+ "domain": donorColumnSpec["domain"],
31
+ "name": donorColumnSpec["name"],
32
+ "type": donorColumnSpec["valueType"]
33
+ },
34
+ donorColumnSpec["axesSpec"][0],
35
+ {
36
+ "annotations": {
37
+ "pl7.app/label": "Clonotyping block id"
38
+ },
39
+ "name": "pl7.app/blockId",
40
+ "type": "String"
41
+ }
42
+ ],
43
+ "kind": "PColumn",
44
+ "name": "mixcr.com/clns",
45
+ "valueType": "File"
46
+ }
47
+
48
+
49
+ sampleToDonor := {}
50
+
51
+ // columns with meta could be fetched as data direcctly
52
+ for k, v in donorColumn.get("data").getDataAsJson()["data"] {
53
+ sampleId := json.decode(k)[0]
54
+ sampleToDonor[sampleId] = v
55
+ }
56
+
57
+ // build pColumn by hand
58
+ dataBuilder := smart.structBuilder(_P_COLUMN_DATA_RESOURCE_MAP, json.encode({ keyLength: 3 }))
59
+
60
+ // collect all the clns files that we have into pColumn
61
+ for blockId, dataset in datasets {
62
+ for sKey, fileRef in dataset.get("data").inputs() {
63
+ sampleId := json.decode(sKey)[0]
64
+ donor := sampleToDonor[sampleId]
65
+ dataBuilder.createInputField(json.encode([donor, sampleId, blockId])).set(fileRef)
66
+ }
67
+ }
68
+
69
+ return {
70
+ spec: resultSpec,
71
+ data: dataBuilder.lockAndBuild()
72
+ }
73
+ }
74
+
75
+ // to use the file as a library, we should explicitly export functions
76
+ export ll.toStrict({
77
+ groupDataByDonorId: groupDataByDonorId
78
+ })
Binary file
Binary file
package/format.el ADDED
@@ -0,0 +1,43 @@
1
+ ;; This program formats all files inside src directory. Usage: emacs --script ./format.el
2
+
3
+ (defun install-go-mode ()
4
+ "Installs go-mode"
5
+ (require 'package)
6
+ (add-to-list 'package-archives
7
+ '("melpa-stable" . "https://stable.melpa.org/packages/"))
8
+ (package-initialize)
9
+ (unless package-archive-contents
10
+ (package-refresh-contents))
11
+
12
+ (package-install 'go-mode t)
13
+ (require 'go-mode))
14
+
15
+ ;; spaces -> tabs only at the beginning of lines
16
+ (setq tabify-regexp "^\t* [ \t]+")
17
+
18
+ (defun format-file (file)
19
+ "Formats a file according to slightly changed Go rules"
20
+ (message "Format %s" file)
21
+ (save-excursion
22
+ (find-file file)
23
+ (delete-trailing-whitespace) ;; deletes whitespaces
24
+ (go-mode) ;; sets golang rules for indentation
25
+ (tabify (point-min) (point-max)) ;; spaces -> tabs in the whole file
26
+ (indent-region (point-min) (point-max)) ;; indentation in the whole file
27
+ (save-buffer))) ;; save file
28
+
29
+ (install-go-mode)
30
+
31
+ ;; change syntax of a standard go-mode a bit
32
+ (advice-add
33
+ 'go--in-composite-literal-p
34
+ :filter-return
35
+ (lambda (&rest r) t))
36
+
37
+ ;; find all files in src
38
+ (setq files (directory-files-recursively "src" "\\.tengo\\'"))
39
+
40
+ ;; call format on every file.
41
+ (dolist (file files)
42
+ (format-file file))
43
+
package/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ declare type TemplateFromFile = { readonly type: "from-file"; readonly path: string; };
2
+ declare type TplName = "reconstruct-shm-trees" | "process" | "main";
3
+ declare const Templates: Record<TplName, TemplateFromFile>;
4
+ export { Templates };
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+ module.exports = { Templates: {
2
+ 'reconstruct-shm-trees': { type: 'from-file', path: require.resolve('./dist/tengo/tpl/reconstruct-shm-trees.plj.gz') },
3
+ 'process': { type: 'from-file', path: require.resolve('./dist/tengo/tpl/process.plj.gz') },
4
+ 'main': { type: 'from-file', path: require.resolve('./dist/tengo/tpl/main.plj.gz') }
5
+ }}
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@platforma-open/milaboratories.mixcr-shm-trees.workflow",
3
+ "version": "2.0.0",
4
+ "type": "module",
5
+ "description": "Tengo-based template",
6
+ "//": {
7
+ "build": "node ./scripts/build-static.mjs src/pfconv_params.json src/pfconv_params.lib.tengo && rm -rf dist && pl-tengo check && pl-tengo build && ./create_tags.sh"
8
+ },
9
+ "devDependencies": {
10
+ "@platforma-sdk/tengo-builder": "^1.15.0",
11
+ "@platforma-sdk/workflow-tengo": "^1.6.3",
12
+ "@milaboratories/software-pframes-conv": "^1.6.3",
13
+ "@platforma-open/milaboratories.software-small-binaries": "^1.14.4",
14
+ "@platforma-open/milaboratories.software-mixcr": "4.7.0-113-develop",
15
+ "@platforma-sdk/test": "^1.7.16",
16
+ "vitest": "^2.1.3",
17
+ "typescript": "~5.5.4"
18
+ },
19
+ "scripts": {
20
+ "build": "rm -rf dist && pl-tengo check && pl-tengo build",
21
+ "format": "/usr/bin/env emacs --script ./format.el"
22
+ }
23
+ }