<pre class="lang-py prettyprint-override"><code>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 = &quot;https://bindingdb.org/axis2/services/BDBService/getTargetByCompound?smiles={SMILES}&amp;cutoff={similarity_cutoff}&quot;
    if type(smile) != str:
        return None
    else:
        similarity_cutoff = &quot;0.85&quot;

        url = url.replace(&quot;{SMILES}&quot;, smile)
        url = url.replace(&quot;{similarity_cutoff}&quot;, similarity_cutoff)

        response = requests.get(url)

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

        else:
            return None
        return response
for i in range(0,len(smiles)):
    resp = downloader(smiles[i])
    if resp == None:
        pass
    else:
        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:]] = []
                dictionary[x.tag[29:]].append(x.text)
        df = pd.DataFrame(dictionary)
        if len(df.columns) &gt; 0:
            df = df.loc[df['tanimoto'] &gt; &quot;0.85&quot;]
            df = df.drop_duplicates(subset='smiles',keep = 'first')
            df.replace({'na': pd.NA}, inplace=True)
            df = df.dropna()
            name = &quot;Valeriana jatamansi/{}.csv&quot;.format(metabolite[i])
            df.to_csv(name,index = False)
        else:
            pass
</code></pre>
<p>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)</p>
<p>This is the downloaded version:
<a href="https://i.sstatic.net/dMlPh.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/dMlPh.png" alt="enter image description here" /></a></p>
<p>This is the online version:
<a href="https://i.sstatic.net/DWkxO.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/DWkxO.png" alt="enter image description here" /></a>
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.</p>

CC BY-SA 4.0
2023-11-10T15:49:41.433Z
It would help if you showed an example where the code and the online database show different results.
Ram RS
CC BY-SA 4.0
2023-11-11T07:20:33.617Z
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.
Neeleshwar Pandey
<python><database><public-databases><api>
Need help with binding DB API
# Need help with binding DB API

(Asked by: username_0 on 2023-11-10)

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
    else:
        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

        else:
            return None
        return response
for i in range(0,len(smiles)):
    resp = downloader(smiles[i])
    if resp == None:
        pass
    else:
        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:]] = []
                dictionary[x.tag[29:]].append(x.text)
        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)
        else:
            pass

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:

This is the online version:

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.

**Tags:** python, database, public-databases, api
> **Comments:**
> **username_1**: It would help if you showed an example where the code and the online database show different results.  
> **username_0**: 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.  

---

## 0 answers

