import pandas as pd
import requests
import xml.etree.ElementTree as ET
df = pd.read_excel('file.xlsx')
smiles = df['SMILES'].to_list()
metabolite =  df['Plant_metabolite'].to_list()
def downloader(smile):
    url = "https://bindingdb.org/axis2/services/BDBService/getTargetByCompound?smiles={SMILES}&cutoff={similarity_cutoff}"
    if type(smile) != str:
        return None
        similarity_cutoff = "0.85"

        url = url.replace("{SMILES}", smile)
        url = url.replace("{similarity_cutoff}", similarity_cutoff)

        response = requests.get(url)

        if response.status_code == 200:
            response = response.text

            return None
        return response
for i in range(0,len(smiles)):
    resp = downloader(smiles[i])
    if resp == None:
        tree = ET.fromstring(resp)
        dictionary = {}
        for j in range(3,len(tree)):
            for x in tree[j]:
                if x.tag[29:] not in dictionary.keys(): 
                    dictionary[x.tag[29:]] = []
        df = pd.DataFrame(dictionary)
        if len(df.columns) > 0:
            df = df.loc[df['tanimoto'] > "0.85"]
            df = df.drop_duplicates(subset='smiles',keep = 'first')
            df.replace({'na': pd.NA}, inplace=True)
            df = df.dropna()
            name = "Valeriana jatamansi/{}.csv".format(metabolite[i])
            df.to_csv(name,index = False)

This my code which I am using to download targets for my compound, but there is a difference between the output returned by the API and in the online database? Like the names of the targets and other stuff... For example: For alpha-cadanol (SMILES: CC1=CC2C(CC1)C@@(O)CC[C@@H]2C(C)C)

This is the downloaded version: enter image description here

This is the online version: enter image description here Is there something wrong in the code, or is something else the problem here? Is there any other method to do the same thing? The similarity cutoff is 0.85 both in scripts and online, and affinity value for online portal is set up as 10000, no affinity filter is provided by the API.

  • 1
    $\begingroup$ It would help if you showed an example where the code and the online database show different results. $\endgroup$
    – Ram RS
    Nov 10, 2023 at 15:49
  • 1
    $\begingroup$ Edited, please check the updated question now and I hope it's clear now. It's a partial screenshot of the online version, the are a few more targets which are left out. $\endgroup$ Nov 11, 2023 at 7:20


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.