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

ENH: Use BIDS URIs to track Sources in sidecars #3255

Merged
merged 27 commits into from
Mar 22, 2024

Conversation

tsalo
Copy link
Collaborator

@tsalo tsalo commented Mar 11, 2024

Closes #3252. This is just a first pass- it only modifies the RawSources for now. I can add the immediate Sources in another PR (this'll require a lot more effort).

Changes proposed in this pull request

  • Add DatasetLinks field to the dataset_description.json
    • The input dataset is called raw
    • Any other datasets supplied through --derivatives are automatically named deriv-<index>. We might want to support named derivatives at some point.
  • Replace BIDS-relative paths in RawSources fields with BIDS-URIs.
  • Change RawSources to Sources in the sidecar files, since RawSources is deprecated.

Documentation that should be reviewed

I'll probably need to update the documentation, but haven't yet.

Copy link

codecov bot commented Mar 11, 2024

Codecov Report

Attention: Patch coverage is 93.33333% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 73.60%. Comparing base (c46c893) to head (7e73f04).
Report is 1 commits behind head on master.

Files Patch % Lines
fmriprep/config.py 80.00% 2 Missing ⚠️
fmriprep/utils/bids.py 88.88% 2 Missing ⚠️
fmriprep/cli/run.py 0.00% 1 Missing ⚠️
fmriprep/interfaces/bids.py 96.77% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3255      +/-   ##
==========================================
+ Coverage   73.24%   73.60%   +0.36%     
==========================================
  Files          54       56       +2     
  Lines        4164     4240      +76     
==========================================
+ Hits         3050     3121      +71     
- Misses       1114     1119       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tsalo
Copy link
Collaborator Author

tsalo commented Mar 13, 2024

I'm stumped. I can't figure out why config.execution.dataset_links isn't working.

Copy link
Collaborator

@mgxd mgxd left a comment

Choose a reason for hiding this comment

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

hey @tsalo - took a quick look through to try to help get you unstuck

fmriprep/interfaces/bids.py Outdated Show resolved Hide resolved
fmriprep/interfaces/bids.py Outdated Show resolved Hide resolved
fmriprep/interfaces/bids.py Outdated Show resolved Hide resolved
fmriprep/interfaces/bids.py Outdated Show resolved Hide resolved
fmriprep/utils/bids.py Outdated Show resolved Hide resolved
fmriprep/utils/bids.py Outdated Show resolved Hide resolved
fmriprep/workflows/bold/outputs.py Outdated Show resolved Hide resolved
fmriprep/workflows/bold/outputs.py Outdated Show resolved Hide resolved
fmriprep/workflows/bold/outputs.py Outdated Show resolved Hide resolved
fmriprep/workflows/bold/outputs.py Outdated Show resolved Hide resolved
@tsalo
Copy link
Collaborator Author

tsalo commented Mar 14, 2024

It's working! Thanks @mgxd!

I have a few ideas for next steps:

  1. Unit test of BIDSURI, as you recommended.
  2. Modify BIDSURI to accept a numinputs parameter and populate in[i] inputs, similar to Nipype's Merge interface.
    • This way, we can provide filenames from different sources without having to merge them.
  3. Return DerivativesDataSink out_files from some output workflows to pass along to others.
    • For example, take the output file from ds_bold_native_wf and pass it along to ds_volumes_wf.
    • Actually tracking down each proximal source is probably going to take a bit of effort.

@tsalo tsalo marked this pull request as ready for review March 21, 2024 16:29
@tsalo
Copy link
Collaborator Author

tsalo commented Mar 21, 2024

I have the unit test implemented, as well as a more flexible BIDSURI class. I think tracking immediate source files should happen in a future PR.

@tsalo tsalo requested review from mgxd and effigies March 21, 2024 16:31
Copy link
Collaborator

@mgxd mgxd left a comment

Choose a reason for hiding this comment

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

Nice, looks pretty good - just one question on the BIDURI implementation

fmriprep/interfaces/bids.py Show resolved Hide resolved
@effigies
Copy link
Member

From the artifacts, full-run/sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-coreg_boldref.json has:

{
  "Sources": [
    "/scratch/fmriprep_24_0_wf/sub_01_wf/bold_task_mixedgamblestask_run_01_wf/bold_fit_wf/hmc_boldref_wf/gen_avg/sub-01_task-mixedgamblestask_run-01_bold_average.nii.gz"
  ]
}

Possibly we were already screwing this up, but this seems worth fixing.

@tsalo
Copy link
Collaborator Author

tsalo commented Mar 22, 2024

@effigies I took a crack at it. I'll fix any bugs that come up in the CI.

@tsalo
Copy link
Collaborator Author

tsalo commented Mar 22, 2024

Aha!

{
  "Sources": [
    "bids::sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-hmc_boldref.nii.gz"
  ]
}

@effigies
Copy link
Member

One last one:

sub-02/func/sub-02_task-cuedSGT_run-01_desc-brain_mask.json

{
  "Sources": [
    "bids:raw:sub-02/func/sub-02_task-cuedSGT_run-01_echo-1_bold.nii.gz",
    "bids:raw:sub-02/func/sub-02_task-cuedSGT_run-01_echo-2_bold.nii.gz",
    "bids:raw:sub-02/func/sub-02_task-cuedSGT_run-01_echo-3_bold.nii.gz",
    "/scratch/fmriprep_24_0_wf/sub_02_wf/bold_task_cuedSGT_run_01_echo_1_wf/bold_fit_wf/bold_hmc_wf/fsl2itk/mat2itk.txt",
    "bids::sub-02/func/sub-02_task-cuedSGT_run-01_from-boldref_to-auto00000_mode-image_xfm.txt"
  ]
}

@effigies
Copy link
Member

This is awesome. Thanks so much for taking the time to work on this.

@effigies effigies changed the title Use BIDS URIs to track Sources in sidecars ENH: Use BIDS URIs to track Sources in sidecars Mar 22, 2024
@effigies effigies added this to the 24.0.0 milestone Mar 22, 2024
@tsalo
Copy link
Collaborator Author

tsalo commented Mar 22, 2024

I can't figure out what's going on with ds005. It's failing but I'm not seeing any crash files in the artifacts.

@effigies
Copy link
Member

Fun:

Traceback (most recent call last):
  File "/opt/conda/envs/fmriprep/lib/python3.11/multiprocessing/forkserver.py", line 274, in main
    code = _serve_one(child_r, fds,
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/fmriprep/lib/python3.11/multiprocessing/forkserver.py", line 313, in _serve_one
    code = spawn._main(child_r, parent_sentinel)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/fmriprep/lib/python3.11/multiprocessing/spawn.py", line 131, in _main
    prepare(preparation_data)
  File "/opt/conda/envs/fmriprep/lib/python3.11/multiprocessing/spawn.py", line 246, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "/opt/conda/envs/fmriprep/lib/python3.11/multiprocessing/spawn.py", line 297, in _fixup_main_from_path
    main_content = runpy.run_path(main_path,
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen runpy>", line 291, in run_path
  File "<frozen runpy>", line 98, in _run_module_code
  File "<frozen runpy>", line 88, in _run_code
  File "/opt/conda/envs/fmriprep/bin/fmriprep", line 5, in <module>
    from fmriprep.cli.run import main
  File "/opt/conda/envs/fmriprep/lib/python3.11/site-packages/fmriprep/cli/run.py", line 25, in <module>
    from .. import config
  File "/opt/conda/envs/fmriprep/lib/python3.11/site-packages/fmriprep/config.py", line 378, in <module>
    class execution(_Config):
  File "/opt/conda/envs/fmriprep/lib/python3.11/site-packages/fmriprep/config.py", line 442, in execution
    work_dir = Path('work').absolute()
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/fmriprep/lib/python3.11/pathlib.py", line 979, in absolute
    return self._from_parts([self.cwd()] + self._parts)
                             ^^^^^^^^^^
  File "/opt/conda/envs/fmriprep/lib/python3.11/pathlib.py", line 907, in cwd
    return cls(os.getcwd())
               ^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory

Let's hope this is just a weird one-off. Rerunning.

@effigies
Copy link
Member

I think the error is actually #3256. Not sure why the error text is hidden, but nothing in this PR seems to be causing any error.

@effigies effigies merged commit 6f8c965 into nipreps:master Mar 22, 2024
16 of 17 checks passed
effigies added a commit that referenced this pull request Jun 17, 2024
24.0.0 (June 17, 2024)

New feature release in the 24.0.x series.

This release is an incremental improvement on 23.2.x, with some
fixes for bugs discovered in the updated workflow.

New features include separation of HTML reports by session for subjects
with many BOLD runs, a new ``--fs-no-resume`` option to improve interoperability
with less typical FreeSurfer directories, such as those generated by longitudinal
FreeSurfer or FastSurfer, and adoption of DatasetLinks and BIDS-URIs, to follow
the recommendations of recent versions of BIDS.

With thanks to Dimitri Papadopoulos, Basile Pinsard, Celine Provins, Taylor Salo
and Wang Hao-Ting for their contributions!

* FIX: Add "double" type to allowed DisplacementFieldTransform (#3287)
* FIX: Require recent templateflow, select correct aparc dseg.tsv (#3256)
* FIX: Ensure proper templates are retrieved with sloppy (#3251)
* FIX: Delete summary from functional report when separated by sessions (#3223)
* FIX: Support lists in bids filter file containing ``null`` or ``*`` (#3215)
* FIX: Re-enable anat fasttrack for dataset without t1w (#3202)
* ENH: Use BIDSURI in init_ds_boldmask_wf (#3297)
* ENH: Add templateflow to DatasetLinks (#3267)
* ENH: Track proximal sources of functional GIFTIs (#3263)
* ENH: Support named derivative paths (#3264)
* ENH: Track Sources for standard-space outputs (#3262)
* ENH: Add --fs-no-resume option to reuse existing FreeSurfer outputs without resuming (#3142)
* ENH: Use BIDS URIs to track Sources in sidecars (#3255)
* ENH: Ignore unselected subjects in BIDSLayoutIndexer (#3236)
* ENH: Add metadata for motion parameters (#3245)
* ENH: Separate anatomical and functional reports per session for densely sampled dataset (#3191)
* ENH: Leverage T2w if available for BOLD -> anat coregistration (#3208)
* RF: Fix ITK warp conversion to nitransforms format (#3300)
* RF: Load report assembler from nireports (#3177)
* DOC: Clarify ``--dvars-spike-threshold`` uses standardized DVARS (#3205)
* TST: Update test to reflect new report generation behavior (#3210)
* STY: Manual conversions to f-strings (#3241)
* STY: Apply ruff/pyupgrade rule UP031 (#3280)
* STY: Lint and style check full repository (#3221)
* STY: Adopt ruff for linting and formatting (#3206)
* MNT: Pin libitk 5.3 and note dependencies (#3298)
* MNT: Upgrade ruff pre-commit, add fixing checks (#3283)
* MNT: Complete transition from flake8/black to ruff (#3279)
* MNT: Apply Repo-Review suggestions (#3194)
* MNT: Verbatim copy of Apache license 2.0 (#3259)
* MNT: Bump cryptography from 41.0.7 to 42.0.4 (#3234)
* MNT: Drop copyright year, unused dunder fields (#3247)
* MNT: Update environment pins (#3226)
* MNT: Bump codecov/codecov-action from 3 to 4 (#3219)
* DOCKER: Restore mincinfo binary (#3249)
* CI: Move to new circle machine tags (#3248)
* CI: Avoid ruff warning (#3244)
* CI: Pass ruff tests (#3243)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Track sources with DatasetLinks and BIDS-URIs
3 participants