-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EEG] Database Architecture for HED Tags (#8036)
This contains the necessary changes for adding HED Tag support to the database. There is a single use script that should be run to archive the events files.
- Loading branch information
Showing
6 changed files
with
214 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
-- ############################## CAPTURE HEDVersion ########################## -- | ||
-- HEDVersion from dataset_description.json to be added to parameter_type | ||
-- Entry in physiological_parameter_file will be added on dataset import** | ||
INSERT INTO parameter_type (Name, Type, Description, SourceFrom) VALUES | ||
('HEDVersion', 'text', 'HED Schema Version','physiological_parameter_file') | ||
; | ||
|
||
-- ############################## HANDLE EVENT FILES ########################## -- | ||
-- Create `physiological_event_file` table | ||
CREATE TABLE `physiological_event_file` ( | ||
`EventFileID` int(10) unsigned NOT NULL AUTO_INCREMENT, | ||
`PhysiologicalFileID` int(10) unsigned NOT NULL, | ||
`FileType` varchar(20) NOT NULL, | ||
`FilePath` varchar(255) DEFAULT NULL, | ||
`LastUpdate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | ||
`LastWritten` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
PRIMARY KEY (`EventFileID`), | ||
KEY `FK_physio_file_ID` (`PhysiologicalFileID`), | ||
KEY `FK_event_file_type` (`FileType`), | ||
CONSTRAINT `FK_event_file_type` FOREIGN KEY (`FileType`) REFERENCES `ImagingFileTypes` (`type`), | ||
CONSTRAINT `FK_physio_file_ID` FOREIGN KEY (`PhysiologicalFileID`) REFERENCES `physiological_file` (`PhysiologicalFileID`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 | ||
; | ||
|
||
-- Create reference to EventFileID in `physiological_task_event` table | ||
SET FOREIGN_KEY_CHECKS= 0; | ||
ALTER TABLE physiological_task_event | ||
ADD COLUMN `EventFileID` int(10) unsigned NOT NULL AFTER PhysiologicalFileID, | ||
ADD KEY `FK_event_file` (`EventFileID`), | ||
ADD CONSTRAINT `FK_event_file` FOREIGN KEY (`EventFileID`) REFERENCES `physiological_event_file` (`EventFileID`) | ||
; | ||
|
||
-- Create column for assembled HEd tags in `physiological_task_event` table | ||
ALTER TABLE physiological_task_event | ||
ADD COLUMN `AssembledHED` text DEFAULT NULL | ||
; | ||
|
||
-- Insert files into `physiological_event_file` table | ||
INSERT INTO physiological_event_file (PhysiologicalFileID, FilePath, FileType) | ||
SELECT DISTINCT PhysiologicalFileID, FilePath, 'tsv' FROM physiological_task_event | ||
; | ||
|
||
-- Update EventFileID reference in `physiological_task_event` table | ||
UPDATE physiological_task_event te | ||
SET EventFileID=(SELECT EventFileID FROM physiological_event_file WHERE PhysiologicalFileID=te.PhysiologicalFileID) | ||
; | ||
|
||
-- Delete FilePath column in `physiological_task_event` table | ||
ALTER TABLE physiological_task_event | ||
DROP COLUMN FilePath | ||
; | ||
|
||
|
||
-- ############################## EVENT FILES ARCHIVE ########################## -- | ||
CREATE TABLE `physiological_event_archive` ( | ||
`EventArchiveID` int(10) unsigned NOT NULL AUTO_INCREMENT, | ||
`PhysiologicalFileID` int(10) unsigned NOT NULL, | ||
`Blake2bHash` varchar(128) NOT NULL, | ||
`FilePath` varchar(255) NOT NULL, | ||
PRIMARY KEY (`EventArchiveID`), | ||
KEY `FK_phy_file_ID` (`PhysiologicalFileID`), | ||
CONSTRAINT `FK_phy_file_ID` FOREIGN KEY (`PhysiologicalFileID`) REFERENCES `physiological_file` (`PhysiologicalFileID`) ON DELETE CASCADE | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 | ||
; | ||
|
||
|
||
-- ############################## CAPTURE EVENT PARAMETERS ########################## -- | ||
CREATE TABLE `physiological_event_parameter` ( | ||
`EventParameterID` int(10) unsigned NOT NULL AUTO_INCREMENT, | ||
`EventFileID` int(10) unsigned NOT NULL, | ||
`ParameterName` varchar(255) NOT NULL, | ||
`Description` text DEFAULT NULL, | ||
`LongName` varchar(255) DEFAULT NULL, | ||
`Units` varchar(50) DEFAULT NULL, | ||
`isCategorical` enum('Y', 'N') DEFAULT NULL, | ||
`HED` text DEFAULT NULL, | ||
PRIMARY KEY (`EventParameterID`), | ||
KEY `FK_event_file_ID` (`EventFileID`), | ||
CONSTRAINT `FK_event_file_ID` FOREIGN KEY (`EventFileID`) REFERENCES `physiological_event_file` (`EventFileID`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 | ||
; | ||
|
||
CREATE TABLE `physiological_event_parameter_category_level` ( | ||
`CategoricalLevelID` int(10) unsigned NOT NULL AUTO_INCREMENT, | ||
`EventParameterID` int(10) unsigned NOT NULL, | ||
`LevelName` varchar(255) NOT NULL, | ||
`Description` text DEFAULT NULL, | ||
`HED` text DEFAULT NULL, | ||
PRIMARY KEY (`CategoricalLevelID`), | ||
KEY `FK_event_param_ID` (`EventParameterID`), | ||
CONSTRAINT `FK_event_param_ID` FOREIGN KEY (`EventParameterID`) REFERENCES `physiological_event_parameter` (`EventParameterID`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php declare(strict_types=1); | ||
require_once __DIR__ . "/../generic_includes.php"; | ||
|
||
$db = \NDB_Factory::singleton()->database(); | ||
|
||
$dataDir = $db->pselectOne( | ||
'SELECT Value | ||
FROM Config AS config | ||
INNER JOIN ConfigSettings AS c | ||
ON c.Name=:name AND config.ConfigID=c.ID', | ||
['name' => 'dataDirBasepath'] | ||
); | ||
|
||
$filepaths = $db->pselect( | ||
"SELECT | ||
DISTINCT(FilePath), PhysiologicalFileID | ||
FROM physiological_event_file | ||
WHERE FileType='tsv'", | ||
[] | ||
); | ||
|
||
foreach ($filepaths as $record) { | ||
$tgz_name = str_replace(".tsv", '.tgz', $record['FilePath']); | ||
$tgz_path = $dataDir . $tgz_name; | ||
print_r($tgz_path . "\n"); | ||
$eventPath = $dataDir . $record['FilePath']; | ||
$arch_file = new \PharData($tgz_path); | ||
$arch_file->addFile($eventPath, basename($eventPath)); | ||
|
||
$f = file_get_contents($tgz_path); | ||
$hash = sodium_crypto_generichash($f); | ||
|
||
//Update database with hash | ||
$db->insert( | ||
'physiological_event_archive', | ||
[ | ||
'PhysiologicalFileID' => $record['PhysiologicalFileID'], | ||
'FilePath' => str_replace($dataDir, '', $tgz_path), | ||
'Blake2bHash' => bin2hex($hash) | ||
] | ||
); | ||
} |