Skip to content

Instantly share code, notes, and snippets.

@leelasd
Created November 16, 2021 14:19
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/0949f00f37adbe873b3d7411377c5c7f to your computer and use it in GitHub Desktop.
Save leelasd/0949f00f37adbe873b3d7411377c5c7f to your computer and use it in GitHub Desktop.
Extract approved Drugs from Chembl 29 local 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 DISTINCT m.chembl_id AS compound_chembl_id,s.canonical_smiles,
m.molregno,
m.structure_type,
m.first_in_class,
m.indication_class,
m.first_approval
FROM compound_structures s
RIGHT JOIN molecule_dictionary m ON s.molregno = m.molregno
JOIN compound_records r ON m.molregno = r.molregno
AND m.max_phase IN (3,4)
"""
dat = sqlio.read_sql_query(sql, con)
dat.to_csv('new_approved.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