Cache

Cache Manager

class pybel.manager.base_cache.BaseCacheManager(connection=None, echo=False)[source]

Creates a connection to database and a persistent session using SQLAlchemy

A custom default can be set as an environment variable with the name pybel.constants.PYBEL_CONNECTION, using an RFC-1738 string. For example, a MySQL string can be given with the following form:

mysql+pymysql://<username>:<password>@<host>/<dbname>?charset=utf8[&<options>]

A SQLite connection string can be given in the form:

sqlite:///~/Desktop/cache.db

Further options and examples can be found on the SQLAlchemy documentation on engine configuration.

Parameters:
  • connection (str) – An RFC-1738 database connection string. If None, tries to load from the environment variable PYBEL_CONNECTION then from the config file ~/.config/pybel/config.json whose value for PYBEL_CONNECTION defaults to pybel.constants.DEFAULT_CACHE_LOCATION
  • echo (bool) – Turn on echoing sql
sessionmaker = None

A SQLAlchemy session maker

session = None

A SQLAlchemy session object

create_all(checkfirst=True)[source]

Creates the PyBEL cache’s database and tables

drop_database()[source]

Drops all data, tables, and databases for the PyBEL cache

class pybel.manager.cache.CacheManager(*args, **kwargs)[source]

The definition cache manager takes care of storing BEL namespace and annotation files for later use. It uses SQLite by default for speed and lightness, but any database can be used with its SQLAlchemy interface.

Database Models

This module contains the SQLAlchemy database models that support the definition cache and graph cache.

class pybel.manager.models.Base(**kwargs)

The most base type

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

class pybel.manager.models.Namespace(**kwargs)[source]

Represents a BEL Namespace

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

uploaded

The date of upload

url

Source url of the given namespace definition file (.belns)

keyword

Keyword that is used in a BEL file to identify a specific namespace

name

Name of the given namespace

domain

Domain for which this namespace is valid

species

Taxonomy identifiers for which this namespace is valid

description

Optional short description of the namespace

version

Version of the namespace

created

DateTime of the creation of the namespace definition file

query_url

URL that can be used to query the namespace (eternally from PyBEL)

author

The author of the namespace

license

License information

contact

Contact information

data

Returns the table entry as a dictionary without the SQLAlchemy instance information.

class pybel.manager.models.NamespaceEntry(**kwargs)[source]

Represents a name within a BEL namespace

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

name

Name that is defined in the corresponding namespace definition file

encoding

The biological entity types for which this name is valid

data

Describes the namespaceEntry as dictionary of Namespace-Keyword and Name.

to_json()[source]

Enables json serialization for the class this method is defined in.

class pybel.manager.models.NamespaceEntryEquivalence(**kwargs)[source]

Represents the equivalance classes between entities

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

class pybel.manager.models.Annotation(**kwargs)[source]

Represents a BEL Annotation

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

uploaded

The date of upload

url

Source url of the given annotation definition file (.belanno)

keyword

Keyword that is used in a BEL file to identify a specific annotation

type

Annotation type

description

Optional short description of the given annotation

version

Version of the annotation

created

DateTime of the creation of the given annotation definition

name

Name of the annotation definition

author

Author information

license

License information

contact

Contact information

class pybel.manager.models.AnnotationEntry(**kwargs)[source]

Represents a value within a BEL Annotation

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

name

Name that is defined in the corresponding annotation definition file

data

Describes the annotationEntry as dictionary of Annotation-Keyword and Annotation-Name.

to_json()[source]

Enables json serialization for the class this method is defined in.

class pybel.manager.models.Network(**kwargs)[source]

Represents a collection of edges, specified by a BEL Script

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

name

Name of the given Network (from the BEL file)

version

Release version of the given Network (from the BEL file)

authors

Authors of the underlying BEL file

contact

Contact information extracted from the underlying BEL file

description

Descriptive text extracted from the BEL file

copyright

Copyright information

disclaimer

Disclaimer information

licenses

License information

blob

A pickled version of this network

as_bel()[source]

Gets this network and loads it into a BELGraph

Return type:BELGraph
class pybel.manager.models.Node(**kwargs)[source]

Represents a BEL Term

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

type

The type of the represented biological entity e.g. Protein or Gene

namespacePattern

Contains regex pattern for value identification.

is_variant

Identifies weather or not the given node is a variant

fusion

Identifies weather or not the given node is a fusion

bel

Valid BEL term that represents the given node

to_json()[source]

Enables json serialization for the class this method is defined in.

class pybel.manager.models.Modification(**kwargs)[source]

The modifications that are present in the network are stored in this table.

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

modType

Type of the stored modification e.g. Fusion

modNamespace

Namespace for the modification name

modName

Name of the given modification (used for pmod or gmod)

aminoA

Three letter amino accid code

position

Position

data

Recreates a is_variant dictionary for BELGraph

Returns:Dictionary that describes a variant or a fusion.
Return type:dict
to_json()[source]

Enables json serialization for the class this method is defined in.

class pybel.manager.models.Author(**kwargs)[source]

Contains all author names.

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

class pybel.manager.models.Citation(**kwargs)[source]

The information about the citations that are used to prove a specific relation are stored in this table.

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

type

Type of the stored publication e.g. PubMed

name

Title of the publication

reference

Reference identifier of the publication e.g. PubMed_ID

date

Publication date

data

Creates a citation dictionary that is used to recreate the edge data dictionary of a BELGraph.

Returns:Citation dictionary for the recreation of a BELGraph.
Return type:dict
to_json()[source]

Enables json serialization for the class this method is defined in.

class pybel.manager.models.Evidence(**kwargs)[source]

This table contains the evidence text that proves a specific relationship and refers the source that is cited.

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

text

Supporting text that is cited from a given publication

data

Creates a dictionary that is used to recreate the edge data dictionary for a BELGraph.

Returns:Dictionary containing citation and evidence for a BELGraph edge.
Return type:dict
to_json()[source]

Enables json serialization for the class this method is defined in.

class pybel.manager.models.Edge(**kwargs)[source]

Relationships are represented in this table. It shows the nodes that are in a relation to eachother and provides information about the context of the relation by refaring to the annotation, property and evidence tables.

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

bel

Valid BEL statement that represents the given edge

data

Creates a dictionary of one BEL Edge that can be used to create an edge in a BELGraph.

Returns:Dictionary that contains information about an edge of a BELGraph. Including participants and edge data information.
Return type:dict
class pybel.manager.models.Property(**kwargs)[source]

The property table contains additional information that is used to describe the context of a relation.

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

participant

Identifies which participant of the edge if affected by the given property

modifier

The modifier to the corresponding participant

effectNamespace

Optional namespace that defines modifier value

effectName

Value for specific modifiers e.g. Activity

relativeKey

Relative key of effect e.g. to_tloc or from_tloc

propValue

Value of the effect

data

Creates a property dict that is used to recreate an edge dictionary for a BELGraph.

Returns:Property dictionary of an edge that is participant (sub/obj) related.
Return type:dict
to_json()[source]

Enables json serialization for the class this method is defined in.