English
OneScience
protein structure generation
File size: 2,356 Bytes
8e04e6f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from typing import List, Literal


def extract_cath_code_from_batch(batch):
    cath_code = batch.get("cath_code", None)
    if cath_code:
        # Remove the additional tuple layer introduced during collate
        _cath_code = []
        for codes in cath_code:
            _cath_code.append(
                [code[0] if isinstance(code, tuple) else code for code in codes]
            )
        cath_code = _cath_code
    return cath_code


def extract_cath_code_by_level(
    cath_code: str, level: Literal["C", "A", "T", "H"]
) -> str:
    """Extract cath_code at certain level.

    Args:
      cath_code: CATH code.
      level: Level to be extracted

    Returns:
      CATH code at the corresponding level.
    """
    mapping = {"H": 0, "T": 1, "A": 2, "C": 3}
    return cath_code.rsplit(".", mapping[level])[0]


def mask_cath_code_by_level(
    cath_code: List[str], level: Literal["C", "A", "T", "H"]
) -> str:
    """Mask cath_code at certain level.

    Args:
      cath_code: List of CATH code.
      level: Level to be extracted

    Returns:
      List of CATH code. Replace the corresponding level with unknown token 'x'.
    """
    mapping = {"H": 3, "T": 2, "A": 1, "C": 0}
    _cath_code = []
    for code in cath_code:
        code = code.split(".")
        code[mapping[level]] = "x"
        _cath_code.append(".".join(code))
    return _cath_code


def transform_global_percentage_to_mask_dropout(fold_label_sample_ratio):
    assert (
        len(fold_label_sample_ratio) == 4
    ), "Length of fold_label_sample_ratio should be 4"
    assert (
        sum(fold_label_sample_ratio) == 1.0
    ), "Sum of fold_label_sample_ratio should be 1.0"
    mask_T_prob = sum(fold_label_sample_ratio[:3]) / sum(
        fold_label_sample_ratio
    )  # Among all samples, how many T-level labels are dropped?       (null + C + CA) / (null + C + CA + CAT)
    mask_A_prob = sum(fold_label_sample_ratio[:2]) / (
        sum(fold_label_sample_ratio[:3]) + 1e-10
    )  # Among samples with T labels dropped, how many A-level labels are dropped?    (null + C) / (null + C + CA)
    mask_C_prob = sum(fold_label_sample_ratio[:1]) / (
        sum(fold_label_sample_ratio[:2]) + 1e-10
    )  # Among samples with A and T labels dropped, how many C-level labels are dropped?     null / (null + C)
    return mask_T_prob, mask_A_prob, mask_C_prob