diff chembl.py @ 6:a57de37f12c2 draft

"planemo upload for repository https://github.com/chembl/chembl_webresource_client commit 78f2261af4e00c830ea311337d0aed9b297aad8e"
author bgruening
date Wed, 07 Oct 2020 09:31:40 +0000
parents 1ade252ebe08
children a43a00845834
line wrap: on
line diff
--- a/chembl.py	Tue Jul 28 08:20:47 2020 -0400
+++ b/chembl.py	Wed Oct 07 09:31:40 2020 +0000
@@ -1,62 +1,73 @@
+import argparse
+
+from chembl_webresource_client.new_client import new_client
 from chembl_webresource_client.settings import Settings
+
 Settings.Instance().CACHING = False
-from chembl_webresource_client.new_client import new_client
-import argparse
+
 
 def open_file(filename):
     with open(filename) as f:
         return f.readline().split()[0]
 
+
 def get_smiles(res):
     """
     Get a list of SMILES from function results
-    """ 
+    """
     smiles = set()
-    for smi in res: 
+    for smi in res:
         try:
             smiles.add('{}\t{}'.format(smi['molecule_structures']['canonical_smiles'], smi['molecule_chembl_id']))
         except TypeError:
             continue
     return smiles
 
+
 def sim_search(smiles, tanimoto):
     """
     Return compounds which are within a Tanimoto range of the SMILES input
     """
     similarity = new_client.similarity
     return similarity.filter(smiles=smiles, similarity=tanimoto).only(['molecule_structures', 'molecule_chembl_id'])
-    
+
+
 def substr_search(smiles):
     """
     Return compounds which contain the SMILES substructure input
     """
     substructure = new_client.substructure
     return substructure.filter(smiles=smiles).only(['molecule_structures', 'molecule_chembl_id'])
-    
+
+
 def filter_drugs(mols):
     """
     Return only compounds which are approved drugs
     """
     return mols.filter(max_phase=4)
 
+
 def filter_biotherapeutic(mols):
     """
     Return only biotherapeutic molecules
     """
     return mols.filter(biotherapeutic__isnull=False)
 
+
 def filter_nat_prod(mols):
     """
     Return only natural products
     """
     return mols.filter(natural_product=1)
 
+
 def filter_ro5(mols):
     """
     Return only compounds with no RO5 violations
     """
     return mols.filter(molecule_properties__num_ro5_violations=0)
 
+
 def main():
     parser = argparse.ArgumentParser(description='Search ChEMBL database for compounds')
     parser.add_argument('-i', '--input', help='SMILES input')
@@ -101,7 +112,7 @@
     # write to file
     with open(args.output, 'w') as f:
         f.write('\n'.join(mols))
-    
+
 
 if __name__ == "__main__":
     main()