Skip to content

Commit 72bd9a0

Browse files
authored
add changes made to the BIDS tables for the mnc2bids conversion script (#7474)
This modifies the BIDS tables used to convert MINC datasets into BIDS datasets. In addition, it adds tables to store the path to the created files under the BIDS structure in the database so later on it can be queried via the API.
1 parent 7ac5f77 commit 72bd9a0

File tree

3 files changed

+173
-10
lines changed

3 files changed

+173
-10
lines changed

SQL/0000-00-00-schema.sql

Lines changed: 75 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,12 @@ INSERT INTO `ImagingFileTypes` (type, description) VALUES
477477
('txt', 'text file'),
478478
('nii', 'NIfTI file'),
479479
('nrrd', 'NRRD file format (used by DTIPrep)'),
480-
('grid_0', 'MNI BIC non-linear field for non-linear transformation');
480+
('grid_0', 'MNI BIC non-linear field for non-linear transformation'),
481+
('json', 'JSON file'),
482+
('readme', 'README file'),
483+
('tsv', 'Tab separated values (TSV) file'),
484+
('bval', 'NIfTI DWI file with b-values'),
485+
('bvec', 'NIfTI DWI file with b-vectors');
481486

482487
CREATE TABLE `mri_processing_protocol` (
483488
`ProcessProtocolID` int(11) unsigned NOT NULL AUTO_INCREMENT,
@@ -797,18 +802,34 @@ INSERT INTO `bids_scan_type` (BIDSScanType) VALUES
797802
('T2w'),
798803
('dwi');
799804

805+
CREATE TABLE `bids_phase_encoding_direction` (
806+
`BIDSPhaseEncodingDirectionID` int(3) unsigned NOT NULL AUTO_INCREMENT,
807+
`BIDSPhaseEncodingDirectionName` varchar(3) NOT NULL,
808+
PRIMARY KEY (`BIDSPhaseEncodingDirectionID`)
809+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
810+
811+
INSERT INTO bids_phase_encoding_direction (BIDSPhaseEncodingDirectionName) VALUES
812+
('i'),
813+
('i-'),
814+
('j'),
815+
('j-'),
816+
('k'),
817+
('k-');
818+
800819
CREATE TABLE `bids_mri_scan_type_rel` (
801-
`MRIScanTypeID` int(10) UNSIGNED NOT NULL,
802-
`BIDSCategoryID` int(3) UNSIGNED DEFAULT NULL,
803-
`BIDSScanTypeSubCategoryID` int(3) UNSIGNED DEFAULT NULL,
804-
`BIDSScanTypeID` int(3) UNSIGNED DEFAULT NULL,
805-
`BIDSEchoNumber` int(3) UNSIGNED DEFAULT NULL,
820+
`MRIScanTypeID` int(10) UNSIGNED NOT NULL,
821+
`BIDSCategoryID` int(3) UNSIGNED DEFAULT NULL,
822+
`BIDSScanTypeSubCategoryID` int(3) UNSIGNED DEFAULT NULL,
823+
`BIDSScanTypeID` int(3) UNSIGNED DEFAULT NULL,
824+
`BIDSEchoNumber` int(3) UNSIGNED DEFAULT NULL,
825+
`BIDSPhaseEncodingDirectionID` int(3) UNSIGNED DEFAULT NULL,
806826
PRIMARY KEY (`MRIScanTypeID`),
807827
KEY `FK_bids_mri_scan_type_rel` (`MRIScanTypeID`),
808-
CONSTRAINT `FK_bids_mri_scan_type_rel` FOREIGN KEY (`MRIScanTypeID`) REFERENCES `mri_scan_type` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
809-
CONSTRAINT `FK_bids_category` FOREIGN KEY (`BIDSCategoryID`) REFERENCES `bids_category`(`BIDSCategoryID`),
810-
CONSTRAINT `FK_bids_scan_type_subcategory` FOREIGN KEY (`BIDSScanTypeSubCategoryID`) REFERENCES `bids_scan_type_subcategory` (`BIDSScanTypeSubCategoryID`),
811-
CONSTRAINT `FK_bids_scan_type` FOREIGN KEY (`BIDSScanTypeID`) REFERENCES `bids_scan_type` (`BIDSScanTypeID`)
828+
CONSTRAINT `FK_bids_mri_scan_type_rel` FOREIGN KEY (`MRIScanTypeID`) REFERENCES `mri_scan_type` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
829+
CONSTRAINT `FK_bids_category` FOREIGN KEY (`BIDSCategoryID`) REFERENCES `bids_category`(`BIDSCategoryID`),
830+
CONSTRAINT `FK_bids_scan_type_subcategory` FOREIGN KEY (`BIDSScanTypeSubCategoryID`) REFERENCES `bids_scan_type_subcategory` (`BIDSScanTypeSubCategoryID`),
831+
CONSTRAINT `FK_bids_scan_type` FOREIGN KEY (`BIDSScanTypeID`) REFERENCES `bids_scan_type` (`BIDSScanTypeID`),
832+
CONSTRAINT `FK_bids_phase_encoding_direction` FOREIGN KEY (`BIDSPhaseEncodingDirectionID`) REFERENCES `bids_phase_encoding_direction` (`BIDSPhaseEncodingDirectionID`)
812833
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
813834

814835

@@ -852,6 +873,50 @@ INSERT INTO bids_mri_scan_type_rel
852873
NULL
853874
);
854875

876+
877+
CREATE TABLE `bids_export_file_level_category` (
878+
`BIDSExportFileLevelCategoryID` int(10) unsigned NOT NULL AUTO_INCREMENT,
879+
`BIDSExportFileLevelCategoryName` varchar(12) NOT NULL,
880+
PRIMARY KEY (`BIDSExportFileLevelCategoryID`)
881+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
882+
883+
INSERT INTO bids_export_file_level_category (BIDSExportFileLevelCategoryName) VALUES
884+
('study'),
885+
('image'),
886+
('session');
887+
888+
CREATE TABLE `bids_export_non_imaging_file_category` (
889+
`BIDSNonImagingFileCategoryID` int(10) unsigned NOT NULL AUTO_INCREMENT,
890+
`BIDSNonImagingFileCategoryName` varchar(40) NOT NULL,
891+
PRIMARY KEY (`BIDSNonImagingFileCategoryID`)
892+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
893+
894+
INSERT INTO bids_export_non_imaging_file_category (BIDSNonImagingFileCategoryName) VALUES
895+
('dataset_description'),
896+
('README'),
897+
('bids-validator-config'),
898+
('participants_list_file'),
899+
('session_list_of_scans');
900+
901+
CREATE TABLE `bids_export_files` (
902+
`BIDSExportedFileID` int(10) unsigned NOT NULL AUTO_INCREMENT,
903+
`BIDSExportFileLevelCategoryID` int(10) unsigned NOT NULL,
904+
`FileID` int(10) unsigned DEFAULT NULL,
905+
`SessionID` int(10) unsigned DEFAULT NULL,
906+
`BIDSNonImagingFileCategoryID` int(10) unsigned DEFAULT NULL,
907+
`BIDSCategoryID` int(3) unsigned DEFAULT NULL,
908+
`FileType` varchar(12) NOT NULL,
909+
`FilePath` varchar(255) NOT NULL,
910+
PRIMARY KEY (`BIDSExportedFileID`),
911+
CONSTRAINT `FK_bef_BIDSExportFileLevelID` FOREIGN KEY (`BIDSExportFileLevelCategoryID`) REFERENCES `bids_export_file_level_category` (`BIDSExportFileLevelCategoryID`),
912+
CONSTRAINT `FK_bef_FileID` FOREIGN KEY (`FileID`) REFERENCES `files` (`FileID`),
913+
CONSTRAINT `FK_bef_SessionID` FOREIGN KEY (`SessionID`) REFERENCES `session` (`ID`),
914+
CONSTRAINT `FK_bef_BIDSNonImagingFileCategoryID` FOREIGN KEY (`BIDSNonImagingFileCategoryID`) REFERENCES `bids_export_non_imaging_file_category` (`BIDSNonImagingFileCategoryID`),
915+
CONSTRAINT `FK_bef_ModalityType` FOREIGN KEY (`BIDSCategoryID`) REFERENCES `bids_category` (`BIDSCategoryID`),
916+
CONSTRAINT `FK_bef_FileType` FOREIGN KEY (`FileType`) REFERENCES `ImagingFileTypes` (`type`)
917+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
918+
919+
855920
-- ********************************
856921
-- MRI violations tables
857922
-- ********************************

SQL/9999-99-99-drop_tables.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,13 @@ DROP TABLE IF EXISTS `document_repository`;
134134
DROP TABLE IF EXISTS `document_repository_categories`;
135135

136136
DROP TABLE IF EXISTS `bids_mri_scan_type_rel`;
137+
DROP TABLE IF EXISTS `bids_export_files`;
137138
DROP TABLE IF EXISTS `bids_category`;
138139
DROP TABLE IF EXISTS `bids_scan_type`;
139140
DROP TABLE IF EXISTS `bids_scan_type_subcategory`;
141+
DROP TABLE IF EXISTS `bids_phase_encoding_direction`;
142+
DROP TABLE IF EXISTS `bids_export_non_imaging_file_category`;
143+
DROP TABLE IF EXISTS `bids_export_file_level_category`;
140144
DROP TABLE IF EXISTS `violations_resolved`;
141145
DROP TABLE IF EXISTS `mri_violations_log`;
142146
DROP TABLE IF EXISTS `mri_protocol_checks_group_target`;
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
--
2+
-- Add necessary file types in ImagingFileTypes
3+
--
4+
INSERT INTO ImagingFileTypes (type, description) VALUES
5+
('json', 'JSON file'),
6+
('readme', 'README file'),
7+
('tsv', 'Tab separated values (TSV) file'),
8+
('bval', 'NIfTI DWI file with b-values'),
9+
('bvec', 'NIfTI DWI file with b-vectors');
10+
11+
12+
--
13+
-- Create table to store PhaseEncodingDirection possible values
14+
--
15+
CREATE TABLE `bids_phase_encoding_direction` (
16+
`BIDSPhaseEncodingDirectionID` int(3) unsigned NOT NULL AUTO_INCREMENT,
17+
`BIDSPhaseEncodingDirectionName` varchar(3) NOT NULL,
18+
PRIMARY KEY (`BIDSPhaseEncodingDirectionID`)
19+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
20+
21+
INSERT INTO bids_phase_encoding_direction (BIDSPhaseEncodingDirectionName) VALUES
22+
('i'),
23+
('i-'),
24+
('j'),
25+
('j-'),
26+
('k'),
27+
('k-');
28+
29+
30+
--
31+
-- Alter table bids_mri_scan_type_rel to add a PhaseEncodingDirection field
32+
--
33+
ALTER TABLE bids_mri_scan_type_rel ADD COLUMN BIDSPhaseEncodingDirectionID int(3) unsigned DEFAULT NULL;
34+
ALTER TABLE bids_mri_scan_type_rel
35+
ADD CONSTRAINT `FK_bids_phase_encoding_direction`
36+
FOREIGN KEY (`BIDSPhaseEncodingDirectionID`)
37+
REFERENCES `bids_phase_encoding_direction` (`BIDSPhaseEncodingDirectionID`);
38+
39+
40+
--
41+
-- Table structure for `bids_file_level_category`
42+
--
43+
CREATE TABLE `bids_export_file_level_category` (
44+
`BIDSExportFileLevelCategoryID` int(10) unsigned NOT NULL AUTO_INCREMENT,
45+
`BIDSExportFileLevelCategoryName` varchar(12) NOT NULL,
46+
PRIMARY KEY (`BIDSExportFileLevelCategoryID`)
47+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
48+
49+
INSERT INTO bids_export_file_level_category (BIDSExportFileLevelCategoryName) VALUES
50+
('study'),
51+
('image'),
52+
('session');
53+
54+
55+
56+
--
57+
-- BIDS non-imaging file types
58+
--
59+
CREATE TABLE `bids_export_non_imaging_file_category` (
60+
`BIDSNonImagingFileCategoryID` int(10) unsigned NOT NULL AUTO_INCREMENT,
61+
`BIDSNonImagingFileCategoryName` varchar(40) NOT NULL,
62+
PRIMARY KEY (`BIDSNonImagingFileCategoryID`)
63+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
64+
65+
INSERT INTO bids_export_non_imaging_file_category (BIDSNonImagingFileCategoryName) VALUES
66+
('dataset_description'),
67+
('README'),
68+
('bids-validator-config'),
69+
('participants_list_file'),
70+
('session_list_of_scans');
71+
72+
73+
--
74+
-- Table structure for table `bids_export_files`
75+
--
76+
CREATE TABLE `bids_export_files` (
77+
`BIDSExportedFileID` int(10) unsigned NOT NULL AUTO_INCREMENT,
78+
`BIDSExportFileLevelCategoryID` int(10) unsigned NOT NULL,
79+
`FileID` int(10) unsigned DEFAULT NULL,
80+
`SessionID` int(10) unsigned DEFAULT NULL,
81+
`BIDSNonImagingFileCategoryID` int(10) unsigned DEFAULT NULL,
82+
`BIDSCategoryID` int(3) unsigned DEFAULT NULL,
83+
`FileType` varchar(12) NOT NULL,
84+
`FilePath` varchar(255) NOT NULL,
85+
PRIMARY KEY (`BIDSExportedFileID`),
86+
CONSTRAINT `FK_bef_BIDSExportFileLevelID` FOREIGN KEY (`BIDSExportFileLevelCategoryID`) REFERENCES `bids_export_file_level_category` (`BIDSExportFileLevelCategoryID`),
87+
CONSTRAINT `FK_bef_FileID` FOREIGN KEY (`FileID`) REFERENCES `files` (`FileID`),
88+
CONSTRAINT `FK_bef_SessionID` FOREIGN KEY (`SessionID`) REFERENCES `session` (`ID`),
89+
CONSTRAINT `FK_bef_BIDSNonImagingFileCategoryID` FOREIGN KEY (`BIDSNonImagingFileCategoryID`) REFERENCES `bids_export_non_imaging_file_category` (`BIDSNonImagingFileCategoryID`),
90+
CONSTRAINT `FK_bef_ModalityType` FOREIGN KEY (`BIDSCategoryID`) REFERENCES `bids_category` (`BIDSCategoryID`),
91+
CONSTRAINT `FK_bef_FileType` FOREIGN KEY (`FileType`) REFERENCES `ImagingFileTypes` (`type`)
92+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
93+
94+

0 commit comments

Comments
 (0)