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

package_for_correction.py - move to SCT? #16

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion preprocess/package_for_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ def get_parser():
help="Zip file that contains the packaged data, without the extension. Default: data_to_correct",
default='data_to_correct'
)
parser.add_argument(
'-suffix-files-seg',
help="FILES-SEG suffix. For example _seg or _label-SC_mask",
default='_seg'
)
parser.add_argument(
'-v', '--verbose',
help="Full verbose (for debugging)",
Expand Down Expand Up @@ -116,7 +121,7 @@ def main():
for task, files in dict_yml.items():
for file in files:
if task == 'FILES_SEG':
suffix_label = '_seg'
suffix_label = args.suffix_files_seg # e.g., _seg or _label-SC_mask
elif task == 'FILES_LABEL':
suffix_label = None
elif task == 'FILES_PMJ':
Expand Down
20 changes: 14 additions & 6 deletions preprocess/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,30 @@
from pathlib import Path
from enum import Enum


# BIDS utility tool
def get_subject(file):
"""
Get subject from BIDS file name
:param file:
:return: subject
:param file: input nifti filename (e.g., sub-001_ses-01_T1w.nii.gz) or file path
(e.g., /home/user/MRI/bids/derivatives/labels/sub-001/ses-01/anat/sub-001_ses-01_T1w.nii.gz
:return: subject_id: subject ID (e.g., sub-001)
"""
return file.split('_')[0]
subject = re.search('sub-(.*?)[_/]', file) # [_/] slash or underscore
subject_id = subject.group(0)[:-1] if subject else "" # [:-1] removes the last underscore or slash
return subject_id


def get_ses(file):
"""
Get session from BIDS file name
:param file:
:return: ses
:param file: input nifti filename (e.g., sub-001_ses-01_T1w.nii.gz) or file path
(e.g., /home/user/MRI/bids/derivatives/labels/sub-001/ses-01/anat/sub-001_ses-01_T1w.nii.gz
:return: sessionID: session ID (e.g., ses-01)
"""
return file.split('_')[1]
session = re.findall(r'ses-..', file) # .. - any two characters (e.g., ses-01 or ses-M0)
sessionID = session[0] if session else "" # Return None if there is no session
return sessionID


def get_contrast(file):
Expand Down