Snippets

Dénes Türei reAAao: Untitled snippet

Created by Dénes Türei
#!/usr/bin/env python

# Dénes Türei EMBL 2017
# turei.denes@gmail.com

import pypath

def logp_neg(slogp):
    
    return slogp is not None and float(slogp) < 0.0

def pchembl_gt_5(pch):
    
    return any(float(p) > 5.0 for p in pch.split(';'))

# initialize a PyPath instance:
pa = pypath.PyPath()
pa.kinases_list() # load the list of kinases from kinase.com

# create a Chembl instance:
chembl_access = ('defaults.mysql', 'chembl')
c = pypath.chembl.Chembl(chembl_access)

# run a targets for compounds query:
c.pchembl_select += ',\nmd.max_phase AS max_phase\n'
c.compounds_targets(
    pa.lists['kin'], # UniProt IDs of the kinases
    assay_types = ['B'], # only binding assays
    pchembl = True, # include pchembl values
    action_type = True,
    compound_props = ['alogp', 'acd_logp'] # include logp values
)

result = list(c.result)
hdr = sorted(result[0].keys())
result = [[r[h] for h in hdr] for r in result]

# filter to negative logP
neg_logp = [r for r in result if logp_neg(r[0]) or logp_neg(r[2])]
# filter to pChEMBL > 5.0
pchembl5 = [r for r in neg_logp if pchembl_gt_5(r[6])]
# filter to development phase
phase1   = [r for r in pchembl5 if r[5] > 0]

# add gene names
_ = [r.append(pa.mapper.map_name(r[-2], 'uniprot', 'genesymbol')[0]) for r in pchembl5]
hdr.append('gene_symbol')

# write to file

with open('chembl_kinases_neg-logp_pchembl5_phase1234.tab', 'w') as fp:
    
    _ = fp.write('%s\n' % '\t'.join(hdr))
    
    _ = fp.write('\n'.join('\t'.join(map(str, r)) for r in phase1))

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.