Exemple #1
0
def getSubjectIDfromUUID(nidm_file_tuples, subject_uuid):
    for file in nidm_file_tuples:
        rdf_graph = OpenGraph(file)
        id_generator = rdf_graph.objects(
            subject=subject_uuid, predicate=Constants.NDAR['src_subject_id'])
        for id in id_generator:
            return id
    return None
Exemple #2
0
def GetDataelementDetails(nidm_files_tuple, dataelement):
    result = {}

    for file in nidm_files_tuple:
        rdf_graph = OpenGraph(file)
        for de_uri in rdf_graph.subjects(predicate=isa,
                                         object=Constants.NIDM['DataElement']):
            dti = getDataTypeInfo(rdf_graph, de_uri)

            # check if this is the correct one
            if not (dataelement in [
                    str(dti['label']),
                    str(dti['dataElement']),
                    str(dti['dataElementURI'])
            ]):
                continue

            for key in dti.keys():
                result[key] = dti[key]
            result['inProjects'] = set()

            # figure out what project the dataelement was used in
            uri = dti["dataElementURI"]

            a_list = rdf_graph.subjects(predicate=uri)
            for a in a_list:  # a is an assessment / AcquisitionObject
                b_list = rdf_graph.objects(
                    subject=a, predicate=Constants.PROV['wasGeneratedBy'])
                for b in b_list:  # b is an Acquisition / Activity
                    c_list = rdf_graph.objects(
                        subject=b, predicate=Constants.DCT['isPartOf'])
                    for c in c_list:  # c is a session
                        d_list = rdf_graph.objects(
                            subject=c, predicate=Constants.DCT['isPartOf'])
                        for d in d_list:  # d is most likely a project
                            if d in rdf_graph.subjects(
                                    predicate=isa,
                                    object=Constants.NIDM['Project']):
                                result['inProjects'].add("{} ({})".format(
                                    str(d), file))

            return result  # found it, we are done

    if result == {}:  # didn't find it yet, check the CDEs
        cde_graph = nidm.experiment.CDE.getCDEs()
        for de_uri in cde_graph.subjects(predicate=isa):
            dti = getDataTypeInfo(cde_graph, de_uri)

            # check if this is the correct one
            if not (dataelement in [
                    str(dti['label']),
                    str(dti['dataElement']),
                    str(dti['dataElementURI'])
            ]):
                continue

            for key in dti.keys():
                result[key] = dti[key]
            result['inProjects'] = set()
            result['inProjects'].add("Common Data Element")

            for file in nidm_files_tuple:
                rdf_graph = OpenGraph(file)
                if result['dataElementURI'] in rdf_graph.predicates():
                    result['inProjects'].add(file)

            return result  # found it, we are done

    return result