OpenMS
ParamJSONFile Class Reference

Load from JSON (in a Common Workflow Language (CWL) compatible way) into the Param class. More...

#include <OpenMS/FORMAT/ParamJSONFile.h>

Collaboration diagram for ParamJSONFile:
[legend]

Public Member Functions

void store (const std::string &filename, const Param &param, const ToolInfo &tool_info) const
 Write Json file with set values. More...
 
void writeToStream (std::ostream *os_ptr, const Param &param) const
 

Static Public Member Functions

static bool load (const std::string &filename, Param &param)
 Read JSON file that is formatted in CWL conforming style. More...
 

Public Attributes

bool flatHierarchy {}
 If set to true, all parameters will be listed on when writing the JSON file. The names will be expanded to include the nesting hierarchy. More...
 

Detailed Description

Load from JSON (in a Common Workflow Language (CWL) compatible way) into the Param class.

The JSON file must contain one top level mapping of param value names to actual values.
These values can be one of the following types:
    - null
    - boolean
    - int
    - long
    - float
    - double
    - string
    - a CWL style file path ({ "class": "File", "path": "./myFolder/myFile.txt" })
    - an array of these

param value names match the command line option without the leading '-'. Optionally the ':'
can be replaced with a double underscore "__".
{
"in": {
"class": "File",
"path": "./myFolder/myFile.txt"
},
"out_prefix": "test_cwl_",
"algorithm:threshold": 5,
"algorithm:score_type": "ID"
}

Same file with "__" instead of ':' as the section separator.

{
"in": {
"class": "File",
"path": "./myFolder/myFile.txt"
},
"out_prefix": "test_cwl_",
"algorithm__threshold": 5,
"algorithm__score_type": "ID"
}

Member Function Documentation

◆ load()

static bool load ( const std::string &  filename,
Param param 
)
static

Read JSON file that is formatted in CWL conforming style.

Parameters
filenameThe file from where to read the Param object.
paramA param object with pre-filled defaults, which are updated by the values in the JSON file
Returns
returns true if file was successfully loaded; false if an unknown (non-default) parameter name was encountered in the JSON file
Exceptions
Exception::FileNotFoundis thrown if the file could not be found
Exception::ParseErroris thrown if an error occurs during parsing

◆ store()

void store ( const std::string &  filename,
const Param param,
const ToolInfo tool_info 
) const

Write Json file with set values.

Parameters
filenameThe name of the file the param data structure should be stored in.
paramThe param data structure that should be stored.
tool_infounused, required for compatiblity with ParamCWLFile
Exceptions
std::ios::failureis thrown if the file could not be created

◆ writeToStream()

void writeToStream ( std::ostream *  os_ptr,
const Param param 
) const

Member Data Documentation

◆ flatHierarchy

bool flatHierarchy {}

If set to true, all parameters will be listed on when writing the JSON file. The names will be expanded to include the nesting hierarchy.