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

Discrepancy in image-label file names in the BIDS-formatted dataset #14

Open
naga-karthik opened this issue Nov 12, 2022 · 6 comments
Open

Comments

@naga-karthik
Copy link
Collaborator

I was working on a preprocessing script to crop the images using the spinal cord masks as the reference and came across a minor discrepancy in the names of the (image, label) pairs in the BIDS-formatted version of the dataset. Particularly, the image name for a subject is as follows sub-m023917_ses-20130506_acq-ax_T2w.nii.gz (note the existence of _T2w suffix here) and the corresponding labels for the same subject is as follows: (i) cord label sub-m023917_ses-20130506_acq-ax_seg-manual.nii.gz, (ii) lesion label sub-m023917_ses-20130506_acq-ax_lesion-manual.nii.gz (the suffix _T2w is not mentioned in the file names).

The preprocessing script could indeed be changed to take this into account, but I wanted to make sure whether this was intended while creating the BIDS version of the dataset. If not, then this has to be fixed in order to reduce manual tweaking of the preprocessing script.

@jqmcginnis
Copy link
Collaborator

@naga-karthik good catch - I will definitely address this in the next update!

@kiristern
Copy link
Collaborator

kiristern commented Dec 12, 2022

here is a quick terminal command to modify the filenames. Note, you must first cd into the derivatives/labels folder, then run:

for f in ` find . -name '*lesion-manual.nii.gz' ` ; do mv $f "${f%lesion-manual.nii.gz}T2w_lesion-manual.nii.gz"; done

there may be a better way to do this, but it worked for me for now.
must also do for seg-manual, for a copy-paste:

for f in ` find . -name '*seg-manual.nii.gz' ` ; do mv $f "${f%seg-manual.nii.gz}T2w_seg-manual.nii.gz"; done

Repeat for .json files

@naga-karthik
Copy link
Collaborator Author

Thanks, Kiri, for the bash commands! I added them into a script that could be run from the root directory.

#!/bin/bash
# This file fixes the names of the derivatives to conform to BIDS' format of derivatives naming. 
# Originally, the contrast name (suffix) was missing from the derivative file names. 
# This script finds all the manual labels and prefixes them with the contrast name

cd derivatives/labels

# the type of contrast to be prefix-ed
contrast_type='T2w'

# for the nifti files
for f in ` find . -name '*lesion-manual.nii.gz' ` ; 
do 
    mv $f "${f%lesion-manual.nii.gz}${contrast_type}_lesion-manual.nii.gz"; 
done

# for the json files
for f in ` find . -name '*lesion-manual.json' ` ; 
do 
    mv $f "${f%lesion-manual.json}${contrast_type}_lesion-manual.json"; 
done


# # uncomment these lines (and comment above lines) to revert it back
# for f in ` find . -name '*lesion-manual.nii.gz' ` ; 
# do 
#     mv $f "${f%_T2w*}_lesion-manual.nii.gz"; 
# done

# for f in ` find . -name '*lesion-manual.json' ` ; 
# do 
#     mv $f "${f%_T2w*}_lesion-manual.json";
# done

This could be run once to rename all the files according to the proper BIDS convention for the labels.

@jqmcginnis
Copy link
Collaborator

@naga-karthik @kiristern I believe this should work for the json files out of the box, but renaming the NIFTIs without unzipping first will result in corrupted files because the zipped file will have a different name.

@jcohenadad
Copy link
Member

@naga-karthik @kiristern I believe this should work for the json files out of the box, but renaming the NIFTIs without unzipping first will result in corrupted files because the zipped file will have a different name.

as long as the file extension is not changed (eg: mv blabla.nii blabla.nii.gz) this should work

@jqmcginnis
Copy link
Collaborator

as long as the file extension is not changed (eg: mv blabla.nii blabla.nii.gz) this should work

You are absolutely right, I was not aware of this. Thank you!

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

No branches or pull requests

4 participants