def getActivityData(nidm_file_tuples, acquisition_id): acquisition_uri = expandID(acquisition_id, Constants.NIIRI) result = [] category = None for file in nidm_file_tuples: rdf_graph = OpenGraph(file) # find everything generated by the acquisition for (data_object, p1, o1) in rdf_graph.triples( (None, Constants.PROV['wasGeneratedBy'], acquisition_uri)): # make sure this is an acquisition object if (data_object, isa, Constants.NIDM['AcquisitionObject']) in rdf_graph: category = 'instrument' # iterate over all the items in the acquisition object for (s, p, o) in rdf_graph.triples((data_object, None, None)): dti = getDataTypeInfo(rdf_graph, p) if (dti): # there is a DataElement describing this predicate value_type = makeValueTypeFromDataTypeInfo( value=trimWellKnownURIPrefix(o), data_type_info_tuple=dti) result.append(value_type) else: #Don't know exactly what this is so just set a label and be done. if (data_object, isa, Constants.ONLI['assessment-instrument'] ) in rdf_graph: result.append( makeValueType(value=trimWellKnownURIPrefix(o), label=simplifyURIWithPrefix( nidm_file_tuples, str(p)))) #result[ simplifyURIWithPrefix(nidm_file_list, str(p)) ] = trimWellKnownURIPrefix(o) else: result.append( makeValueType(value=trimWellKnownURIPrefix(o), label=URITail(str(p)))) # result[ URITail(str(p))] = trimWellKnownURIPrefix(o) # or maybe it's a stats collection elif isAStatCollection(nidm_file_tuples, data_object): category = 'derivative' for (s, p, o) in rdf_graph.triples((data_object, None, None)): cde = getDataTypeInfo(rdf_graph, p) result.append( makeValueTypeFromDataTypeInfo( value=str(o), data_type_info_tuple=cde)) # result[ URITail(str(p)) ] = str(o) return ActivityData(category=category, uuid=trimWellKnownURIPrefix(acquisition_uri), data=result)
def getActivityData(nidm_file_list, acquisition_id): acquisition_uri = expandID(acquisition_id, Constants.NIIRI) result = [] category = None for file in nidm_file_list: rdf_graph = OpenGraph(file) # find everything generated by the acquisition for (data_object, p1, o1) in rdf_graph.triples( (None, Constants.PROV['wasGeneratedBy'], acquisition_uri)): # make sure this is an acquisition object if (data_object, isa, Constants.NIDM['AcquisitionObject']) in rdf_graph: category = 'instrument' # iterate over all the items in the acquisition object for (s, p, o) in rdf_graph.triples((data_object, None, None)): # if this is a onli:assessment-instrument then use the prefix names if (data_object, isa, Constants.ONLI['assessment-instrument'] ) in rdf_graph: result.append( makeValueType(value=trimWellKnownURIPrefix(o), label=simplifyURIWithPrefix( nidm_file_list, str(p)))) #result[ simplifyURIWithPrefix(nidm_file_list, str(p)) ] = trimWellKnownURIPrefix(o) else: result.append( makeValueType(value=trimWellKnownURIPrefix(o), label=URITail(str(p)))) # result[ URITail(str(p))] = trimWellKnownURIPrefix(o) # or maybe it's a stats collection elif isAStatCollection(nidm_file_list, data_object): category = 'derivative' for (s, p, o) in rdf_graph.triples((data_object, None, None)): cde = getDataTypeInfo(rdf_graph, p) result.append( makeValueType(value=str(o), label=str(cde['label']), hasUnit=str(cde['hasUnit']), datumType=str(cde['datumType']), measureOf=str(cde['measureOf']), isAbout=str(cde['isAbout']), dataElement=URITail(str(p)))) # result[ URITail(str(p)) ] = str(o) return ActivityData(category=category, uuid=trimWellKnownURIPrefix(acquisition_uri), data=result)
def getSubject(nidm_file_tuples, acquisition_id): acquisition_uri = expandID(acquisition_id, Constants.NIIRI) subjects = [] for file in nidm_file_tuples: rdf_graph = OpenGraph(file) #find all the sessions for (acq, p, blank) in rdf_graph.triples( (acquisition_uri, Constants.PROV['qualifiedAssociation'], None)): for (s2, p2, sub) in rdf_graph.triples( (blank, Constants.PROV['agent'], None)): if (blank, Constants.PROV['hadRole'], Constants.SIO['Subject']) in rdf_graph: return sub return None
def GetProjectAttributes(nidm_files_tuple, project_id): result = { ACQUISITION_MODALITY: set([]), IMAGE_CONTRAST_TYPE: set([]), IMAGE_USAGE_TYPE: set([]), TASK: set([]) } project_uuid = expandUUID(project_id) for file in nidm_files_tuple: rdf_graph = OpenGraph(file) #find all the projects for (project, pred, o) in rdf_graph.triples( (None, None, Constants.NIDM['Project'])): #check if it is our project if str(project) == str(project_uuid): # get all the basic data from the project for (proj, predicate, object) in rdf_graph.triples( (project, None, None)): result[matchPrefix(str(predicate))] = str(object) # now drill into the acquisition objects to get some specific # elements: AcquisitionModality, ImageContrastType, ImageUsageType, Task sessions = getSessions(nidm_files_tuple, project_id) for s in sessions: acquistions = getAcquisitions(nidm_files_tuple, s) for a in acquistions: acq_obj = getActivityData(nidm_files_tuple, a) for de in acq_obj.data: if de.label == 'hadAcquisitionModality': result[ACQUISITION_MODALITY].add(de.value) if de.label == 'hadImageContrastType': result[IMAGE_CONTRAST_TYPE].add(de.value) if de.label == 'hadImageUsageType': result[IMAGE_USAGE_TYPE].add(de.value) if de.label == 'Task': result[TASK].add(de.value) # de-set-ify items so they will play nice with JSON later result[ACQUISITION_MODALITY] = list(result[ACQUISITION_MODALITY]) result[IMAGE_CONTRAST_TYPE] = list(result[IMAGE_CONTRAST_TYPE]) result[IMAGE_USAGE_TYPE] = list(result[IMAGE_USAGE_TYPE]) result[TASK] = list(result[TASK]) return result
def getProjects(nidm_file_tuples): projects = [] for file in nidm_file_tuples: rdf_graph = OpenGraph(file) #find all the sessions for (project, p, o) in rdf_graph.triples( (None, isa, Constants.NIDM['Project'])): projects.append(project) return projects
def getSubjectUUIDsfromID(nidm_file_tuples, sub_id): uuids = [] for file in nidm_file_tuples: rdf_graph = OpenGraph(file) result = rdf_graph.triples( (None, Constants.NDAR['src_subject_id'], None)) for (s, p, o) in result: if str(o) == str(sub_id): uuids.append(URITail(s)) return uuids
def getAcquisitions(nidm_file_tuples, session_id): session_uri = expandID(session_id, Constants.NIIRI) acquisitions = [] for file in nidm_file_tuples: rdf_graph = OpenGraph(file) #find all the sessions for (acq, p, o) in rdf_graph.triples((None, isPartOf, session_uri)): #check if it is a acquisition if (acq, isa, Constants.NIDM['Acquisition']) in rdf_graph: acquisitions.append(acq) return acquisitions
def getSessions(nidm_file_tuples, project_id): project_uri = expandID(project_id, Constants.NIIRI) sessions = [] for file in nidm_file_tuples: rdf_graph = OpenGraph(file) #find all the sessions for (session, p, o) in rdf_graph.triples( (None, isa, Constants.NIDM['Session'])): #check if it is part of our project if (session, isPartOf, project_uri) in rdf_graph: sessions.append(session) return sessions