예제 #1
0
def register_examples(manager: Manager, user_datastore: SQLAlchemyUserDatastore, butler: User) -> None:
    """Insert example graphs."""
    for graph in (sialic_acid_graph, egf_graph, statin_graph, homology_graph):
        if not manager.has_name_version(graph.name, graph.version):
            logger.info('uploading public example graph: %s', graph)
            insert_graph(manager, graph, user=butler, public=True)

    test_user = user_datastore.find_user(email='*****@*****.**')
    if test_user:
        for graph in (braf_graph,):
            if not manager.has_name_version(graph.name, graph.version):
                logger.info('uploading internal example graph: %s', graph)
                insert_graph(manager, graph, user=test_user, public=False)
예제 #2
0
def insert_graph(
    manager: Manager,
    graph: BELGraph,
    user: User,
    public: bool = True,
    use_tqdm: bool = False,
) -> Network:
    """Insert a graph and also make a report.

    :param manager: A PyBEL manager
    :param graph: A BEL graph
    :param user: The identifier of the user to report. Defaults to 1. Can also give a user object.
    :param public: Should the network be public? Defaults to False.
    :param use_tqdm: Show a progress bar? Defaults to False.
    :raises: TypeError
    """
    if manager.has_name_version(graph.name, graph.version):
        logger.info('database already has %s', graph)
        return manager.get_network_by_name_version(graph.name, graph.version)

    network = manager.insert_graph(graph, use_tqdm=use_tqdm)

    report = Report(public=public, user=user)

    fill_out_report(graph=graph, network=network, report=report)

    manager.session.add(report)
    manager.session.commit()

    return network