Views
No views yet
TransHLA is a tool designed to discern whether a peptide will be recognized by HLA as an epitope.TransHLA is the first tool capable of directly identifying peptides as epitopes without the need for inputting HLA alleles. Due the different length of epitopes, we trained two models. The first is TransHLA_I, which is used for the detection of the HLA-I epitope, the other is TransHLA_II, which is used for the detection of the HLA-II epitope.TransHLA is a hybrid transformer model that utilizes a transformer encoder module and a deep CNN module. It is trained using pretrained sequence embeddings from ESM2 and contact map structural features as inputs. It can serve as a preliminary screening for the currently popular tools that are specific for HLA-epitope binding affinity.pytorch, fair-esm, and transformers. Additionally, the CUDA version must be 11.8 or higher; otherwise, the model will need to be run on CPU.pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
pip install transformers
pip install fair-esm1from transformers import AutoTokenizer
2from transformers import AutoModel
3import torch
4
5
6
7def pad_inner_lists_to_length(outer_list,target_length=16):
8 for inner_list in outer_list:
9 padding_length = target_length - len(inner_list)
10 if padding_length > 0:
11 inner_list.extend([1] * padding_length)
12 return outer_list
13
14
15if __name__ == "__main__":
16 device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
17 print(f"Using {device} device")
18 tokenizer = AutoTokenizer.from_pretrained("facebook/esm2_t33_650M_UR50D")
19 model = AutoModel.from_pretrained("SkywalkerLu/TransHLA_I", trust_remote_code=True)
20 model.to(device)
21 peptide_examples = ['EDSAIVTPSR','SVWEPAKAKYVFR']
22 peptide_encoding = tokenizer(peptide_examples)['input_ids']
23 peptide_encoding = pad_inner_lists_to_length(peptide_encoding)
24 print(peptide_encoding)
25 peptide_encoding = torch.tensor(peptide_encoding)
26 outputs,representations = model(peptide_encoding.to(device))
27 print(outputs)
28 print(representations)1from transformers import AutoTokenizer
2from transformers import AutoModel
3import torch
4
5
6
7
8def pad_inner_lists_to_length(outer_list,target_length=23):
9 for inner_list in outer_list:
10 padding_length = target_length - len(inner_list)
11 if padding_length > 0:
12 inner_list.extend([1] * padding_length)
13 return outer_list
14
15
16
17if __name__ == "__main__":
18 device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
19 print(f"Using {device} device")
20 tokenizer = AutoTokenizer.from_pretrained("facebook/esm2_t33_650M_UR50D")
21 model = AutoModel.from_pretrained("SkywalkerLu/TransHLA_II", trust_remote_code=True)
22 model.to(device)
23 model.eval()
24 peptide_examples = ['KMIYSYSSHAASSL','ARGDFFRATSRLTTDFG']
25 peptide_encoding = tokenizer(peptide_examples)['input_ids']
26 peptide_encoding = pad_inner_lists_to_length(peptide_encoding)
27 peptide_encoding = torch.tensor(peptide_encoding)
28 outputs,representations = model(peptide_encoding.to(device))
29 print(outputs)
30 print(representations)
31