Ejemplo n.º 1
0
    def setUpClass(cls):
        """Set up this class with several pre-loaded BEL graphs."""
        super().setUpClass()

        with mock_bel_resources:
            cls.thorough_graph = from_bel_script(test_bel_thorough, manager=cls.manager, disallow_nested=False)
            cls.slushy_graph = from_bel_script(
                test_bel_slushy,
                manager=cls.manager,
                disallow_unqualified_translocations=True,
                disallow_nested=True,
            )
            cls.simple_graph = from_bel_script_url(Path(test_bel_simple).as_uri(), manager=cls.manager)
            cls.isolated_graph = from_bel_script(test_bel_isolated, manager=cls.manager)
            cls.misordered_graph = from_bel_script(test_bel_misordered, manager=cls.manager, citation_clearing=False)
Ejemplo n.º 2
0
def ci(directory: str, connection: str, required_annotations: List[str]):
    """Run in continuous integration setting."""
    repo = Repo(directory)

    file_names = get_changed(repo)
    if not file_names:
        click.secho(f'{EMOJI} no BEL files changed')
        sys.exit(0)

    manager = Manager(connection=connection)

    failures = []
    for file_name in file_names:
        click.echo(f'{EMOJI} file changed: {file_name}')
        t = time.time()
        graph = from_bel_script(file_name,
                                manager=manager,
                                required_annotations=required_annotations)
        fg_color = 'green'
        if graph.warnings:
            failures.append((file_name, graph))
            fg_color = 'red'

        click.secho(
            f'{EMOJI} done checking: {file_name} ({time.time() - t:.2f} seconds)',
            fg=fg_color)
        click.echo(graph.summary_str())

    if not failures:
        sys.exit(0)

    click.echo('')
    for file_name, graph in failures:
        click.secho(f'failed: {file_name} - {graph}', fg='red')
    sys.exit(1)
Ejemplo n.º 3
0
def process_belscript(file_name, **kwargs):
    """Return a PybelProcessor by processing a BEL script file.

    Key word arguments are passed directly to pybel.from_path,
    for further information, see
    pybel.readthedocs.io/en/latest/io.html#pybel.from_path
    Some keyword arguments we use here differ from the defaults
    of PyBEL, namely we set `citation_clearing` to False
    and `no_identifier_validation` to True.

    Parameters
    ----------
    file_name : str
        The path to a BEL script file.

    Returns
    -------
    bp : PybelProcessor
        A PybelProcessor object which contains INDRA Statements in
        bp.statements.
    """
    if 'citation_clearing' not in kwargs:
        kwargs['citation_clearing'] = False
    if 'no_identifier_validation' not in kwargs:
        kwargs['no_identifier_validation'] = True
    pybel_graph = pybel.from_bel_script(file_name, **kwargs)
    return process_pybel_graph(pybel_graph)
Ejemplo n.º 4
0
    def setUpClass(cls):
        """Set up the class with a BEL graph and its corresponding SQLAlchemy model."""
        super().setUpClass()

        with mock_bel_resources:
            cls.graph = from_bel_script(test_bel_simple,
                                        manager=cls.manager,
                                        disallow_nested=False)
            cls.network = cls.manager.insert_graph(cls.graph)
Ejemplo n.º 5
0
def get_graph(graph_name: str, force: bool = False) -> pybel.BELGraph:
    """Get the Selventa large corpus as a BEL Graph."""
    url = f'https://github.com/cthoyt/selventa-knowledge/raw/master/selventa_knowledge/{graph_name}.bel'
    cache_path = module.join(name=f'{graph_name}.bel.pickle')
    if cache_path.exists() and not force:
        return pybel.load(cache_path)
    path = module.ensure(url=url, force=force)
    graph = pybel.from_bel_script(path, citation_clearing=False)
    pybel.dump(graph, path.as_posix())
    return graph
Ejemplo n.º 6
0
    def test_bep_0008(self):
        """Test parsing works right"""
        graph = from_bel_script(test_bel_with_obo)
        self.assertIn('hgnc', graph.namespace_pattern)
        self.assertEqual(r'\d+', graph.namespace_pattern['hgnc'])

        self.assertEqual(0, graph.number_of_warnings(), msg=',\n'.join(map(str, graph.warnings)))

        self.assertEqual(2, graph.number_of_nodes())
        self.assertIn(Protein(namespace='hgnc', identifier='391', name='AKT1'), graph)
        self.assertIn(Protein(namespace='hgnc', identifier='3236', name='EGFR'), graph)
Ejemplo n.º 7
0
def upload_neurommsig_graphs(manager: Manager):
    """Only upload NeuroMMSig Sample Networks."""
    if not (os.path.exists(alzheimer_directory)
            and os.path.isdir(alzheimer_directory)):
        logger.warning('directory does not exist: %s', alzheimer_directory)
        return

    if not os.path.exists(neurommsig_directory):
        logger.info('created neurommsig directory: %s', neurommsig_directory)
        os.makedirs(neurommsig_directory)

    path = os.path.join(alzheimer_directory, 'alzheimers.bel')
    gpickle_path = os.path.join(alzheimer_directory, 'alzheimers.gpickle')

    if os.path.exists(gpickle_path):
        graph = from_pickle(gpickle_path)
    elif os.path.exists(path):
        graph = from_bel_script(path, manager=manager)
        to_pickle(graph, gpickle_path)
    else:
        raise RuntimeError('missing NeuroMMSig source file: {}'.format(path))

    subgraphs = {
        name: subgraph
        for name, subgraph in get_subgraphs_by_annotation(
            graph, annotation='Subgraph').items()
        if name in neurommsig_sample_networks
    }

    networks = []

    for subgraph_name, subgraph in subgraphs.items():
        subgraph.name = 'NeuroMMSig AD {}'.format(subgraph_name)
        subgraph.authors = 'Daniel Domingo-Fernandez et. al'
        subgraph.version = graph.version
        subgraph.license = graph.license

        # output to directory as gpickle
        to_pickle(
            subgraph,
            os.path.join(neurommsig_directory,
                         '{}.gpickle'.format(subgraph_name)))

        network = insert_graph(manager, subgraph, public=True, use_tqdm=True)
        networks.append(network)

    write_manifest(neurommsig_directory, networks)
Ejemplo n.º 8
0
def parse(manager: WebManager, path: str, public: bool):
    """Parses a BEL script and uploads."""
    t = time.time()
    graph = from_bel_script(path, manager=manager)
    logger.info('parsing done in %.2f seconds', time.time() - t)
    insert_graph(manager, graph, public=public, use_tqdm=True)