File: SCOP.py

package info (click to toggle)
python-biopython 1.42-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 17,584 kB
  • ctags: 12,272
  • sloc: python: 80,461; xml: 13,834; ansic: 7,902; cpp: 1,855; sql: 1,144; makefile: 203
file content (64 lines) | stat: -rw-r--r-- 2,103 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Copyright 2000 by Jeffrey Chang.  All rights reserved.
# This code is part of the Biopython distribution and governed by its
# license.  Please see the LICENSE file that should have been included
# as part of this package.

"""
Provides code to access SCOP over the WWW.  The main SCOP web page
is available at:
http://scop.mrc-lmb.cam.ac.uk/scop/

Functions:
search       Access the main CGI script.
_open

"""
import string
import urllib

from Bio import File

def search(pdb=None, key=None, sid=None, disp=None, dir=None, loc=None,
           cgi='http://scop.mrc-lmb.cam.ac.uk/scop/search.cgi', **keywds):
    """search(pdb=None, key=None, sid=None, disp=None, dir=None, loc=None,
    cgi='http://scop.mrc-lmb.cam.ac.uk/scop/search.cgi', **keywds)

    Access search.cgi and return a handle to the results.  See the
    online help file for an explanation of the parameters:
    http://scop.mrc-lmb.cam.ac.uk/scop/help.html

    Raises an IOError if there's a network error.
    
    """
    params = {'pdb' : pdb, 'key' : key, 'sid' : sid, 'disp' : disp,
              'dir' : dir, 'loc' : loc}
    variables = {}
    for k in params.keys():
        if params[k] is not None:
            variables[k] = params[k]
    variables.update(keywds)
    return _open(cgi, variables)

def _open(cgi, params={}, get=1):
    """_open(cgi, params={}, get=1) -> UndoHandle

    Open a handle to SCOP.  cgi is the URL for the cgi script to access.
    params is a dictionary with the options to pass to it.  get is a boolean
    that describes whether a GET should be used.  Does some
    simple error checking, and will raise an IOError if it encounters one.

    """
    # Open a handle to SCOP.
    options = urllib.urlencode(params)
    if get:  # do a GET
        fullcgi = cgi
        if options:
            fullcgi = "%s?%s" % (cgi, options)
        handle = urllib.urlopen(fullcgi)
    else:    # do a POST
        handle = urllib.urlopen(cgi, options)

    # Wrap the handle inside an UndoHandle.
    uhandle = File.UndoHandle(handle)
    # Should I check for 404?  timeout?  etc?
    return uhandle