def test_isolated_upgrade(self): lines = to_bel_lines(self.isolated_graph) with mock_bel_resources: reconstituted = from_lines(lines, manager=self.manager) self.bel_isolated_reconstituted(reconstituted)
def serialize_namespaces(namespaces, connection, path, directory): """Parses a BEL document then serializes the given namespaces (errors and all) to the given directory""" from pybel import from_lines from .definition_utils import export_namespaces graph = from_lines(path, manager=connection) export_namespaces(namespaces, graph, directory)
def async_compile(lines, connection, allow_nested=False, citation_clearing=False, store_parts=False): log.info('starting compilation') manager = build_manager(connection) try: graph = from_lines(lines, manager=manager, allow_nested=allow_nested, citation_clearing=citation_clearing) add_canonical_names(graph) except requests.exceptions.ConnectionError as e: message = 'Connection to resource could not be established.' log.exception(message) return message except InconsistientDefinitionError as e: message = '{} was defined multiple times.'.format(e.definition) log.exception(message) return message except Exception as e: message = 'Compilation error: {}'.format(e) log.exception(message) return message try: network = manager.insert_graph(graph, store_parts=store_parts) except IntegrityError: log_graph(graph, current_user, precompiled=False, failed=True) message = integrity_message.format(graph.name, graph.version) log.exception(message) manager.rollback() return message except Exception as e: log_graph(graph, current_user, precompiled=False, failed=True) message = "Error storing in database: {}".format(e) log.exception(message) return message log.info('done storing [%d]', network.id) try: add_network_reporting(manager, network, current_user, graph.number_of_nodes(), graph.number_of_edges(), len(graph.warnings), precompiled=False) except IntegrityError: message = 'Problem with reporting service.' log.exception(message) manager.rollback() return message return network.id
def test_difference(self): a = pybel.from_lines(test_bel_1.split('\n')) b = pybel.from_lines(test_bel_2.split('\n')) self.assertFalse(graph_entities_equal(a, b)) self.assertFalse(graph_topologically_equal(a, b)) self.assertFalse(graph_provenance_equal(a, b)) ''' d_nodes = { MIA, AKT1_Ph } self.assertEqual(d_nodes, set(d.nodes())) ''' d_edges = { (MIA, AKT1_Ph): { 'relation': 'directlyDecreases', 'SupportingText': 'Evidence 2', 'TESTAN2': '3' }, (FADD, CASP8): { 'relation': 'increases', 'SupportingText': 'Evidence 3', 'TESTAN1': '3' }, (AKT1, CASP8): { 'relation': 'association', 'SupportingText': 'Evidence 3', 'TESTAN1': '3' }, (CASP8, AKT1): { 'relation': 'association', 'SupportingText': 'Evidence 3', 'TESTAN1': '3' } } difference = graph_edges_difference(b, a) self.assertEqual({(AKT1, AKT1_Ph), (MIA, AKT1_Ph)}, difference)
def bel_to_cx(file, connection, output): """Convert a BEL Script from STDIN and write a CX document to STDOUT.""" try: graph = from_lines(file, manager=connection) except Exception: log.exception('error occurred while loading BEL.') sys.exit(1) try: to_cx_file(graph, output) except Exception: log.exception('error occurred in conversion to CX.') sys.exit(2) sys.exit(0)
def test_isolated_upgrade(self, mock): lines = to_bel_lines(self.isolated_graph) reconstituted = from_lines(lines, manager=self.manager) self.bel_isolated_reconstituted(reconstituted)
def test_thorough_upgrade(self): lines = to_bel_lines(self.thorough_graph) reconstituted = from_lines(lines, manager=self.manager) self.bel_thorough_reconstituted(reconstituted, check_citation_name=False)
def view_compile(): """An upload form for a BEL script""" form = CompileForm(save_network=True) if not form.validate_on_submit(): return render_template('compile.html', form=form, current_user=current_user) log.info('Running on %s', form.file.data.filename) t = time.time() # Decode the file with the given decoding (utf-8 is default) lines = codecs.iterdecode(form.file.data.stream, form.encoding.data) try: graph = from_lines( lines, manager=manager, allow_nested=form.allow_nested.data, citation_clearing=(not form.citation_clearing.data) ) add_canonical_names(graph) except requests.exceptions.ConnectionError as e: flash("Resource doesn't exist.", category='error') return render_error(e) except InconsistientDefinitionError as e: log.error('%s was defined multiple times', e.definition) flash('{} was defined multiple times.'.format(e.definition), category='error') return redirect(url_for('view_compile')) except Exception as e: log.exception('compilation error') flash('Compilation error: {}'.format(e)) return redirect(url_for('view_compile')) if not enable_cache: flash('Sorry, graph storage is not currently enabled.', category='warning') log_graph(graph, current_user, precompiled=False) return render_graph_summary(0, graph) if not form.save_network.data and not form.save_edge_store.data: log_graph(graph, current_user, precompiled=False) return render_graph_summary(0, graph) try: network = manager.insert_graph(graph, store_parts=form.save_edge_store.data) except IntegrityError: log_graph(graph, current_user, precompiled=False, failed=True) log.exception('integrity error') flash(integrity_message.format(graph.name, graph.version), category='error') manager.rollback() return redirect(url_for('view_compile')) except Exception as e: log_graph(graph, current_user, precompiled=False, failed=True) log.exception('general storage error') flash("Error storing in database: {}".format(e), category='error') return redirect(url_for('view_compile')) log.info('done storing %s [%d]', form.file.data.filename, network.id) try: add_network_reporting(manager, network, current_user, graph.number_of_nodes(), graph.number_of_edges(), len(graph.warnings), precompiled=False, public=form.public.data) except IntegrityError: log.exception('integrity error') flash('problem with reporting service', category='warning') manager.rollback() return redirect(url_for('view_summary', graph_id=network.id))
def serialize_namespaces(namespaces, connection, path, directory): """Parses a BEL document then serializes the given namespaces (errors and all) to the given directory""" graph = from_lines(path, manager=connection) export_namespaces(namespaces, graph, directory)