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

Add NIRS support to BIDS Validator #952

Merged
merged 48 commits into from
Aug 31, 2022
Merged

Conversation

rob-luke
Copy link
Member

@rob-luke rob-luke commented May 7, 2020

This PR is to add NIRS support as described in the NIRS BEP


Note:

  • Revert all links to custom branch for test data just before merging!!

@codecov
Copy link

codecov bot commented May 7, 2020

Codecov Report

Merging #952 (dfc83d6) into master (ee7d94c) will increase coverage by 0.19%.
The diff coverage is 95.12%.

@@            Coverage Diff             @@
##           master     bids-standard/legacy-validator#952      +/-   ##
==========================================
+ Coverage   83.36%   83.55%   +0.19%     
==========================================
  Files          91       91              
  Lines        3691     3758      +67     
  Branches     1123     1146      +23     
==========================================
+ Hits         3077     3140      +63     
- Misses        518      522       +4     
  Partials       96       96              
Impacted Files Coverage Δ
bids-validator/validators/nifti/nii.js 69.49% <ø> (ø)
bids-validator/validators/tsv/checkTypeCol.js 100.00% <ø> (ø)
bids-validator/utils/summary/collectModalities.js 91.66% <50.00%> (-1.82%) ⬇️
bids-validator/utils/type.js 90.25% <90.00%> (-0.01%) ⬇️
bids-validator/validators/json/json.js 100.00% <100.00%> (ø)
bids-validator/validators/tsv/tsv.js 93.85% <100.00%> (+0.55%) ⬆️
...ids-validator/validators/tsv/validateTsvColumns.js 52.53% <100.00%> (+0.30%) ⬆️
bids-validator/validators/events/hed.js 90.90% <0.00%> (+1.07%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@rob-luke
Copy link
Member Author

@sappelhoff is there a resident javascript expert I can request advice from regarding this PR? I am trying to implement the following logic from bids-standard/bids-specification#802 but I am unable to make it work.

Logic:

  • If the field ShortChannelCount is present in *_nirs.json file.
  • then, the column short_channel must be present in the *_channels.tsv file.

I have been trying to replicate some of the logic from PET (bids-standard/bids-validator@08d9a4e) but I am new to javascript and cant make sense of the logic. Any help is appreciated, even. link to similar functionality in the codebase may help put me on the right path.

@sappelhoff
Copy link
Member

I hope @rwblair can help with that. I once had a similar issue that would involve checking JSON contingent on TSV contents (so the other way around from your issue): https://github.com/bids-standard/bids-validator/issues/673

Right now, I don't know where to start with that unfortunately.

@rwblair
Copy link
Member

rwblair commented Jun 9, 2021

My apologies for the delay in response.

So pet_blood specifies 'requires_tsv_non_custom_columns' key/value for which tsv columns are required in its json schema spec:
https://github.com/bids-standard/bids-validator/blob/master/bids-validator/validators/json/schemas/pet_blood.json#L1

Here is the location in the tsv validator where the 'requires_tsv_non_custom_columns' fields are used to make sure the proper columns exist:
https://github.com/bids-standard/bids-validator/blob/c60daacf3dbb4cea5a07d5274947c366cf4c0e3a/bids-validator/validators/tsv/validateTsvColumns.js#L137

Here a specific value in a json field forces a specific TSV column to be required, but the NIRS situation is the reverse, a specific value somewhere in TSV forces a json field to become required.

I am thinking about how best to approach this and writing up some example code for the tsv validator that I'll push to this branch to see what you think.

@rob-luke
Copy link
Member Author

rob-luke commented Jun 9, 2021

My apologies for the delay in response.

Please don't apologise. We all have other aspects to our lives. I appreciate you taking a look at this problem. If you can push an example solution to this logic I can try and expand on that to each case where we need this behaviour. Thanks again

@rwblair
Copy link
Member

rwblair commented Jun 10, 2021

I added a new property to the json schema 'required_if_tsv_value_present':
https://github.com/bids-standard/bids-validator/blob/2b22d9884bdfca21d166abd1ec5442381b8ccd72/bids-validator/validators/json/schemas/nirs.json#L92

Specifies which column in the tsv to check against and which value should be present once. The I added additonal valdiation steps to validateTsvColumns that mirror how pet used their custom schema property. I rerused their error code it probably should be changed, BUT the evidence line there right now is probably good enough to give users an idea of whats going on:

https://github.com/bids-standard/bids-validator/blob/2b22d9884bdfca21d166abd1ec5442381b8ccd72/bids-validator/validators/tsv/validateTsvColumns.js#L201

@rob-luke how big are these tsv files typically? iteratting over the rows multiple times checking for specific values might become slow if they are massive.

I have not tested the code or written tests for it. Is there a good example dataset? Let me know what you think.

@rob-luke
Copy link
Member Author

Huge thanks @rwblair.

how big are these tsv files typically?

The not very big. My hardware has 50 channels. I imagine future devices could have 2-300 channels. There would be a practical upper limit to how many sensors you could fit on a head (think EEG).

checking for specific values might become slow if they are massive.

Lets worry about that when it happens. Lets get the code working correctly first, then optimise.

I have not tested the code or written tests for it. Is there a good example dataset?

Here is a dataset that I have been testing on: https://github.com/rob-luke/BIDS-NIRS-Tapping/tree/master

I added a ShortChannelCount in the nirs.json file locally and the validator throws this error...

image

Is there any way I can help you debug this issue?

Let me know what you think.

This is awesome. thank you so much!

@rob-luke
Copy link
Member Author

rob-luke commented Jul 8, 2021

Thanks @rwblair the code now runs and ensures the variable ShortChannelCount is greater than 0. But it does not yet ensure that the required column is in *_channels.tsv. I will spend some time to add some tests etc and see what I can figure out. Thanks for your help!

@rwblair
Copy link
Member

rwblair commented Jul 8, 2021

First batch of work committed last week or so left short_channel requirement out. The spec makes it seem as if it is always optional or recommended not required:
"If the field ShortChannelCount is populated, then the optional column short_channel may be used in *_channels.tsv to describe which channels were specified as short."

ShortChannelCount is listed as recommended.

from short_channel entry:
"Is the channel designated as short. The total number of channels listed as short channels should be stored in ShortChannelCount in *_fnirs.csv."

My last commit should throw an error if it ShortChannelCount is present but there is no short_channel column, if this is what we want to happen then the spec may need to be updated. I added a 'requires_tsv_non_custom_columns' property to the ShortChannelCount json schema entry specifying 'short_channel'.

For pet blood the tsv headers specified in 'requires_tsv_non_custom_columns' would only be evaluated if the json field was boolean, and set to true. I updated this logic to do this check if the field is boolean and its value is true, otherwise do the check if its 'truthy' in javascript, (not 0, false, null, etc).

Sorry I never responded with a theory of my first set of commits. Regarding testing, its much easier to debug the validator if you run it from the command-line. Notice the error from the compiled web version you posted doesn't show a filename or line number that corresponds to whats in the repository/uncompiled files. Is running the validator from the command line an option for you?

@rob-luke
Copy link
Member Author

rob-luke commented Jul 9, 2021

Hi @rwblair,

You are absolutely correct. I was getting confused. I was mixing up the spec and what I was wondering was possible with the validator. Thanks for sticking with me.

The spec makes it seem as if it is always optional or recommended not required:
"If the field ShortChannelCount is populated, then the optional column short_channel may be used in *_channels.tsv to describe which channels were specified as short."

You are correct. My apologies. The spec is correct, I was wrong.

Sorry I never responded with a theory of my first set of commits.

No worries, to be honest I have been kinda short on time lately too.

Regarding testing, its much easier to debug the validator if you run it from the command-line. Notice the error from the compiled web version you posted doesn't show a filename or line number that corresponds to whats in the repository/uncompiled files. Is running the validator from the command line an option for you?

I haven't tried the command line usage yet. I will try that next, thanks for the tip. I am new to this type of programming, so the tips are appreciated.

As next steps I will try and add some test data and tests. And try to understand your code 😉, I will try and be self sufficient, but if I get stuck again I may ping you again. Thanks for the help

@rwblair
Copy link
Member

rwblair commented Jul 9, 2021

So we probably want to have the short_channel thing be a warning instead of an error. As of right now there is now good way to indicate that using just the json schemas. We could imagine a new property in the json schemas "recommends_tsv_non_custom_columns" alongside "requires_tsv_non_custom_columns". It would be the same code as thevalidateJsonRequiredHeaders function just create a different Issue (Ideally we would just extend the existing function to be able to report both issues, or at least reuse the common code)

Feel free to ask as many questions as you want. I'm having trouble giving good instructions to help situate you but at least I can answer questions!

@rob-luke
Copy link
Member Author

Thanks @rwblair I will get back to this soon and will surely have some more questions. I appreciate you keeping this aligned with master!

@rob-luke
Copy link
Member Author

Some test data is now available at bids-standard/bids-examples#305

@rob-luke rob-luke force-pushed the nirs branch 3 times, most recently from a1fbdeb to 63af1f7 Compare January 31, 2022 02:22
two small fixes to correctly validate example NIRS dataset
Copy link
Member

@sappelhoff sappelhoff left a comment

Choose a reason for hiding this comment

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

just a note: the mne-bids CI is failing due to the nirs validator: https://github.com/mne-tools/mne-bids/runs/7000412391?check_suite_focus=true#step:15:465

it may be beneficial to look into whether this is a validator issue or an mne-bids nirs-specific issue.

@rob-luke
Copy link
Member Author

it may be beneficial to look into whether this is a validator issue or an mne-bids nirs-specific issue.

It is saying that the filename sub-01_ses-01_acq-01_optodes.tsv is not valid, which it should be. So I think its a validator issue to debug.

@rob-luke
Copy link
Member Author

rob-luke commented Jun 22, 2022

look into whether this is a validator issue

dd1f4f2 seems to have fixed the issue (see mne-tools/mne-bids#1020). However, I am not very confident about my regex skills. So if anyone can take a second look over the regex that would be greatly appreciated

https://github.com/bids-standard/bids-validator/blob/dd1f4f2cb60432533716111b13cda6bbee7dd2ef/bids-validator/bids_validator/rules/file_level_rules.json#L515

@rwblair
Copy link
Member

rwblair commented Jun 27, 2022

@rob-luke regex looks good, tested it out with a dataset with nirs with session and seemed to work. Updated the regex to match style of other rules that can match back or forward slashes for directory seperators.

@rob-luke
Copy link
Member Author

Thank you kindly @rwblair !!!

@sappelhoff sappelhoff marked this pull request as draft July 21, 2022 16:03
@sappelhoff sappelhoff added the BEP ongoing BIDS Extension Proposal label Jul 21, 2022
@rwblair rwblair marked this pull request as ready for review August 30, 2022 18:19
@rwblair rwblair changed the title WIP: Add NIRS support to BIDS Validator Add NIRS support to BIDS Validator Aug 30, 2022
@rwblair
Copy link
Member

rwblair commented Aug 30, 2022

I believe this is ready. I'm going to let it sit for another day pending changes in the specification PR.

@sappelhoff
Copy link
Member

@rwblair in mne-tools/mne-bids#1061 we now have a file like this failing validation:

./sub-01/ses-01/nirs/sub-01_ses-01_acq-01_coordsystem.json

https://github.com/mne-tools/mne-bids/runs/8116368480?check_suite_focus=true#step:15:470

image

I believe this should pass 🤔 did the recent changes introduce an issue? cc @rob-luke

@hoechenberger
Copy link
Collaborator

@sappelhoff It's missing a task entity, no?

@sappelhoff
Copy link
Member

a coordsystem shouldn't be task dependent AFAIK 🤔

if adding a task to the file would make it valid, then something's off in the validator 🤔

@rwblair
Copy link
Member

rwblair commented Aug 31, 2022

@sappelhoff try with that latest commit. Silly issue in the regex that covers coordsystem suffix.

@sappelhoff
Copy link
Member

This seems to have fixed it, thanks a lot, @rwblair!

@rwblair rwblair merged commit 1c95985 into bids-standard:master Aug 31, 2022
@rob-luke
Copy link
Member Author

rob-luke commented Sep 1, 2022

🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉
Thank you @sappelhoff @rwblair @nellh @robertoostenveld @hoechenberger !!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BEP ongoing BIDS Extension Proposal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants