<jupyter_start><jupyter_text>The purpose of this notebook is to parse all of the PubChem numbers from the kegg_compound master dataset and write them to a csv file so that our pubchem_client tool can pull all the corresponding SMILES strings from PubChem<jupyter_code># imports

import pandas as pd
from core import *
# read kegg compound dataset into dataframe

compound_df = create_kegg_df('../datasets/KEGG_compound_db_entries.gz', 'compound')
# parse pubchem id from each row in compound dataframe

compound_df['pubchem_id'] = [parse_pubchem_ids(row['dblinks']) for _, row in compound_df.iterrows()]
# function to check lengths of pubchem ids in dataframe

def check_length_dist(dataframe, field):
    id_lengths = [len(data) for data in dataframe[field]]

    values, counts = np.unique(id_lengths, return_counts=True)

    for i in range(len(values)):
        print("{}: {}".format(values[i], counts[i]))

    print("\ntotal numbers: {}\ndataframe shape: {}".format(counts.sum(), dataframe.shape))
# check lengths of pubchem ids in dataframe

check_length_dist(compound_df, 'pubchem_id')
# remove zero rows

compound_df = compound_df[compound_df['pubchem_id'] != '']
compound_df.shape
prom_com_df = pd.read_csv('promiscuous_products.csv')
prom_coms = prom_com_df['product'].unique().tolist()
len(prom_coms)

bool_mask = [True if row['entry'] in prom_coms else False for _, row in compound_df.iterrows()]
selected_compound_df = compound_df[bool_mask]
print(selected_compound_df.shape)
selected_compound_df.head()
compound_df.head()
# write to csv file

compound_df.to_csv('../datasets/KEGG_compounds_no_SMILES.csv')
!ls ../datasets/<jupyter_output>KEGG_compound.csv
KEGG_compound_db_entries.csv
KEGG_compound_db_entries.gz
KEGG_enzymes_all_data.gz
KEGG_reaction_db_entries.tar.gz
cleaned_promiscous_enzyme_df.csv
cofactor_list.csv
df_cleaned_kegg_with_smiles.csv
playground_df_cleaned_kegg_with_smiles.csv
promiscuous_cleaned_KEGGtoPubChem.csv
promiscuous_enzyme.csv
promiscuous_enzyme_list.xlsx
pubchem_ids_promiscuous_enzyme_products.csv
substrate_product_combined_promiscuous.csv
vectorized_enzyme.csv
{'fraction_non_alphanumeric': 0.09279321714554875, 'fraction_numerical': 0.0, 'mean_word_length': 6.5587188612099645, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '261188', 'license': 'MIT', 'n_tokens_mistral': 768, 'n_tokens_neox': 746, 'n_words': 164, 'path': 'deprecated/notebooks/generate_kegg_compound_master_list.ipynb', 'repo_name': 'metamoles/metamoles', 'size': '2123'}