Exemple #1
0
def standalone_get_subgraphs(inputs, score_attribute, group, threshold, min_size, max_size):
    flatter = Flatten()
    tcc = ThresholdedConnectedComponents(attribute=score_attribute, more_than=False, shrink_graphs=True,
                                         threshold=threshold,
                                         min_size=min_size,
                                         max_size=max_size)
    for e in flatter.transform(tcc.transform(inputs)):
        yield e
Exemple #2
0
    def _transform_single(self, graph):
        '''
        Parameters
        ----------
        score_attribute: string
            name of the attribute used
        group: string
            annnotate in this field
        Returns
        -------
        '''

        graphcopy = graph.copy()
        maxnodeid = max(graph.nodes())

        # def f(n,d): d[score_attribute] = graph.degree(n)
        # node_operation(graph,f)

        tcc = ThresholdedConnectedComponents(attribute=self.score_attribute, more_than=False, shrink_graphs=True)
        components = tcc._extract_ccomponents(graph, threshold=self.score_threshold, min_size=self.min_size,
                                              max_size=self.max_size)

        nodeset = {n for g in components for n in g.nodes()}

        def f(n, d):
            d[self.group_attribute] = '~' if n in nodeset else '-'

        node_operation(graph, f)

        # now we either contract what we have, or additionally rename the contracted nodes according to the group estimator

        graph = name_estimation(graph, self.group_attribute, self.layer, graphcopy, self.vectorizer, self.nameestimator,
                                    components)
        #else:
        #    graph = contraction([graph],
        #                        contraction_attribute=group,
        #                        modifiers=[],
        #                        nesting=False, dont_contract_attribute_symbol='-').next()

        graph = nx.relabel_nodes(graph, dict(
            zip(graph.nodes(), range(maxnodeid + 1, 1 + maxnodeid + graph.number_of_nodes()))), copy=False)

        graph.graph['original']= graphcopy
        graph.graph['layer']=self.layer
        return graph