Skip to content

Expression Context

Depending on when an expression is evaluated, it may include "context variables". These are variables available to the expression interpreter at run-time (similar to the library of available functions).

  • record: An object containing the current dataset record (or "row") currently being processed. You can access field values in the record using Python dictionary notation (e.g. record['field']) or by dot notation (e.g. record.field).
  • value: The value of the current field before being processed. This can be used as a shortcut for retrieving the current value.
  • source_filename: The filename of the file being imported. This is only available for expressions for fields passed into a dataset import with a manifest or object_id. This is useful if metadata is encoded within the filename e.g. sample info or genome build. This value will be None for dataset imports with records (i.e. when no file is provided)..
  • source_dataset: the ID of the source SolveBio dataset. This is the same as the source_id in a dataset migration. This value is always None for dataset imports (since the source is a file or a list of JSON records, not a dataset).
  • target_dataset: the ID of the target SolveBio dataset. This is the same as the target_id in a dataset migration and the dataset_id in a dataset import.

Using Context Variables

The following example shows how these variables can be used during annotation (i.e. when importing or migrating datasets):

If the current record is:

{"message": "hello"}

The following fields have valid expressions:

{
    # Replace the value of `message` with "hello world"
    "message": {
        "expression": 'value + "world"',
        "ordering": 0
    }

    # Create a new field containing ["hello", "world"]
    "split_message": {
        "expression": 'record.message.split()',
        "ordering": 1
        "is_list": True
    }
}

The output would be:

{"message": "hello world", "split_message": ["hello", "world"]}

Using the Evaluate Endpoint

When evaluating individual expressions using the evaluate endpoint, no context is included by default. You can provide custom a dictionary of context variables through the data parameter.