GLASS_GPCR_SELFIES / README.md
ejy's picture
Update README.md
fd811ee verified
metadata
dataset_info:
  features:
    - name: Y_affinity
      dtype: float64
    - name: smiles
      dtype: string
    - name: seq
      dtype: string
    - name: Y_binary
      dtype: int64
    - name: Y_log_affinity
      dtype: float64
    - name: selfies
      dtype: string
  splits:
    - name: train
      num_bytes: 606248442.8293403
      num_examples: 740566
  download_size: 161743110
  dataset_size: 606248442.8293403

From the GLASS GPCR database, converted to SELFIES

Steps to prepare the database:

  1. Download the GLASS database
wget https://zhanggroup.org/GLASS/downloads/interactions_active.tsv
wget https://zhanggroup.org/GLASS/downloads/interactions_inactives.tsv
wget https://zhanggroup.org/GLASS/downloads/targets.tsv
wget https://zhanggroup.org/GLASS/downloads/ligands.tsv
  1. Select just the columns of interest
cut -d$'\t' -f6,9 ligands.tsv > ligands2.tsv
cut -d$'\t' -f2,5 targets.tsv > targets2.tsv
cut -d$'\t' -f1,2,4,5 interactions_active.tsv > interactions_active2.tsv
cut -d$'\t' -f1,2,4,5 interactions_inactives.tsv > interactions_inactives2.tsv
  1. Parse interactions
import pandas as pd
import numpy as np

ligands = pd.read_csv('ligands2.tsv', sep='\t')
proteins = pd.read_csv('targets2.tsv', sep='\t')

actives = pd.read_csv('interactions_active2.tsv', sep='\t')
inactives = pd.read_csv('interactions_inactives2.tsv', sep='\t')

ligand_dict = {}

for index, item in ligands.iterrows():
  ligand_dict[item['InChI Key']] = item['Canonical SMILES']

protein_dict = {}

for index, item in proteins.iterrows():
  protein_dict[item['UniProt ID']] = item['FASTA Sequence']

def rehydrate_interactions(x):
  uniprot_id = x['UniProt ID']
  inchi_id = x['InChI Key']

  smile = ligand_dict[inchi_id]
  fasta = protein_dict[uniprot_id]

  return smile, fasta

actives[["smiles", "seq"]] = actives.apply(rehydrate_interactions, axis=1, result_type="expand")
inactives[["smiles", "seq"]] = inactives.apply(rehydrate_interactions, axis=1, result_type="expand")

actives = actives.drop(columns=['UniProt ID', 'InChI Key'])
inactives = inactives.drop(columns=['UniProt ID', 'InChI Key'])

actives['Y_binary'] = len(actives) * [1]
inactives['Y_binary'] = len(inactives) * [0]

merged = pd.concat([actives, inactives], axis=0)
merged = merged[merged['Unit'] == 'nM']

merged = merged.drop(columns=['Unit'])
merged = merged.reset_index()
merged = merged.drop(columns=['index'])

merged['Value'] = merged['Value'].map(lambda x: x.strip('>').strip(' ').strip('<'))
merged['Value'] = merged['Value'].map(lambda x: x.split(" - ")[0])
merged['Value'] = pd.to_numeric(merged['Value'], errors='coerce')
merged = merged.rename(columns={"Value": "Y_affinity"})
merged = merged[merged['Y_affinity'] != 0]
merged['Y_log_affinity'] = 6 - np.log(merged['Y_affinity']) / np.log(10)
merged = merged[merged['Y_log_affinity'] >= 0]
merged = merged[merged['Y_log_affinity'] <= 10]

shuffled = merged.sample(frac=1)
shuffled = shuffled.reset_index()
shuffled = shuffled.drop(columns=['index'])
  1. Convert SMILES to SELFIES
from datasets import Dataset, DatasetDict
from datasets import load_dataset
import selfies

dataset = Dataset.from_pandas(shuffled, split='train')

def smiles_to_selfies(dataset):
  try:
    return {"selfies": selfies.encoder(dataset["smiles"])}
  except selfies.EncoderError:
    return {"selfies": None}

dataset_selfies = dataset.map(smiles_to_selfies)
dataset_selfies = dataset_selfies.filter(lambda dataset: dataset["selfies"] != None)
  1. Compute protein ('prot_bert') / ligand embeddings ('SELFIES-RoBERTa-PubChem10M')
from sentence_transformers import SentenceTransformer
import re
import pickle
import os.path

# Protein embeddings
all_proteins_shortened = dataset_selfies.unique('seq')

protein_sequences = [re.sub(r"[UZOB]", "X", sequence) for sequence in all_proteins_shortened]
protein_sequences = [" ".join(sequence) for sequence in protein_sequences]

protein_model = SentenceTransformer('Rostlab/prot_bert')
protein_model.max_seq_length = 512

protein_emb = protein_model.encode(protein_sequences)

protein_embeddings = dict(zip(protein_sequences, protein_emb))

with open('glass_protein_embeddings.pkl', "wb") as fOut:
  pickle.dump(protein_embeddings, fOut, protocol=pickle.HIGHEST_PROTOCOL)

# Ligand embeddings
all_selfies_shortened = dataset_selfies.unique('selfies')

ligand_sequences = [sequence for sequence in all_selfies_shortened]

ligand_model = SentenceTransformer('ejy/SELFIES-RoBERTa-PubChem10M')
ligand_model.max_seq_length = 128

ligand_emb = ligand_model.encode(ligand_sequences)

ligand_embeddings = dict(zip(ligand_sequences, ligand_emb))

with open('glass_ligand_embeddings.pkl', "wb") as fOut:
  pickle.dump(ligand_embeddings, fOut, protocol=pickle.HIGHEST_PROTOCOL)