Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
def GetDataelements(nidm_files_tuple):
    result = {"data_elements": {"uuid": [], "label": [], "data_type_info": []}}
    found_uris = set()

    for file in nidm_files_tuple:
        rdf_graph = OpenGraph(file)
        #find all the datatypes
        for de_uri in rdf_graph.subjects(predicate=isa,
                                         object=Constants.NIDM['DataElement']):
            if de_uri not in found_uris:  # don't add duplicates
                dti = getDataTypeInfo(rdf_graph, de_uri)
                result['data_elements']['uuid'].append(
                    str(dti['dataElementURI']))
                result['data_elements']['label'].append(str(dti['label']))
                result['data_elements']['data_type_info'].append(dti)
                found_uris.add(de_uri)
        # find all the datatypes
        for de_uri in rdf_graph.subjects(
                predicate=isa, object=Constants.NIDM['PersonalDataElement']):
            if de_uri not in found_uris:  # don't add duplicates
                dti = getDataTypeInfo(rdf_graph, de_uri)
                result['data_elements']['uuid'].append(
                    str(dti['dataElementURI']))
                result['data_elements']['label'].append(str(dti['label']))
                result['data_elements']['data_type_info'].append(dti)
                found_uris.add(de_uri)

    # now look for any of the CDEs
    all_predicates = GetAllPredicates(nidm_files_tuple)
    cde_graph = nidm.experiment.CDE.getCDEs()
    cde_types = cde_graph.subjects(predicate=Constants.RDFS['subClassOf'],
                                   object=Constants.NIDM['DataElement'])
    cde_type_set = set()  # i.e. fs:DataElement
    known_cde_types = set()  # i.e. fs_003579
    for t in cde_types:
        cde_type_set.add(t)
        for s in cde_graph.subjects(predicate=isa, object=t):
            known_cde_types.add(s)

    for predicate in all_predicates:
        if predicate in known_cde_types:
            dti = getDataTypeInfo(cde_graph, predicate)
            result['data_elements']['uuid'].append(str(dti['dataElementURI']))
            result['data_elements']['label'].append(str(dti['label']))
            result['data_elements']['data_type_info'].append(dti)

    return result
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
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