-
Notifications
You must be signed in to change notification settings - Fork 2
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
Read/write nested data as flattened parameter name to and from toml file #48
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d57754f
Add expandable types to kitchensink catalog
sverhoeven 44670ec
Use tomlSchema when writing toml
sverhoeven 380398c
Document tomlSchema
sverhoeven 0b9a0a4
English
sverhoeven 7404f94
More tests and better workflow2tomltext()
sverhoeven 1a5eeb8
Use 2 spaces for indentation inside toml
sverhoeven 387dab6
Remove no-tabs rule skip as toml is now written with 2 spaces instead…
sverhoeven 22db0f2
Implement toml2parameters
sverhoeven 3378f83
Remove no-tabs rule skip as toml is now written with 2 spaces instead…
sverhoeven 34fbe9a
English
sverhoeven a80c641
Formatting
sverhoeven 07884fd
Merge branch 'read-expandable2toml' into write-expandable2toml
sverhoeven effed48
Add topoaa.mol usecase to kitchensink catalog
sverhoeven File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,347 @@ | ||
# tomlSchema | ||
|
||
Any array or object value can be written in different ways to a toml file. | ||
Use the toml schema in the catalog to overwrite the default behaviour. | ||
|
||
The default behavior is to write the value as a nested structure like | ||
|
||
In memory have parameter object like | ||
|
||
```js | ||
{ | ||
key1: [ 1, 2 ], // Array of scalar | ||
key2: [ "a", "b" ], // Array of scalar | ||
key3: { a: 1, b: 2}, // Object | ||
key4: { a: [ 1, 2 ]}, // Object with array of scalar | ||
key5: [ { a: 1 }, { a: 2 }], // Array with objects | ||
key6: [ { a: [ 1, 2 ]} ], // Array with oboject with array of scalar | ||
key7: [ [ 1, 2], [ 3 ,4 ] ], // Array of array of scalar | ||
key8: [ [ { a: 1 }, { a: 2 }], [ { a: 3 } ,{ a: 4 } ] ], // Array of array of object | ||
} | ||
``` | ||
|
||
The parameter object JSON shema is defined in the catalog. | ||
|
||
The resulting toml would look like | ||
|
||
```toml | ||
key1 = [ 1, 2 ] | ||
key2 = [ "a", "b" ] | ||
key3.a = 1 | ||
key3.b = 2 | ||
key4.a = [ 1, 2 ] | ||
key5 = [ { a = 1 }, { a = 2 }] | ||
key6 = [ { a = [ 1, 2 ]} ] | ||
key7 = [ [ 1, 2], [ 3 ,4 ] ] | ||
key8 = [ [ { a = 1 }, { a = 2 }], [ { a = 3 } ,{ a = 4 } ] ] | ||
``` | ||
|
||
The tomlSchema object follows the tree structure of the schema hierarchy. | ||
|
||
Special keywords in tomlSchema: | ||
|
||
1. **indexed**, when true will have array index appended to key | ||
2. **flatten**, when true will have object property names appended to key | ||
3. **sectioned**, when true will write children inside own table (for example `[<module>.<key>]`) | ||
4. **items**, to nest a toml schema for an array item | ||
5. **properties**, to nest a toml schema for an object property | ||
|
||
Below are examples of supported toml schema snippets. | ||
|
||
## Array of scalars | ||
|
||
In toml | ||
|
||
```toml | ||
param_1 = 11 | ||
param_2 = 22 | ||
param_3 = 33 | ||
``` | ||
|
||
In catalog | ||
|
||
```yaml | ||
schema: | ||
type: object | ||
properties: | ||
param: | ||
type: array | ||
items: | ||
type: number | ||
tomlSchema: | ||
param: | ||
indexed: true | ||
``` | ||
|
||
In memory | ||
|
||
```json | ||
{ | ||
"param": [11, 22, 33] | ||
} | ||
``` | ||
|
||
## Array of objects flattened | ||
|
||
In toml | ||
|
||
```toml | ||
name_something_1 = 11 | ||
name_else_1 = 22 | ||
name_something_2 = 33 | ||
name_else_2 = 44 | ||
``` | ||
|
||
In catalog | ||
|
||
```yaml | ||
schema: | ||
type: object | ||
properties: | ||
name: | ||
type: array | ||
items: | ||
type: object | ||
properties: | ||
something: | ||
type: number | ||
else: | ||
type: number | ||
tomlSchema: | ||
name: | ||
indexed: true | ||
items: | ||
flatten: true | ||
``` | ||
|
||
In memory | ||
|
||
```json | ||
{ | ||
"name": [{ | ||
"something": 11, | ||
"else": 22, | ||
}, { | ||
"something": 33, | ||
"else": 44, | ||
}] | ||
} | ||
``` | ||
|
||
## Array of objects sectioned | ||
|
||
In toml | ||
|
||
```toml | ||
[[name]] | ||
something = 11 | ||
else = 22 | ||
|
||
[[name]] | ||
something = 33 | ||
else = 44 | ||
Peter9192 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
In catalog | ||
|
||
```yaml | ||
schema: | ||
type: object | ||
properties: | ||
name: | ||
type: array | ||
items: | ||
type: object | ||
properties: | ||
something: | ||
type: number | ||
else: | ||
type: number | ||
tomlSchema: | ||
name: | ||
items: | ||
sectioned: true | ||
``` | ||
|
||
In memory | ||
|
||
```json | ||
{ | ||
"name": [{ | ||
"something": 11, | ||
"else": 22, | ||
}, { | ||
"something": 33, | ||
"else": 44, | ||
}] | ||
} | ||
``` | ||
|
||
## Array of array of objects | ||
|
||
In toml | ||
|
||
```toml | ||
fle_sta_1_1 = 11 | ||
fle_end_1_1 = 22 | ||
fle_sta_1_2 = 33 | ||
fle_end_1_2 = 44 | ||
fle_sta_2_1 = 55 | ||
fle_end_2_1 = 66 | ||
``` | ||
|
||
In catalog | ||
|
||
```yaml | ||
schema: | ||
type: object | ||
additionalProperties: false | ||
properties: | ||
fle: | ||
type: array | ||
description: Outer array is molecule index | ||
items: | ||
type: array | ||
description: Inner array is segment index | ||
items: | ||
type: object | ||
properties: | ||
sta: | ||
title: Starting residue number | ||
type: number | ||
end: | ||
title: End residue number | ||
type: number | ||
additionalProperties: false | ||
tomlSchema: | ||
fle: | ||
indexed: true | ||
items: | ||
indexed: true | ||
items: | ||
flatten: true | ||
``` | ||
|
||
In memory | ||
|
||
```json | ||
{ | ||
"fle": [ | ||
[ | ||
{ | ||
"sta": 11, | ||
"end": 22 | ||
}, | ||
{ | ||
"sta": 33, | ||
"end": 44 | ||
} | ||
], | ||
[ | ||
{ | ||
"sta": 55, | ||
"end": 66 | ||
} | ||
] | ||
] | ||
} | ||
``` | ||
|
||
## Array of objects with object as toml table and scalar as array prop | ||
|
||
In toml | ||
|
||
```toml | ||
[topoaa.mol_1] | ||
cyclicpept = false | ||
hisd_1 = 13 | ||
hisd_2 = 42 | ||
|
||
[topoaa.mol_2] | ||
cyclicpept = true | ||
hisd_1 = 314 | ||
hisd_2 = 512 | ||
``` | ||
|
||
In catalog | ||
|
||
```yaml | ||
schema: | ||
type: object | ||
properties: | ||
mol: | ||
type: array | ||
items: | ||
type: object | ||
properties: | ||
cyclicpept: | ||
type: boolean | ||
hisd: | ||
type: array | ||
items: | ||
type: number | ||
tomlSchema: | ||
mol: | ||
indexed: true | ||
items: | ||
sectioned: true | ||
properties: | ||
hisd: | ||
indexed: true | ||
``` | ||
|
||
In memory | ||
|
||
```json | ||
{ | ||
"mol": [{ | ||
"cyclicpept": false, | ||
"hisd": [13, 42] | ||
}, { | ||
"cyclicpept": true, | ||
"hisd": [314, 512] | ||
}] | ||
} | ||
``` | ||
|
||
## Node parameter where value is an object as section | ||
|
||
In toml | ||
|
||
```toml | ||
[somenode] | ||
|
||
[somenode.foo] | ||
bar.bla = 'hi' | ||
``` | ||
|
||
In catalog | ||
|
||
```yaml | ||
schema: | ||
type: object | ||
properties: | ||
foo: | ||
type: object | ||
properties: | ||
bar: | ||
type: object | ||
properties: | ||
bla: | ||
type: string | ||
tomlSchema: | ||
foo: | ||
sectioned: true | ||
``` | ||
|
||
In memory parameters for node called `somenode`. | ||
|
||
```json | ||
{ | ||
"foo": { | ||
"bar": { | ||
"bla": "hi" | ||
} | ||
} | ||
} | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
11, 22, and 33 are just example numbers, but due to their structure and correspondence to the params, it took me some time to realize they might as well be random other numbers. Perhaps we could consider making them a bit more arbitrary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose those number to easily map the indices to the values. Using arbitrary numbers would make it harder to investigate any errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this is the documentation, not testing code or so