facade Package

facade Package

basicworc Module

class WORC.facade.basicworc.BasicWORC(name='WORC')[source]

Bases: SimpleWORC

Facade around the main WORC object for simple interaction.

Based upon the SimpleWORC object, but with additional functionality: - Sources of WORC (e.g. images_train, segmentations_train, …)

can be directly assessed.

Please also see the WORCTutorial Github.

__init__(name='WORC')[source]

Initialize SimpleWORC object.

Parameters

name: string, default WORC

String to identify name of experiments. Will be used in the temporary files and outputs.

__module__ = 'WORC.facade.basicworc'
execute()[source]

Execute the experiment.

Before executing the actual experiment, this function will first run several validators and check the provided setup to make sure some of the most common made error are caught before running the experiment.

simpleworc Module

class WORC.facade.simpleworc.SimpleWORC(name='WORC')[source]

Bases: object

Facade around the main WORC object for simple interaction.

Please also see the WORCTutorial Github.

__dict__ = mappingproxy({'__module__': 'WORC.facade.simpleworc', '__doc__': 'Facade around the main WORC object for simple interaction.\n\n    Please also see the `WORCTutorial Github <https://github.com/MStarmans91/WORCTutorial/>`_.\n    ', '__init__': <function SimpleWORC.__init__>, 'set_fixed_splits': <function SimpleWORC.set_fixed_splits>, 'set_image_types': <function SimpleWORC.set_image_types>, 'features_from_this_directory': <function SimpleWORC.features_from_this_directory>, 'images_from_this_directory': <function SimpleWORC.images_from_this_directory>, 'segmentations_from_this_directory': <function SimpleWORC.segmentations_from_this_directory>, 'masks_from_this_directory': <function SimpleWORC.masks_from_this_directory>, 'labels_from_this_file': <function SimpleWORC.labels_from_this_file>, 'semantics_from_this_file': <function SimpleWORC.semantics_from_this_file>, 'set_registration_parameterfile': <function SimpleWORC.set_registration_parameterfile>, 'run_inference': <function SimpleWORC.run_inference>, 'predict_labels': <function SimpleWORC.predict_labels>, '_set_and_validate_estimators': <function SimpleWORC._set_and_validate_estimators>, 'count_num_subjects': <function SimpleWORC.count_num_subjects>, '_validate': <function SimpleWORC._validate>, 'binary_classification': <function SimpleWORC.binary_classification>, 'multiclass_classification': <function SimpleWORC.multiclass_classification>, 'regression': <function SimpleWORC.regression>, 'survival': <function SimpleWORC.survival>, 'add_config_overrides': <function SimpleWORC.add_config_overrides>, 'add_evaluation': <function SimpleWORC.add_evaluation>, 'set_tmpdir': <function SimpleWORC.set_tmpdir>, 'set_multicore_execution': <function SimpleWORC.set_multicore_execution>, 'features_from_radiomix_xlsx': <function SimpleWORC.features_from_radiomix_xlsx>, '_check_traintest': <function SimpleWORC._check_traintest>, 'execute': <function SimpleWORC.execute>, '__dict__': <attribute '__dict__' of 'SimpleWORC' objects>, '__weakref__': <attribute '__weakref__' of 'SimpleWORC' objects>, '__annotations__': {}})
__init__(name='WORC')[source]

Initialize SimpleWORC object.

Parameters

name: string, default WORC

String to identify name of experiments. Will be used in the temporary files and outputs.

__module__ = 'WORC.facade.simpleworc'
__weakref__

list of weak references to the object (if defined)

add_config_overrides(config)[source]

Add manual overrides for the WORC configuration.

For a full list of options, see the WORC Config chapter for allowed options.

Example usage:

overrides = {
‘Classification’: {

‘classifiers’: ‘SVM’,

}, ‘Featsel’: {

# Other estimators do not support multiclass ‘SelectFromModel_estimator’: ‘RF’

}

} self.add_config_overrides(overrides)

Parameters

config: dictionary

Determine which options to override with which values.

add_evaluation(selected_label=0)[source]

Add the evaluation workflow to the standard WORC workflow.

Adds several evaluation measures, including:

  • Computation of 95% confidence intervals for performance

  • Univariate testing of features

  • ROC curve with confidence bands construction

  • Ranking of patients based on percentage / posterior

  • Decompositions (e.g. PCA, t-SNE)

See the WORC documentation for additional info.

Parameters

selected_label: integer, default 0

Determine for which of the labels to be predicted the evaluate workflow should be executed.

binary_classification(estimators=None, scoring_method='f1_weighted', coarse=True)[source]

Tell WORC do to a binary classification experiment.

Parameters

estimators: list

List of strings with names of valid estimators. See the WORC Config chapter for allowed options.

If coarse, only an SVM will be used. If not, the default full config will be used.

scoring_method: string, default f1

Name of the scoring method used to rank the workflows. See the WORC Config chapter for allowed options.

coarse: boolean, default True

Determine whether to do a coarse or full experiment.

count_num_subjects()[source]

Count the number of subjects in the experiment.

execute()[source]

Execute the experiment.

Before executing the actual experiment, this function will first run several validators and check the provided setup to make sure some of the most common made error are caught before running the experiment.

features_from_radiomix_xlsx(feature_file)[source]

Use a feature file which is generated by the OncoRadiomics Radiomix tool.

features_from_this_directory(directory, feature_file_name='features.hdf5', glob='*/', is_training=True)[source]

Use features from a directory as sources in WORC.

SimpleWORC uses a directory glob to look for files meeting the requirements to include, based on the input parameters.

Example: When using “directory = C:UsersMyNameFeatureFolder”, features_from_this_directory will include all features.hdf5 files from all subfolders in the directory.

Parameters

directory: string

Identifies the root directory in which to search for feature files.

feature_file_name: string, default features.hdf5

Name of the files which will be included. Can include wildcards (*).

glob: string, default */

Identify the search string to be used in the glob. Can include wildcards (*).

is_training: Boolean, default True

Identify whether these features should be used in the training or test dataset.

images_from_this_directory(directory, image_file_name='image.nii.gz', glob='*/', is_training=True)[source]

Use images from a directory as sources in WORC.

SimpleWORC uses a directory glob to look for files meeting the requirements to include, based on the input parameters.

Example: When using “directory = C:UsersMyNameImageFolder”, images_from_this_directory will include all image.nii.gz files from all subfolders in the directory.

Parameters

directory: string

Identifies the root directory in which to search for image files.

image_file_name: string, default image.nii.gz

Name of the files which will be included. Can include wildcards (*).

glob: string, default */

Identify the search string to be used in the glob. Can include wildcards (*).

is_training: Boolean, default True

Identify whether these images should be used in the training or test dataset.

labels_from_this_file(file_path, is_training=True)[source]

Define which file should be used by WORC to extract the object labels.

Should be a .csv or .txt file: see the WORC user manual for more details on the formatting of this file.

Parameters

file_path: basestring

Location of the file to be used as label file. Can be a .csv or .txt file.

is_training: Boolean, default True

Identify whether this label file should be used in the training or test dataset.

masks_from_this_directory(directory, mask_file_name='mask.nii.gz', glob='*/', is_training=True)[source]

Use masks from a directory as sources in WORC.

Masks are used in a variety of tools to ``mask’’ certain parts of the image, e.g. in the normalization. Masks are fully optional.

SimpleWORC uses a directory glob to look for files meeting the requirements to include, based on the input parameters.

Example: When using “directory = C:UsersMyNameMaskFolder”, masks_from_this_directory will include all mask.nii.gz files from all subfolders in the directory.

Parameters

directory: string

Identifies the root directory in which to search for mask files.

mask_file_name: string, default mask.nii.gz

Name of the files which will be included. Can include wildcards (*).

glob: string, default */

Identify the search string to be used in the glob. Can include wildcards (*).

is_training: Boolean, default True

Identify whether these masks should be used in the training or test dataset.

multiclass_classification(estimators=None, scoring_method='f1_weighted', coarse=True)[source]

Tell WORC do to a multiclass classification experiment.

Parameters

estimators: list

List of strings with names of valid estimators. See the WORC Config chapter for allowed options.

If coarse, only an SVM will be used. If not, the default full config will be used.

scoring_method: string, default f1

Name of the scoring method used to rank the workflows. See the WORC Config chapter for allowed options.

coarse: boolean, default True

Determine whether to do a coarse or full experiment.

predict_labels(label_names)[source]

Determine which label(s) to predict in your experiments.

The labels(s) you want to predict should be given in strings and should be included in the header of your labels_from_this_file csv. Note that you therefore first need to use that function to determine which label file to use, and afterwards use this function to select one of the headers / columns containing the actual label.

Parameters

label_names: list

List of strings containing the label name(s) to predict. For each label, a separate (classification) model will be created, or, if a multilabel experiment is run, a singel multiclass / multilabel classification model

regression(estimators=None, scoring_method='r2', coarse=True)[source]

Tell WORC do to a regression experiment.

Parameters

estimators: list

List of strings with names of valid estimators. See the WORC Config chapter for allowed options.

If coarse, only SVR will be used. If not, the default full config will be used.

scoring_method: string, default r2

Name of the scoring method used to rank the workflows. See the WORC Config chapter for allowed options.

coarse: boolean, default True

Determine whether to do a coarse or full experiment.

run_inference(trained_model, config_files)[source]

Run inference on a dataset using a previously trained WORC model.

Parameters

trained_model: basestring

Location of the HDF5 file of the trained model from WORC, commonly named “estimator_all_0.hdf5”.

config_files: basestring

List of location of the .ini file of the configurations of the trained model from WORC, commonly named like “config_CT_0_all_0.ini”. Note: these are the config files for the feature extraction, not the model training itself, which is embedded in the trained model.

segmentations_from_this_directory(directory, segmentation_file_name='segmentation.nii.gz', glob='*/', is_training=True)[source]

Use segmentations from a directory as sources in WORC.

Segmentations define the region of interest from which the features are extracted.

SimpleWORC uses a directory glob to look for files meeting the requirements to include, based on the input parameters.

Example: When using “directory = C:UsersMyNameSegmentationFolder”, segmentations_from_this_directory will include all segmentation.nii.gz files from all subfolders in the directory.

directory: string

Identifies the root directory in which to search for segmentation files.

segmentation_file_name: string, default segmentation.nii.gz

Name of the files which will be included. Can include wildcards (*).

glob: string, default */

Identify the search string to be used in the glob. Can include wildcards (*).

is_training: Boolean, default True

Identify whether these segmentations should be used in the training or test dataset.

semantics_from_this_file(file_path, is_training=True)[source]

Define which file should be used by WORC to extract the semantic features.

The values in these file can be used as semantic, i.e. non-computational, features in WORC. Should be a .csv file: see the WORC user manual for more details on the formatting of this file.

Parameters

file_path: basestring

Location of the file to be used as semantics file. Can be a .csv or .txt file.

is_training: Boolean, default True

Identify whether this semantics file should be used in the training or test dataset.

set_fixed_splits(fixed_splits_csv)[source]

Provide CSV with fixed splits for cross-validation.

Parameters

fixed_splits_csv: string

Path of CSV file

set_image_types(image_types)[source]

Set the type of images to be processed.

Parameters

image_types: list of strings

Names of types of images that are provided to WORC.

set_multicore_execution()[source]

“Execute experiment in multicore mode.

By default, SimpleWORC executes experiments in LinearExecution mode, meaning that only a single core will be used and jobs are executed in series. When multicore mode is enabled, jobs are parallellized over all available cores, which majorly speeds up the computation.

Note: SimpleWORC has an automatic detector for the BIGR and Snellius cluster. Hence, on those clusters, do not use the multicore execution, as this will overwrite the changes applied by the detectors.

set_registration_parameterfile(file_path)[source]

Define which elastix parameter file(s) should be used by WORC to perform the registration.

More information can be found in the elastix documentation on the format and settings: https://github.com/SuperElastix/elastix/wiki. Examples of parameter files can be found in the elastix model zoo github repo: https://github.com/SuperElastix/ElastixModelZoo/tree/master/models/default.

If you want to use multiple parameter files sequentially in the registration, simply use this function multiple times.

Parameters

file_path: basestring

Location of the file to be used, should be a .txt file.

set_tmpdir(tmpdir)[source]

Set a directory for storing temporary files from the experiment.

If not specified, the default fastr tmpdir is used, see fastr.config.mounts['tmp'] .

survival(estimators, scoring_method, coarse=True)[source]

Tell WORC do to a regression experiment. Not implemented yet.

Subpackages