# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: 'Python 3.8.3 64-bit (''base'': conda)'
#     language: python
#     name: python_defaultSpec_1599028283407
# ---

# +
import pandas as pd
import grequests
import urllib.parse
from tqdm import tqdm
import json
from pandas import json_normalize
import time




# + tags=[]
SERVER_URL = "https://npclassifier.ucsd.edu"

df = pd.read_csv("smiles.tsv", sep="\t")
#df = pd.read_csv("/Users/pma/Dropbox/Research_UNIGE/git_repos/pybatchclassyfire/data/sanitized_structure.tsv", sep="\t")
#df = df.head(1000)

all_urls = []

for entry in tqdm(df.to_dict(orient="records")):
    smiles = str(entry["smiles"])
    if len(smiles) > 5:
        request_url = "{}/classify?smiles={}".format(SERVER_URL, urllib.parse.quote(smiles))
        all_urls.append(request_url)

# Lets actually do the query and measure the speed
rs = (grequests.get(u) for u in all_urls)
responses = grequests.map(rs, size=20)

# + tags=[]

start = time.time()
all_responses_list = [response.json() for response in responses]
end = time.time()
print(end - start)


# -

flattened_classified_json = json_normalize(all_responses_list)

# + tags=[]
flattened_classified_json.info()
# -

df = flattened_classified_json

df

# +
flattened_classified_json.to_csv('NP_classy_opennpdb.tsv', sep = '\t')


# -

df = pd.read_csv("/Users/pma/Dropbox/Research_UNIGE/git_repos/NP-Classifier/notebooks/NP_classy_opennpdb.tsv", sep="\t")

df

coltodrop = ['fp1', 'fp2']
df.drop(coltodrop, axis=1, inplace= True)

# + tags=[]
colnames(df)
# -

df.to_csv('NP_classy_opennpdb.tsv', sep = '\t', index = False)

df.rename(columns={ df.columns[-1]: "your value" })



StarcoderdataJupyterScriptsDedupFiltered