コード例 #1
0
def test_GetParticipantDetails():

    import time
    start = time.time()

    restParser = RestParser()
    if cmu_test_project_uuid:
        project = cmu_test_project_uuid
    else:
        projects = restParser.run(BRAIN_VOL_FILES, '/projects')
        project = projects[0]
    import time
    start = time.time()
    subjects = restParser.run(BRAIN_VOL_FILES,
                              '/projects/{}/subjects'.format(project))
    subject = subjects['uuid'][0]

    Query.GetParticipantInstrumentData(BRAIN_VOL_FILES, project, subject)

    details = Query.GetParticipantDetails(BRAIN_VOL_FILES, project, subject)

    assert ('uuid' in details)
    assert ('id' in details)
    assert ('activity' in details)
    assert ('instruments' in details)
    assert ('derivatives' in details)

    end = time.time()
    runtime = end - start
コード例 #2
0
def test_uri_projects_subjects_id():
    global test_person_uuid

    restParser = RestParser()
    if cmu_test_project_uuid:
        project = cmu_test_project_uuid
    else:
        result = restParser.run(['./cmu_a.nidm.ttl'], '/projects')
        project = result[0]
    result = restParser.run(['./cmu_a.nidm.ttl'],
                            '/projects/{}/subjects'.format(project))
    subject = result['uuid'][0]

    uri = '/projects/{}/subjects/{}'.format(project, subject)
    result = restParser.run(['./cmu_a.nidm.ttl'], uri)

    assert type(result) == dict
    assert result['uuid'] == subject
    assert len(result['instruments']) > 2

    instruments = result['instruments'].values()
    all_keys = []
    for i in instruments:
        all_keys += i.keys()
    assert 'AGE_AT_SCAN' in all_keys

    assert len(result['derivatives']) > 0
コード例 #3
0
ファイル: test_rest.py プロジェクト: albertcrowley/PyNIDM
def test_uri_project_list():

    import uuid

    kwargs={Constants.NIDM_PROJECT_NAME:"FBIRN_PhaseII",Constants.NIDM_PROJECT_IDENTIFIER:9610,Constants.NIDM_PROJECT_DESCRIPTION:"Test investigation"}
    proj1_uuid = str(uuid.uuid1())
    proj2_uuid = str(uuid.uuid1())
    project = Project(uuid=proj1_uuid,attributes=kwargs)
    #save a turtle file
    with open("uritest.ttl",'w') as f:
        f.write(project.serializeTurtle())

    kwargs={Constants.NIDM_PROJECT_NAME:"FBIRN_PhaseIII",Constants.NIDM_PROJECT_IDENTIFIER:1200,Constants.NIDM_PROJECT_DESCRIPTION:"Test investigation2"}
    project = Project(uuid=proj2_uuid,attributes=kwargs)
    #save a turtle file
    with open("uritest2.ttl",'w') as f:
        f.write(project.serializeTurtle())

    restParser = RestParser()
    result = restParser.run(['uritest.ttl', 'uritest2.ttl'], '/projects')


    project_uuids = []

    for uuid in result:
        project_uuids.append(uuid)

    assert type(result) == list
    assert len(project_uuids) >= 2
    assert proj1_uuid in project_uuids
    assert proj2_uuid in project_uuids

    os.remove("uritest.ttl")
    os.remove("uritest2.ttl")
コード例 #4
0
def test_dataelement_list():
    rest_parser = RestParser(output_format=RestParser.OBJECT_FORMAT)
    result = rest_parser.run(OPENNEURO_FILES, '/dataelements')

    assert type(result) == dict
    assert "data_elements" in result
    assert 'uuid' in result["data_elements"]
    assert 'label' in result["data_elements"]
    assert 'data_type_info' in result["data_elements"]

    assert len(result["data_elements"]["label"]) != 0
    assert len(result["data_elements"]["label"]) == len(
        result["data_elements"]["uuid"])
    assert len(result["data_elements"]["label"]) == len(
        result["data_elements"]["data_type_info"])

    for label in result["data_elements"]["label"]:
        assert label in [
            str(x["label"]) for x in result["data_elements"]["data_type_info"]
        ]

    for uuid in result["data_elements"]["uuid"]:
        assert uuid in [
            str(x["dataElementURI"])
            for x in result["data_elements"]["data_type_info"]
        ]

    # now check for derivatives
    result = rest_parser.run(BRAIN_VOL_FILES, '/dataelements')
    assert type(result) == dict
    assert 'Left-WM-hypointensities Volume_mm3 (mm^3)' in result[
        'data_elements']['label']
コード例 #5
0
def setup():
    global cmu_test_project_uuid, cmu_test_subject_uuid

    if Path(REST_TEST_FILE).is_file():
        os.remove(REST_TEST_FILE)
    makeTestFile(filename=REST_TEST_FILE,
                 params={
                     'PROJECT_UUID': 'p1',
                     'PROJECT2_UUID': 'p2'
                 })

    for f in ['./cmu_a.nidm.ttl', 'caltech.nidm.ttl']:
        if Path(f).is_file():
            os.remove(f)

    if not Path('./cmu_a.nidm.ttl').is_file():
        urllib.request.urlretrieve(
            "https://raw.githubusercontent.com/dbkeator/simple2_NIDM_examples/master/datasets.datalad.org/abide/RawDataBIDS/CMU_a/nidm.ttl",
            "cmu_a.nidm.ttl")
        restParser = RestParser(output_format=RestParser.OBJECT_FORMAT)
        projects = restParser.run(['./cmu_a.nidm.ttl'], '/projects')
        cmu_test_project_uuid = projects[0]
        subjects = restParser.run(
            ['./cmu_a.nidm.ttl'],
            '/projects/{}/subjects'.format(cmu_test_project_uuid))
        cmu_test_subject_uuid = subjects['uuid'][0]

    if not Path('./caltech.nidm.ttl').is_file():
        urllib.request.urlretrieve(
            "https://raw.githubusercontent.com/dbkeator/simple2_NIDM_examples/master/datasets.datalad.org/abide/RawDataBIDS/Caltech/nidm.ttl",
            "caltech.nidm.ttl")
コード例 #6
0
def setup():
    global cmu_test_project_uuid
    global cmu_test_subject_uuid

    for f in ['./cmu_a.nidm.ttl', 'caltech.nidm.ttl']:
        if Path(f).is_file():
            os.remove(f)

    if not Path('./cmu_a.nidm.ttl').is_file():
        urllib.request.urlretrieve(
            "https://raw.githubusercontent.com/dbkeator/simple2_NIDM_examples/master/datasets.datalad.org/abide/RawDataBIDS/CMU_a/nidm.ttl",
            "cmu_a.nidm.ttl")

    if not Path('./caltech.nidm.ttl').is_file():
        urllib.request.urlretrieve(
            "https://raw.githubusercontent.com/dbkeator/simple2_NIDM_examples/master/datasets.datalad.org/abide/RawDataBIDS/Caltech/nidm.ttl",
            "caltech.nidm.ttl")

    restParser = RestParser(output_format=RestParser.OBJECT_FORMAT)
    projects = restParser.run(BRAIN_VOL_FILES, '/projects')
    for p in projects:
        proj_info = restParser.run(BRAIN_VOL_FILES, '/projects/{}'.format(p))
        if type(proj_info) == dict and 'dctypes:title' in proj_info.keys(
        ) and proj_info['dctypes:title'] == 'ABIDE CMU_a Site':
            cmu_test_project_uuid = p
            break
    subjects = restParser.run(
        BRAIN_VOL_FILES, '/projects/{}/subjects'.format(cmu_test_project_uuid))
    cmu_test_subject_uuid = subjects['uuid'][0]
コード例 #7
0
def go():
    restParser = RestParser(output_format=RestParser.OBJECT_FORMAT,
                            verbosity_level=5)
    result = restParser.run(
        ["ttl/cmu_a.nidm.ttl"],
        "projects/dad0f09c-49ec-11ea-9fd8-003ee1ce9545?fields=fs_000003")
    print(result)
コード例 #8
0
def test_uri_subject_list():
    restParser = RestParser(output_format=RestParser.OBJECT_FORMAT)
    result = restParser.run(ALL_FILES, '/subjects')

    assert type(result) == dict
    assert type(result['subject']) == list
    assert len(result['subject']) > 10
コード例 #9
0
ファイル: profiler.py プロジェクト: yukaizou2015/PyNIDM
def go():
    restParser = RestParser(output_format=RestParser.OBJECT_FORMAT,
                            verbosity_level=5)
    result = restParser.run([
        "ttl/caltech.ttl"
    ], '/projects/e059fc5e-67aa-11ea-84b4-003ee1ce9545/subjects?filter=instruments.ADOS_MODULE gt 2'
                            )
    print(result)
コード例 #10
0
def test_CheckSubjectMatchesFilter():
    restParser = RestParser()
    if cmu_test_project_uuid:
        project = cmu_test_project_uuid
    else:
        projects = restParser.run(BRAIN_VOL_FILES, '/projects')
        project = projects[0]
    subjects = restParser.run(BRAIN_VOL_FILES,
                              '/projects/{}/subjects'.format(project))
    subject = subjects['uuid'][0]

    derivatives = Query.GetDerivativesDataForSubject(BRAIN_VOL_FILES, project,
                                                     subject)

    for skey in derivatives:
        for vkey in derivatives[skey]['values']:
            dt = vkey
            val = derivatives[skey]['values'][vkey]['value']
            if (dt and val):
                break

    # find an actual stat and build a matching filter to make sure our matcher passes it
    filter = "derivatives.{} eq {}".format(dt, val)
    assert Query.CheckSubjectMatchesFilter(BRAIN_VOL_FILES, project, subject,
                                           filter)

    instruments = Query.GetParticipantInstrumentData(BRAIN_VOL_FILES, project,
                                                     subject)
    for (i, inst) in instruments.items():
        if 'AGE_AT_SCAN' in inst:
            age = inst['AGE_AT_SCAN']

    older = str(float(age) + 1)
    younger = str(float(age) - 1)

    assert Query.CheckSubjectMatchesFilter(
        BRAIN_VOL_FILES, project, subject,
        "instruments.AGE_AT_SCAN eq {}".format(str(age)))
    assert (Query.CheckSubjectMatchesFilter(
        BRAIN_VOL_FILES, project, subject,
        "instruments.AGE_AT_SCAN lt {}".format(younger)) == False)
    assert (Query.CheckSubjectMatchesFilter(
        BRAIN_VOL_FILES, project, subject,
        "instruments.AGE_AT_SCAN gt {}".format(younger)) == True)
    assert Query.CheckSubjectMatchesFilter(
        BRAIN_VOL_FILES, project, subject,
        "instruments.AGE_AT_SCAN lt {}".format(older))
    assert (Query.CheckSubjectMatchesFilter(
        BRAIN_VOL_FILES, project, subject,
        "instruments.AGE_AT_SCAN gt {}".format(older)) == False)

    eq__format = "instruments.{} eq '{}'".format('WISC_IV_VOCAB_SCALED', 'nan')
    assert Query.CheckSubjectMatchesFilter(BRAIN_VOL_FILES, project, subject,
                                           eq__format)
    eq__format = "instruments.{} eq '{}'".format('WISC_IV_VOCAB_SCALED',
                                                 'not a match')
    assert (Query.CheckSubjectMatchesFilter(BRAIN_VOL_FILES, project, subject,
                                            eq__format) == False)
コード例 #11
0
def test_dataelement_details_in_projects_field():
    rest_parser = RestParser(output_format=RestParser.OBJECT_FORMAT)
    # result = rest_parser.run(OPENNEURO_FILES, '/dataelements')
    # dti = rest_parser.run(OPENNEURO_FILES, '/dataelements/{}'.format(result["data_elements"]["label"][0]))
    # assert len(dti['inProjects']) >= 1

    # find a data element that we are using for at least one subject
    data_element_label = 'Right-non-WM-hypointensities normMax (MR)'
    dti = rest_parser.run(BRAIN_VOL_FILES,
                          '/dataelements/{}'.format(data_element_label))
    assert len(dti['inProjects']) >= 1
コード例 #12
0
ファイル: test_rest.py プロジェクト: albertcrowley/PyNIDM
def test_uri_projects_subjects_1():
    global test_p2_subject_uuids

    proj_uuid = 'p2'
    restParser = RestParser()
    result = restParser.run([REST_TEST_FILE], '/projects/{}/subjects'.format(proj_uuid))

    assert type(result) == dict
    assert len(result['uuid']) == 2

    assert test_p2_subject_uuids[0] in result['uuid']
    assert test_p2_subject_uuids[1] in result['uuid']
コード例 #13
0
ファイル: test_rest.py プロジェクト: albertcrowley/PyNIDM
def test_uri_subjects():
    global cmu_test_subject_uuid

    restParser = RestParser()
    restParser.setOutputFormat(RestParser.OBJECT_FORMAT)
    result = restParser.run(BRAIN_VOL_FILES, '/subjects/{}'.format(cmu_test_subject_uuid))

    assert type(result) == dict
    assert 'uuid' in result
    assert 'instruments' in result
    assert 'derivatives' in result

    assert cmu_test_subject_uuid == result['uuid']
コード例 #14
0
ファイル: test_rest.py プロジェクト: albertcrowley/PyNIDM
def test_project_fields_not_found():
    # test that things don't break if the field isn't in project
    rest_parser = RestParser(verbosity_level=0)
    rest_parser.setOutputFormat(RestParser.OBJECT_FORMAT)

    field = 'not_real_field'
    project = rest_parser.run( BRAIN_VOL_FILES, "/projects/{}?fields={}".format(cmu_test_project_uuid, field) )


    print (project)
    keys = set( [ i for i in project ]  )

    assert "error" in keys
コード例 #15
0
ファイル: test_rest.py プロジェクト: AKUMAR0019/PyNIDM
def test_uri_project_id():

    # try with the real brain volume files
    restParser = RestParser()
    result = restParser.run(BRAIN_VOL_FILES, '/projects')
    project = result[0]
    result = restParser.run(BRAIN_VOL_FILES, '/projects/{}'.format(project))

    assert 'dctypes:title' in result
    assert 'sio:Identifier' in result
    assert 'subjects' in result
    assert len(result['subjects']) > 2
    assert 'data_elements' in result
    assert len(result['data_elements']) > 2
コード例 #16
0
ファイル: test_rest.py プロジェクト: AKUMAR0019/PyNIDM
def test_project_fields_not_found():
    # test that things don't break if the field isn't in project
    rest_parser = RestParser(verbosity_level=0)
    rest_parser.setOutputFormat(RestParser.OBJECT_FORMAT)

    field = 'not_real_field'
    project = rest_parser.run(
        BRAIN_VOL_FILES,
        "/projects/{}?fields={}".format(cmu_test_project_uuid, field))

    assert ('field_values' in project)
    fv = project['field_values']
    assert (type(fv) == list)
    assert len(fv) == 0
コード例 #17
0
ファイル: test_rest.py プロジェクト: AKUMAR0019/PyNIDM
def test_project_fields_instruments():
    rest_parser = RestParser(verbosity_level=0)
    rest_parser.setOutputFormat(RestParser.OBJECT_FORMAT)

    field = 'AGE_AT_SCAN'
    project = rest_parser.run(
        BRAIN_VOL_FILES,
        "/projects/{}?fields={}".format(cmu_test_project_uuid, field))

    assert ('field_values' in project)
    fv = project['field_values']
    assert (type(fv) == list)
    fields_used = set([i["field"] for i in fv])
    assert field in fields_used
コード例 #18
0
def test_uri_project_id():

    # try with the real brain volume files
    restParser = RestParser()
    # result = restParser.run(OPENNEURO_FILES, '/projects')
    project = OPENNEURO_PROJECT_URI
    result = restParser.run(OPENNEURO_FILES, '/projects/{}'.format(project))

    assert 'dctypes:title' in result
    assert 'sio:Identifier' in result
    assert 'subjects' in result
    assert len(result['subjects']['uuid']) > 2
    assert 'data_elements' in result
    assert len(result['data_elements']['uuid']) > 1
コード例 #19
0
ファイル: test_rest.py プロジェクト: albertcrowley/PyNIDM
def test_project_fields_deriv():
    rest_parser = RestParser(verbosity_level=0)
    rest_parser.setOutputFormat(RestParser.OBJECT_FORMAT)

    field = 'fs_000003'
    project = rest_parser.run( BRAIN_VOL_FILES, "/projects/{}?fields={}".format(cmu_test_project_uuid, field) )

    # edited by DBK to account for only field values being returned
    #assert( 'field_values' in project )
    assert (len(project) > 0)
    #fv = project['field_values']
    fv = project
    assert( type( fv ) == list )
    fields_used = set( [ i.label for i in fv ]  )
    assert 'Brain Segmentation Volume (mm^3)' in fields_used
コード例 #20
0
ファイル: test_rest.py プロジェクト: albertcrowley/PyNIDM
def test_ExtremeFilters():
    restParser = RestParser(output_format=RestParser.OBJECT_FORMAT)
    if cmu_test_project_uuid:
        project = cmu_test_project_uuid
    else:
        projects  = restParser.run(BRAIN_VOL_FILES, '/projects')
        project = projects[0]

    details = restParser.run(BRAIN_VOL_FILES, '/projects/{}?filter=AGE_AT_SCAN gt 200'.format(project))
    assert len(details['subjects']['uuid']) == 0
    assert len(details['data_elements']['uuid']) > 0

    details = restParser.run(BRAIN_VOL_FILES, '/projects/{}?filter=instruments.AGE_AT_SCAN gt 0'.format(project))
    assert len(details['subjects']['uuid']) > 0
    assert len(details['data_elements']['uuid']) > 0
コード例 #21
0
def test_project_fields_instruments():
    rest_parser = RestParser(verbosity_level=0)
    rest_parser.setOutputFormat(RestParser.OBJECT_FORMAT)

    field = 'AGE_AT_SCAN'
    project = rest_parser.run(
        BRAIN_VOL_FILES,
        "/projects/{}?fields={}".format(cmu_test_project_uuid, field))

    # edited by DBK to account for only field values being returned
    #assert( 'field_values' in project )
    assert (len(project) > 0)
    #fv = project['field_values']
    fv = project
    assert (type(fv) == list)
    fields_used = set([i["field"] for i in fv])
    assert field in fields_used
コード例 #22
0
ファイル: test_rest.py プロジェクト: albertcrowley/PyNIDM
def test_odd_isabout_uris():
    rest_parser = RestParser(verbosity_level=0)
    # rest_parser.setOutputFormat(RestParser.CLI_FORMAT)
    rest_parser.setOutputFormat(RestParser.OBJECT_FORMAT)

    field = 'http://www.cognitiveatlas.org/ontology/cogat.owl#CAO_00962'
    fields = rest_parser.run( BRAIN_VOL_FILES, "/projects?fields={}".format(field) )

    # edited by DBK to account for only field values being returned
    #assert( 'field_values' in project )
    assert (len(fields) > 0)
    #fv = project['field_values']
    print (fields)
    fv = fields
    assert( type( fv ) == list )
    fields_used = set( [ i.label for i in fv ]  )
    assert 'ADOS_TOTAL' in fields_used
コード例 #23
0
def test_brain_vols():
    restParser = RestParser()
    if cmu_test_project_uuid:
        project = cmu_test_project_uuid
    else:
        project = (restParser.run(BRAIN_VOL_FILES, '/projects'))[0]
    subjects = restParser.run(BRAIN_VOL_FILES,
                              '/projects/{}/subjects'.format(project))
    subject = subjects['uuid'][0]

    data = Query.GetDerivativesDataForSubject(BRAIN_VOL_FILES, None, subject)

    assert (len(data) > 0)
    for key in data:
        assert ('StatCollectionType' in data[key])
        assert ('URI' in data[key])
        assert ('values' in data[key])
コード例 #24
0
ファイル: test_rest.py プロジェクト: albertcrowley/PyNIDM
def test_multiple_project_fields():
    rest_parser = RestParser(verbosity_level=0)
    # rest_parser.setOutputFormat(RestParser.CLI_FORMAT)
    rest_parser.setOutputFormat(RestParser.OBJECT_FORMAT)

    field = 'fs_000003,ilx_0100400'  # ilx0100400 is 'isAbout' age
    fields = rest_parser.run( BRAIN_VOL_FILES, "/projects?fields={}".format(field) )

    # edited by DBK to account for only field values being returned
    #assert( 'field_values' in project )
    assert (len(fields) > 0)
    #fv = project['field_values']
    print (fields)
    fv = fields
    assert( type( fv ) == list )
    fields_used = set( [ i.label for i in fv ]  )
    assert 'Brain Segmentation Volume (mm^3)' in fields_used
    assert 'age at scan' in fields_used
コード例 #25
0
ファイル: test_rest.py プロジェクト: albertcrowley/PyNIDM
def test_Filter_Flexibility():
    restParser = RestParser(output_format=RestParser.OBJECT_FORMAT)
    if cmu_test_project_uuid:
        project = cmu_test_project_uuid
    else:
        projects  = restParser.run(BRAIN_VOL_FILES, '/projects')
        project = projects[0]

    synonyms = Query.GetDatatypeSynonyms(tuple(BRAIN_VOL_FILES),project, 'ADOS_MODULE')
    real_synonyms = [x for x in synonyms if len(x) > 1]

    assert len(real_synonyms) > 1

    for syn in real_synonyms:
        if ' ' in syn:
            continue
        details = restParser.run(BRAIN_VOL_FILES, '/projects/{}?filter=instruments.{} gt 2'.format(project, syn))
        assert len(details['subjects']['uuid']) > 0
        assert len(details['data_elements']['uuid']) > 0
コード例 #26
0
ファイル: test_rest.py プロジェクト: albertcrowley/PyNIDM
def test_GetProjectsComputedMetadata():

    files = []

    rest = RestParser()
    rest.nidm_files = tuple(BRAIN_VOL_FILES)
    meta_data = Query.GetProjectsMetadata(BRAIN_VOL_FILES)
    rest.ExpandProjectMetaData(meta_data)
    parsed = Query.compressForJSONResponse(meta_data)

    for project_id in parsed['projects']:
        if parsed['projects'][project_id][str(Constants.NIDM_PROJECT_NAME)] == "ABIDE CMU_a Site":
            p3 = project_id
            break
    assert parsed['projects'][p3][str(Constants.NIDM_PROJECT_NAME)] == "ABIDE CMU_a Site"
    assert parsed['projects'][p3][Query.matchPrefix(str(Constants.NIDM_NUMBER_OF_SUBJECTS))] == 14
    assert parsed['projects'][p3]["age_min"] == 21.0
    assert parsed['projects'][p3]["age_max"] == 33.0
    assert set(parsed['projects'][p3][str(Constants.NIDM_GENDER)]) == set(['1', '2'])
コード例 #27
0
def test_dataelement_details():
    rest_parser = RestParser(output_format=RestParser.OBJECT_FORMAT)
    # result = rest_parser.run(OPENNEURO_FILES, '/dataelements')
    #
    # dti = rest_parser.run(OPENNEURO_FILES, '/dataelements/{}'.format(result["data_elements"]["label"][0]))
    #
    # assert "label" in dti
    # assert "description" in dti
    # assert "isAbout" in dti
    # assert "inProjects" in dti
    #
    # # make sure the text formatter doesn't fail horribly
    # rest_parser.setOutputFormat(RestParser.CLI_FORMAT)
    # txt = rest_parser.run(OPENNEURO_FILES, '/dataelements/{}'.format(result["data_elements"]["label"][0]))
    #

    dti = rest_parser.run(
        OPENNEURO_FILES,
        '/dataelements/Left-WM-hypointensities Volume_mm3 (mm^3)')
    print(dti)
コード例 #28
0
def setup():
    global cmu_test_project_uuid, cmu_test_subject_uuid, OPENNEURO_PROJECT_URI, OPENNEURO_SUB_URI

    if Path(REST_TEST_FILE).is_file():
        os.remove(REST_TEST_FILE)
    makeTestFile(filename=REST_TEST_FILE,
                 params={
                     'PROJECT_UUID': 'p1',
                     'PROJECT2_UUID': 'p2'
                 })

    for f in ['./cmu_a.nidm.ttl', 'caltech.nidm.ttl']:
        if Path(f).is_file():
            os.remove(f)

    if not Path('./cmu_a.nidm.ttl').is_file():
        urllib.request.urlretrieve(
            "https://raw.githubusercontent.com/dbkeator/simple2_NIDM_examples/master/datasets.datalad.org/abide/RawDataBIDS/CMU_a/nidm.ttl",
            "cmu_a.nidm.ttl")

    if not Path('./caltech.nidm.ttl').is_file():
        urllib.request.urlretrieve(
            "https://raw.githubusercontent.com/dbkeator/simple2_NIDM_examples/master/datasets.datalad.org/abide/RawDataBIDS/Caltech/nidm.ttl",
            "caltech.nidm.ttl")

    restParser = RestParser(output_format=RestParser.OBJECT_FORMAT)
    projects = restParser.run(BRAIN_VOL_FILES, '/projects')
    for p in projects:
        proj_info = restParser.run(BRAIN_VOL_FILES, '/projects/{}'.format(p))
        if 'dctypes:title' in proj_info.keys(
        ) and proj_info['dctypes:title'] == 'ABIDE CMU_a Site':
            cmu_test_project_uuid = p
            break
    subjects = restParser.run(
        BRAIN_VOL_FILES, '/projects/{}/subjects'.format(cmu_test_project_uuid))
    cmu_test_subject_uuid = subjects['uuid'][0]

    if not Path('./ds000168.nidm.ttl').is_file():
        urllib.request.urlretrieve(
            "https://raw.githubusercontent.com/dbkeator/simple2_NIDM_examples/master/datasets.datalad.org/openneuro/ds000168/nidm.ttl",
            "ds000168.nidm.ttl")

    projects2 = restParser.run(OPENNEURO_FILES, '/projects')
    for p in projects2:
        proj_info = restParser.run(OPENNEURO_FILES, '/projects/{}'.format(p))
        if 'dctypes:title' in proj_info.keys() and proj_info[
                'dctypes:title'] == 'Offline Processing in Associative Learning':
            OPENNEURO_PROJECT_URI = p
    subjects = restParser.run(
        OPENNEURO_FILES, '/projects/{}/subjects'.format(OPENNEURO_PROJECT_URI))
    OPENNEURO_SUB_URI = subjects['uuid'][0]
コード例 #29
0
def test_project_fields_instruments():
    rest_parser = RestParser(verbosity_level=0)

    # projects = rest_parser.run(BRAIN_VOL_FILES, '/projects')
    # proj_uuid = projects[0]
    proj_uuid = cmu_test_project_uuid

    rest_parser.setOutputFormat(RestParser.OBJECT_FORMAT)

    field = 'age at scan'
    uri = "/projects/{}?fields={}".format(proj_uuid, field)
    project = rest_parser.run(BRAIN_VOL_FILES, uri)

    # edited by DBK to account for only field values being returned
    #assert( 'field_values' in project )
    assert (len(project) > 0)
    #fv = project['field_values']
    fv = project
    assert (type(fv) == list)
    fields_used = set([i.label for i in fv])
    assert field in fields_used
コード例 #30
0
ファイル: test_rest.py プロジェクト: albertcrowley/PyNIDM
def test_uri_projects_subjects_id():
    global test_person_uuid

    restParser = RestParser()
    # result = restParser.run(OPENNEURO_FILES, '/projects')
    project = OPENNEURO_PROJECT_URI
    result = restParser.run(OPENNEURO_FILES, '/projects/{}/subjects'.format(project))
    subject = result['uuid'][0]

    uri = '/projects/{}/subjects/{}'.format(project,subject)
    result = restParser.run(OPENNEURO_FILES, uri)

    assert type(result) == dict
    assert result['uuid'] == subject
    assert len(result['instruments']) > 2

    instruments = result['instruments'].values()
    all_keys = []
    for i in instruments:
        all_keys += i.keys()
    assert 'age' in all_keys