Create a Template
Introduction
The template is a set of instructions for how to map your dataset to a Flywheel project.
All projects in Flywheel are made up of subjects, sessions, and acquisitions. Using the template in the config file, leverage the folder and file structure on your local machine to map your dataset to subjects, sessions, and acquisitions. With the template , you can also use folder or filenames as additional metadata fields.
Instruction Steps
Mapping your Dataset Folder Structure to Flywheel
To successfully upload your dataset, you must define the labels for subjects, sessions, and acquisitions. Below is an example of the most basic template for uploading DICOM files.
The steps below explain how to build your own template for labeling subject, sessions, and acquisitions.
- To begin, open a plain text editor such as TextEdit, Notepad, Sublime, etc.
-
Copy and paste the first step of your template:
This first pattern field corresponds to the top folder of your dataset.
-
Configure how your first folder and any data inside it will map to the Flywheel project. Below is an overview of the available options. See the reference section at the end of this article for more details.
-
Use the {subject}, {session}, or {acquisition} variables to create labels: You can use all or part of the folder name for the label. To use all of the folder name for the subject label:
For example if you had the following folder name it would become a subject label:
Example folder name Subject label sub-01 sub-01 To use only part of the folder name, replace a portion of the folder with the "{subject}" variable. For example:
Example folder name Subject label 001-subject-Nov-2021 001 002- subject-Nov-2021 002 See all of the default variables available for the template.
-
Add custom metadata: Metadata have many useful applications in Flywheel including being used to properly categorize data, create collections, or curate a dataview. CThe template allows you to use folder or file names as metadata fields. For example:
For example
Example folder name Metadata 001-subject-Nov-2021 dataset: Nov-2021 Note: this metadata field is added to the sessions of your project
-
Skip this folder: Use regex to skip this folder level and move on to the next:
-
Use filenames for labels in Flywheel: Oftentimes the filename has useful information. To leverage the filename for a label, add a scan step for filenames.
The filename scan allows for regex pattern matching, so you can pull out only the relevant information in each filename. For example:
The above template would take the filename without the extension and make it the acquisition label. For example:
Example filename Acquisition label SAG T1.dicom SAG T1 Tip
Use angled brackets <> instead of curly brackets {} when using regex to assign variables. This is a requirement of Python regex.
-
-
Add a second
-pattern:
to the template. This corresponds to the first subfolder of your dataset. The teYou can use any of the above mapping methods. For example: -
Continue for each new subfolder level in your dataset until you reach the last folder you wish to upload. To package files for upload, use
packfile_type
orscan
:-
Compress all files into a packfile: If you don't have DICOM data, you should still compress all of your images for upload using
packfile_type: <filetype>
. This creates a single zip file for upload. For example:or
-
Organize DICOM files based on metadata: If you have DICOM data and you would like to organize data using the
seriesinstanceuid
tag, use the dicom scan step:When dicom scan is enabled, Flywheel parses all files with the
.dcm
extension in that folder. Flywheel pulls out relevant metadata from the DICOM files to use as Flywheel metadata and compresses all data into a zip file for upload.If the file is not a valid DICOM file, the file is not uploaded and the import stops by default. To determine if a file is valid DICOM, we look for a
DICM
string at byte 128. However, you can use the--ignore-scan
flag in your CLI command to set it so that Flywheel only ignores the invalid DICOM file and continues to upload valid files. -
"Select" folders for upload: When there are multiple folders at the same level, you can use
select:
to set different rules for each folder:This example only scans files that end in the common DICOM file extension, .dcm.
-
-
Review your template. Verify that you have added each of these variables once:
- {subject}
- {session}
- {acquisition}
-
Verify that your template is valid YAML using an online tool such as YAML lint.
Reference
For more information about the various options available when creating an Ingest Template, see the Ingest Template Reference documentation.