The OpenCGA Python Client provides a user-friendly API to work with OpenCGA through the REST Web Services. Python client is called pyOpenCGA, some of the main features include:
pyOpenCGA has been implemented and contributed by Pablo Marin and David Gomez and it is based on the previous pyCGA library implemented by Antonio Rueda and Daniel Perez from Genomics England.
Python client requires at least Python 3.x, although most of the code is fully compatible with Python 2.7. You can install pyOpenCGA either from PyPI repository or from the source code.
You can find stable releases of pyOpenCGA at https://pypi.org/project/pyopencga/, installing is as simple as:
## Latest stable version pip install pyopencga |
Python client source code can be found in OpenCGA GitHub repository at https://github.com/opencb/opencga/tree/develop/opencga-client/src/main/python/pyOpenCGA. To install any stable of development version of pyOpenCGA we will first need to clone the right branch of OpenCGA repository and install the library using the setup.py file.
## Latest stable version git clone -b master https://github.com/opencb/opencga.git ## Move to the pyOpenCGA client folder cd opencga/opencga-client/src/main/python/pyOpenCGA/ ## Install the library python setup.py install |
Developers only need to create an instance of the ConfigClient class passing it as an argument to the OpenCGAClient. They can optionally pass the user and password or a valid token to start doing calls as an authenticated user. The only role of the OpenCGAClient class is to work as a factory of the actual clients.
## Import OpenCGAClient and ConfigClient classes from pyopencga.opencga_client import OpenCGAClient from pyopencga.opencga_config import ConfigClient ## Creating ConfigClient host = 'localhost:8080/opencga' cc = ConfigClient() config_dict = cc.get_basic_config_dict(host) ## Create an instance of OpenCGAClient passing the user credentials oc = OpenCGAClient(configuration=config_dict, user="user", pwd="password") |
OpenCGAClient class works as a factory containing all the different clients necessary to call to any REST web service.
As described in RESTful Web Services#RESTResponse, most of the web services return a QueryResponse object containing a list of QueryResults. This structure has been maintained in the Python library and everytime a call to any WS is done, the response is automatically encapsulated into a custom QueryResponse class that automatically stores all the different values returned and defines a few public methods to help users navigating through the data.
The QueryResponse methods developed are:
## Return the first QueryResult from the QueryResponse. first() ## Return the first result from the 'index' QueryResult. ## If 'index' is not provided, it will automatically show the first result of the first QueryResult result(index) ## Return an iterator to help iterating over all the results. results() ## Return the total number of results obtained. num_total_results() |
The client implements at least one function for each available resource (user, project, study, etc.). Currently, the following functions are available:
## User oc.users.login(user, pwd, **options) oc.users.refresh_token(user, **options) oc.users.logout() oc.users.info(query_id, **options) oc.users.create(data, **options) oc.users.update(query_id, data, **options) oc.users.delete(**options) oc.users.projects(user, **options) oc.users.update_password(user, pwd, newpwd, **options) oc.users.configs(user, **options) oc.users.update_configs(user, data, action, **options) oc.users.filters(user, **options) oc.users.update_filters(user, data, action, **options) oc.users.update_filter(user, filter_name, data, **options) ## Projects oc.projects.info(query_id, **options) oc.projects.create(data, **options) oc.projects.update(query_id, data, **options) oc.projects.delete(**options) oc.projects.search(**options) oc.projects.studies(project, **options) oc.projects.aggregation_stats(project, **options) oc.projects.increment_release(project, **options) ## Studies oc.studies.info(query_id, **options) oc.studies.create(data, **options) oc.studies.update(query_id, data, **options) oc.studies.delete(**options) oc.studies.acl(query_id, **options) oc.studies.update_acl(memberId, data, **options) oc.studies.groups(study, **options) oc.studies.search(**options) oc.studies.scan_files(study, **options) oc.studies.resync_files(study, **options) oc.studies.create_groups(study, data, **options) oc.studies.update_groups(study, data, action, *options) oc.studies.update_users_from_group(study, group, data, action, **options) oc.studies.permission_rules(study, entity, **options) oc.studies.update_permission_rules(study, entity, data, action, **options) oc.studies.variablesets(study, **options) oc.studies.update_variablesets(study, data, action, **options) oc.studies.aggregation_stats(study, **options) oc.studies.update_variable_from_variableset(study, variable_set, action, **options) ## Individuals oc.individuals.info(query_id, **options) oc.individuals.create(data, **options) oc.individuals.update(query_id, data, **options) oc.individuals.delete(**options) oc.individuals.search(**options) oc.individuals.aggregation_stats(**options) oc.individuals.update_annotations(query_id, annotationset_id, data, **options) oc.individuals.acl(query_id, **options) oc.individuals.update_acl(memberId, data, **options) ## Samples oc.samples.info(query_id, **options) oc.samples.create(data, **options) oc.samples.update(query_id, data, **options) oc.samples.delete(**options) oc.samples.search(**options) oc.samples.load(file, **options) oc.samples.aggregation_stats(**options) oc.samples.update_annotations(query_id, annotationset_id, data, **options) oc.samples.acl(query_id, **options) oc.samples.update_acl(memberId, data, **options) ## Files oc.files.info(query_id, **options) oc.files.create(data, **options) oc.files.update(query_id, data, **options) oc.files.delete(**options) oc.files.search(**options) oc.files.aggregation_stats(**options) oc.files.bioformats(**options) oc.files.formats(**options) oc.files.scan_folder(folder, **options) oc.files.list_folder(folder, **options) oc.files.content(file, **options) oc.files.grep(file, **options) oc.files.refresh(file, **options) oc.files.tree_folder(folder, **options) oc.files.upload(data, **options) oc.files.download(file, **options) oc.files.update_annotations(query_id, annotationset_id, data, **options) oc.files.acl(query_id, **options) oc.files.update_acl(memberId, data, **options) ## Jobs oc.jobs.info(query_id, **options) oc.jobs.create(data, **options) oc.jobs.update(query_id, data, **options) oc.jobs.delete(**options) oc.jobs.search(**options) oc.jobs.visit(job, **options) oc.jobs.acl(query_id, **options) oc.jobs.update_acl(memberId, data, **options) ## Families oc.families.info(query_id, **options) oc.families.create(data, **options) oc.families.update(query_id, data, **options) oc.families.delete(**options) oc.families.search(**options) oc.families.aggregation_stats(**options) oc.families.update_annotations(query_id, annotationset_id, data, **options) oc.families.acl(query_id, **options) oc.families.update_acl(memberId, data, **options) ## Cohorts oc.cohorts.info(query_id, **options) oc.cohorts.create(data, **options) oc.cohorts.update(query_id, data, **options) oc.cohorts.delete(**options) oc.cohorts.search(**options) oc.cohorts.aggregation_stats(**options) oc.cohorts.samples(self, cohort, **options) oc.cohorts.update_annotations(query_id, annotationset_id, data, **options) oc.cohorts.acl(query_id, **options) oc.cohorts.update_acl(memberId, data, **options) ## Disease Panels oc.panels.info(query_id, **options) oc.panels.create(data, **options) oc.panels.update(query_id, data, **options) oc.panels.delete(**options) oc.panels.search(**options) oc.panels.acl(query_id, **options) oc.panels.update_acl(memberId, data, **options) |
Table of Contents: