Skip to main content

Python client for CellBase

Project description

PyCellBase

  • PyCellBase is a Python package that provides programmatic access to the comprehensive RESTful web service API that has been implemented for the CellBase database, providing an easy, lightweight, fast and intuitive access to it.

  • This package can be used to access to relevant biological information in a user-friendly way without the need of local databases installations.

  • Data is always available by a high-availability cluster and queries have been tuned to ensure a real-time performance.

  • PyCellBase offers the convenience of an object-oriented scripting language and provides the ability to integrate the obtained results into other Python applications.

  • More info about this package in the Python client section of the CellBase Wiki

Installation

Cloning

PyCellBase can be cloned in your local machine by executing in your terminal:

$ git clone https://github.com/opencb/cellbase.git

Once you have downloaded the project you can install the library:

$ cd cellbase/clients/python
$ python setup.py install

PyPI

PyCellBase is stored in PyPI and can be installed via pip:

$ pip install pycellbase

REST client library

PyCellBase consumes the RESTful web services provided by CellBase, providing a simple and fast access to the database. A series of clients and methods have been implemented to retrieve specific resources from the main features.

Getting started

The first step is to import the module and initialize the CellBaseClient:

>>> from pycellbase.cbclient import CellBaseClient
>>> cbc = CellBaseClient()

The second step is to create the specific client for the data we want to query (in this example we want to obtain information for a gene):

>>> gc = cbc.get_gene_client()

And now, you can start asking to the CellBase RESTful service by providing a query ID:

>>> tfbs_responses = gc.get_tfbs('BRCA1')  # Obtaining TFBS for this gene

Responses are retrieved as JSON formatted data. Therefore, fields can be queried by key:

>>> tfbs_responses = gc.get_tfbs('BRCA1')
>>> tfbs_responses[0]['result'][0]['tfName']
'E2F4'

>>> transcript_responses = gc.get_transcript('BRCA1')
>>> 'Number of transcripts: %d' % (len(transcript_responses[0]['result']))
'Number of transcripts: 27'

>>> for tfbs_response in gc.get_tfbs('BRCA1,BRCA2,LDLR'):
...     print('Number of TFBS for "%s": %d' % (tfbs_response['id'], len(tfbs_response['result'])))
'Number of TFBS for "BRCA1": 175'
'Number of TFBS for "BRCA2": 43'
'Number of TFBS for "LDLR": 141'

Data can be accessed specifying comma-separated IDs or a list of IDs:

>>> tfbs_responses = gc.get_tfbs('BRCA1')
>>> len(tfbs_responses)
1

>>> tfbs_responses = gc.get_tfbs('BRCA1,BRCA2')
>>> len(tfbs_responses)
2

>>> tfbs_responses = gc.get_tfbs(['BRCA1', 'BRCA2'])
>>> len(tfbs_responses)
2

If there is an available resource in the CellBase Webservices, but there is not an available method in this python package, the CellBaseClient can be used to create the URL of interest and query the RESTful service:

>>> tfbs_responses = cbc.get(category='feature', subcategory='gene', query_id='BRCA1', resource='tfbs')
>>> tfbs_responses[0]['result'][0]['tfName']
'E2F4'

Optional filters and extra options can be added as key-value parameters (value can be a comma-separated string or a list):

>>> tfbs_responses = gc.get_tfbs('BRCA1')
>>> len(res[0]['result'])
175

>>> tfbs_responses = gc.get_tfbs('BRCA1', include='name,id')  # Return only name and id
>>> len(res[0]['result'])
175

>>> tfbs_responses = gc.get_tfbs('BRCA1', include=['name', 'id'])  # Return only name and id
>>> len(res[0]['result'])
175

>>> tfbs_responses = gc.get_tfbs('BRCA1', **{'include': 'name,id'])  # Return only name and id
>>> len(res[0]['result'])
175

>>> tfbs_responses = gc.get_tfbs('BRCA1', limit=100)  # Limit to 100 results
>>> len(res[0]['result'])
100

>>> tfbs_responses = gc.get_tfbs('BRCA1', skip=100)  # Skip first 100 results
>>> len(res[0]['result'])
75

What can I ask for?

The best way to know which data can be retrieved for each client is either checking out the RESTful web services section of the CellBase Wiki or the CellBase web services

Configuration

Configuration stores the REST services host, API version and species.

Getting the default configuration:

>>> ConfigClient().get_default_configuration()
{'version': 'v4',
 'species': 'hsapiens',
 'rest': {'hosts': ['http://bioinfo.hpc.cam.ac.uk:80/cellbase']}}

Showing the configuration parameters being used at the moment:

>>> cbc.show_configuration()
{'host': 'bioinfo.hpc.cam.ac.uk:80/cellbase',
 'version': 'v4',
 'species': 'hsapiens'}

A custom configuration can be passed to CellBaseClient using a ConfigClient object. JSON and YAML files are supported:

>>> from pycellbase.cbconfig import ConfigClient
>>> from pycellbase.cbclient import CellBaseClient

>>> cc = ConfigClient('config.json')
>>> cbc = CellBaseClient(cc)

A custom configuration can also be passed as a dictionary:

>>> from pycellbase.cbconfig import ConfigClient
>>> from pycellbase.cbclient import CellBaseClient

>>> custom_config = {'rest': {'hosts': ['bioinfo.hpc.cam.ac.uk:80/cellbase']}, 'version': 'v4', 'species': 'hsapiens'}
>>> cc = ConfigClient(custom_config)
>>> cbc = CellBaseClient(cc)

If you want to change the configuration on the fly you can directly modify the ConfigClient object:

>>> cc = ConfigClient()
>>> cbc = CellBaseClient(cc)

>>> cbc.show_configuration()['version']
'v4'
>>> cc.version = 'v3'
>>> cbc.show_configuration()['version']
'v3'

Use case

A use case where PyCellBase is used to obtain multiple kinds of data from different sources can be found in this Jupyter Notebook

Command-line tools

A command-line interface, called cbtools.py, has been implemented with several tools to ease and speed up frequently performed tasks in bioinformatics. These tools make use of the REST client library and offer a further output processing to facilitate its analysis.

ID converter

This tool annotates genomic features with all their associated IDs, making use of 74 different sources for human, including most common databases such as Ensembl, NCBI, RefSeq, Reactome, OMIM, PDB, miRBase or UniProt among others. In addition, it supports heterogeneous input files with IDs from different sources.

$ cbtools.py xref file_with_ids.vcf > output.txt

HGVS calculator

This tool annotates variants with their associated HGVS names. Given a variant (in the format “chromosome:position:reference:alternate”), this tool returns all the associated HGVS names for many different types of reference sequence.

$ cbtools.py hgvs 19:45411941:T:C

A file with multiple variants can also be used.

$ cbtools.py hgvs file_with_variants.txt > output.txt

VCF annotator

This tool takes a VCF file as input and returns it with its variants annotated with a broad range of information such as consequence types, population frequencies, overlapping sequence repeats, cytobands, gene expression, conservation scores, clinical significance (ClinVar, COSMIC, diseases and drugs), functional scores and more.

$ cbtools.py annotation input.vcf > output.vcf

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycellbase-4.7.1.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

pycellbase-4.7.1-py2.py3-none-any.whl (27.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pycellbase-4.7.1.tar.gz.

File metadata

  • Download URL: pycellbase-4.7.1.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.9.1 pkginfo/1.4.1 requests/2.19.1 setuptools/37.0.0 requests-toolbelt/0.8.0 tqdm/4.15.0 CPython/2.7.12

File hashes

Hashes for pycellbase-4.7.1.tar.gz
Algorithm Hash digest
SHA256 f09ede0372f9d29d9367abeeeef1661fc0f29848c06d98368c8bddb123e94830
MD5 f194838faaa8dcf735d51263e9bb10c2
BLAKE2b-256 ed4c33767b858e9f217f38d3bdc3ff3cef2a82e2dbfcd1fa3b43891e2be7500c

See more details on using hashes here.

Provenance

File details

Details for the file pycellbase-4.7.1-py2.py3-none-any.whl.

File metadata

  • Download URL: pycellbase-4.7.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 27.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.9.1 pkginfo/1.4.1 requests/2.19.1 setuptools/37.0.0 requests-toolbelt/0.8.0 tqdm/4.15.0 CPython/2.7.12

File hashes

Hashes for pycellbase-4.7.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d11f0202eda7a87d60c64b0ad65b380bf864815274bda196c69c55a257140daa
MD5 83d33e7a337dd152d472bd59c0752fde
BLAKE2b-256 584aa608ab7a5f034e50919497a81730035e7875afee0c7e937410db2c375d3f

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page