kripodb.webservice

Module for Client for kripo web service

exception kripodb.webservice.client.Incomplete(message, absent_identifiers)[source]
exception kripodb.webservice.client.IncompleteFragments(absent_identifiers, fragments)[source]
exception kripodb.webservice.client.IncompletePharmacophores(absent_identifiers, pharmacophores)[source]
class kripodb.webservice.client.WebserviceClient(base_url)[source]

Client for kripo web service

Example

>>> client = WebserviceClient('http://localhost:8084/kripo')
>>> client.similar_fragments('3j7u_NDP_frag24', 0.85)
[{'query_frag_id': '3j7u_NDP_frag24', 'hit_frag_id': '3j7u_NDP_frag23', 'score': 0.8991}]
Parameters:base_url (str) – Base url of web service. e.g. http://localhost:8084/kripo
fragments_by_id(fragment_ids, chunk_size=100)[source]

Retrieve fragments by their identifier

Parameters:
  • fragment_ids (List[str]) – List of fragment identifiers
  • chunk_size (int) – Number of fragment to retrieve in a single http request
Returns:

List of fragment information

Return type:

list[dict]

Raises:

IncompleteFragments – When one or more of the identifiers could not be found.

fragments_by_pdb_codes(pdb_codes, chunk_size=450)[source]

Retrieve fragments by their PDB code

Parameters:
  • pdb_codes (List[str]) – List of PDB codes
  • chunk_size (int) – Number of PDB codes to retrieve in a single http request
Returns:

List of fragment information

Return type:

list[dict]

Raises:

requests.HTTPError – When one of the PDB codes could not be found.

similar_fragments(fragment_id, cutoff, limit=1000)[source]

Find similar fragments to query.

Parameters:
  • fragment_id (str) – Query fragment identifier
  • cutoff (float) – Cutoff, similarity scores below cutoff are discarded.
  • limit (int) – Maximum number of hits. Default is None for no limit.
Returns:

Query fragment identifier, hit fragment identifier and similarity score

Return type:

list[dict]

Raises:

request.HTTPError – When fragment_id could not be found

Kripo datafiles wrapped in a webservice

class kripodb.webservice.server.KripodbJSONEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None)[source]

JSON encoder for KripoDB object types

Copied from http://flask.pocoo.org/snippets/119/

default(obj)[source]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    return JSONEncoder.default(self, o)
kripodb.webservice.server.get_fragment_phar(fragment_id)[source]

Pharmacophore in phar format of fragment

Parameters:fragment_id (str) – Fragment identifier
Returns:Pharmacophore|problem
Return type:flask.Response|connexion.lifecycle.ConnexionResponse
kripodb.webservice.server.get_fragment_svg(fragment_id, width, height)[source]

2D drawing of fragment in SVG format

Parameters:
  • fragment_id (str) – Fragment identifier
  • width (int) – Width of SVG in pixels
  • height (int) – Height of SVG in pixels
Returns:

SVG document|problem

Return type:

flask.Response|connexion.lifecycle.ConnexionResponse

kripodb.webservice.server.get_fragments(fragment_ids=None, pdb_codes=None)[source]

Retrieve fragments based on their identifier or PDB code.

Parameters:
  • fragment_ids (List[str]) – List of fragment identifiers
  • pdb_codes (List[str]) – List of PDB codes
Returns:

List of fragment information

Return type:

list[dict]

Raises:

werkzeug.exceptions.NotFound – When one of the fragments_ids or pdb_code could not be found

kripodb.webservice.server.get_similar_fragments(fragment_id, cutoff, limit)[source]

Find similar fragments to query.

Parameters:
  • fragment_id (str) – Query fragment identifier
  • cutoff (float) – Cutoff, similarity scores below cutoff are discarded.
  • limit (int) – Maximum number of hits. Default is None for no limit.
Returns:

List of dict with query fragment identifier, hit fragment identifier and similarity score

Return type:

list[dict]

Raises:

werkzeug.exceptions.NotFound – When the fragments_id could not be found

kripodb.webservice.server.get_version()[source]
Returns:Version of web service
Return type:dict[version]
kripodb.webservice.server.serve_app(similarities, fragments, pharmacophores, internal_port=8084, external_url='http://localhost:8084/kripo')[source]

Serve webservice forever

Parameters:
  • similarities – Filename of similarity matrix hdf5 file
  • fragments – Filename of fragments database file
  • pharmacophores – Filename of pharmacophores hdf5 file
  • internal_port – TCP port on which to listen
  • external_url (str) – URL which should be used in Swagger spec
kripodb.webservice.server.wsgi_app(similarities, fragments, pharmacophores, external_url='http://localhost:8084/kripo')[source]

Create wsgi app

Parameters:
  • similarities (SimilarityMatrix) – Similarity matrix to use in webservice
  • fragments (FragmentsDb) – Fragment database filename
  • pharmacophores – Filename of pharmacophores hdf5 file
  • external_url (str) – URL which should be used in Swagger spec
Returns:

connexion.App