Skip to content

Instantly share code, notes, and snippets.

View mnowotka's full-sized avatar

Michał Nowotka mnowotka

  • Bolt
  • Warsaw, PL
View GitHub Profile
@mnowotka
mnowotka / fail.py
Last active August 29, 2015 13:55
region finding
from collections import defaultdict
from itertools import chain
from banyan import SortedDict, OverlappingIntervalsUpdator
class Rectangle(object):
def __init__(self, left, top, right, bottom):
self.left = left
self.bottom = bottom
self.right = right
@mnowotka
mnowotka / example.py
Last active August 29, 2015 13:58
REST client examples
# necessary imports first:
from chembl_webresource_client import *
# create resource object:
compounds = CompoundResource()
# before you do anythong else, please check webservices status:
print compounds.status()
True
# our standard invocation:
from chembl_webresource_client import *
targets = TargetResource()
print targets.status()
True
# status returns True so we can proceed:
#first let's get a single target:
t = targets.get('CHEMBL2477')
# first things first:
from chembl_webresource_client import *
assays = AssayResource()
print assays.status()
True
# assays are simple, we can get them by chembl ID:
a = assays.get('CHEMBL1217643')
print a
{u'assayType': u'B', u'chemblId': u'CHEMBL1217643', u'journal': u'Bioorg. Med. Chem. Lett.',
from chembl_webresource_client import *
compounds = CompoundResource()
cs = compounds.get(['CHEMBL%s' % x for x in range(1,1001)])
from bioservices import *
s = ChEMBLdb(verbose=False)
res = []
for i in range(1,1001):
try:
res.append(s.get_compounds_by_chemblId('CHEMBL%s' % i))
except:
res.append(404)
# let's import settings class first:
from chembl_webresource_client.settings import Settings
# we can now decide which protocol to use:
Settings.Instance().WEBSERVICE_PROTOCOL = 'http'
# point our client to our local webservices instance
Settings.Instance().WEBSERVICE_DOMAIN = 'localhost'
# and change their prefix:
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{
"metadata": {
"name": "",
"signature": "sha256:f784ff75e0dec53c6fef16fc487214e1f81833324cfa31e787b2ed105592c612"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
import requests
from chembl_webresource_client import *
# For some special SMILES, using GET method against webservices will end up with failure:
res = requests.get('https://www.ebi.ac.uk/chemblws/compounds/smiles/CN1C\C(=C/c2ccc(C)cc2)\C3=C(C1)C(C(=C(N)O3)C#N)c4ccc(C)cc4')
print res.ok
False
print res.status_code