コード例 #1
0
    def getFieldInfoForSubject(self, project, subject):
        '''
        Returns a dictionary of activities where the subject has matching field data
        The result[activity] is the full data_element so to get the value you would use result[activity].value
        Note that a subject could match the same field in multiple activities.

        :param project:
        :param subject:
        :return:
        '''
        result = {}
        # if we got fields, drill into each subject and pull out the field data
        # subject details -> derivitives / instrument -> values -> element
        if 'fields' in self.query and len(self.query['fields']) > 0:
            # get all the synonyms for all the fields - we can seach for them all at once
            field_synonyms = functools.reduce(operator.iconcat, [
                Query.GetDatatypeSynonyms(self.nidm_files, project, x)
                for x in self.query['fields']
            ], [])

            # print (field_synonyms)

            for activity in Navigate.getActivities(self.nidm_files, subject):
                activity_data = Navigate.getActivityData(
                    self.nidm_files, activity)
                # print ([ x.label for x in activity.data])
                for data_element in activity_data.data:
                    if not set([
                            data_element.dataElement, data_element.label,
                            data_element.isAbout
                    ]).isdisjoint(set(field_synonyms)):
                        result[Query.URITail(activity)] = data_element
        return result
コード例 #2
0
    def projects(self):
        result = []
        field_values = []
        self.restLog("Returning all projects", 2)
        projects = Query.GetProjectsUUID(self.nidm_files)
        for uuid in projects:
            result.append(str(uuid).replace(Constants.NIIRI, ""))

        # if we got fields, drill into each subject and pull out the field data
        # subject details -> derivitives / instrument -> values -> element
        if 'fields' in self.query and len(self.query['fields']) > 0:
            subjects_set = set()
            dataelements_set = set()
            self.restLog("Using fields {}".format(self.query['fields']), 2)
            # result['field_values'] = []

            for proj in projects:
                # get all the synonyms for all the fields
                field_synonyms = functools.reduce(operator.iconcat, [
                    Query.GetDatatypeSynonyms(self.nidm_files, proj, x)
                    for x in self.query['fields']
                ], [])

                files = self.nidm_files
                all_subjects = Query.GetParticipantUUIDsForProject(
                    self.nidm_files, proj, self.query['filter']
                )  # nidm_file_list= files, project_id=proj['uuid'], filter=self.query['filter']):
                for sub in all_subjects['uuid']:

                    for activity in Navigate.getActivities(
                            self.nidm_files, sub):
                        activity = Navigate.getActivityData(
                            self.nidm_files, activity)
                        for data_element in activity.data:
                            if data_element.dataElement in field_synonyms:
                                field_values.append(
                                    data_element._replace(subject=sub))
                                subjects_set.add(sub)
                                dataelements_set.add((data_element.datumType,
                                                      data_element.label))

            if len(field_values) == 0:
                raise ValueError("Supplied field not found. (" +
                                 ", ".join(self.query['fields']) + ")")
            else:
                summary_result = {}
                summary_result['subjects'] = {"uuid": [], "subject id": []}
                for sub in subjects_set:
                    summary_result["subjects"]["uuid"].append(sub)
                    summary_result["subjects"]["subject id"].append("")
                summary_result['data_elements'] = {"uuid": [], "lable": []}
                for de in dataelements_set:
                    summary_result['data_elements']["uuid"] = de[0]
                    summary_result['data_elements']["label"] = de[1]
                summary_result['field_values'] = field_values
                return self.projectSummaryFormat(summary_result)

        return self.format(result, ["UUID"])
コード例 #3
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
コード例 #4
0
    def projectSummary(self):

        match = re.match(r"^/?projects/([^/]+)$", self.command)
        id = parse.unquote(str(match.group(1)))
        self.restLog("Returing project {} summary".format(id), 2)

        result = nidm.experiment.Navigate.GetProjectAttributes(self.nidm_files,
                                                               project_id=id)
        result['subjects'] = Query.GetParticipantUUIDsForProject(
            self.nidm_files, project_id=id, filter=self.query['filter'])
        result['data_elements'] = Query.GetProjectDataElements(self.nidm_files,
                                                               project_id=id)

        # if we got fields, drill into each subject and pull out the field data
        # subject details -> derivitives / instrument -> values -> element
        if 'fields' in self.query and len(self.query['fields']) > 0:
            self.restLog("Using fields {}".format(self.query['fields']), 2)
            result['field_values'] = []
            # get all the synonyms for all the fields
            field_synonyms = functools.reduce(operator.iconcat, [
                Query.GetDatatypeSynonyms(self.nidm_files, id, x)
                for x in self.query['fields']
            ], [])
            for sub in result['subjects']['uuid']:

                for activity in Navigate.getActivities(self.nidm_files, sub):
                    activity = Navigate.getActivityData(
                        self.nidm_files, activity)
                    for data_element in activity.data:
                        if data_element.dataElement in field_synonyms:
                            result['field_values'].append(
                                data_element._replace(subject=sub))

            if len(result['field_values']) == 0:
                raise ValueError("Supplied field not found. (" +
                                 ", ".join(self.query['fields']) + ")")

        return self.projectSummaryFormat(result)