Last active
October 6, 2015 19:17
-
-
Save aschreyer/3040757 to your computer and use it in GitHub Desktop.
Credimus RESTful web service How-to
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
# make sure the headers accept JSON | |
headers = {'accept': 'application/json'} | |
response = requests.get('http://marid.bioc.cam.ac.uk/credo/chemcomps/001', headers=headers) | |
response.status_code # returns 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
headers = {'accept': 'application/json'} | |
# the file to upload: web service only looks for the 'file' field | |
files = {'file': open('003.sdf')} | |
# post the structure to the resource for doing a USR search against all chemical components | |
response = requests.post('http://marid.bioc.cam.ac.uk/credo/chemcomps/sim/usr/', | |
headers=headers, files=files, params={'limit':25}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
response = requests.get('http://marid.bioc.cam.ac.uk/credo/contacts/', headers=headers, | |
params={'biomolecule_id':56818, 'ligand_id':241717, 'Contact.is_hbond':'t'}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
# the file to upload: REST resource only looks for the 'structure' field | |
files = {'structure': open('structure.pdb')} | |
# post the structure to the resource to identify all contacts and return JSON | |
# contact search should be restricted with the optional 'pdb_chain_id' and | |
# 'res_num' params | |
response = requests.post('http://marid.bioc.cam.ac.uk/credo/contacts/json', | |
files=files, params={'title':'foo', 'pdb_chain_id':'B'}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the returned column data | |
response.json().get('data') | |
[2, u'001', u'001', None, None, u'[(1S)-1-(3-phenylpropyl)-4-(3-pyridyl)butyl] (2R)-1-[2,2-difluoro-2-(3,4,5-trimethoxyphenyl)acetyl]piperidine-2-carboxylate', u'2001-11-06', u'2011-06-04', u'COc1cc(cc(c1OC)OC)C(C(=O)N2CCCC[C@H]2C(=O)O[C@@H](CCCc3ccccc3)CCCc4cccnc4)(F)F', 624.715, 45, 35, 10, 2, 0.285714, 0, 0, 0, 48, 17, 4, 3, 8, 0, 87.19, 7.258, 0.457143, 1, 0.142935, True, True, False, False, False, False, False, False, False, False, False, True, False] | |
# the metadata of the response: column names and data types | |
response.json().get('metadata') | |
[[u'chem_comp_id', u'INTEGER'], [u'het_id', u'VARCHAR(3)'], [u'three_letter_code', u'VARCHAR(3)'], [u'replaced_by_het_id', u'VARCHAR(8)'], [u'nstd_parent_het_id', u'TEXT'], [u'iupac_name', u'TEXT'], [u'initial_date', u'DATE'], [u'modified_date', u'DATE'], [u'ism', u'TEXT'], [u'mw', u'REAL'], [u'num_hvy_atoms', u'INTEGER'], [u'num_carbons', u'INTEGER'], [u'num_heteroatoms', u'INTEGER'], [u'num_halides', u'INTEGER'], [u'het_carb_ratio', u'REAL'], [u'formal_charge_count', u'INTEGER'], [u'formal_charge_sum', u'INTEGER'], [u'num_chiral_centers', u'INTEGER'], [u'num_bonds', u'INTEGER'], [u'num_rotors', u'INTEGER'], [u'num_ring_systems', u'INTEGER'], [u'num_aro_ring_systems', u'INTEGER'], [u'num_lipinski_hbond_acceptors', u'INTEGER'], [u'num_lipinski_hbond_donors', u'INTEGER'], [u'tpsa', u'REAL'], [u'xlogp', u'REAL'], [u'fraction_csp3', u'REAL'], [u'alerts', u'INTEGER'], [u'qed', u'REAL'], [u'has_std_atoms', u'BOOLEAN'], [u'has_butyl', u'BOOLEAN'], [u'is_solvent', u'BOOLEAN'], [u'is_nat_product', u'BOOLEAN'], [u'is_amino_acid', u'BOOLEAN'], [u'is_nucleotide', u'BOOLEAN'], [u'is_saccharide', u'BOOLEAN'], [u'is_block_buster', u'BOOLEAN'], [u'is_fragment', u'BOOLEAN'], [u'is_drug_like', u'BOOLEAN'], [u'is_lead', u'BOOLEAN'], [u'is_drug', u'BOOLEAN'], [u'is_approved_drug', u'BOOLEAN']] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment