From 5f7f3db6a433a4e6c03325d05261fe9f2d96a2d7 Mon Sep 17 00:00:00 2001 From: Mike Tyszka Date: Thu, 26 Jan 2023 14:35:55 -0800 Subject: [PATCH] v2023.1.26 Fix Flywheel folder handling for Web vs CLI downloads --- CHANGELOG.md | 6 ++++++ README.md | 2 +- bidskit/flywheel.py | 20 ++++++++++++++++---- docs/Flywheel.md | 2 +- setup.py | 2 +- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa3e8e4..edafaf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # BIDSKIT Changelog +## Version 2023.1.26 +- Fixed folder name handling for Web vs CLI Flywheel DICOM downloads + +## Version 2023.1.12 +- Add support for Flywheel DICOM download curation + ## Version 2022.2.1 - Added support for complex-valued, bias corrected and multiecho image types - Added command line control for rec-, echo- and part- keys in BIDS filenames diff --git a/README.md b/README.md index cfe1567..debb935 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # BIDSKIT -### Version 2023.1.12 +### Version 2023.1.26 Python utilities for converting from DICOM to BIDS neuroimaging formats. The *bidskit* console command takes a directory tree containing imaging series from one or more subjects (eg T1w MPRAGE, BOLD EPI, Fieldmaps), converts the imaging data to Nifti-1 format with JSON metadata files (sidecars) and populates a directory tree according to the latest BIDS specification. diff --git a/bidskit/flywheel.py b/bidskit/flywheel.py index 72d9226..242e341 100644 --- a/bidskit/flywheel.py +++ b/bidskit/flywheel.py @@ -36,7 +36,7 @@ def unpack(dataset_dir): src_dir = op.join(dataset_dir, 'sourcedata') os.makedirs(src_dir, exist_ok=True) - # Look for one or more flywheel tarballs + # Look for one or more flywheel tarballs in the BIDS dataset root folder fw_tarball_list = sorted(glob(op.join(dataset_dir, 'flywheel_*.tar'))) if len(fw_tarball_list) < 1: @@ -50,12 +50,24 @@ def unpack(dataset_dir): subprocess.run(['tar', 'xf', tb_fname, '-C', src_dir]) # bidskit uses sourcedata// organization - # Flywheel uses sourcedata/flywheel////SESSION> + # Flywheel uses sourcedata/////SESSION> # so move folder up three levels within sourcedata and - # delete sourcedata/flywheel folder tree + # delete sourcedata/ folder tree + # Currently FWDIRNAME can be either 'flywheel' for web downloads or 'scitran' + # for CLI downloads + + # Check for existence of sourcedata/flywheel or sourcedata/scitran folders + # following untarring + fw_web_dir = op.join(src_dir, 'flywheel') + fw_cli_dir = op.join(src_dir, 'scitran') + if op.isdir(fw_web_dir): + fw_dir = fw_web_dir + elif op.isdir(fw_cli_dir): + fw_dir = fw_cli_dir + else: + raise Exception(f'Neither sourcedata/flywheel or sourcedata/scitran exist following tar extraction') # Assume only one group/project present in sourcedata following tarball unpacking - fw_dir = op.join(src_dir, 'flywheel') subj_dir_list = sorted(glob(op.join(fw_dir, '*', '*', '*'))) for subj_dir in subj_dir_list: print(f' Moving {subj_dir} to {src_dir}') diff --git a/docs/Flywheel.md b/docs/Flywheel.md index 0520841..4465e20 100644 --- a/docs/Flywheel.md +++ b/docs/Flywheel.md @@ -4,7 +4,7 @@ Flywheel allows export of all DICOM data from a project, subject or session from The data exports to an uncompressed tar archive (*tarball*) with the following example folder organization: ``` -flywheel +flywheel or scitran └── odoherty └── OLEL └── JOD_OLEL_031 diff --git a/setup.py b/setup.py index 131ed42..39ca6a3 100644 --- a/setup.py +++ b/setup.py @@ -45,7 +45,7 @@ # For a discussion on single-sourcing the version across setup.py and the # project code, see # https://packaging.python.org/en/latest/single_source_version.html - version='2023.1.12', # Required + version='2023.1.26', # Required # This is a one-line description or tagline of what your project does. This # corresponds to the "Summary" metadata field: