Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to store params #43

Merged
merged 7 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Added
- Functional testing framework with concrete tests for `methods.set_env()`
- Functional test for `bam_parser.parse_bam_header()`.
- Dump parameters with `json_extractor.store_params_json()`

---

Expand Down
24 changes: 24 additions & 0 deletions config/store_object_as_json/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Storage of map-like objects into JSON

This module takes an arbritrary map-like object and a `File`, and converts the object into JSON and saves it into
the path-specified by `File`.

## Example

Shown is an example to store the `params` object into as a JSON file into the log folder.

Example:
```Nextflow
includeConfig "/path/to/store_object_as_json.config"
...
methods {
...
setup = {
...
json_extractor.store_object_as_json(
params, // object to be stored
new File("${params.log_output_dir}/params.json")
)
}
}
```
12 changes: 12 additions & 0 deletions config/store_object_as_json/store_object_as_json.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import groovy.json.JsonOutput

json_extractor {
store_object_as_json = { Map object, File destination ->
json_object = JsonOutput.prettyPrint(JsonOutput.toJson(object))
File parent = destination.getParentFile()
if (!parent.exists()) {
parent.mkdirs()
}
destination.write(json_object)
}
}
Loading