def to_web(self, host=None, user=None, password=None): """Send the model to BEL Commons by wrapping :py:func:`pybel.to_web` The parameters ``host``, ``user``, and ``password`` all check the PyBEL configuration, which is located at ``~/.config/pybel/config.json`` by default Parameters ---------- host : Optional[str] The host name to use. If none, first checks the PyBEL configuration entry ``PYBEL_REMOTE_HOST``, then the environment variable ``PYBEL_REMOTE_HOST``. Finally, defaults to https://bel-commons.scai.fraunhofer.de. user : Optional[str] The username (email) to use. If none, first checks the PyBEL configuration entry ``PYBEL_REMOTE_USER``, then the environment variable ``PYBEL_REMOTE_USER``. password : Optional[str] The password to use. If none, first checks the PyBEL configuration entry ``PYBEL_REMOTE_PASSWORD``, then the environment variable ``PYBEL_REMOTE_PASSWORD``. Returns ------- response : requests.Response The response from the BEL Commons network upload endpoint. """ response = pybel.to_web(self.model, host=host, user=user, password=password) return response
def to_web(self, host=None, user=None, password=None): """Send the model to BEL Commons by wrapping :py:func:`pybel.to_web` The parameters ``host``, ``user``, and ``password`` all check the PyBEL configuration, which is located at ``~/.config/pybel/config.json`` by default Parameters ---------- host : Optional[str] The host name to use. If none, first checks the PyBEL configuration entry ``PYBEL_REMOTE_HOST``, then the environment variable ``PYBEL_REMOTE_HOST``. Finally, defaults to https://bel-commons.scai.fraunhofer.de. user : Optional[str] The username (email) to use. If none, first checks the PyBEL configuration entry ``PYBEL_REMOTE_USER``, then the environment variable ``PYBEL_REMOTE_USER``. password : Optional[str] The password to use. If none, first checks the PyBEL configuration entry ``PYBEL_REMOTE_PASSWORD``, then the environment variable ``PYBEL_REMOTE_PASSWORD``. Returns ------- response : requests.Response The response from the BEL Commons network upload endpoint. """ response = pybel.to_web(self.model, host=host, user=user, password=password) return response
def machine(agents, local, connection, host): """Get content from the INDRA machine and upload to BEL Commons.""" from indra.sources import indra_db_rest from pybel import from_indra_statements, to_web statements = indra_db_rest.get_statements(agents=agents) click.echo('got {} statements from INDRA'.format(len(statements))) graph = from_indra_statements( statements, name='INDRA Machine for {}'.format(', '.join(sorted(agents))), version=time.strftime('%Y%m%d'), ) click.echo('built BEL graph with {} nodes and {} edges'.format( graph.number_of_nodes(), graph.number_of_edges())) if 0 == len(graph): click.echo('not uploading empty graph') sys.exit(-1) if local: manager = Manager(connection=connection) to_database(graph, manager=manager) else: resp = to_web(graph, host=host) resp.raise_for_status()
def upload(manager, path, skip_check_version, to_service, service_url, exclude_directory_pattern, debug): """Upload gpickles""" set_debug_param(debug) if os.path.isdir(path): log.info('uploading recursively from: %s', path) upload_recursive(path, connection=manager, exclude_directory_pattern=exclude_directory_pattern) elif os.path.isfile(path): from pybel import from_pickle graph = from_pickle(path, check_version=(not skip_check_version)) if to_service: from pybel import to_web to_web(graph, service_url) else: from pybel import to_database to_database(graph, connection=manager, store_parts=True)
def convert_paths(paths, connection=None, upload=False, pickle=False, canonicalize=True, infer_central_dogma=True, enrich_citations=False, send=False, version_in_path=False, **kwargs): """Recursively parses and either uploads/pickles graphs in a given set of files :param iter[str] paths: The paths to convert :param connection: The connection :type connection: None or str or pybel.manager.Manager :param bool upload: Should the networks be uploaded to the cache? :param bool pickle: Should the networks be saved as pickles? :param bool canonicalize: Calculate canonical nodes? :param bool infer_central_dogma: Should the central dogma be inferred for all proteins, RNAs, and miRNAs :param bool enrich_citations: Should the citations be enriched using Entrez Utils? :param bool send: Send to PyBEL Web? :param bool version_in_path: Add the current pybel version to the pathname :param kwargs: Parameters to pass to :func:`pybel.from_path` """ manager = Manager.ensure(connection) failures = [] for path in paths: log.info('parsing: %s', path) try: graph = from_path(path, manager=manager, **kwargs) except Exception as e: log.exception('problem parsing %s', path) failures.append((path, e)) continue if canonicalize: add_canonical_names(graph) if infer_central_dogma: infer_central_dogma_mutator(graph) if enrich_citations: enrich_pubmed_citations(graph=graph, manager=manager) if upload: to_database(graph, connection=manager, store_parts=True) if pickle: name = path[:-len( '.bel')] # gets rid of .bel at the end of the file name if version_in_path: new_path = '{}-{}.gpickle'.format(name, get_pybel_version()) else: new_path = '{}.gpickle'.format(name) to_pickle(graph, new_path) log.info('output pickle: %s', new_path) if send: response = to_web(graph) log.info('sent to PyBEL Web with response: %s', response.json()) return failures
def post(path, url, skip_check_version): """Posts the given graph to the PyBEL Web Service via JSON""" from pybel import from_pickle, to_web graph = from_pickle(path, check_version=(not skip_check_version)) to_web(graph, url)
def upload(manager: BELManagerMixin, host: str): """Upload BEL to BEL Commons.""" graph = manager.to_bel() pybel.to_web(graph, host=host, public=True)