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

[BUG] 'pattern' error during BUILDING JOB: slice timing correction #967

Open
4 of 9 tasks
JacMatu opened this issue Mar 27, 2023 · 38 comments · Fixed by #969
Open
4 of 9 tasks

[BUG] 'pattern' error during BUILDING JOB: slice timing correction #967

JacMatu opened this issue Mar 27, 2023 · 38 comments · Fixed by #969
Labels
bug 🐛 Something isn't working

Comments

@JacMatu
Copy link

JacMatu commented Mar 27, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Operating system

  • Linux
  • Mac
  • Windows

Operating system version

  • Mac OS Version 13 "ventura"

SPM 12 version

  • 7771
  • 7487
  • 7219

Platform

  • MATLAB
  • Octave

Platform version

  • MATLAB 2019a

bidspm version

v3.0.0

bidspm branch / commit number

Expected Behavior

bidspm basic preprocessing called with

bidspm(bids_dir, output_dir, 'subject', ...
       'participant_label', subject_label, ...
       'action', 'preprocess', ...
       'task', task_label, ...
       'ignore', {'qa'}, ... 
       'space', {'individual', 'IXI549Space'}, ...
       'fwhm', 2);

Current Behavior & Error message

'pattern' requires one of the following:
  Antenna Toolbox
  Communications Toolbox
  Phased Array System Toolbox

Error in getAcquisitionTime (line 28)
                   '\n- slice timing: ' pattern], ...

Error in setBatchSTC (line 66)
  acquisitionTime = getAcquisitionTime(sliceOrder, repetitionTime);

Error in bidsSTC (line 47)
      matlabbatch = setBatchSTC(matlabbatch, BIDS, opt, regexify(subLabel));

Error in bidspm>preprocess (line 251)
      bidsSTC(opt);

Error in bidspm>executeAction (line 142)
      preprocess(args);

Error in bidspm (line 77)
    executeAction(action, args);

Error in step_1_bidspm_preprocess (line 24)
bidspm(bids_dir, output_dir, 'subject', ...

Anything else?

error_2023-03-27T18-10.log

@JacMatu JacMatu added the bug 🐛 Something isn't working label Mar 27, 2023
@github-actions
Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

@Remi-Gau
Copy link
Contributor

Ok defo a bug but this also means there is something wrong with your slice timing info.
Can you send me the json of one of your bold file?

@JacMatu
Copy link
Author

JacMatu commented Mar 27, 2023 via email

@Remi-Gau
Copy link
Contributor

@all-contributors add @JacMatu for bug, userTesting

@allcontributors
Copy link
Contributor

@Remi-Gau

I've put up a pull request to add @JacMatu! 🎉

@JacMatu
Copy link
Author

JacMatu commented Apr 18, 2023 via email

@JacMatu
Copy link
Author

JacMatu commented Apr 18, 2023 via email

@Remi-Gau
Copy link
Contributor

I think you will need to drop the log manually in the github windows and not just by email.

Also if you have several runs with different slice timing values:

  • the bids validator should throw a warning
  • if bidspm throws an error then that's good because there is no way it can know what to do it this case: meaning you are going to have to figure out which slice timing the is the good one.

@Remi-Gau
Copy link
Contributor

send me the log in any case

@Remi-Gau
Copy link
Contributor

bidspm should throw a warning and I wonder if SPM won't crash after that:

logger('WARNING', msg, 'id', id, 'filename', mfilename(), 'options', opt);

@JacMatu
Copy link
Author

JacMatu commented Apr 18, 2023

@Remi-Gau
Copy link
Contributor

thanks
can you also send me the bold.json files of a "normal" run and that of a "abnormal" run in terms of slice timing values

@Remi-Gau Remi-Gau reopened this Apr 18, 2023
@JacMatu
Copy link
Author

JacMatu commented Apr 18, 2023

Ok, I've found even a third set of values, which is extremely puzzling since it was all done with the same protocol.
(I'm compressing them since guthub doesn't allow .json files.

Run01 = rare, weird case of "abnormality"
Run02 = popular "abnormal" timings
Run03 = dominant "normal" timings...

All in the same subject... I used dcm2bids for conversion, I'm not sure if that can cause some issues.

matuszewski_bold_jsons.zip

@Remi-Gau
Copy link
Contributor

Thanks for those.
I can try to implement further checks and better error messages in bidspm to catch those inconsistencies.
I could also try to implement the slice timing differently so that it only uses the slice timing value of a given run to process it, instead of assuming that all the runs being preprocessed have the same slice timing values.
But I am kinda reluctant to do that because I think that it is valid assumption to make, and that if this assumption is not fullfiled then something is off.
what do you think?

@JacMatu
Copy link
Author

JacMatu commented Apr 18, 2023

Absolutely, I see no reason why copied protocol would have different timings between runs and subjects in a random manner. If that would always be the same run# or group then maybe that would be experimentor's / technician's error in setting up the protocol... But this?

I have no idea what's going on...

@JacMatu
Copy link
Author

JacMatu commented Apr 18, 2023

These differences are literally in 0.0025 s, I doubt it will affect the BOLD signal, but it's annoying in the BIDS perfect world...

@Remi-Gau
Copy link
Contributor

at this stage I am more into: if even the scanner sequence are adding some jitter just for fun what hope do we have at reproducible results... 🤷🏾

@JacMatu
Copy link
Author

JacMatu commented Apr 18, 2023

Yeah. I kind of see two solutions for now (to quickly move with the analyses since I want to learn models and mvpa too)

  1. ignore slice timing corrections in the preprocessing - what would be the fastest way with BIDSPM?

  2. change the values in json files, assuming that this is a weird bug. But I really don't want to manually change values in json files, this seems fishy.

@JacMatu
Copy link
Author

JacMatu commented Apr 18, 2023

So the weird thing is that
a) bidsvalidator has no issues with differences in jsons regarding the slice timing, not even a warning
b) bidspm preprocesses some of the subjects who have single abnormal run without an issue, but spits out errors for others. I'll look into that more tomorrow

@Remi-Gau
Copy link
Contributor

closing for now

reopen or open an new issue if something related reappears

@JacMatu
Copy link
Author

JacMatu commented May 8, 2023

Follow up on the issue:
40 subjects in the database
23 had "deviant" slice timings in at least 1 of 6 runs
bidspm preprocessing worked for 19 of them without any errors (+ all 17 "standard subjects)
error_2023-05-08T22-57.log

Only 4 are left with identical error of Acquisition time cannot be < to any slice timing value.

If I'm not mistaken (I have checked other random "deviant" subjects), this issue might be related to the fact that these subjects have "deviant" values in the run01. I.e., there are other subjects with identical slice timings e.g. in run05 (but their run01 is "typical") and there were no errors during preprocessing. Is it possible that run01 servers as some sort of reference or value check and then everything is assumed to be constant across runs?

@Remi-Gau
Copy link
Contributor

Remi-Gau commented May 9, 2023

there is kind of something like this:

% all slice timing should be the same,
% so we check against the first only
sliceOrder = sliceTiming{1};
for i = 1:numel(sliceTiming)
if sliceTiming{i} ~= sliceOrder
sliceOrder = [];
msg = sprintf('Inconsistent slice timing found for filter:\n%s.\n\n', ...
bids.internal.create_unordered_list(filter));
id = 'inconsistentSliceTimingValues';
logger('WARNING', msg, 'id', id, 'filename', mfilename(), 'options', opt);
return
end
end

this checks that all runs have the same slice timing values: so it checks each run against the first one

but what puzzles me is that the error you report happens here:

acquisitionTime = getAcquisitionTime(sliceOrder, repetitionTime);

where as the check that all runs have the same values happens before:

sliceOrder = getAndCheckSliceOrder(BIDS, opt, filter);

so if some of your runs have different slice timing, this should have been caught earlier

are you using the lastest version that is on the main branch?

@JacMatu
Copy link
Author

JacMatu commented May 9, 2023

No, I'm using the fix-acq_time_error branch from Your remote that you created when I first opened that issue

@JacMatu
Copy link
Author

JacMatu commented May 12, 2023

Hi Remi, just to follow up: I've tried to run this analyses with up-to-date main branch bidspm and the error is the same.
error_2023-05-12T12-47.log

@Remi-Gau Remi-Gau reopened this May 12, 2023
@Remi-Gau
Copy link
Contributor

Do you have this data somewhere I can check it? On GIN?

@JacMatu
Copy link
Author

JacMatu commented May 12, 2023

I have a toy repo which served as a datalad 101 on gin, what do you need? Raw data from 1 subject that is problematic and one that is not? Or something else too?

@JacMatu
Copy link
Author

JacMatu commented May 12, 2023

Gin repo should be here
https://gin.g-node.org/JacMatu/GIN_TOY_REPO_JM
(I've added you as a collaborator),
RAW/sub-blind01 is working fine
RAW/sub-blind12 produces this error

Sorry it's not a perfect yoda structure, let me know if you need anything else

@Remi-Gau
Copy link
Contributor

that's perfect
if I need more I will ping you

@Remi-Gau
Copy link
Contributor

@JacMatu
you probably want to make your BIDS dataset valid to avoid being in a world of pain later

@Remi-Gau
Copy link
Contributor

at least add a dataset_description.json: bidspm cannot even start for me even if I use 'skip_validation', false

@Remi-Gau
Copy link
Contributor

In case you are lazy like me, there is a function in bids matlab to create an empty dataset_description.json you can then fill in:

ds_desc = bids.Description();
ds_desc.write(fullfile(pwd, 'GIN_TOY_REPO_JM');

@Remi-Gau
Copy link
Contributor

doing some basic QA

indeed the slice timing values are different for many runs

bids_dir = fullfile(this_dir, '..', 'GIN_TOY_REPO_JM');
BIDS = bids.layout(bids_dir);

%%
subjects = bids.query(BIDS, 'subjects');

%%
clc
for i_sub = 1:numel(subjects)
    meta = bids.query(BIDS, 'metadata', ...
                      'sub', subjects{i_sub}, ...
                      'suffix', 'bold', ...
                      'target', 'SliceTiming');

    values = [];
    equal_to_run_1 = [];
    for i = 1:numel(meta)
        values(:,i) = meta{i};
        equal_to_run_1(:,i) = meta{i} == meta{1}; %#ok<*SAGROW>
    end

    fprintf('\nSliceTiming subject: %s\n', subjects{i_sub})
    disp(values);
    fprintf('\nEqual to run 1\n')
    disp(equal_to_run_1);

end

Gives me:

each columns are the values from one run

the second output for each subject has 1 if the value on a given row is equal to that same value for run 1: in brief ideally it should all be 1 and bidspm should crash if any value is 0

apparently it does not crash for the first subject, so some fixing is required

SliceTiming subject: blind01
         0         0         0         0         0         0
    0.0575    0.0550    0.0575    0.0575    0.0575    0.0575
    0.1150    0.1125    0.1150    0.1150    0.1150    0.1150
    0.1700    0.1700    0.1725    0.1725    0.1725    0.1725
    0.2275    0.2275    0.2300    0.2300    0.2300    0.2300
    0.2850    0.2850    0.2875    0.2875    0.2875    0.2875
    0.3425    0.3425    0.3450    0.3450    0.3450    0.3450
    0.4000    0.4000    0.4025    0.4025    0.4025    0.4025
    0.4575    0.4575    0.4575    0.4600    0.4600    0.4600
    0.5150    0.5150    0.5150    0.5175    0.5175    0.5175
    0.5725    0.5725    0.5725    0.5750    0.5750    0.5750
    0.6300    0.6300    0.6300    0.6325    0.6325    0.6325
    0.6875    0.6875    0.6875    0.6900    0.6900    0.6900
    0.7450    0.7450    0.7450    0.7475    0.7475    0.7475
    0.8025    0.8025    0.8025    0.8025    0.8050    0.8050
    0.8600    0.8600    0.8600    0.8600    0.8625    0.8625
    0.9175    0.9175    0.9175    0.9175    0.9200    0.9175
    0.9750    0.9750    0.9750    0.9750    0.9750    0.9750
    1.0325    1.0300    1.0325    1.0325    1.0325    1.0325
    1.0900    1.0875    1.0900    1.0900    1.0900    1.0900
    1.1450    1.1450    1.1475    1.1475    1.1475    1.1475
    1.2025    1.2025    1.2050    1.2050    1.2050    1.2050
    1.2600    1.2600    1.2625    1.2625    1.2625    1.2625
    1.3175    1.3175    1.3200    1.3200    1.3200    1.3200
    1.3750    1.3750    1.3775    1.3775    1.3775    1.3775
    1.4325    1.4325    1.4325    1.4350    1.4350    1.4350
    1.4900    1.4900    1.4900    1.4925    1.4925    1.4925
    1.5475    1.5475    1.5475    1.5500    1.5500    1.5500
    1.6050    1.6050    1.6050    1.6075    1.6075    1.6075
    1.6625    1.6625    1.6625    1.6650    1.6650    1.6650
    1.7200    1.7200    1.7200    1.7225    1.7225    1.7225
    1.7775    1.7775    1.7775    1.7800    1.7800    1.7800
    1.8350    1.8350    1.8350    1.8350    1.8375    1.8375
    1.8925    1.8925    1.8925    1.8925    1.8950    1.8950
    1.9500    1.9500    1.9500    1.9500    1.9525    1.9500

Equal to run 1
     1     1     1     1     1     1
     1     0     1     1     1     1
     1     0     1     1     1     1
     1     1     0     0     0     0
     1     1     0     0     0     0
     1     1     0     0     0     0
     1     1     0     0     0     0
     1     1     0     0     0     0
     1     1     1     0     0     0
     1     1     1     0     0     0
     1     1     1     0     0     0
     1     1     1     0     0     0
     1     1     1     0     0     0
     1     1     1     0     0     0
     1     1     1     1     0     0
     1     1     1     1     0     0
     1     1     1     1     0     1
     1     1     1     1     1     1
     1     0     1     1     1     1
     1     0     1     1     1     1
     1     1     0     0     0     0
     1     1     0     0     0     0
     1     1     0     0     0     0
     1     1     0     0     0     0
     1     1     0     0     0     0
     1     1     1     0     0     0
     1     1     1     0     0     0
     1     1     1     0     0     0
     1     1     1     0     0     0
     1     1     1     0     0     0
     1     1     1     0     0     0
     1     1     1     0     0     0
     1     1     1     1     0     0
     1     1     1     1     0     0
     1     1     1     1     0     1

SliceTiming subject: blind12
         0         0         0         0         0         0
    0.0575    0.0575    0.0550    0.0575    0.0575    0.0575
    0.1150    0.1150    0.1125    0.1150    0.1150    0.1150
    0.1725    0.1725    0.1700    0.1725    0.1725    0.1725
    0.2300    0.2300    0.2275    0.2300    0.2300    0.2300
    0.2875    0.2875    0.2850    0.2850    0.2875    0.2875
    0.3450    0.3450    0.3425    0.3425    0.3450    0.3450
    0.4025    0.4025    0.4000    0.4000    0.4025    0.4000
    0.4600    0.4600    0.4575    0.4575    0.4600    0.4575
    0.5175    0.5175    0.5150    0.5150    0.5175    0.5150
    0.5750    0.5750    0.5725    0.5725    0.5750    0.5725
    0.6325    0.6325    0.6300    0.6300    0.6325    0.6300
    0.6900    0.6900    0.6875    0.6875    0.6900    0.6875
    0.7475    0.7475    0.7450    0.7450    0.7475    0.7450
    0.8050    0.8050    0.8025    0.8025    0.8050    0.8025
    0.8625    0.8600    0.8600    0.8600    0.8600    0.8600
    0.9200    0.9175    0.9175    0.9175    0.9175    0.9175
    0.9775    0.9750    0.9750    0.9750    0.9750    0.9750
    1.0325    1.0325    1.0325    1.0325    1.0325    1.0325
    1.0900    1.0900    1.0875    1.0900    1.0900    1.0900
    1.1475    1.1475    1.1450    1.1475    1.1475    1.1475
    1.2050    1.2050    1.2025    1.2050    1.2050    1.2050
    1.2625    1.2625    1.2600    1.2625    1.2625    1.2625
    1.3200    1.3200    1.3175    1.3175    1.3200    1.3200
    1.3775    1.3775    1.3750    1.3750    1.3775    1.3775
    1.4350    1.4350    1.4325    1.4325    1.4350    1.4325
    1.4925    1.4925    1.4900    1.4900    1.4925    1.4900
    1.5500    1.5500    1.5475    1.5475    1.5500    1.5475
    1.6075    1.6075    1.6050    1.6050    1.6075    1.6050
    1.6650    1.6650    1.6625    1.6625    1.6650    1.6625
    1.7225    1.7225    1.7200    1.7200    1.7225    1.7200
    1.7800    1.7800    1.7775    1.7775    1.7800    1.7775
    1.8375    1.8375    1.8350    1.8350    1.8375    1.8350
    1.8950    1.8925    1.8925    1.8925    1.8925    1.8925
    1.9525    1.9500    1.9500    1.9500    1.9500    1.9500

Equal to run 1
     1     1     1     1     1     1
     1     1     0     1     1     1
     1     1     0     1     1     1
     1     1     0     1     1     1
     1     1     0     1     1     1
     1     1     0     0     1     1
     1     1     0     0     1     1
     1     1     0     0     1     0
     1     1     0     0     1     0
     1     1     0     0     1     0
     1     1     0     0     1     0
     1     1     0     0     1     0
     1     1     0     0     1     0
     1     1     0     0     1     0
     1     1     0     0     1     0
     1     0     0     0     0     0
     1     0     0     0     0     0
     1     0     0     0     0     0
     1     1     1     1     1     1
     1     1     0     1     1     1
     1     1     0     1     1     1
     1     1     0     1     1     1
     1     1     0     1     1     1
     1     1     0     0     1     1
     1     1     0     0     1     1
     1     1     0     0     1     0
     1     1     0     0     1     0
     1     1     0     0     1     0
     1     1     0     0     1     0
     1     1     0     0     1     0
     1     1     0     0     1     0
     1     1     0     0     1     0
     1     1     0     0     1     0
     1     0     0     0     0     0
     1     0     0     0     0     0

@Remi-Gau
Copy link
Contributor

what I think I am going to do is to modify how the slice time correction is run: I will run one job per run if not all runs have the same slice timing, but it will defo throw a warning

@Remi-Gau
Copy link
Contributor

that means that slice timing will be run on your data but you should probably figure out why your data has different slice timing for different runs

@JacMatu
Copy link
Author

JacMatu commented May 12, 2023

Thank you Remi, I'll try to get in touch with physicists from my previous lab on that.
In the meantime, should I re-run the preprocessing for everyone with slice timings performed run-by-run?

My main folder goes through the BIDS validator without an error, sorry I just copied 2 subjects to the gin repo to share with you.

@Remi-Gau
Copy link
Contributor

Thank you Remi, I'll try to get in touch with physicists from my previous lab on that. In the meantime, should I re-run the preprocessing for everyone with slice timings performed run-by-run?

I suspect you will have to re-run your preprocessing for everyone indeed.

Once again the differences are not big so I would be surprised if this made a difference in the end. But maybe just to make you can make sure that things were done right.

My main folder goes through the BIDS validator without an error, sorry I just copied 2 subjects to the gin repo to share with you.

ha OK I wondering how you were getting bidspm started otherwise. 😮

@JacMatu
Copy link
Author

JacMatu commented May 12, 2023

Ok, should be easier when it works for every subject instead of trying to find a pattern or errors like a madman.

Let me know if that's something that I should change in bidspm config locally or do you plan to have a dedicated branch with a different slice timing approach that you described.

@Remi-Gau
Copy link
Contributor

most likely I will open a PR to make bidspm smarter and do this kind of thing automatically, so the only thing you should have to do is update bidspm and run it

@Remi-Gau Remi-Gau modified the milestone: v3.1.0 Jun 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants