validate.data_io.read_inputs#

Cohort discovery, importing data and analysis settings to DataCapsule

Inputs:

Required inputs
 Raw data or pre-computed predictors

    * Raw data
        cohort_dir/
            pt001/   (scan, dose and structure files: DICOM, NIfTI or NRRD)
            pt002/
            ...
    * Predictors (CSV input)
        One row per patient."ID" is required. Other columns are model-dependent.
        Columns containing DVH metrics should be named "<structure> <metric>"  as in the model file (e.g. "Esophagus meanDose").
        Values must already be fractionation-corrected if the model requires correction.

Optional inputs:

    * plan_structures_csv (optional input alongside raw data)
    One row per patient. Only "ID" is required; every other column is optional.

        ID               Patient folder name under cohort_dir.
        Plan name        DICOM only: RTDOSE file name, used where more than one dose plan is available.
        Prescribed dose (Gy)  Total prescribed dose. Number only, in Gy.
        Fraction size (Gy)    Dose per fraction. Number only, in Gy.
        Fraction number  Number of fractions.
        Scan file        NIfTI/NRRD only: scan file name or wildcard pattern.
        Dose file        NIfTI/NRRD only: dose file name or wildcard pattern.
                         The loaded dose is used as dose index 0.
        <structure>      One column per structure the model requires, named as in
                         the model. The value is:
                         DICOM      : Structure name in the RTSTRUCT
                         NIfTI/NRRD : Mask file name or pattern, or "file:label"
                                   for a label map (e.g. "labels.nii.gz:3")

    File names and patterns are relative to the patient's folder and
    must match exactly one file.

    Example:
    ID,Prescribed dose (Gy),Fraction size (Gy),Fraction number,Scan file,Dose file,Parotids,Oral cavity
    pt_1,70,2,35,scan_*.nii.gz,dose_*.nii.gz,Parotids.nii.gz,labels.nii.gz:3

    * predictors_csv (optional, raw data only)

Functions

discoverPatients(cohortDir)

List patient subdirectories of a cohort directory.

getDoseIndex(planC[, patientId, patientInfo])

Return the index of the dose to use for this patient.

getFractionation(patientInfo)

Return this patient's (fxSize, fxNum) from plan_structures_csv.

inferFileFormat(dataDir)

Return data format.

loadPatientInfo(csvPath)

Read optional CSV files (plan_structures_csv, predictors_csv, outcomes_csv) indexed by patient ID.

loadPatientPlanC(record)

Load a single patient's planC from a DICOM, NIfTI or NRRD folder.

validate.data_io.read_inputs.discoverPatients(cohortDir)[source]#

List patient subdirectories of a cohort directory.

Parameters:

cohortDir (str) – Path to the parent directory holding DICOM/ NIfTI/NRRD data.

Returns:

list of (patientId, dicomDir) tuples, sorted by patientId. validate’s own outputs (VALIDATE_OUTPUT_NAMES: the log folder, settings file and task log) are skipped, since the cohort folder may also be the analysis folder, and so are analysis folders inside the cohort folder (subfolders holding a settings file).

validate.data_io.read_inputs.inferFileFormat(dataDir)[source]#

Return data format. Identifies raw data format (dicom) or (nifti_nrrd).

validate.data_io.read_inputs.loadPatientPlanC(record)[source]#

Load a single patient’s planC from a DICOM, NIfTI or NRRD folder.

Parameters:

record (validate.core.data_capsule.PatientRecord) – The patient directory is in record.file_info.data_dir (DICOM). For NIfTI/NRRD, record.file_info.scan_file (required) and dose_file (optional) name the scan and dose, and record.file_info.structure_files maps each modelled structure to its mask file, or “file:label” for a label map (default: binary mask, label 1); all relative to that folder. Each mask is named after its modelled structure in planC.

Returns:

cerr.plan_container.PlanC

validate.data_io.read_inputs.loadPatientInfo(csvPath)[source]#

Read optional CSV files (plan_structures_csv, predictors_csv, outcomes_csv) indexed by patient ID.

All columns besides “ID” are optional and only consulted when needed:

In plan_structures_csv:

"Plan name"       - RTDOSE file name, to disambiguate patients with
                      more than one dose (see getDoseIndex).
"Prescribed dose (Gy)" - total prescribed dose (Gy).
"Fraction size (Gy)"   - dose per fraction (Gy).
"Fraction number"  - number of fractions.
Supplying any two of the last three lets the third be derived (see
getFractionation).

In predictors_csv:

"<structure> <metric>" - start_from: predictors only. One column per
                      dose metric the model uses, named as in the
                      model file (e.g. "Esophagus meanDose").
                      Values must already be fractionation-corrected
                      if the model requires correction.
"<predictor>"     - one column per non-dose predictor the model lists,
                      named as in the model file (e.g. "gender",
                      "concurrentChemo"). Values are the numeric codes
                      from the model's "desc" (e.g. Female = 1).
With raw data, only non-dose predictors are read from this file; dose
metrics are computed from the images.

In outcomes_csv:

Parameters:

csvPath (str) – path to a CSV with an “ID” column matching the DICOM subdirectory names.

Returns:

pandas.DataFrame indexed by “ID”.

validate.data_io.read_inputs.getDoseIndex(planC, patientId=None, patientInfo=None)[source]#

Return the index of the dose to use for this patient.

If planC has no dose, None is returned. If it has exactly one dose, that dose is used. Otherwise patientInfo (a row of loadPatientInfo’s result) must supply a “Plan name” value (RTDOSE file name), matched against each dose’s doseFileName.

Parameters:
  • planC (cerr.plan_container.PlanC) – patient’s plan container.

  • patientId (str) – DICOM subdirectory name, used in error messages.

  • patientInfo (pandas.Series or None) – this patient’s row from loadPatientInfo, required when planC has more than one dose.

validate.data_io.read_inputs.getFractionation(patientInfo)[source]#

Return this patient’s (fxSize, fxNum) from plan_structures_csv.

A missing value is derived from “Prescribed dose (Gy)” and the other one. Either value is None if it can’t be resolved.

Parameters:

patientInfo (pandas.Series or None) – this patient’s row from loadPatientInfo. None if no plan_structures_csv was given, or this patient has no row in it.