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_prosite_raw   Interface to the get-prosite-raw CGI script. 
 15  get_sprot_raw     Interface to the get-sprot-raw CGI script. 
 16  sprot_search_ful  Interface to the sprot-search-ful CGI script. 
 17  sprot_search_de   Interface to the sprot-search-de CGI script. 
 18  _open 
 19   
 20  """ 
 21   
 22  import warnings 
 23  warnings.warn("Bio.WWW.ExPASy is deprecated. The functions in Bio.WWW.ExPASy  are now available from Bio.ExPASy.", 
 24                DeprecationWarning) 
 25   
 26   
27 -def get_prodoc_entry(id, cgi='http://www.expasy.ch/cgi-bin/get-prodoc-entry'):
28 """get_prodoc_entry(id, 29 cgi='http://www.expasy.ch/cgi-bin/get-prodoc-entry') -> handle 30 31 Get a handle to a PRODOC entry at ExPASy in HTML format. 32 33 For a non-existing key XXX, ExPASy returns a web page containing 34 this line: 35 'There is no PROSITE documentation entry XXX. Please try again.' 36 """ 37 # XXX need to check to see if the entry exists! 38 return _open("%s?%s" % (cgi, id))
39
40 -def get_prosite_entry(id, 41 cgi='http://www.expasy.ch/cgi-bin/get-prosite-entry'):
42 """get_prosite_entry(id, 43 cgi='http://www.expasy.ch/cgi-bin/get-prosite-entry') -> handle 44 45 Get a handle to a PROSITE entry at ExPASy in HTML format. 46 47 For a non-existing key XXX, ExPASy returns a web page containing 48 this line: 49 'There is currently no PROSITE entry for XXX. Please try again.' 50 """ 51 # XXX need to check to see if the entry exists! 52 return _open("%s?%s" % (cgi, id))
53
54 -def get_prosite_raw(id, cgi='http://www.expasy.ch/cgi-bin/get-prosite-raw.pl'):
55 """get_prosite_raw(id, 56 cgi='http://www.expasy.ch/cgi-bin/get-prosite-raw.pl') 57 -> handle 58 59 Get a handle to a raw PROSITE or PRODOC entry at ExPASy. 60 61 For a non-existing key, ExPASy returns nothing. 62 """ 63 import urllib, socket 64 handle = urllib.urlopen("%s?%s" % (cgi, id)) 65 66 # Peek at the first character to see if anything is available. 67 # ExPASy returns nothing for non-existing keys 68 69 start = handle.fp._sock.recv(1, socket.MSG_PEEK) 70 if not start: # ExPASy returned nothing 71 raise IOError, "no results" 72 73 return handle
74
75 -def get_sprot_raw(id, cgi='http://www.expasy.ch/cgi-bin/get-sprot-raw.pl'):
76 """get_sprot_raw(id, cgi='http://www.expasy.ch/cgi-bin/get-sprot-raw.pl') 77 -> handle 78 79 Get a handle to a raw SwissProt entry at ExPASy. 80 81 For a non-existing key XXX, ExPASy returns a web page containing 82 this line: 83 'XXX is not a valid identifier.' 84 """ 85 return _open("%s?%s" % (cgi, id))
86
87 -def sprot_search_ful(text, make_wild=None, swissprot=1, trembl=None, 88 cgi='http://www.expasy.ch/cgi-bin/sprot-search-ful'):
89 """sprot_search_ful(text, make_wild=None, swissprot=1, trembl=None, 90 cgi='http://www.expasy.ch/cgi-bin/sprot-search-ful') -> handle 91 92 Search SwissProt by full text. 93 94 """ 95 variables = {'SEARCH' : text} 96 if make_wild: 97 variables['makeWild'] = 'on' 98 if swissprot: 99 variables['S'] = 'on' 100 if trembl: 101 variables['T'] = 'on' 102 return _open(cgi, variables)
103
104 -def sprot_search_de(text, swissprot=1, trembl=None, 105 cgi='http://www.expasy.ch/cgi-bin/sprot-search-de'):
106 """sprot_search_de(text, swissprot=1, trembl=None, 107 cgi='http://www.expasy.ch/cgi-bin/sprot-search-de') -> handle 108 109 Search SwissProt by name, description, gene name, species, or 110 organelle. 111 112 """ 113 variables = {'SEARCH' : text} 114 if swissprot: 115 variables['S'] = 'on' 116 if trembl: 117 variables['T'] = 'on' 118 return _open(cgi, variables)
119
120 -def scanprosite1(seq=None, id=None, exclude_frequent=None, 121 cgi='http://expasy.cbr.nrc.ca/cgi-bin/scanprosite/scanprosite?1'):
122 """scanprosite1(seq=None, id=None, exclude_frequent=None, 123 cgi='http://expasy.cbr.nrc.ca/cgi-bin/scanprosite/scanprosite?1') -> handle 124 125 Scan a sequence for a Prosite pattern. Either a sequence or a SwissProt/ 126 trEMBL sequence can be passed. exclude_frequent specifies whether to 127 exclude patterns with high probability. 128 129 """ 130 variables = {} 131 if seq: 132 variables['SEQ'] = seq 133 if id: 134 variables['ID'] = id 135 if exclude_frequent: 136 variables['box'] = 'ok' 137 return _open(cgi, variables, get=0)
138
139 -def _open(cgi, params={}, get=1):
140 """_open(cgi, params={}, get=1) -> UndoHandle 141 142 Open a handle to ExPASy. cgi is the URL for the cgi script to access. 143 params is a dictionary with the options to pass to it. get is a boolean 144 that describes whether a GET should be used. Does some 145 simple error checking, and will raise an IOError if it encounters one. 146 147 """ 148 import urllib 149 from Bio import File 150 151 # Open a handle to ExPASy. 152 options = urllib.urlencode(params) 153 if get: # do a GET 154 fullcgi = cgi 155 if options: 156 fullcgi = "%s?%s" % (cgi, options) 157 handle = urllib.urlopen(fullcgi) 158 else: # do a POST 159 handle = urllib.urlopen(cgi, options) 160 161 # Wrap the handle inside an UndoHandle. 162 uhandle = File.UndoHandle(handle) 163 164 # If the key doesn't exist, ExPASy returns nothing. 165 if not uhandle.peekline(): 166 raise IOError, "no results" 167 168 return uhandle
169