Exemplo n.º 1
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)
Exemplo n.º 2
0
 def subjectsList(self):
     match = re.match(r"^/?projects/([^/]+)/subjects/?$", self.command)
     project = match.group((1))
     self.restLog(
         "Returning all agents matching filter '{}' for project {}".format(
             self.query['filter'], project), 2)
     # result = Query.GetParticipantUUIDsForProject(self.nidm_files, project, self.query['filter'], None)
     all_subjects = Navigate.getSubjects(self.nidm_files, project)
     result = {}
     result['uuid'] = []
     result['subject id'] = []
     for sub_uuid in all_subjects:
         if Query.CheckSubjectMatchesFilter(self.nidm_files, project,
                                            sub_uuid, self.query['filter']):
             uuid_string = (str(sub_uuid)).split('/')[
                 -1]  # srip off the http://whatever/whatever/
             result['uuid'].append(uuid_string)
             sid = Navigate.getSubjectIDfromUUID(self.nidm_files, sub_uuid)
             result['subject id'].append(str(sid))
     return self.format(result)