コード例 #1
0
ファイル: test_rest.py プロジェクト: josephmje/PyNIDM
def test_brain_vols():

    projects  = restParser(BRAIN_VOL_FILES, '/projects')
    subjects = restParser(BRAIN_VOL_FILES, '/projects/{}/subjects'.format(projects[0]))
    subject = subjects[0]

    data = Query.getStatsDataForSubject(BRAIN_VOL_FILES, subject)


    assert(len(data) > 0)
    assert('StatCollectionType' in data[0])
    assert('URI' in data[0])
    assert('values' in data[0])
コード例 #2
0
def test_uri_project_id():

    kwargs = {
        Constants.NIDM_PROJECT_NAME: "FBIRN_PhaseII",
        Constants.NIDM_PROJECT_IDENTIFIER: 9610,
        Constants.NIDM_PROJECT_DESCRIPTION: "1234356 Test investigation"
    }
    project = Project(uuid="_123456", attributes=kwargs)
    #save a turtle file
    with open("uri2test.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="_654321", attributes=kwargs)
    #save a turtle file
    with open("uri2test2.ttl", 'w') as f:
        f.write(project.serializeTurtle())

    result = restParser(['uri2test.ttl', 'uri2test2.ttl'],
                        '/projects/nidm:_123456')

    pp = pprint.PrettyPrinter()
    pp.pprint(result)

    assert type(result) == dict
    assert result["dct:description"] == "1234356 Test investigation"
コード例 #3
0
ファイル: test_rest.py プロジェクト: josephmje/PyNIDM
def test_uri_project_list():

    kwargs={Constants.NIDM_PROJECT_NAME:"FBIRN_PhaseII",Constants.NIDM_PROJECT_IDENTIFIER:9610,Constants.NIDM_PROJECT_DESCRIPTION:"Test investigation"}
    project = Project(uuid="_123456",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="_654321",attributes=kwargs)
    #save a turtle file
    with open("uritest2.ttl",'w') as f:
        f.write(project.serializeTurtle())

    result = restParser(['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 "_123456" in project_uuids
    assert "_654321" in project_uuids

    os.remove("uritest.ttl")
    os.remove("uritest2.ttl")
コード例 #4
0
ファイル: rest-server.py プロジェクト: josephmje/PyNIDM
 def get(self, all):
     files = getTTLFiles()
     if len(files) == 0:
         return ({
             'error':
             'No NIDM files found. You may need to add NIDM ttl files to ~/PyNIDM/ttl'
         })
     return restParser(files, all, 5)
コード例 #5
0
ファイル: test_rest.py プロジェクト: josephmje/PyNIDM
def test_uri_projects_subjects_1():
    global test_p2_subject_uuids

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

    assert type(result) == list
    assert len(result) == 2

    assert test_p2_subject_uuids[0] in result
    assert test_p2_subject_uuids[1] in result
コード例 #6
0
ファイル: test_rest.py プロジェクト: josephmje/PyNIDM
def test_GetParticipantDetails():
    projects  = restParser(BRAIN_VOL_FILES, '/projects')
    project = projects[0]
    subjects = restParser(BRAIN_VOL_FILES, '/projects/{}/subjects'.format(projects[0]))
    subject = subjects[0]

    import time
    start = time.time()

    Query.GetParticipantInstrumentData( BRAIN_VOL_FILES, project, subject )

    end = time.time()
    runtime = end - start
    # assert (runtime <  12)

    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 ('stats' in details)
コード例 #7
0
ファイル: test_rest.py プロジェクト: josephmje/PyNIDM
def test_uri_projects_subjects_id():
    global test_person_uuid

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

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

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

    for i in result['instruments']:
        assert 'AGE_AT_SCAN' in result['instruments'][i]
        age = float(result['instruments'][i]['AGE_AT_SCAN'])
        # WIP commented out by DBK to get tests to pass for the moment.  Needs updating?
        # assert  age > 0

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

    kwargs={Constants.NIDM_PROJECT_NAME:"FBIRN_PhaseII",Constants.NIDM_PROJECT_IDENTIFIER:9610,Constants.NIDM_PROJECT_DESCRIPTION:"1234356 Test investigation"}
    project = Project(uuid="_123456",attributes=kwargs)
    #save a turtle file
    with open("uri2test.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="_654321",attributes=kwargs)
    #save a turtle file
    with open("uri2test2.ttl",'w') as f:
        f.write(project.serializeTurtle())

    result = restParser(['uri2test.ttl', 'uri2test2.ttl'], '/projects/{}_123456'.format(Query.matchPrefix(Constants.NIIRI)) )

    assert type(result) == dict
    assert result["dct:description"] == "1234356 Test investigation"

    os.remove("uri2test.ttl")
    os.remove("uri2test2.ttl")
コード例 #9
0
def query(nidm_file_list, query_file, output_file, get_participants,
          get_instruments, get_instrument_vars, uri, j, verbosity):

    #query result list
    results = []

    if get_participants:
        df = GetParticipantIDs(nidm_file_list.split(','),
                               output_file=output_file)
    elif get_instruments:
        #first get all project UUIDs then iterate and get instruments adding to output dataframe
        project_list = GetProjectsUUID(nidm_file_list.split(','))
        count = 1
        for project in project_list:
            if count == 1:
                df = GetProjectInstruments(nidm_file_list.split(','),
                                           project_id=project)
                count += 1
            else:
                df = df.append(
                    GetProjectInstruments(nidm_file_list.split(','),
                                          project_id=project))

        #write dataframe
        #if output file parameter specified
        if (output_file is not None):

            df.to_csv(output_file)
            #with open(output_file,'w') as myfile:
            #    wr=csv.writer(myfile,quoting=csv.QUOTE_ALL)
            #    wr.writerow(df)

            #pd.DataFrame.from_records(df,columns=["Instruments"]).to_csv(output_file)
        else:
            print(df)
    elif get_instrument_vars:
        #first get all project UUIDs then iterate and get instruments adding to output dataframe
        project_list = GetProjectsUUID(nidm_file_list.split(','))
        count = 1
        for project in project_list:
            if count == 1:
                df = GetInstrumentVariables(nidm_file_list.split(','),
                                            project_id=project)
                count += 1
            else:
                df = df.append(
                    GetInstrumentVariables(nidm_file_list.split(','),
                                           project_id=project))

        #write dataframe
        #if output file parameter specified
        if (output_file is not None):

            df.to_csv(output_file)
        else:
            print(df)
    elif uri:
        df = restParser(nidm_file_list.split(','), uri, int(verbosity))
        if j:
            print(dumps(df))
        else:
            if type(df) == list:
                for x in df:
                    print(x)
            elif type(df) == dict:
                for k in df.keys():
                    print(str(k) + ' ' + str(df[k]))
            else:
                print(df)
    else:
        #read query from text fiile
        with open(query_file, 'r') as fp:
            query = fp.read()
        df = sparql_query_nidm(nidm_file_list.split(','), query, output_file)

    return df