Package: pyopencga
ContentsPyOpenCGAInstallationCloningPip installUsageImport pyOpenCGA packageSetting up server host configurationLog in to OpenCGA host serverExamplesWhat can I ask for?PyOpenCGAThis Python client package makes use of the comprehensive RESTful web services API implemented for theOpenCGAplatform.
OpenCGA is an open-source project that implements a high-performance, scalable and secure platform for Genomic data analysis and visualisationOpenCGA 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 theOpenCGA DocsInstallationCloningPyOpenCGA can be cloned in your local machine by executing in your terminal:$ git clone https://github.com/opencb/opencga.gitOnce you have downloaded the project you can install the library. We recommend to install it inside avirtual environment:$ cd opencga/tree/develop/opencga-client/src/main/python/pyOpenCGA
$ python setup.py installPip installRun the following command in the shell:$ pip install pyopencgaUsageImport pyOpenCGA packageThe first step is to import the ClientConfiguration and OpenCGAClient from pyOpenCGA:>>>frompyopencga.opencga_configimportClientConfiguration>>>frompyopencga.opencga_clientimportOpenCGAClientSetting up server host configurationThe 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 serverWith 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)ExamplesThe 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 clientNow you can start asking to the OpenCGA RESTful service with pyOpenCGA:>>>forprojectinprojects.search(owner=user).get_results():...print(project['id'])project1project2[...]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 responsesData can be accessed specifying comma-separated IDs or a list of IDs:>>>samples='NA12877,NA12878,NA12879'>>>samples_list=['NA12877','NA12878','NA12879']>>>sc=oc.samples>>>forresultinsc.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"}]>>>forresultinsc.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 checkOpenCGA web servicesswagger.