用于opencga rest web服务的rest客户机
pyopencga的Python项目详细描述
内容
PyOpenCGA
这个python客户机包使用了为OpenCGA平台实现的全面restful web服务api。 opencga是一个开源项目,它为基因组数据分析和可视化实现了一个高性能、可扩展和安全的平台
opencga为当前基因组学中的大数据分析和可视化实现了一个安全、高效的平台。 opencga使用最先进的技术将数据扩展到PB级。opencga的设计和实现是为了与 几百万个基因组。它建立在三个主要组件之上:目录、变量和对齐存储和分析。
有关此项目的详细信息,请参见OpenCGA Docs
Installation
Cloning
pyopencga可以通过在终端中执行在本地计算机中克隆:
$ git clone https://github.com/opencb/opencga.git
下载项目后,可以安装库。我们建议将其安装在virtual environment:
$ cd opencga/tree/develop/opencga-client/src/main/python/pyOpenCGA $ python setup.py install
Usage
Import pyOpenCGA package
第一步是从pyopencga导入configclient和opencgaclient:
>>>frompyopencga.opencga_configimportConfigClient>>>frompyopencga.opencga_clientimportOpenCGAClient
Setting up server host configuration
第二步是设置opencga主机服务器配置,您可以获得一个指定opencga服务器主机的基本配置字典:
>>>host='http://bioinfodev.hpc.cam.ac.uk/opencga-test'# Use a server host where you have an account>>>cc=ConfigClient()>>>config_dict=cc.get_basic_config_dict(host)>>>print(config_dict){'version':'v1','rest':{'hosts':['http://bioinfodev.hpc.cam.ac.uk/opencga-test']}}
Log in to OpenCGA host server
使用此配置,您可以初始化opencgaclient并登录到opencga用户帐户,指定用户和密码:
>>>oc=OpenCGAClient(configuration=config_dict,user='user_id',pwd='user_password')
对于脚本编写或使用jupyter笔记本,最好从外部json文件加载用户凭据。
登录后,必须使用会话的令牌将客户端的访问权传播到主机服务器:
>>>token=oc.session_id>>>print(token)eyJhbGciOi...>>>oc=OpenCGAClient(configuration=config_dict,session_id=token)
Examples
下一步是为我们要查询的数据创建特定的客户端:
>>>projects=oc.projects# Query for projects>>>studies=oc.studies# Query for studies>>>samples=oc.samples()# Query for samples>>>cohorts=oc.cohorts()# Query for cohorts
现在您可以开始使用pyopencga请求opencga restful服务:
>>>forprojectinprojects.search(owner=user).results():...print(project['id'])project1project2[...]
访问查询响应数据有四种不同的方法:
>>>foo_client.method().first()# Returns the first QueryResult>>>foo_client.method().result(position=0)# Returns the result from all QueryResults in a given position>>>foo_client.method().results()# Iterates over all the results of all the QueryResults>>>foo_client.method().response# Returns the raw response of the QueryResponse
可以通过指定逗号分隔的ID或ID列表来访问数据:
>>>samples='NA12877,NA12878,NA12879'>>>samples_list=['NA12877','NA12878','NA12879']>>>sc=oc.samples>>>forresultinsc.info(query_id=samples,study='user@project1:study1').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').results():...print(result['id'],result['attributes']['OPENCGA_INDIVIDUAL']['disorders'])NA12877[{'id':'OMIM6500','name':"Chron's Disease"}]NA12878[]NA12879[{'id':'OMIM6500','name':"Chron's Disease"}]
可选的过滤器和额外的选项可以添加为键值参数(其中的值可以是逗号分隔的字符串或列表)。
What can I ask for?
了解每个客户机检查OpenCGA web services招摇过市时可以检索哪些数据的最佳方法。