File size: 1,544 Bytes
8a0d2b8
 
 
 
 
 
 
 
4c1b5d1
8a0d2b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
This files includes a predict function for the Tox21.
As an input it takes a list of SMILES and it outputs a nested dictionary with 
SMILES and target names as keys.
"""

#---------------------------------------------------------------------------------------
# Dependencies
from typing import List
import random
from collections import defaultdict
#---------------------------------------------------------------------------------------
class Tox21RandomClassifier():
    """
    A random classifier that assigns a random toxicity score to a given SMILES string.  
    """
    
    def __init__(self):
        
        self.target_names = [
            "NR-AR", 
            "NR-AR-LBD", 
            "NR-AhR", 
            "NR-Aromatase", 
            "NR-ER", 
            "NR-ER-LBD", 
            "NR-PPAR-gamma", 
            "SR-ARE", 
            "SR-ATAD5", 
            "SR-HSE", 
            "SR-MMP", 
            "SR-p53"
        ]

    def predict(self, smiles_list:List[str]) -> dict:
        """
        Predicts all Tox21 targets for a given list of SMILES strings by assigning
        random toxicity scores.
        """

        predictions = defaultdict(dict)
        for smiles in smiles_list:
            for target in self.target_names:
                predictions[smiles][target] = random.random()
        return predictions

def predict(smiles_list: List[str]) -> dict:
    """
    Applies the classifier to a list of SMILES strings.
    """
    model = Tox21RandomClassifier()
    return model.predict(smiles_list)