Update README.md
Browse files
README.md
CHANGED
|
@@ -47,10 +47,27 @@ Here is an example of how to use PDeepPP to process protein sequences and obtain
|
|
| 47 |
|
| 48 |
```python
|
| 49 |
import torch
|
|
|
|
| 50 |
from transformers import AutoModel
|
| 51 |
from processing_pdeeppp import PDeepPPProcessor
|
| 52 |
|
| 53 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 55 |
print(f"Using {device} device")
|
| 56 |
model = AutoModel.from_pretrained("fondress/PDeepPP_ACE", trust_remote_code=True)
|
|
@@ -59,11 +76,18 @@ model.to(device)
|
|
| 59 |
# Example protein sequences
|
| 60 |
protein_sequences = ["MKVSTYSTQ", "MSRSTYV"]
|
| 61 |
|
| 62 |
-
#
|
| 63 |
processor = PDeepPPProcessor(pad_char="X", target_length=33)
|
| 64 |
-
inputs = processor(sequences=protein_sequences, ptm_mode=True, return_tensors="pt") # Set ptm_mode=True for PTM processing
|
| 65 |
|
| 66 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
model.eval()
|
| 68 |
outputs = model(**inputs)
|
| 69 |
print(outputs["logits"])
|
|
|
|
| 47 |
|
| 48 |
```python
|
| 49 |
import torch
|
| 50 |
+
import numpy as np
|
| 51 |
from transformers import AutoModel
|
| 52 |
from processing_pdeeppp import PDeepPPProcessor
|
| 53 |
|
| 54 |
+
# 加载预训练的特征表示
|
| 55 |
+
train_representations_path = "./pretrained_weights/Hydroxyproline_P/train_combined_representations.npy" # 替换为你的路径
|
| 56 |
+
test_representations_path = "./pretrained_weights/Hydroxyproline_P/test_combined_representations.npy" # 替换为你的路径
|
| 57 |
+
|
| 58 |
+
# 检查文件是否存在
|
| 59 |
+
assert os.path.exists(train_representations_path), "预训练的 train_combined_representations.npy 文件不存在!"
|
| 60 |
+
assert os.path.exists(test_representations_path), "预训练的 test_combined_representations.npy 文件不存在!"
|
| 61 |
+
|
| 62 |
+
# 加载预训练特征
|
| 63 |
+
train_representations = np.load(train_representations_path)
|
| 64 |
+
test_representations = np.load(test_representations_path)
|
| 65 |
+
|
| 66 |
+
# 转换为 PyTorch 张量
|
| 67 |
+
train_representations_tensor = torch.tensor(train_representations)
|
| 68 |
+
test_representations_tensor = torch.tensor(test_representations)
|
| 69 |
+
|
| 70 |
+
# 加载 `PDeepPP` 模型
|
| 71 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 72 |
print(f"Using {device} device")
|
| 73 |
model = AutoModel.from_pretrained("fondress/PDeepPP_ACE", trust_remote_code=True)
|
|
|
|
| 76 |
# Example protein sequences
|
| 77 |
protein_sequences = ["MKVSTYSTQ", "MSRSTYV"]
|
| 78 |
|
| 79 |
+
# 初始化 PDeepPPProcessor
|
| 80 |
processor = PDeepPPProcessor(pad_char="X", target_length=33)
|
|
|
|
| 81 |
|
| 82 |
+
# 预处理序列
|
| 83 |
+
inputs = processor(sequences=protein_sequences, ptm_mode=True, return_tensors="pt") # 设置 ptm_mode=True 处理 PTM 数据
|
| 84 |
+
|
| 85 |
+
# 替换模型输入的嵌入表示为预训练特征
|
| 86 |
+
# 假设 inputs["input_embeds"] 是需要被替换的嵌入
|
| 87 |
+
# 在此处选择测试集中的预训练特征作为示例
|
| 88 |
+
inputs["input_embeds"] = test_representations_tensor[:len(protein_sequences)].to(device)
|
| 89 |
+
|
| 90 |
+
# 进行预测
|
| 91 |
model.eval()
|
| 92 |
outputs = model(**inputs)
|
| 93 |
print(outputs["logits"])
|