Package Bio :: Package WWW :: Module ExPASy
[hide private]
[frames] | no frames]

Source Code for Module Bio.WWW.ExPASy

  1  # Copyright 2000 by Jeffrey Chang.  All rights reserved. 
  2  # This code is part of the Biopython distribution and governed by its 
  3  # license.  Please see the LICENSE file that should have been included 
  4  # as part of this package. 
  5   
  6  """ 
  7  This module provides code to access resources at ExPASy over the WWW. 
  8  http://www.expasy.ch/ 
  9   
 10   
 11  Functions: 
 12  get_prodoc_entry  Interface to the get-prodoc-entry CGI script. 
 13  get_prosite_entry Interface to the get-prosite-entry CGI script. 
 14  get_sprot_raw     Interface to the get-sprot-raw.pl CGI script. 
 15  sprot_search_ful  Interface to the sprot-search-ful CGI script. 
 16  sprot_search_de   Interface to the sprot-search-de CGI script. 
 17  _open 
 18   
 19  """ 
 20  import time 
 21  import urllib 
 22   
 23  from Bio import File 
 24   
25 -def get_prodoc_entry(id, cgi='http://www.expasy.ch/cgi-bin/get-prodoc-entry'):
26 """get_prodoc_entry(id, 27 cgi='http://www.expasy.ch/cgi-bin/get-prodoc-entry') -> handle 28 29 Get a handle to a PRODOC entry at ExPASy. 30 31 """ 32 # XXX need to check to see if the entry exists! 33 return _open("%s?%s" % (cgi, id))
34
35 -def get_prosite_entry(id, 36 cgi='http://www.expasy.ch/cgi-bin/get-prosite-entry'):
37 """get_prosite_entry(id, 38 cgi='http://www.expasy.ch/cgi-bin/get-prosite-entry') -> handle 39 40 Get a handle to a PROSITE entry at ExPASy. 41 42 """ 43 # XXX need to check to see if the entry exists! 44 return _open("%s?%s" % (cgi, id))
45
46 -def get_sprot_raw(id, cgi='http://www.expasy.ch/cgi-bin/get-sprot-raw.pl'):
47 """get_sprot_raw(id, cgi='http://www.expasy.ch/cgi-bin/get-sprot-raw.pl') 48 -> handle 49 50 Get a handle to a raw SwissProt entry at ExPASy. 51 52 """ 53 return _open("%s?%s" % (cgi, id))
54
55 -def sprot_search_ful(text, make_wild=None, swissprot=1, trembl=None, 56 cgi='http://www.expasy.ch/cgi-bin/sprot-search-ful'):
57 """sprot_search_ful(text, make_wild=None, swissprot=1, trembl=None, 58 cgi='http://www.expasy.ch/cgi-bin/sprot-search-ful') -> handle 59 60 Search SwissProt by full text. 61 62 """ 63 variables = {'SEARCH' : text} 64 if make_wild: 65 variables['makeWild'] = 'on' 66 if swissprot: 67 variables['S'] = 'on' 68 if trembl: 69 variables['T'] = 'on' 70 return _open(cgi, variables)
71
72 -def sprot_search_de(text, swissprot=1, trembl=None, 73 cgi='http://www.expasy.ch/cgi-bin/sprot-search-de'):
74 """sprot_search_de(text, swissprot=1, trembl=None, 75 cgi='http://www.expasy.ch/cgi-bin/sprot-search-de') -> handle 76 77 Search SwissProt by name, description, gene name, species, or 78 organelle. 79 80 """ 81 variables = {'SEARCH' : text} 82 if swissprot: 83 variables['S'] = 'on' 84 if trembl: 85 variables['T'] = 'on' 86 return _open(cgi, variables)
87
88 -def scanprosite1(seq=None, id=None, exclude_frequent=None, 89 cgi='http://expasy.cbr.nrc.ca/cgi-bin/scanprosite/scanprosite?1'):
90 """scanprosite1(seq=None, id=None, exclude_frequent=None, 91 cgi='http://expasy.cbr.nrc.ca/cgi-bin/scanprosite/scanprosite?1') -> handle 92 93 Scan a sequence for a Prosite pattern. Either a sequence or a SwissProt/ 94 trEMBL sequence can be passed. exclude_frequent specifies whether to 95 exclude patterns with high probability. 96 97 """ 98 variables = {} 99 if seq: 100 variables['SEQ'] = seq 101 if id: 102 variables['ID'] = id 103 if exclude_frequent: 104 variables['box'] = 'ok' 105 return _open(cgi, variables, get=0)
106
107 -def _open(cgi, params={}, get=1):
108 """_open(cgi, params={}, get=1) -> UndoHandle 109 110 Open a handle to ExPASy. cgi is the URL for the cgi script to access. 111 params is a dictionary with the options to pass to it. get is a boolean 112 that describes whether a GET should be used. Does some 113 simple error checking, and will raise an IOError if it encounters one. 114 115 """ 116 # Open a handle to ExPASy. 117 options = urllib.urlencode(params) 118 if get: # do a GET 119 fullcgi = cgi 120 if options: 121 fullcgi = "%s?%s" % (cgi, options) 122 handle = urllib.urlopen(fullcgi) 123 else: # do a POST 124 handle = urllib.urlopen(cgi, options) 125 126 # Wrap the handle inside an UndoHandle. 127 uhandle = File.UndoHandle(handle) 128 129 # If the key doesn't exist, ExPASy returns nothing. 130 if not uhandle.peekline(): 131 raise IOError, "no results" 132 133 return uhandle
134