![]() |
Table of Contents
ZSIInstall ZSIThe ZSI module is available for download from the Python Web Services Project pages. See the documentation for details of how to install into your Python environment. If you are using a package based system (e.g. Ubuntu, CentOS, Cygwin, etc.) check the package listing for a ZSI package. Using ZSI ServiceProxyZSI provides an interface to services which provide a WSDL description in a similar way to SOAPpy using the ServiceProxy package. For example using the WSDbfetch service: Import the ServiceProxy package: from ZSI.ServiceProxy import ServiceProxy
Create an interface to the service using wsdlUrl = 'http://www.ebi.ac.uk/ws/services/WSDbfetch?wsdl' dbfetchSrv = ServiceProxy(wsdl=wsdlUrl)
The service object ( resultDict = dbfetchSrv.fetchData(query='UNIPROT:ADH1A_HUMAN', format='fasta', style='raw') result = resultDict['fetchDataReturn']
The
The methods in the WSDbfetch all use simple string parameters. Many of the other EBI services use more complex input structures. For example WSWUBlast requires a structure containing the various parameters and the input sequence to be passed to the # Import WSDL package from ZSI.ServiceProxy import ServiceProxy # Create service interface wsdlUrl = 'http://www.ebi.ac.uk/Tools/webservices/wsdl/WSWUBlast.wsdl' server = ServiceProxy(wsdl=wsdlUrl) # Query sequence seq = """>Q8E5Q5_STRA3 MKLSKRYRFWQKVIKALGVLALIATLVLVVYLYKLGILNDSNELKDLVHKYEFWGPMIFI VAQIVQIVFPVIPGGVTTVAGFLIFGPTLGFIYNYIGIIIGSVILFWLVKFYGRKFVLLF MDQKTFDKYESKLETSGYEKFFIFCMASPISPADIMVMITGLSNMSIKRFVTIIMITKPI SIIGYSYLWIYGGDILKNFLN""" # Structure containing parameters blast_params = { 'program':'blastp', # Protein vs. protein search 'database':'swissprot', # Database to search 'email':'your@email', # User e-mail address 'async':1 # Async submission } # Structure containing the sequence data blast_data = [{'type':'sequence', 'content':seq}] # Submit the job to the service passing the data structures jobIdDict = server.runWUBlast(params=blast_params, content=blast_data) jobId = jobIdDict['jobid'] print jobId
The # Poll till job finishes statusStr = 'PENDING' while statusStr == 'RUNNING' or statusStr == 'PENDING': statusDict = server.checkStatus(jobid=jobId) statusStr = statusDict['status'] print statusStr if statusStr == 'RUNNING' or statusStr == 'PENDING': time.sleep(15) # Get the result resultDict = server.poll(jobid=jobId, type='tooloutput') result = resultDict['result'] print result
Using ZSI wsdl2py stubs
An alternative to using the ServiceProxy approach is to generate client stubs for the service which you can then use in your client. ZSI provides the Generate the stubs from the WSDL: wsdl2py "http://www.ebi.ac.uk/ws/services/WSDbfetch?wsdl"
The creates a set of files containing the code required to interact with the service. In your client you then import the package: from WSDBFetchServerService_client import *
Create an instance of the service interface: dbfetchSrv = WSDBFetchServerServiceLocator().getWSDbfetch()
The service object ( # Build the request request = fetchDataRequest() request._query = 'UNIPROT:ADH1A_HUMAN' request._format = 'fasta' request._style = 'raw' # Call the service response = dbfetchSrv.fetchData(request) # Extract the result result = response._fetchDataReturn
The
The methods in the WSDbfetch all use simple string parameters. Many of the other EBI services use more complex input structures. For example WSWUBlast requires a structure containing the various parameters and the input sequence to be passed to the # Import generated stubs package from WSWUBlast_services import * # Create service interface server = WSWUBlastServiceLocator().getWSWUBlast() # Query sequence seq = """>Q8E5Q5_STRA3 MKLSKRYRFWQKVIKALGVLALIATLVLVVYLYKLGILNDSNELKDLVHKYEFWGPMIFI VAQIVQIVFPVIPGGVTTVAGFLIFGPTLGFIYNYIGIIIGSVILFWLVKFYGRKFVLLF MDQKTFDKYESKLETSGYEKFFIFCMASPISPADIMVMITGLSNMSIKRFVTIIMITKPI SIIGYSYLWIYGGDILKNFLN""" # Structure containing parameters class inputParams_class: _program = 'blastp' # Protein vs. protein search _database = 'swissprot' # Database to search _email = 'your@email' # User e-mail address _async = 1 # Async submission # Structure containing the sequence data class data_class: _type = 'sequence' _content = seq # Create the request request = runWUBlastRequest() request._params = inputParams_class request._content = [ data_class ] # Submit the job to the service passing the data structures response = server.runWUBlast(request) jobId = response._jobid print jobId
The # Poll till job finishes status = 'PENDING' while status == 'RUNNING' or status == 'PENDING': request = statusRequest() request._jobid = jobId response = server.checkStatus(request) status = response._status print status if status == 'RUNNING' or status == 'PENDING': time.sleep(15) # Get the result request = pollRequest() request._jobid = jobId request._type = 'tooloutput' response = server.poll(request) result = response._result print result
ExamplesThe complete source code for the examples is available:
Sample ClientsMost SOAP Web Services at EMBL-EBI have sample clients which provide command-line access to the service and example code. For Python some of the clients are based on ZSI. Document/literal SOAP
RPC/encoded SOAP![]() |