Skip to content

utils

load_json(path)

Loads a json file into a dictionary.

Parameters:

Name Type Description Default
path str

Path to the .json file to load.

required

Returns:

Type Description
Dict

Content of the .json file as a dictionary.

Source code in pydebiaseddta/utils.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def load_json(path: str) -> Dict:
    """Loads a json file into a dictionary.

    Parameters
    ----------
    path : str
        Path to the .json file to load.

    Returns
    -------
    Dict
        Content of the .json file as a dictionary.
    """
    with open(path, "r") as f:
        return json.load(f)

load_sample_dta_data(mini=False)

Loads a portion of the BDB dataset for fast experimenting.

Parameters:

Name Type Description Default
mini bool, optional

Whether to load all drug-target pairs embedded in the library, or a mini version. Set to True for fast prototyping and False to quickly train a model. Defaults to False.

False

Returns:

Type Description
Dict[str, List]

The dictionary has three keys: "train", "val", and "test", each corresponding to different folds of the dataset. Each key maps to a list with three elements: list of chemicals, list of proteins, and list of affinity scores. The elements in the same index of the lists correspond to a drug-target affinity measurement.

Source code in pydebiaseddta/utils.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def load_sample_dta_data(mini: bool = False) -> Dict[str, List]:
    """Loads a portion of [the BDB dataset](https://arxiv.org/pdf/2107.05556.pdf) for fast experimenting.

    Parameters
    ----------
    mini : bool, optional
        Whether to load all drug-target pairs embedded in the library, or a mini version.
        Set to `True` for fast prototyping and `False` to quickly train a model.
        Defaults to `False`.

    Returns
    -------
    Dict[str, List]
        The dictionary has three keys: `"train"`, `"val"`, and `"test"`, each corresponding to different folds of the dataset.
        Each key maps to a list with three elements: *list of chemicals*, *list of proteins*, and *list of affinity scores*. 
        The elements in the same index of the lists correspond to a drug-target affinity measurement.
    """
    sample_data_path = f"{package_path}/data/dta_sample_data/dta_sample_data.json"
    if mini:
        sample_data_path = f"{package_path}/data/dta/dta_sample_data.mini.json"
    with open(sample_data_path) as f:
        return json.load(f)

load_sample_smiles()

Returns examples SMILES strings from ChEMBL for testing.

Returns:

Type Description
List[str]

SMILES examples from ChEMBL.

Source code in pydebiaseddta/utils.py
30
31
32
33
34
35
36
37
38
39
40
def load_sample_smiles() -> List[str]:
    """Returns examples SMILES strings from ChEMBL for testing.

    Returns
    -------
    List[str]
        SMILES examples from ChEMBL.
    """
    sample_data_path = f"{package_path}/data/sequence/chembl27.mini.smiles"
    with open(sample_data_path) as f:
        return [line.strip() for line in f.readlines()]

save_json(obj, path)

Saves a dictionary in json format. The indent is set to 4 for readability.

Parameters:

Name Type Description Default
obj Dict

Dictionary to store.

required
path str

Path to store the .json file.

required

Returns:

Type Description
None
Source code in pydebiaseddta/utils.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def save_json(obj: Dict, path: str) -> None:
    """Saves a dictionary in json format. The indent is set to 4 for readability.

    Parameters
    ----------
    obj : Dict
        Dictionary to store.
    path : str
        Path to store the .json file.

    Returns
    -------
    None
    """
    with open(path, "w") as f:
        json.dump(obj, f, indent=4)