def subjects(self): self.restLog("Returning info about subjects", 2) projects = Navigate.getProjects(self.nidm_files) result = {'subject': []} if 'fields' in self.query and len(self.query['fields']) > 0: result['fields'] = {} for proj in projects: subs = Navigate.getSubjects(self.nidm_files, proj) for s in subs: result['subject'].append([ Query.URITail(s), Navigate.getSubjectIDfromUUID(self.nidm_files, s) ]) # print ("getting info for " + str(s)) x = self.getFieldInfoForSubject(proj, s) if x != {}: result['fields'][Query.URITail(s)] = x return self.subjectFormat(result)
def subjectsList(self): match = re.match(r"^/?projects/([^/]+)/subjects/?$", self.command) project = match.group((1)) self.restLog( "Returning all agents matching filter '{}' for project {}".format( self.query['filter'], project), 2) # result = Query.GetParticipantUUIDsForProject(self.nidm_files, project, self.query['filter'], None) all_subjects = Navigate.getSubjects(self.nidm_files, project) result = {} result['uuid'] = [] result['subject id'] = [] for sub_uuid in all_subjects: if Query.CheckSubjectMatchesFilter(self.nidm_files, project, sub_uuid, self.query['filter']): uuid_string = (str(sub_uuid)).split('/')[ -1] # srip off the http://whatever/whatever/ result['uuid'].append(uuid_string) sid = Navigate.getSubjectIDfromUUID(self.nidm_files, sub_uuid) result['subject id'].append(str(sid)) return self.format(result)
def test_navigate_get_acquisition_data_by_subject(): set_of_keys_returned = set([]) set_of_activities = set([]) subjects = Navigate.getSubjects(OPENNEURO_FILES, OPENNEURO_PROJECT_URI) assert len(subjects) > 0 for s in subjects: activities = Navigate.getActivities(nidm_file_tuples=OPENNEURO_FILES, subject_id=s) assert len(activities) > 0 for a in activities: set_of_activities.add(str(a)) ad = Navigate.getActivityData(OPENNEURO_FILES, a) assert len(ad.data) > 5 for vt in ad.data: set_of_keys_returned.add(vt.label) assert 'age' in set_of_keys_returned assert 'InversionTime' in set_of_keys_returned assert 'hadAcquisitionModality' in set_of_keys_returned
def test_navigate_get_acquisition_data_by_subject(): set_of_keys_returned = set([]) set_of_activities = set([]) subjects = Navigate.getSubjects(BRAIN_VOL_FILES, PROJECT_URI) assert len(subjects) > 0 for s in subjects: activities = Navigate.getActivities(nidm_file_list=BRAIN_VOL_FILES, subject_id=s) assert len(activities) > 0 for a in activities: set_of_activities.add(str(a)) ad = Navigate.getActivityData(BRAIN_VOL_FILES, a) assert len(ad.data) > 5 for vt in ad.data: set_of_keys_returned.add(vt.label) assert 'AGE_AT_SCAN' in set_of_keys_returned assert 'Left-Accumbens-area (voxels)' in set_of_keys_returned assert 'hadAcquisitionModality' in set_of_keys_returned
def GetProjectsComputedMetadata(nidm_file_list): ''' :param nidm_file_list: List of one or more NIDM files to query across for list of Projects :return: Dictionay or projects, each project having a dictionary of project stats including age_max, age_min, gender list, and handedness list. ''' meta_data = {"projects": {}} projects = Navigate.getProjects(tuple(nidm_file_list)) for p in projects: proj_id = nidm.experiment.tools.rest.RestParser.getTailOfURI(str(p)) meta_data["projects"][proj_id] = {"age_max": 0, "age_min": sys.maxsize, "gender": [], "handedness": [] } meta_data["projects"][proj_id].update(Navigate.GetProjectAttributes(tuple(nidm_file_list), p)) gender_set = set() hand_set = set() subjects = Navigate.getSubjects(tuple(nidm_file_list), p) for s in subjects: activities = Navigate.getActivities(tuple(nidm_file_list), s) meta_data["projects"][proj_id]["number_of_subjects"] = len(subjects) for a in activities: data = Navigate.getActivityData(tuple(nidm_file_list), a) if type(data) == nidm.experiment.Navigate.ActivityData: for x in data.data: if x.isAbout == Constants.NIDM_IS_ABOUT_AGE: if float(x.value) > meta_data["projects"][proj_id]["age_max"]: meta_data["projects"][proj_id]["age_max"] = float(x.value) if float(x.value) < meta_data["projects"][proj_id]["age_min"]: meta_data["projects"][proj_id]["age_min"] = float(x.value) if x.isAbout == Constants.NIDM_IS_ABOUT_GENDER: gender_set.add(str(x.value)) if x.isAbout == Constants.NIDM_IS_ABOUT_HANDEDNESS: hand_set.add(str(x.value)) meta_data["projects"][proj_id]["gender"] = list(gender_set) meta_data["projects"][proj_id]["handedness"] = list(hand_set) return meta_data