Skip to content

Instantly share code, notes, and snippets.

@leelasd
Created November 16, 2021 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leelasd/e609e5ad87050a5638ec790041ac164d to your computer and use it in GitHub Desktop.
Save leelasd/e609e5ad87050a5638ec790041ac164d to your computer and use it in GitHub Desktop.
Extract Permeability Data from Chembl SQL database
import psycopg2
import pandas as pd
import pandas.io.sql as sqlio
con = psycopg2.connect(database="chembl_29", user="leelasd", password="", host="127.0.0.1", port="5432")
print("Database opened successfully")
sql="""SELECT m.chembl_id AS compound_chembl_id,
s.canonical_smiles,
r.compound_key,
a.description AS assay_description, act.standard_type,
d.pubmed_id AS pubmed_id_or_doi,
act.standard_relation,
act.standard_value,
act.standard_units,
act.activity_comment
FROM compound_structures s,
molecule_dictionary m,
compound_records r,
docs d,
activities act,
assays a,
target_dictionary t
WHERE s.molregno = m.molregno
AND m.molregno = r.molregno
AND r.record_id = act.record_id
AND r.doc_id = d.doc_id
AND act.assay_id = a.assay_id
AND a.tid = t.tid
AND a.assay_type = 'A'
AND ((a.description LIKE '%Permeability%') OR (a.description LIKE '%permeability%'))
"""
dat = sqlio.read_sql_query(sql, con)
dat.to_csv('perm.csv',index=False)
print("Operation done successfully")
con.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment