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

Return lists of defaced t1w and t2w and define it for t2w #83

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion bidsonym/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def plot_defaced(bids_dir, subject_label, session=None, t2w=None):
plt.savefig(opj(bidsonym_path,
t1w[t1w.rfind('/')+1:t1w.rfind('.nii')] + '_desc-brainmaskdeid.png'))

defaced_t2w = None
if t2w is not None:
if session is not None:
defaced_t2w = layout.get(subject=subject_label, extension='nii.gz', suffix='T2w',
Expand All @@ -67,7 +68,7 @@ def plot_defaced(bids_dir, subject_label, session=None, t2w=None):
plt.savefig(opj(bids_dir, 'sourcedata/bidsonym/sub-%s' % subject_label,
t2w[t2w.rfind('/')+1:t2w.rfind('.nii')] + '_desc-brainmaskdeid.png'))

return (t1w, t2w)
return (defaced_t1w, defaced_t2w)


def gif_defaced(bids_dir, subject_label, session=None, t2w=None):
Expand Down
23 changes: 13 additions & 10 deletions bidsonym/run_deeid.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,15 @@ def run_deeid():
subjects_to_analyze = layout.get(return_type='id', target='subject')

list_part_prob = []
part = None
session = None

for part in subjects_to_analyze:
if part not in layout.get_subjects():
list_part_prob.append(part)
if len(list_part_prob) >= 1:
raise Exception("The participant(s) you indicated are not present in the BIDS dataset, please check again."
"This refers to:")
print(list_part_prob)
f"This refers to: {list_part_prob}")

if args.session:
list_sessions = args.session
Expand All @@ -133,6 +135,7 @@ def run_deeid():
print(sessions_to_analyze)

list_ses_prob = []
list_t1w = []

if args.session and args.session != ["all"]:

Expand All @@ -148,8 +151,7 @@ def run_deeid():

if len(list_ses_prob) >= 1:
raise Exception("The session(s) you indicated are not present in the BIDS dataset, please check again."
"This refers to:")
print(list_ses_prob)
f"This refers to: {list_ses_prob}")

list_t1w = layout.get(subject=subject_label, extension='nii.gz',
suffix='T1w', return_type='filename',
Expand Down Expand Up @@ -240,6 +242,7 @@ def run_deeid():

if args.deface_t2w:

list_t2w = []
if args.session and args.session != ["all"]:

for ses in args.session:
Expand All @@ -249,8 +252,7 @@ def run_deeid():

if len(list_ses_prob) >= 1:
raise Exception("The session(s) you indicated are not present in the BIDS dataset, please check again."
"This refers to:")
print(list_ses_prob)
f"This refers to: {list_ses_prob}")

list_t2w = layout.get(subject=subject_label,
extension='nii.gz', suffix='T2w',
Expand All @@ -262,7 +264,7 @@ def run_deeid():
extension='nii.gz', suffix='T2w',
return_type='filename')

if list_t2w == []:
if not list_t2w:
raise Exception("You indicated that a T2w image should be defaced as well."
"However, no T2w image exists for subject %s and indicated sessions."
"Please check again." % subject_label)
Expand All @@ -278,6 +280,7 @@ def run_deeid():
source_t2w = copy_no_deid(args.bids_dir, subject_label,
T2_file)

T1_file = None
if 'ses' in T2_file:

session = T2_file[T2_file.rfind('ses')+4:].split("_")[0]
Expand Down Expand Up @@ -324,20 +327,20 @@ def run_deeid():
t2w=None)
clean_up_files(args.bids_dir, subject_label, session=None)

elif len(T1_file) == 1 and args.deface_t2w:
elif len(T1_files) == 1 and args.deface_t2w:
create_graphics(args.bids_dir, subject_label, session=None,
t2w=True)
clean_up_files(args.bids_dir, subject_label, session=None)

elif len(T1_file) >= 1 and args.deface_t2w is False:
elif len(T1_files) >= 1 and args.deface_t2w is False:

for session in sessions_to_analyze:
create_graphics(args.bids_dir, subject_label,
session=session, t2w=None)
clean_up_files(args.bids_dir, subject_label,
session=session)

elif len(T1_file) >= 1 and args.deface_t2w:
elif len(T1_files) >= 1 and args.deface_t2w:

for session in sessions_to_analyze:
create_graphics(args.bids_dir, subject_label,
Expand Down
Loading