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

Source Code for Package Bio.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  """Code to access resources at ExPASy over the WWW. 
  7   
  8  See http://www.expasy.org/ 
  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   
 19  """ 
 20   
 21  # Importing these functions with leading underscore as not intended for reuse 
 22  from Bio._py3k import urlopen as _urlopen 
 23  from Bio._py3k import urlencode as _urlencode 
 24  from Bio._py3k import _binary_to_string_handle 
 25   
 26   
27 -def get_prodoc_entry(id, 28 cgi='http://prosite.expasy.org/cgi-bin/prosite/get-prodoc-entry'):
29 """Get a text handle to a PRODOC entry at ExPASy in HTML format. 30 31 >>> from Bio import ExPASy 32 >>> with ExPASy.get_prodoc_entry('PDOC00001') as in_handle: 33 ... html = in_handle.read() 34 ... 35 >>> with open("myprodocrecord.html", "w") as out_handle: 36 ... out_handle.write(html) 37 ... 38 39 For a non-existing key XXX, ExPASy returns an HTML-formatted page 40 containing this text: 'There is currently no PROSITE entry for' 41 """ 42 return _binary_to_string_handle(_urlopen("%s?%s" % (cgi, id)))
43 44
45 -def get_prosite_entry(id, 46 cgi='http://prosite.expasy.org/cgi-bin/prosite/get-prosite-entry'):
47 """Get a text handle to a PROSITE entry at ExPASy in HTML format. 48 49 >>> from Bio import ExPASy 50 >>> with ExPASy.get_prosite_entry('PS00001') as in_handle: 51 ... html = in_handle.read() 52 ... 53 >>> with open("myprositerecord.html", "w") as out_handle: 54 ... out_handle.write(html) 55 ... 56 57 For a non-existing key XXX, ExPASy returns an HTML-formatted page 58 containing this text: 'There is currently no PROSITE entry for' 59 """ 60 return _binary_to_string_handle(_urlopen("%s?%s" % (cgi, id)))
61 62
63 -def get_prosite_raw(id, cgi=None):
64 """Get a text handle to a raw PROSITE or PRODOC record at ExPASy. 65 66 The cgi argument is deprecated due to changes in the ExPASy 67 website. 68 69 For a non-existing key, ExPASy returns nothing. 70 71 >>> from Bio import ExPASy 72 >>> from Bio.ExPASy import Prosite 73 >>> with ExPASy.get_prosite_raw('PS00001') as handle: 74 ... record = Prosite.read(handle) 75 ... 76 >>> print(record.accession) 77 PS00001 78 79 80 For a non-existing key, ExPASy returns an error: 81 82 >>> handle = get_prosite_raw("does_not_exist") 83 Traceback (most recent call last): 84 ... 85 urllib.error.HTTPError: HTTP Error 404: Not Found 86 87 """ 88 url = "http://prosite.expasy.org/%s.txt" % id 89 return _binary_to_string_handle(_urlopen(url))
90 91
92 -def get_sprot_raw(id):
93 """Get a text handle to a raw SwissProt entry at ExPASy. 94 95 For an ID of XXX, fetches http://www.uniprot.org/uniprot/XXX.txt 96 (as per the http://www.expasy.ch/expasy_urls.html documentation). 97 98 >>> from Bio import ExPASy 99 >>> from Bio import SwissProt 100 >>> with ExPASy.get_sprot_raw("O23729") as handle: 101 ... record = SwissProt.read(handle) 102 ... 103 >>> print(record.entry_name) 104 CHS3_BROFI 105 106 For a non-existing identifier, UniProt returns an error: 107 108 >>> ExPASy.get_sprot_raw("DOES_NOT_EXIST") 109 Traceback (most recent call last): 110 ... 111 urllib.error.HTTPError: HTTP Error 404: Not Found 112 113 """ 114 url = "http://www.uniprot.org/uniprot/%s.txt" % id 115 return _binary_to_string_handle(_urlopen(url))
116 117
118 -def sprot_search_ful(text, make_wild=None, swissprot=1, trembl=None, 119 cgi='http://www.expasy.ch/cgi-bin/sprot-search-ful'):
120 """Search SwissProt by full text (BROKEN).""" 121 variables = {'SEARCH': text} 122 if make_wild: 123 variables['makeWild'] = 'on' 124 if swissprot: 125 variables['S'] = 'on' 126 if trembl: 127 variables['T'] = 'on' 128 options = _urlencode(variables) 129 fullcgi = "%s?%s" % (cgi, options) 130 handle = _binary_to_string_handle(_urlopen(fullcgi)) 131 return handle
132 133
134 -def sprot_search_de(text, swissprot=1, trembl=None, 135 cgi='http://www.expasy.ch/cgi-bin/sprot-search-de'):
136 """Search SwissProt (BROKEN). 137 138 Search by name, description, gene name, species, or organelle. 139 """ 140 variables = {'SEARCH': text} 141 if swissprot: 142 variables['S'] = 'on' 143 if trembl: 144 variables['T'] = 'on' 145 options = _urlencode(variables) 146 fullcgi = "%s?%s" % (cgi, options) 147 return _binary_to_string_handle(_urlopen(fullcgi))
148