Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Feature] SQL Patch and functionality for EEG BIDS Derivatives #7345

Merged
merged 19 commits into from
Apr 27, 2021

Conversation

AlexandraLivadas
Copy link
Contributor

@AlexandraLivadas AlexandraLivadas commented Feb 22, 2021

This PR contains an SQL patch to create new tables for the annotation features that will be added in the Electrophysiology Browser module. This PR also includes basic functionalities in the EEG Browser to support these derivatives, including a filter in the main menu and a download option for annotation files.

To test this change

  1. Run this patch and see that all statements work properly
  2. Go to the main page and see that a filter has been added to filter between data that has derivatives and data that does not
    a. Note that in order to test the filter, data will need to be added to the annotation_file table
  3. Go to one of the session pages (raw or all types) and see that a "Download" button has been added for annotation files.
    a. Note again that in order to test this button, data must be added to the annotation_file and annotation_archive tables. If needed, I can add a patch that will add data to these tables but this patch should be deleted before the PR is merged

Main Menu with Filter:
Screen Shot 2021-04-06 at 11 50 40 PM

Sessions page with download annotations:
Screen Shot 2021-03-17 at 2 12 21 PM

@AlexandraLivadas AlexandraLivadas added Feature PR or issue introducing/requiring at least one new feature SQL PR contains SQL modifications such as schema changes and new SQL scripts labels Feb 22, 2021
@AlexandraLivadas AlexandraLivadas changed the title [New Feature] SQL Patch for BIDS Derivatives [New Feature] SQL Patch for EEG Browser Derivatives Feb 22, 2021
@AlexandraLivadas AlexandraLivadas changed the title [New Feature] SQL Patch for EEG Browser Derivatives [New Feature] SQL Patch for Electrophysiology Browser Derivatives Feb 22, 2021
@AlexandraLivadas AlexandraLivadas changed the title [New Feature] SQL Patch for Electrophysiology Browser Derivatives [New Feature] SQL Patch for Electrophysiology Derivatives Feb 22, 2021
@AlexandraLivadas AlexandraLivadas changed the title [New Feature] SQL Patch for Electrophysiology Derivatives [New Feature] SQL Patch for EEG BIDS Derivatives Feb 22, 2021
Copy link
Collaborator

@cmadjar cmadjar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlexandraLivadas LGTM. See minor comments attached to the review.

CREATE TABLE `annotation_instance` (
`AnnotationInstanceID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`AnnotationFileID` INT(10) UNSIGNED NOT NULL,
`ParameterFileID` INT(10) UNSIGNED NOT NULL,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`ParameterFileID` INT(10) UNSIGNED NOT NULL,
`AnnotationParameterID` INT(10) UNSIGNED NOT NULL,

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep the same column name as in the table annotation_instance.

`AbsoluteTime` TIMESTAMP,
`Description` VARCHAR(255),
PRIMARY KEY (`AnnotationInstanceID`),
CONSTRAINT `FK_parameter_file_ID`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CONSTRAINT `FK_parameter_file_ID`
CONSTRAINT `FK_annotation_parameter_ID`

`Description` VARCHAR(255),
PRIMARY KEY (`AnnotationInstanceID`),
CONSTRAINT `FK_parameter_file_ID`
FOREIGN KEY (`ParameterFileID`)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
FOREIGN KEY (`ParameterFileID`)
FOREIGN KEY (`AnnotationParameterID`)

REFERENCES `physiological_file` (`PhysiologicalFileID`),
CONSTRAINT `FK_annotation_file_type`
FOREIGN KEY (`FileType`)
REFERENCES `annotation_file_type` (`Type`)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
REFERENCES `annotation_file_type` (`Type`)
REFERENCES `annotation_file_type` (`FileType`)


-- Create annotation_file_type table
CREATE TABLE `annotation_file_type` (
`Type` VARCHAR(20) NOT NULL UNIQUE,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`Type` VARCHAR(20) NOT NULL UNIQUE,
`FileType` VARCHAR(20) NOT NULL UNIQUE,

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be consistent with the FK in subsequent table

Copy link
Collaborator

@cmadjar cmadjar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AlexandraLivadas AlexandraLivadas changed the title [New Feature] SQL Patch for EEG BIDS Derivatives [New Feature] SQL Patch and functionality for EEG BIDS Derivatives Mar 12, 2021
Copy link
Contributor

@christinerogers christinerogers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great additions Alex !

  • 1 change requested on the "session" page : "Annotation Files" button rename and meove below events.
  • main module page: tweak the filter language and order, and also use the Links column to show when there is derived data (no new column needed)

@AlexandraLivadas AlexandraLivadas marked this pull request as ready for review March 17, 2021 18:22
@AlexandraLivadas AlexandraLivadas requested review from cmadjar and christinerogers and removed request for cmadjar March 17, 2021 18:43
Copy link
Contributor

@christinerogers christinerogers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Alex, thanks for these updates! it's coming along nicely

I've spotted a few more things to bring into better alignment with how 'Events' fields are consistently named.

Quick question for you and also @cmadjar 's input --:

  1. Could these schema changes go in with the electrophysiology tables instead of a new schema file? (0000...6-Derivatives.sql) These tables include EEG field names hardcoded like Physiology_file_id, or channel in annotation_instance table.

  2. Because they're presently very EEG-specific, I think it's better to name the tables as the Events tables are named: e.g. physiological_annotation_file instead of annotation_file ?

Remind me, was this considered?

Additional comments / tiny changes included inline below, please review.

type: 'select',
options: {
Raw: 'Raw',
Derivatives: 'Derivatives',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Derivatives: 'Derivatives',
Derivative: 'Derivative',

@@ -0,0 +1,117 @@
-- SQL tables for BIDS derivative file structure
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filename should change to ...electrophysiology_annotation_tables

@@ -30,6 +30,7 @@ class FilePanel extends Component {
'download_electrode_info',
'download_channels_info',
'download_events',
'download_annotation_files',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to match events:

Suggested change
'download_annotation_files',
'download_annotations',

target='_blank'
download={this.state.data.downloads[0].file}
>
<button id='btn_download_annotation_files'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<button id='btn_download_annotation_files'
<button id='btn_download_annotations'

see above

style={stylesFile.div.element.download_title}
>Annotations</div>
<div className={'col-xs-2'}>
<a id='download_annotation_files'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<a id='download_annotation_files'
<a id='download_annotations'

update to match

modules/electrophysiology_browser/php/sessions.class.inc Outdated Show resolved Hide resolved
@@ -268,7 +268,8 @@ function testEEGBrowserWithSitePermissions()
*/
function testFilters()
{
$this->safeGet($this->url . "/electrophysiology_browser/");
$this->markTestSkipped('Must be updated with annotation additions to pass');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->markTestSkipped('Must be updated with annotation additions to pass');
$this->markTestSkipped('Must be updated with annotations to pass');

is this suggestion here more accurate?

@@ -342,6 +343,7 @@ function testFilters()
*/
function testEEGBrowserSortableByColumn()
{
$this->markTestSkipped('Must be updated with annotation additions to pass');
Copy link
Contributor

@christinerogers christinerogers Mar 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same : "annotations" is perhaps clearer than "annotation additions" ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more instances of the same below...

@AlexandraLivadas
Copy link
Contributor Author

@christinerogers To respond to your latest comments/requested changes, I think putting the SQL changes in the same schema as the EEG (physiological) tables does make sense in this case. You're right that these tables are only related to physiological files and cannot be applied to other types of files or modules, so it makes sense to rename the tables to make that relation clearer. I've made the requested changes :)

s.ID AS SessionID,
s.CenterID AS CenterID,
s.ProjectID AS ProjectID
s.ProjectID AS ProjectID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary white spaces

@@ -47,10 +47,17 @@ class ElectrophysiologyBrowserRowProvisioner
s.Visit_label AS Visit_Label,
MIN(pf.AcquisitionTime) AS Acquisition_Time,
MIN(pf.InsertTime) AS Insert_Time,
GROUP_CONCAT(DISTINCT pot.OutputTypeName) AS Links,
GROUP_CONCAT(DISTINCT CASE
WHEN pot.OutputTypeName='derivatives' THEN 'raw,derivative'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be WHEN pot.OutputTypeName='derivatives' THEN 'raw,derivatives' otherwise the type is unrecognized (sessions.inc.class only accept raw and derivatives as valid types).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Christine requested that I change all "derivatives" to singular. Is it alright if I change sessions.class.inc to take "raw" or "derivative" as valid output types instead to match?

Copy link
Contributor

@laemtl laemtl Mar 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to think that renaming the fields in the query is prone to mistakes as it introduces mismatches between the backend/frontend and the database naming convention. Ideally, the database entry should match but I don't know if changing it at this point is a good idea.

ELSE 'raw'
END) AS Links,
GROUP_CONCAT(DISTINCT CASE
WHEN pot.OutputTypeName='derivatives' THEN 'Derivative'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be WHEN pot.OutputTypeName='derivatives' THEN 'Derivatives' to be consistent with the row entries (since the recommended change above).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at Christine's requested changes above, she requested that I change all mentions of "Derivatives" to singular and not plural

Copy link
Contributor

@laemtl laemtl Mar 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Therefore the sessions class needs an update (and ideally the database entry: SQL/0000-00-05-ElectrophysiologyTables.sql).

name: 'type',
type: 'select',
options: {
Raw: 'Raw',
Copy link
Contributor

@laemtl laemtl Mar 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be more flexible to pass the options as props to stay consistent with the database state. (see how this is done for Site, Project). That way, if a new element is added in the table physiological_output_type, it will automatically be added in the filter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

GROUP_CONCAT(DISTINCT pot.OutputTypeName) AS Links,
GROUP_CONCAT(DISTINCT CASE
WHEN pot.OutputTypeName='derivatives' THEN 'raw,derivative'
ELSE 'raw'
Copy link
Contributor

@laemtl laemtl Mar 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works until a new type is added in OutputTypeName. It will fall in the else case and be assigned to 'raw'.
It's safer to change for ELSE pot.OutputTypeName

END) AS Links,
GROUP_CONCAT(DISTINCT CASE
WHEN pot.OutputTypeName='derivatives' THEN 'Derivative'
ELSE 'Raw'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here... this works until a new type is added in OutputTypeName. It will fall in the else case and be assigned to 'Raw'.

@@ -47,10 +47,17 @@ class ElectrophysiologyBrowserRowProvisioner
s.Visit_label AS Visit_Label,
MIN(pf.AcquisitionTime) AS Acquisition_Time,
MIN(pf.InsertTime) AS Insert_Time,
GROUP_CONCAT(DISTINCT pot.OutputTypeName) AS Links,
Copy link
Contributor

@laemtl laemtl Mar 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GROUP_CONCAT/DISTINCT combo prevents duplicates entries when a session contains multiple files of the same type (ex: 2 raw files will display only one raw link in the data table). For 2 files of mixed type, it will display raw twice in the links in the data table (since ''raw", and ''raw,derivative" are distinct).
Screenshot from 2021-03-19 19-22-59

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue has been resolved in the latest commit, and the picture in the PR description has been updated to show the new view!

@laemtl
Copy link
Contributor

laemtl commented Mar 20, 2021

I noticed the filter Type stopped working for entries containing multiple files:
In this case, type is a string containing all the values: 'derivative,raw', which doesn't match either derivative or raw.

{
"Site": "Ottawa",
"PSCID": "OTT174",
"DCCID": "300174",
"Project": "Pumpernickel",
"Visit Label": "V1",
"Acquisition Time": "2019-06-19 09:17:05",
"Insertion Time": "2019-08-21 15:10:13",
"Links": "derivative,raw",
"Type": "derivative,raw",
"SessionID": "174"
}

@christinerogers
Copy link
Contributor

@AlexandraLivadas how are you doing with these comments? Stuck anywhere?


-- Create annotation_archive which will store archives of all the annotation files for
-- Front-end download
CREATE TABLE `physiological_annotation_archive` (
Copy link
Contributor

@laemtl laemtl Apr 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TO DISCUSS - If the annotations need to be synchronized with user inputs, this table should maybe be deleted and the zip created on the fly when download is requested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point. This is the way that the pysiological files are handled in general, which is why I implemented it this way. You're right though that in this case, it does not make sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, let's follow the example of the .tgz created by the pipeline specifically as a downloadable package.
e.g. bids_imports/Face13_BIDSVersion_1.1.0/sub-OTT166/ses-V1/eeg/sub-OTT166_ses-V1_task-faceO_eeg.tgz
Basically the archive for annotations should be created/structured similarly.

Agreed this should be revisited and discussed when we come to adding/editing annotations in the module - e.g. are all .tgz updated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok in that case I will leave this table in, as that is how it's structured for the physiological tables/files.

Copy link
Contributor

@christinerogers christinerogers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work, @AlexandraLivadas

@driusan Could you please final review?

It's blocking another time-sensitive PR, thanks.

@laemtl
Copy link
Contributor

laemtl commented Apr 22, 2021

@AlexandraLivadas
Tests are failing since the last changes. Can you rebase and see if that helps? Otherwise, I suspect a MySQL problem.

@laemtl
Copy link
Contributor

laemtl commented Apr 23, 2021

@driusan The PR is now passing the tests.

@christinerogers
Copy link
Contributor

christinerogers commented Apr 23, 2021

Thanks @AlexandraLivadas and @laemtl
Ready for final review - @cmadjar I think this is good to go, but in case you want to re-review.

@driusan if you have time - thanks for looking at it when you can, this is blocking a few other PRs which are important for a mid-May grant deliverable.

@driusan driusan merged commit b6c59bb into aces:main Apr 27, 2021
driusan pushed a commit that referenced this pull request Apr 28, 2021
Re-enable and fix skipped tests in PR #7345.
AlexandraLivadas added a commit to AlexandraLivadas/Loris that referenced this pull request Jun 29, 2021
…ces#7345)

This contains an SQL patch to create new tables for the annotation features that will be added in the Electrophysiology Browser module. It also includes basic functionalities in the EEG Browser to support these derivatives, including a filter in the main menu and a download option for annotation files.
AlexandraLivadas pushed a commit to AlexandraLivadas/Loris that referenced this pull request Jun 29, 2021
Re-enable and fix skipped tests in PR aces#7345.
@ridz1208 ridz1208 added this to the 24.0.0 milestone Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocking PR should be prioritized because it is blocking the progress of another task Feature PR or issue introducing/requiring at least one new feature Passed Manual Tests PR has undergone proper testing by at least one peer Priority: High PR or issue should be prioritised over others for review and testing SQL PR contains SQL modifications such as schema changes and new SQL scripts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants