Donders-Institute / bidscoin

BIDScoin converts your source-level neuroimaging data to BIDS
https://bidscoin.readthedocs.io
GNU General Public License v3.0
131 stars 35 forks source link

Can I use dynamic value to fill in a suffix #188

Closed mateuszpawlik closed 1 year ago

mateuszpawlik commented 1 year ago

I tried to use a dynamic value to fill in a suffix value, for example, use <SeriesDescription:anat-(.*?)_ses> to retrieve T1w from anat-T1w_ses-B_acq-T1wHCPLI SeriesDescription. BIDScoin creates a drop-down for a suffix with one value being <SeriesDescription:anat-(.*?)_ses>.

I don't know if it's an expected behavior. This feature works as expected for other fields like acq.

marcelzwiers commented 1 year ago

Interesting use case that I haven't considered so far. I've just made a small patch, can you test it?

mateuszpawlik commented 1 year ago

21be19e had some errors. I'm building 24c48ce

mateuszpawlik commented 1 year ago

I can't execute bidsmapper. Here's some relevant output lines:

WARNING | Invalid run-item with suffix: "<SeriesDescription:anat-(.*?)_ses>" (anat -> sub--unknown/ses--unknown/DICOM_anat_id001)

and

Traceback (most recent call last):
  File "/usr/local/bin/bidsmapper", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.9/dist-packages/bidscoin/bidsmapper.py", line 266, in main
    bidsmapper(rawfolder    = args.sourcefolder,
  File "/usr/local/lib/python3.9/dist-packages/bidscoin/bidsmapper.py", line 163, in bidsmapper
    mainwin = bidseditor.MainWindow(bidsfolder, bidsmap_new, template)
  File "/usr/local/lib/python3.9/dist-packages/bidscoin/bidseditor.py", line 132, in __init__
    self.set_tab_bidsmap(dataformat)
  File "/usr/local/lib/python3.9/dist-packages/bidscoin/bidseditor.py", line 354, in set_tab_bidsmap
    self.update_subses_samples(self.output_bidsmap, dataformat)
  File "/usr/local/lib/python3.9/dist-packages/bidscoin/bidseditor.py", line 475, in update_subses_samples
    if self.datasource.dynamicvalue(run['bids'].get('suffix'), True, True) in bids.get_derivatives(datatype):
AttributeError: 'MainWindow' object has no attribute 'datasource'

This happens also without using a dynamic value for a suffix.

marcelzwiers commented 1 year ago

It's actually the bidseditor that crashes. I just fixed it in f406021adc3f23e2e1c08a620b7424a24d04f6d2 (hopefully, because the bidseditor is not covered by my pytests :-))

mateuszpawlik commented 1 year ago

It seems to work but the warning is still there:

WARNING | Invalid run-item with suffix: "<SeriesDescription:anat-(.*?)_ses>" (anat -> sub--unknown/ses--unknown/DICOM_anat_id001)
marcelzwiers commented 1 year ago

Yes, I was expecting that a bit. When the template bidsmap is loaded, it is checked for BIDS validity. However, the run-items in the template don't have associated data sources, which are needed to update the values dynamically. I'll see if I can handle it a bit more gracefully

mateuszpawlik commented 1 year ago

Maybe it is the right way. It's an advanced feature.

Many thanks for the implementation. I'll continue tomorrow with the testing.

marcelzwiers commented 1 year ago

Should be better now

mateuszpawlik commented 1 year ago

I'm not sure what exactly to check because the warning is the same.

marcelzwiers commented 1 year ago

The warning should be gone now.... Did you use the latest code?

mateuszpawlik commented 1 year ago

I built it again, just to be sure, and the warning is still there :thinking:

marcelzwiers commented 1 year ago

Ok, don't know for sure if it really helps but I made another fix

mateuszpawlik commented 1 year ago

With cbf56d0 the warning is gone.

I only see INFO | Could not validate every run-item in the bidsmap that could be relevant but not necessarily.

marcelzwiers commented 1 year ago

That is intended (but indeed a bit verbose) behaviour, it means that the dynamic suffix could not be checked against the BIDS schema