Web Services at the EBI

Using dbfetch


General information
Python Class
Using cgi scripts.

General Information

Type Retrieve_EBI_Entries
Authority URL http://www.ebi.ac.uk
Documentation Richard Christen
Contact e-mail christen@unice.fr
Description  Data retrieval at EBI is usually through SRS. It can now be accessed at EBI via web services, as described .
This page provides more explanations on how to use this web service and some python examples (SOAP.py package required).
Asynchronous???.
Programming langage: Python demo code.
See importance notice: using cgi scripts


This service is very simple to use.
I provide below a python code to run it with demos:
It uses Tk for graphical interface, therefore it only requires Python (see python.org)
Note: that this is a demo program, I have tried to debbug it, but I may have forgotten some things.
Note: For the moment I have decided to stick to cgi scripts, because they are easier to use, more powerfull and easier to find out which kind of error occured (see bottom of this page).

#Python Class
#!/usr/bin/env python
#
# Sample WSDbfetch client in Python
#
# Tested with:
#   Python 2.4.1
#  Python 2.5
#   SOAPpy 0.12.0
 


import sys
from SOAPpy import WSDL   
from Tkinter import *
import time

class Fetch_Ebi_Web_Services:
    '''use the Dbfetch services on database as explained at
    http://www.ebi.ac.uk/Tools/webservices/help/databases
       try two alternate servers, and check for proper response,
       print error message while it keeps trying
    '''
    def __init__(self):
        self.chose_url()                        #choose url
        self.server = WSDL.Proxy(self.wsdlUrl)        # init server
        self.supported_dbs=[]
        self.supported_formats=[]
        self.supported_styles=[]
       
        #fill in supported databases, formats and styles
        #NOTE this is for demo purpose
        #in real app, call these functions within a while
        #and recall until
       
   
    def proxy(self,influx=None, outflux=None):
        #set values to 1 to see import and export strings
        if influx !=None:
            server.soapproxy.config.dumpSOAPOut = 1
        if outflux!=None:
            server.soapproxy.config.dumpSOAPIn = 1
   
    def chose_url(self,arg=None):
        #choose ebi url for web services
        if arg==None:
            self.wsdlUrl = 'http://www.ebi.ac.uk/~hpm/wsdl/WSDbfetch.wsdl'
        else:
            self.wsdlUrl = 'http://www.ebi.ac.uk/Tools/webservices/wsdl/WSDbfetch.wsdl'
           
           
    def getSupportedDBs(self):
        '''returns a list of available dbs'''
        try:
            self.chose_url()                        #choose url
            self.server = WSDL.Proxy(self.wsdlUrl)
            self.supported_dbs = self.server.getSupportedDBs()
        except:
            try:
                print 'getSupportedDBs first url failed, try alternate'
                self.chose_url('alternate')
                self.server = WSDL.Proxy(self.wsdlUrl)
                self.supported_dbs = self.server.getSupportedDBs()
            except:
                print 'getSupportedDBs failed'
                time.sleep(2)
                return []
        return self.supported_dbs        #two modes of usage...
   
    def getSupportedFormats(self):
        '''returns a list of available format, i.e fasta, embl...
        for some reason, it does not work every time, so try,except
        '''
        try:
            self.chose_url()                        #choose url
            self.server = WSDL.Proxy(self.wsdlUrl)
            self.supported_formats= self.server.getSupportedFormats()
        except:
            try:
                print 'getSupportedFormats first url failed, try alternate'
                self.chose_url('alternate')
                self.server = WSDL.Proxy(self.wsdlUrl)
                self.supported_formats= self.server.getSupportedFormats()
            except:
                print 'getSupportedFormats failed'
                time.sleep(2)
                return []
        return self.supported_formats
   
    def getSupportedStyles(self):
        '''returns a list of available styles i.e. '''
        try:
            self.chose_url()                        #choose url
            self.server = WSDL.Proxy(self.wsdlUrl)
            self.supported_styles = self.server.getSupportedStyles()
        except:
            try:
                print 'getSupportedStyles first url failed, try alternate'
                self.chose_url('alternate')
                self.server = WSDL.Proxy(self.wsdlUrl)
                self.supported_styles = self.server.getSupportedStyles()
            except:
                print 'getSupportedStyles failed'
                time.sleep(2)
                return []
        return self.supported_styles
   
    def fetchData(self, database=None,query=None,format=None, style=None):
        '''get data from EBI according to
        database
        accession or ID
        format
        style
        if not argument provided, returns a simple example
        '''
        #check first if a database is given and if it really exists, if not provides one
        if database==None:
            self.database='uniprot'
        else:
            if database not in self.supported_dbs:
                print 'not supported database'
            else:
                self.database=database
       
        #check next if a query is given and if not provides one
        if query==None:
            self.query='slpi_human'
       
        #check given format, if not provide one
        if format==None:
            self.dataFormat = 'default'
        else:
            if format not in self.supported_formats:
                print 'not supported format'
            else:
                self.dataFormat=format
       
        #check given style if not, provide one
        if style==None:
            self.dataStyle = 'default'
        else:
            if style not in self.supported_styles:
                print 'not supported style'
            else:
                self.dataStyle=style
       
        question=self.database+':'+self.query
        try:
            self.chose_url()                        #choose url
            self.server = WSDL.Proxy(self.wsdlUrl)
            self.fetch_data = self.server.fetchData(question, self.dataFormat, self.dataStyle)
        except:
            try:
                print 'fetchData first url failed, try alternate'
                self.chose_url('alternate')
                self.server = WSDL.Proxy(self.wsdlUrl)
                self.fetch_data = self.server.fetchData(question, self.dataFormat, self.dataStyle)
            except:
                print 'fetch data failed'
                time.sleep(2)
                return []
        return self.fetch_data
       
if __name__ == '__main__':
    def run_fetch(arg):
        supported_dbs=[]
        supported_formats=[]
        supported_styles=[]
        fetch_data=[]
       
        web_service=Fetch_Ebi_Web_Services()
       
        while supported_dbs==[]:
            supported_dbs=web_service.getSupportedDBs()
        supported_dbs.sort()
           
        while supported_formats==[]:
            supported_formats=web_service.getSupportedFormats()
        supported_formats.sort()
       
        while supported_styles==[]:
            supported_styles=web_service.getSupportedStyles()
        supported_styles.sort()
       
        while fetch_data==[]:
            fetch_data=web_service.fetchData()
       
        if arg=='simple':
            print 'results:'
            print len(supported_dbs),len(supported_formats),len(supported_styles),len(fetch_data)
        elif arg=='print':
            print
            print '###################               Supported databases'
            for el in supported_dbs:
                print el
            print
            print '###################               Supported formats'
            for el in supported_formats:
                print el
            print
            print '###################               Supported styles'       
            for el in supported_styles:
                print el
            print
            print '###################               web_service.fetchData'
            for el in fetch_data:
                print el
       
        print '*'*15,'    DONE   ','*'*15
       
       
    root=Tk()
    Button(root, text='run fetchdata', command=lambda arg='simple': run_fetch(arg)).pack()
    Button(root, text='run fetchdata see results', command=lambda arg='print': run_fetch(arg)).pack()
    Button(root, text='QUIT', command=root.quit).pack()
    Label(root,text=' this is a demo program for fetchdata ebi webservice').pack()
    root.mainloop()

Using cgi scripts.

Presently, I find it easier to use access via cgi scripts.
You can gain direct access using scripts such as:
Provide up to 200 ids or accession numbers separated by commas, examples for embl database:
http://www.ebi.ac.uk/cgi-bin/dbfetch?db=EMBL&id=HS231,AL035660&style=raw
http://www.ebi.ac.uk/cgi-bin/dbfetch?db=EMBL&id=HS231,AL035660&style=fasta
http://www.ebi.ac.uk/cgi-bin/dbfetch?db=EMBL&id=HS231,AL035660&style=emblxml

Alternatively, you can also get data via the SRS server:
html: http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-noSession+-e+[EMBL:AL035660]
html: http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-noSession+-e+[EMBL:AL035660]+-view+EmblEntry
fasta: http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-noSession+-e+[EMBL:AL035660]+-view+FastaSeqs

The advantage of SRS is its powerfull query langage, that allows to query with more than simply ids or accession numbers, and to link from one database to another
see: http://www.ebi.ac.uk/~srs/wiki/doku.php?id=guides:linkingtosrs
The oter advantage is that SRS is available on many servers worldwide, and that the same syntax can be used.

Web Services are also proposed at different places, but:






       
           
   

       
           

 Last updated 04/04/2007. Richard Christen