A REST client for OpenCGA REST web services
Project description
PyOpenCGA
This Python client package makes use of the comprehensive RESTful web services API implemented for the OpenCGA platform. OpenCGA is an open-source project that implements a high-performance, scalable and secure platform for Genomic data analysis and visualisation
OpenCGA implements a secure and high performance platform for Big Data analysis and visualisation in current genomics. OpenCGA uses the most modern and advanced technologies to scale to petabytes of data. OpenCGA is designed and implemented to work with few million genomes. It is built on top of three main components: Catalog, Variant and Alignment Storage and Analysis.
More info about this project in the OpenCGA Docs
Installation
Cloning
PyOpenCGA can be cloned in your local machine by executing in your terminal:
$ git clone https://github.com/opencb/opencga.git
Once you have downloaded the project you can install the library. We recommend to install it inside a virtual environment:
$ cd opencga/tree/develop/opencga-client/src/main/python/pyOpenCGA $ python setup.py install
Pip install
Run the following command in the shell:
$ pip install pyopencga
Usage
Import pyOpenCGA package
The first step is to import the ClientConfiguration and OpenCGAClient from pyOpenCGA:
>>> from pyopencga.opencga_config import ClientConfiguration
>>> from pyopencga.opencga_client import OpenCGAClient
Setting up server host configuration
The second step is to generate a ClientConfiguration instance by passing a configuration dictionary containing the host to point to or a client-configuration.yml file:
>>> config = ClientConfiguration('/opt/opencga/conf/client-configuration.yml')
>>> config = ClientConfiguration({
"rest": {
"host": "http://bioinfo.hpc.cam.ac.uk/opencga-demo"
}
})
Log in to OpenCGA host server
With this configuration you can initialize the OpenCGAClient, and log in:
>>> oc = OpenCGAClient(config)
>>> oc.login('user')
For scripting or using Jupyter Notebooks is preferable to load user credentials from an external JSON file.
Once you are logged in, it is mandatory to use the token of the session to propagate the access of the clients to the host server:
>>> token = oc.token
>>> print(token)
eyJhbGciOi...
>>> oc = OpenCGAClient(configuration=config_dict, token=token)
Examples
The next step is to get an instance of the clients we may want to use:
>>> projects = oc.projects # Project client
>>> studies = oc.studies # Study client
>>> samples = oc.samples # Sample client
>>> cohorts = oc.cohorts # Cohort client
Now you can start asking to the OpenCGA RESTful service with pyOpenCGA:
>>> for project in projects.search(owner=user).get_results():
... print(project['id'])
project1
project2
[...]
There are two different ways to access to the query response data:
>>> foo_client.method().get_results() # Iterates over all the results of all the QueryResults
>>> foo_client.method().get_responses() # Iterates over all the responses
Data can be accessed specifying comma-separated IDs or a list of IDs:
>>> samples = 'NA12877,NA12878,NA12879'
>>> samples_list = ['NA12877','NA12878','NA12879']
>>> sc = oc.samples
>>> for result in sc.info(query_id=samples, study='user@project1:study1').get_results():
... print(result['id'], result['attributes']['OPENCGA_INDIVIDUAL']['disorders'])
NA12877 [{'id': 'OMIM6500', 'name': "Chron's Disease"}]
NA12878 []
NA12879 [{'id': 'OMIM6500', 'name': "Chron's Disease"}]
>>> for result in sc.info(query_id=samples_list, study='user@project1:study1').get_results():
... print(result['id'], result['attributes']['OPENCGA_INDIVIDUAL']['disorders'])
NA12877 [{'id': 'OMIM6500', 'name': "Chron's Disease"}]
NA12878 []
NA12879 [{'id': 'OMIM6500', 'name': "Chron's Disease"}]
Optional filters and extra options can be added as key-value parameters (where the values can be a comma-separated string or a list).
What can I ask for?
The best way to know which data can be retrieved for each client check OpenCGA web services swagger.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pyopencga-2.2.0.tar.gz
.
File metadata
- Download URL: pyopencga-2.2.0.tar.gz
- Upload date:
- Size: 54.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0958e0e215b7790459bd6472577ed5ea70611e12e0ee338829dd3d2a2ad70981 |
|
MD5 | 66c64d63b3a596c4713423ec1b2d829f |
|
BLAKE2b-256 | 2ffe69ddc17e2c97e337740059357c3cba62a83fa7bc3759ee931397f9e082aa |
Provenance
File details
Details for the file pyopencga-2.2.0-py3-none-any.whl
.
File metadata
- Download URL: pyopencga-2.2.0-py3-none-any.whl
- Upload date:
- Size: 77.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71bc7b542d6fc7426388110da6edfe58d3582aee84f12b41251337dae816982a |
|
MD5 | 6fce24eb0dcd8f40c4487309bbd2efdb |
|
BLAKE2b-256 | 2849028bd830b023c3d005582d6d698db078f6abe73c90742303eaed366cf216 |