Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 9 Next »

Python client pyCGA

pyCGA is the Python client library for OpenCGA RESTful Web Services, all the web services are accessible through this client, and it offers a quick way to query OpenCGA projects programmatically from custom scripts. For further information on how to install pyCGA please refer to RESTful Web Services and Clients#InstallingpyCGA. In the same way than in  Using RESTful Web Services URL tutorial, we will focus on those end points more interesting for HGVA users. In order to make it easy to follow we will use the same examples used in Using RESTful Web Services URL.

First of all, configure and import the library:

Example of configuration file in JSON format
{
    "version": "v1",
    "rest": {
        "hosts": [
            "bioinfodev.hpc.cam.ac.uk/hgva-1.0"
        ]
    }
}


Example of configuration file in YAML format
---
version: v1
rest:
  hosts:
  - bioinfodev.hpc.cam.ac.uk/hgva-1.0


Example of configuration dictionary
configuration = {
    'version': 'v1',
    'rest': {
        'hosts': [
            'bioinfodev.hpc.cam.ac.uk/hgva-1.0'
        ]
    }
}


Load the configuration will be the first step, to use the python client. We will use the ConfigClient class, passing the name of the path of the configuration file or the dictionary with the configuration. After that the instance created will be passed to the Client.

Loading the configuration
from pyCGA.opencgaconfig import ConfigClient
from pyCGA.opencgarestclients import Studies, AnalysisVariant, Projects, Samples, Cohorts



# configuration = '/path/to/configuration_file.json'
# configuration = '/path/to/configuration_file.yaml'
configuration = {
    'version': 'v1',
    'rest': {
        'hosts': [
            '10.5.5.4:8080/opencga-test'
        ]
    }
}

# Initialise configuration
conf = ConfigClient(configuration)


# conf instance should be passed to the clients
study_client = Studies(conf)

Once the library is imported and configured, you can proceed to run the examples below.

Examples

Getting information about genomic variants

Getting information about genomic variants
analysis_variant_client = AnalysisVariant(conf)


# Get TTN variants from the Genome of the Netherlands study, which is framed within the reference_grch37 project ('limit=3' limit the number of results to 3) 
responses = analysis_variant_client.query(gene='TTN', studies='reference_grch37:GONL', limit=3)

# If the response status is 200 (OK), the response will be a dictionary with the responses, this dictionary is equivalent to the json response obtained through the Web Services.  
for response in responses:
	for result in response['result']
		print(result)

Getting information about projects

Getting information about genomic variants
project_client = Projects(conf)


# Getting all metadata for the reference_grch37 project
responses = project_client.info('reference_grch37'


# Getting all studies and their metadata for the cancer_grch37 project
responses = project_client.studies('cancer_grch37')

Getting information about studies

Getting information about genomic variants
study_client = Studies(conf)


# Getting all metadata for all available studies
responses = study_client.search()


#  Getting summary data for study 1kG_phase3 which is framed within project reference_grch37
responses = study_client.summary('reference_grch37:1kG_phase3')


# Getting all metadata for study GONL  which is framed within the project reference_grch37
responses = study_client.info('reference_grch37:GONL')


# Getting all samples metadata for study 1kG_phase3 which is framed within project reference_grch3
responses = study_client.samples('reference_grch37:1kG_phase3')

Getting information about samples

Getting information about genomic variants
sample_client = Samples(conf)


# Get all metadata for sample HG00096 of the 1kG_phase3 study which is framed within the reference_grch37 project
responses = sample_client.info('HG00096', study='reference_grch37:GONL')

Getting information about cohorts

Getting information about genomic variants
cohort_client = Cohorts(conf)


# Get all samples metadata for cohort GBR from study 1kG_phase3 which is framed within project reference_grch37
responses = cohort_client.samples('GBR', study='reference_grch37:1kG_phase3')

Table of Contents:


  • No labels