Mapping File
What is a Convert-Pheno mapping file?
A mapping file is a text file in YAML format (JSON is also accepted) that connects a set of variables to a format that is understood by Convert-Pheno.
In v0.30, the layout is entity-aware:
projectholds project-level metadata.beacongroups Beacon entities at the same level.beacon.individualsholds the semantic mapping rules to the individuals entity from the Beacon v2 models, which remains the central normalized model for mapping-file based conversions.beacon.datasets,beacon.cohorts, andbeacon.biosampleshold optional metadata/defaults for emitted Beacon entities.- These metadata overrides are currently consumed only by the conversion routes that use a mapping file:
csv2bff,redcap2bff, andcdisc2bff.
The beacon.individuals wrapper is mandatory in v0.30.
Mental model
A mapping section inside beacon.individuals, such as diseases, exposures, or treatments, usually answers four different questions:
- Which source columns participate?
Use
fields. - If the source field name is not the ontology label, what field-level term should be searched?
Use
fieldTermLabels. - If the recorded value is not the ontology label, what value-level term should be searched?
Use
valueTermLabels. - If extra target-side attributes are needed, where do they come from?
Use
targetFieldsfor simple target attributes andfieldRulesfor per-field nested rules.
In practice:
fieldTermLabelsdescribes the meaning of the column/header itself.valueTermLabelsdescribes the meaning of the recorded cell value.targetFieldspoints to source columns used to populate target-side attributes such asprimaryKey,age, ordate.fieldRulesholds field-specific nested configuration, for example value-to-term rules or auxiliary pointers such asageAtExposure.
Creating a mapping file
To create a mapping file, start by reviewing the example mapping file provided with the installation. The goal is to replace the contents of such file with those from your REDCap project. The mapping file contains the following types of data:
Minimal mapping skeleton
project:
id: my_project
source: redcap
ontology: ncit
version: 0.1
beacon:
datasets:
id: my-project-dataset
name: My Project Dataset
cohorts:
id: my-project-cohort
name: My Project Cohort
cohortType: study-defined
individuals:
id:
fields: [record_id, visit_name]
targetFields:
primaryKey: record_id
sex:
fields: sex
valueTermLabels:
Male: Male
Female: Female
diseases:
fields: [diagnosis]
valueTermLabels:
UC: Ulcerative Colitis
CD: Crohn Disease
exposures:
fields: [smoking]
fieldTermLabels:
smoking: Smoking
valueTermLabels:
Current smoker: Current Smoker
Ex-smoker: Former Smoker
Never smoked: Never Smoker
info:
fields: [record_id, age, visit_name]
targetFields:
age: age
This skeleton shows the minimum structure most users need first:
projectdefines the source and default ontology.beacongroups all Beacon entity sections in one place.beacon.individualscontains the semantic mapping for the Beaconindividualsentity.beacon.individuals.id.targetFields.primaryKeypoints to the source column used as the main individual identifier.fieldTermLabelsmaps the meaning of a column/header.valueTermLabelsmaps the meaning of a recorded cell value.targetFieldsmaps extra target-side attributes such asage.
| Type | Required (Optional) | Required properties | Optional properties |
|---|---|---|---|
| Internal | project | id, source, ontology, version | description, baselineFieldsToPropagate |
| Beacon entities | beacon | individuals | datasets, cohorts, biosamples |
| Entity mapping | beacon.individuals | id, sex | diseases, exposures, info, interventionsOrProcedures, measures, phenotypicFeatures, treatments, ethnicity, geographicOrigin, karyotypicSex, pedigrees |
These are the properties needed to map your data to the entity individuals in the Beacon v2 Models:
-
beacon.individuals, an
objectcontaining the semantic mapping rules for the Beaconindividualsentity. -
beacon, a top-level
objectwith the entity sections. Usebeacon.datasetsandbeacon.cohortsto override synthesized metadata such asid,name,description,externalUrl,cohortType, orcohortDataTypes. These values are merged with the tool-generated defaults. This augmentation currently applies only tocsv2bff,redcap2bff, andcdisc2bff. -
baselineFieldsToPropagate, an array of columns containing measurements that were taken only at the initial time point (time = 0). Use this if you wish to duplicate these columns across subsequent rows for the same patient ID. It is important to ensure that the row containing baseline information appears first in the CSV.
-
Mapping-file conversions preserve a raw source-row snapshot in the generated
BFFinfoobject by default, such asCSV_columnsorREDCap_columns. This helps users audit mapped values against the input file. Use--no-source-infoto omit these copied source payloads. -
age, a
stringrepresenting the column that points to the age of the patient. -
ageAtProcedure, an
objectrepresenting the column that points to the age when a procedure took place. -
ageOfOnset, an
objectrepresenting the column that points to the age at which the patient first experienced symptoms or was diagnosed with a condition. -
bodySite, an
objectrepresenting the column that points to the part of the body affected by a condition or where a procedure was performed. -
dateOfProcedure, an
objectrepresenting the column that points to when a procedure took place. -
drugDose, an
objectrepresenting the column that points to the dose column for each treatment. -
drugUnit, an
objectrepresenting the column that points to the unit column for each treatment. -
duration, an
objectrepresenting the column that points to the duration column for each treatment. -
durationUnit, an
objectrepresenting the column that points to the duration unit column for each treatment. -
familyHistory, an
objectrepresenting the column that points to the family medical history relevant to the patient's condition. -
fieldRules, a nested
objectwith per-field rules such as value-to-term mappings or auxiliary field configuration likeageAtExposure. Use this when a single Beacon term needs field-specific behavior rather than one global rule. -
fieldTermLabels, is an
objectin the form ofkey: value. Thekeyrepresents the original variable or header name and thevaluerepresents the ontology query phrase used for the field itself. Use this when the column name carries the term meaning. For instance, you may have a variable namedcigarettes_days, but you know that in NCIt the label isAverage Number Cigarettes Smoked a Day. In this case, you will usecigarettes_days: Average Number Cigarettes Smoked a Day. -
fields, can be either a
stringor anarrayconsisting of the name of the source variables that map to that Beacon v2 term. -
procedureCodeLabel , a nested
objectwith specific mappings forinterventionsOrProcedures. -
ontology, it's an
stringto define more granularly the ontology for this particular Beacon v2 term. If not present, the script will use that fromproject.ontology. -
routeOfAdministration, a nested
objectwith specific mappings fortreatments. -
targetFields, is an
objectin the form ofkey: valuethat maps target-side attributes such asprimaryKey,age,date, ordurationto source columns. Use this when the target model expects a named attribute that is not itself an ontology lookup. -
terminology, a nested
objectvalue with user-defined ontology terms. Use this when you already know the exact ontology object and want to bypass database lookup for that term. -
useHeaderAsTermLabel, an
arrayfor columns on which the ontology-term labels have to be assigned from the header instead of the recorded value. This is common for checkbox-like columns where the header says the term and the cell only says whether it is present.Terminology example
terminology:My fav term:id: FOO:12345678label: Label for my fav term -
unit, an
objectrepresenting the column that points to the unit of measurement for a given value or treatment. -
valueTermLabels, is an
objectin the form ofkey: valuewhere thekeyis the original recorded value and thevalueis the ontology query phrase used to map that value. Use this when the cell value carries the term meaning, for exampleCurrent smoker -> Current Smoker. -
visitId, the column with visit occurrence id.
Field vs value mapping
exposures:fields: [smoking, cigarettes_days]fieldTermLabels:smoking: Smokingcigarettes_days: Average Number Cigarettes Smoked a DayvalueTermLabels:Current smoker: Current SmokerEx-smoker: Former SmokerNever smoked: Never SmokerIn this example:
smoking -> Smokingcomes from the field/header, so it belongs infieldTermLabels.Current smoker -> Current Smokercomes from the recorded value, so it belongs invalueTermLabels.
Defining the values in
fieldTermLabelsandvalueTermLabelsBefore assigning values to
fieldTermLabelsorvalueTermLabelsit's important that you think about which ontologies or terminologies you want to use. The fieldproject.ontologydefines the ontology for the whole project, but you can also specify another ontology at the Beacon v2 term level. Once you know which ontologies to use, search for accurate labels first. For example, if you have chosenncit, you can search for the values within NCIt at EBI Search.Convert-Phenowill use these values to retrieve the actual ontology term from its internal databases.