예제 #1
0
    def categorize(self):
        memo = {}
        with click.progressbar(self.graph.nodes(data=True)) as bar:
            for n, data in bar:
                if n == 'Orphanet:98818':
                    import pudb
                    pu.db
                if 'category' not in data or data['category'] == [
                        'named thing'
                ]:
                    superclass = find_superclass(n, self.graph)
                    if superclass is not None:
                        data['category'] = [superclass]
        with click.progressbar(self.graph.edges(data=True)) as bar:
            for u, v, data in bar:
                if 'edge_label' not in data or data[
                        'edge_label'] is None or data[
                            'edge_label'] == 'related_to':
                    relation = data.get('relation')

                    if relation not in memo:
                        memo[relation] = find_superclass(relation, self.graph)

                    if memo[relation] is not None:
                        data['edge_label'] = memo[relation]
예제 #2
0
    def categorize(self) -> None:
        """
        Checks for a node's category property and assigns a category from BioLink Model.
        Checks for an edge's edge_label property and assigns a label from BioLink Model.
        """
        memo = {}
        with click.progressbar(
                self.graph.nodes(data=True),
                label='Finding superclass category for nodes') as bar:
            for n, data in bar:
                if 'category' not in data or data['category'] == [
                        'named thing'
                ]:
                    # if there is no category property for a node
                    # or category is simply 'named thing'
                    # then find a BioLink Model relevant category
                    superclass = find_superclass(n, self.graph)
                    if superclass is not None:
                        data['category'] = [superclass]

        with click.progressbar(
                self.graph.edges(data=True),
                label='Finding superclass category for edges') as bar:
            for u, v, data in bar:
                if 'edge_label' not in data or data[
                        'edge_label'] is None or data[
                            'edge_label'] == 'related_to':
                    # if there is no edge_label property for an edge
                    # or if edge_label property is None
                    # or if edge_label is simply 'related_to'
                    # then find a BioLink Model relevant edge_label
                    relation = data.get('relation')
                    if relation not in memo:
                        superclass = find_superclass(relation, self.graph)
                        memo[relation] = fmt_edgelabel(superclass)

                    if memo[relation] is not None:
                        data['edge_label'] = memo[relation]

        # Set all null categories to the default value, and format all others
        with click.progressbar(self.graph.nodes(data='category'),
                               label='Ensuring valid categories') as bar:
            for n, category in bar:
                if not isinstance(category, list) or category == []:
                    self.graph.node[n]['category'] = ['named thing']
                else:
                    category = [fmt_category(c) for c in category]

        # Set all null edgelabels to the default value, and format all others
        with click.progressbar(self.graph.edges(data=True),
                               label='Ensuring valid edge labels') as bar:
            for u, v, data in bar:
                if 'edge_label' not in data or data['edge_label'] is None:
                    data['edge_label'] = 'related_to'
                else:
                    data['edge_label'] = fmt_edgelabel(data['edge_label'])