Package: pybel
PyBELis a pure Python package for parsing and handling biological networks encoded in
theBiological Expression Language(BEL).It facilitates data interchange between data formats likeNetworkX,
Node-Link JSON,JGIF, CSV, SIF,Cytoscape,CX,INDRA, andGraphDati; database systems
like SQL andNeo4J; and web services likeNDEx,BioDati Studio, andBEL Commons. It also
provides exports for analytical tools likeHiPathia,Drug2waysandSPIA;
machine learning tools likePyKEENandOpenBioLink; and others.Its companion package,PyBEL Tools, contains a
suite of functions and pipelines for analyzing the resulting biological networks.We realize that we have a name conflict with the python wrapper for the cheminformatics package, OpenBabel. If you’re
looking for their python wrapper, seehere.CitationIf you find PyBEL useful for your work, please consider citing:[1]Hoyt, C. T.,et al.(2017).PyBEL: a Computational Framework for Biological Expression Language.Bioinformatics, 34(December), 1–2.InstallationPyBEL can be installed easily fromPyPIwith the following code in
your favorite shell:$pipinstallpybelor from the latest code onGitHubwith:$pipinstallgit+https://github.com/pybel/pybel.gitSee theinstallation documentationfor more advanced
instructions. Also, check the change log atCHANGELOG.rst.Getting StartedMore examples can be found in thedocumentationand in thePyBEL Notebooksrepository.Compiling and Saving a BEL GraphThis example illustrates how the a BEL document from theHuman Brain Pharmacomeproject can be loaded and compiled directly from GitHub.>>>importpybel>>>url='https://raw.githubusercontent.com/pharmacome/conib/master/hbp_knowledge/proteostasis/kim2013.bel'>>>graph=pybel.from_bel_script_url(url)Other functions for loading BEL content from many formats can be found in theI/O documentation.
Note that PyBEL can handleBEL 1.0andBEL 2.0+simultaneously.After you have a BEL graph, there are numerous ways to save it. Thepybel.dumpfunction knows
how to output it in many formats based on the file extension you give. For all of the possibilities,
check theI/O documentation.>>>importpybel>>>graph=...>>># write as BEL>>>pybel.dump(graph,'my_graph.bel')>>># write as Node-Link JSON for network viewers like D3>>>pybel.dump(graph,'my_graph.bel.nodelink.json')>>># write as GraphDati JSON for BioDati>>>pybel.dump(graph,'my_graph.bel.graphdati.json')>>># write as CX JSON for NDEx>>>pybel.dump(graph,'my_graph.bel.cx.json')>>># write as INDRA JSON for INDRA>>>pybel.dump(graph,'my_graph.indra.json')Summarizing the Contents of the GraphTheBELGraphobject has several “dispatches” which are properties that organize its various functionalities.
One is theBELGraph.summarizedispatch, which allows for printing summaries to the console.These examples will use theRAS Modelfrom EMMAA,
so you’ll have to be sure topip install indrafirst. The graph can be acquired and summarized withBELGraph.summarize.statistics()as in:>>>importpybel>>>graph=pybel.from_emmaa('rasmodel',date='2020-05-29-17-31-58')# Needs>>>graph.summarize.statistics()----------------------------------------NamerasmodelVersion2020-05-29-17-31-58NumberofNodes126NumberofNamespaces5NumberofEdges206NumberofAnnotations4NumberofCitations1NumberofAuthors0NetworkDensity1.31E-02NumberofComponents1NumberofWarnings0----------------------------------------The number of nodes of each type can be summarized withBELGraph.summarize.nodes()as in:>>>graph.summarize.nodes(examples=False)Type(3)Count-------------------Protein97Complex27Abundance2The number of nodes with each namespace can be summarized withBELGraph.summarize.namespaces()as in:>>>graph.summarize.namespaces(examples=False)Namespace(4)Count----------------------HGNC94FPLX3CHEBI1TEXT1The edges can be summarized withBELGraph.summarize.edges()as in:>>>graph.summarize.edges(examples=False)EdgeType(12)Count----------------------------------------ProteinincreasesProtein64ProteinhasVariantProtein48ProteinpartOfComplex47ComplexincreasesProtein20ProteindecreasesProtein9ComplexdirectlyIncreasesProtein8ProteinincreasesComplex3AbundancepartOfComplex3ProteinincreasesAbundance1ComplexpartOfComplex1ProteindecreasesAbundance1AbundancedecreasesProtein1Grounding the GraphNot all BEL graphs contain both the name and identifier for each entity. Some even use non-standard prefixes
(also callednamespacesin BEL). Usually, BEL graphs are validated against controlled vocabularies,
so the following demo shows how to add the corresponding identifiers to all nodes.fromurllib.requestimporturlretrieveurl='https://github.com/cthoyt/selventa-knowledge/blob/master/selventa_knowledge/large_corpus.bel.nodelink.json.gz'urlretrieve(url,'large_corpus.bel.nodelink.json.gz')importpybelgraph=pybel.load('large_corpus.bel.nodelink.json.gz')importpybel.groundinggrounded_graph=pybel.grounding.ground(graph)Note: you have to installpyobofor this to work and be running Python 3.7+.Displaying a BEL Graph in JupyterAfter installingjinja2andipython, BEL graphs can be displayed in Jupyter notebooks.>>>frompybel.examplesimportsialic_acid_graph>>>frompybel.io.jupyterimportto_jupyter>>>to_jupyter(sialic_acid_graph)Using the ParserIf you don’t want to use thepybel.BELGraphdata structure and just want to turn BEL statements into JSON
for your own purposes, you can directly use thepybel.parse()function.>>>importpybel>>>pybel.parse('p(hgnc:4617 ! GSK3B) regulates p(hgnc:6893 ! MAPT)'){'source':{'function':'Protein','concept':{'namespace':'hgnc','identifier':'4617','name':'GSK3B'}},'relation':'regulates','target':{'function':'Protein','concept':{'namespace':'hgnc','identifier':'6893','name':'MAPT'}}}This functionality can also be exposed through a Flask-based web application withpython-mpybel.apps.parserafter
installingflaskwithpip install flask. Note that the first run requires about a ~2 second delay to generate
the parser, after which each parse is very fast.Using the CLIPyBEL also installs a command line interface with the commandpybelfor simple utilities such as data
conversion. In this example, a BEL document is compiled then exported toGraphMLfor viewing in Cytoscape.$pybelcompile~/Desktop/example.bel$pybelserialize~/Desktop/example.bel--graphml~/Desktop/example.graphmlIn Cytoscape, open withImport > Network > From File.ContributingContributions, whether filing an issue, making a pull request, or forking, are appreciated. SeeCONTRIBUTING.rstfor more information on getting
involved.AcknowledgementsSupportThe development of PyBEL has been supported by several projects/organizations (in alphabetical order):The Cytoscape ConsortiumEnveda BiosciencesFraunhofer Center for Machine LearningFraunhofer Institute for Algorithms and Scientific Computing (SCAI)Harvard Program in Therapeutic Science - Laboratory of Systems PharmacologyUniversity of BonnFundingDARPA Young Faculty Award W911NF2010255 (PI: Benjamin M. Gyori).TheEuropean Union,European Federation of Pharmaceutical Industries and Associations
(EFPIA), andInnovative Medicines InitiativeJoint
Undertaking underAETIONOMY[grant number 115568], resources of which
are composed of financial contribution from the European Union’s Seventh Framework Programme (FP7/2007-2013) and
EFPIA companies in kind contribution.LogoThe PyBELlogowas designed byScott Colby.