Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"url" : "https://github.com/rjawesome"
},
"dumper" : {
"data_url" : ["https://www.bindingdb.org/bind/downloads/BindingDB_All_2022m5.tsv.zip"],
"data_url" : ["https://www.bindingdb.org/bind/downloads/BindingDB_All_202405_tsv.zip"],
"uncompress" : true
},
"uploader" : {
Expand Down
42 changes: 29 additions & 13 deletions parser.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import csv
import json
import os
from typing import Dict


"""
Dumped file name
"""
DATA_FILE_NAME = 'BindingDB_All_202405.tsv'


"""
Fields of the Imported CSV:

- The array BASE_COLS defines the first columns in each row with data mainly pertaining to the compound.
- A sequence of columns is repeated which creates the data for each protein in the row, which is stored in REPEAT_SUBJECT_COLS.

- Reference: https://www.bindingdb.org/bind/chemsearch/marvin/BindingDB-TSV-Format.pdf
"""
REPEAT_SUBJECT_COLS = [
'BindingDB Target Chain Sequence',
Expand All @@ -30,7 +38,7 @@
'Ligand InChI Key',
'BindingDB MonomerID',
'BindingDB Ligand Name',
'Target Name Assigned by Curator or DataSource',
'Target Name',
'Target Source Organism According to Curator or DataSource',
'Ki (nM)',
'IC50 (nM)',
Expand All @@ -42,6 +50,7 @@
'Temp (C)',
'Curation/DataSource',
'Article DOI',
'BindingDB Entry DOI',
'PMID',
'PubChem AID',
'Patent Number',
Expand Down Expand Up @@ -109,7 +118,7 @@
"uniprot_type": "all",
"relation": False
},
"Target Name Assigned by Curator or DataSource": {
"Target Name": {
"location": "subject.name",
"type": "split_colon",
"uniprot_type": "all",
Expand Down Expand Up @@ -181,6 +190,12 @@
"uniprot_type": "all",
"relation": True
},
"BindingDB Entry DOI": {
"location": "relation.bindingdb_entry_doi",
"type": "string",
"uniprot_type": "all",
"relation": True
},
"PMID": {
"location": "relation.pmid",
"type": "string",
Expand Down Expand Up @@ -327,13 +342,13 @@
},
"UniProt (SwissProt) Secondary ID(s) of Target Chain": {
"location": "subject.uniprot.secondary_accession",
"type": "split_comma",
"type": "split_space",
"uniprot_type": "swissprot",
"relation": False
},
"UniProt (SwissProt) Alternative ID(s) of Target Chain": {
"location": "subject.uniprot.alternative_accession",
"type": "split_comma",
"type": "split_space",
"uniprot_type": "swissprot",
"relation": False
},
Expand All @@ -357,13 +372,13 @@
},
"UniProt (TrEMBL) Secondary ID(s) of Target Chain": {
"location": "subject.uniprot.secondary_accession",
"type": "split_comma",
"type": "split_space",
"uniprot_type": "trembl",
"relation": False
},
"UniProt (TrEMBL) Alternative ID(s) of Target Chain": {
"location": "subject.uniprot.alternative_accession",
"type": "split_comma",
"type": "split_space",
"uniprot_type": "trembl",
"relation": False
}
Expand Down Expand Up @@ -423,6 +438,8 @@ def process_field(field_name: str, value: str):
field_type = COLUMN_DATA[field_name]['type']
if field_type == "int":
return int(value)
if field_type == "split_space":
return value.split(' ')
if field_type == "split_comma":
return value.split(',')
if field_type == "split_semicolon":
Expand All @@ -446,13 +463,13 @@ def read_csv(file: str, delim: str):
continue
else:
base = {'object': {}, 'subject': {}, 'relation': {}}
for j in range(37):
for j in range(38):
if row[j] is not None and row[j] != '' and row[j] != 'NULL':
val = process_field(BASE_COLS[j], row[j])
set_field(base, BASE_COLS[j], val)

repeats = int(row[36]) # Number of Protein Chains in Target
pos = 37
repeats = int(row[37]) # Number of Protein Chains in Target
pos = 38
for j in range(repeats):
info_1 = special_copy(base)
info_2 = special_copy(base)
Expand Down Expand Up @@ -499,8 +516,7 @@ def merge(main: Dict[str, any], other: Dict[str, any]):
def load_data(data_folder):
docs = {}
row_num = 0
for row in read_csv(os.path.join(data_folder, './BindingDB_All.tsv'), '\t'):
# print(row['subject']['uniprot'])
for row in read_csv(os.path.join(data_folder, './' + DATA_FILE_NAME), '\t'):
try:
entry_name = row['subject']['uniprot']['id']
primary_id = row['subject']['uniprot']['accession']
Expand Down Expand Up @@ -531,7 +547,7 @@ def load_data(data_folder):
yield docs[doc_id]


# def main():
# type: ignore # def main():
# from time import time

# cnt = 0
Expand Down