Last active
May 16, 2017 15:10
-
-
Save mattsouth/be714f0046b8f1e72bf8a4df3e668930 to your computer and use it in GitHub Desktop.
Prints the subject_id and experiment_id of XNAT experiments where a scan is missing a snapshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# prints the subject_id and experiment_id of XNAT experiments where a scan is missing a snapshot | |
# used against XNAT 1.6.5 by python 2.7 | |
import xnat # see https://xnat.readthedocs.io/en/latest/ | |
url = raw_input("Enter XNAT url: ") | |
user = raw_input("Enter username: ") | |
session = xnat.connect(url, user=user) | |
name = raw_input("Enter project: ") | |
project = session.projects[name] | |
print 'subject, session' | |
for subject_id in project.subjects.keys(): | |
for experiment_id in project.subjects[subject_id].experiments.keys(): | |
experiment_has_all_snapshots = True | |
for scan_id in project.subjects[subject_id].experiments[experiment_id].scans.keys(): | |
scan_has_snapshot = False | |
for resource_id in project.subjects[subject_id].experiments[experiment_id].scans[scan_id].resources.keys(): | |
resource = project.subjects[subject_id].experiments[experiment_id].scans[scan_id].resources[resource_id] | |
if resource.label=='SNAPSHOTS' and len(resource.files)>0: | |
scan_has_snapshot = True | |
break | |
if scan_has_snapshot==False: | |
experiment_has_all_snapshots = False | |
break | |
if experiment_has_all_snapshots==False: | |
print '{}, {}'.format(subject_id, experiment_id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment