Example #1
0
    def to_indra_statements(self, *args, **kwargs):
        """Dump as a list of INDRA statements.

        :rtype: List[indra.Statement]
        """
        graph = self.to_bel(*args, **kwargs)
        return to_indra_statements(graph)
Example #2
0
 def get_indra_statements(
         self,
         directory: str,
         use_cached: bool = True) -> List['indra.statements.Statement']:
     """Get INDRA statements for the graph."""
     return pybel.to_indra_statements(
         self.get_graph(directory, use_cached=use_cached))
Example #3
0
    def get_graph(
        self,
        directory: Optional[str] = None,
        use_cached: bool = True,
        use_tqdm: bool = True,
    ) -> BELGraph:
        """Get the graph from all sources."""
        if directory is None:
            if self.directory is None:
                raise ValueError
            directory = self.directory

        pickle_path = os.path.join(directory, f'{self.name}.bel.pickle')
        if use_cached and os.path.exists(pickle_path):
            return pybel.from_pickle(pickle_path)

        rv = union(self.get_graphs(use_tqdm=use_tqdm))
        self.metadata.update(rv)

        pybel.to_pickle(rv, pickle_path)

        nodelink_path = os.path.join(directory,
                                     f'{self.name}.bel.nodelink.json')
        pybel.to_json_path(rv, nodelink_path)

        sif_path = os.path.join(directory, f'{self.name}.bel.sif')
        pybel.to_sif_path(rv, sif_path)

        gsea_path = os.path.join(directory, f'{self.name}.bel.gmt')
        pybel.to_gsea_path(rv, gsea_path)

        graphml_path = os.path.join(directory, f'{self.name}.bel.graphml')
        pybel.to_graphml(rv, graphml_path)

        try:
            statements = pybel.to_indra_statements(rv)
        except ImportError:
            pass
        else:
            indra_path = os.path.join(directory, f'{self.name}.indra.pickle')
            with open(indra_path, 'wb') as file:
                pickle.dump(statements, file)

        try:
            from pybel_cx import to_cx_file
        except ImportError:
            pass
        else:
            cx_path = os.path.join(directory, f'{self.name}.bel.cx.json')
            with open(cx_path, 'w') as file:
                to_cx_file(rv, file)

        try:
            from pybel_tools.assembler.html import to_html
        except ImportError:
            pass
        else:
            html_path = os.path.join(directory, 'index.html')
            with open(html_path, 'w') as file:
                print(to_html(rv), file=file)

        return rv
Example #4
0
def iterate_indra_statements(**kwargs
                             ) -> Iterable['indra.statements.Statement']:
    """Iterate over INDRA statements for the universe."""
    for _, _, graph in iterate_universe_graphs(**kwargs):
        yield from pybel.to_indra_statements(graph)