Commit 315c1496 by Andrea Mancini

last update of README.MD > update architecture and added plms; added sh3 fungi…

last update of README.MD > update  architecture and added plms; added sh3 fungi and small datasets; minor updates of others
parent 86e9458c
......@@ -6,24 +6,33 @@ We implemented SPIN, a Transformer model inspired by ESM-2, for functionally cla
We experimented with two Protein families: Thioredoxin (TRX) and SH3. We identify functional classes and subclasses with ProfileView (https://doi.org/10.1101/717249), handling thousands of sequences at a time to create comprehensive groups.
Our goal is to achieve large-scale classification of millions of proteins from extensive databases and ongoing high-throughput sequencing efforts. Moreover, it identifies conserved residues that are crucial for subfamilies, providing insights into the functional nuances of protein subclasses.
**Architecture**:
[Click here](https://zenodo.org/records/17351600) to visit public Zenodo record.
- **Architecture**:
<p align="center">
<img src="images/architecture.png" width="100%" alt="arch">
</p>
**Results**:
## 📊 Results:
Datasets split: Train 80%, Val 10 %, Test 10%
### Families comparison:
Train 80%, Val 10 %, Test 10%
| | Sequences | Classes | Train Accuracy | Train F1 | Val Accuracy | Val F1 | Test Accuracy | Test F1 | Dom Start (± 3) | Dom End (± 3) |
|:---:|:---------:|:-------:|:-------------------:|:--------------------:|:-------------------:|:--------------------:|:-------------------:|:--------------------:|:-------------:|:-------------:|
| TRX | 28151 | 8 | 0.985 ± 0.033 | 0.985 ± 0.033 | 0.913 ± 0.006 | 0.913 ± 0.006 | 0.906 ± 0.003 | 0.906 ± 0.003 | 0.823 ± 0.002 | 0.819 ± 0.002 |
| SH3 | 8088 | 7 | 0.999 ± 0.0003 | 0.999 ± 0.0003 | 0.902 ± 0.0003 | 0.902± 0.0003 | 0.887 ± 0.001 | 0.887 ± 0.001 | 0.969 ± 0.002 | 0.980 ± 0.002 |
| CPF | 14135 | 8 | 0.988 ± 0.0002 | 0.987 ± 0.0002 | 0.982 ± 0.0002 | 0.982 ± 0.0002 | 0.977 ± 0.003 | 0.976 ± 0.003 | 0.963 ± 0.002 | 0.909 ± 0.005 |
| | Sequences | Classes | Train Accuracy | Train F1 | Val Accuracy | Val F1 | Test Accuracy | Test F1 | Dom Start (± 3) | Dom End (± 3) |
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
| TRX | 28601 | 8 | 0.985 ± 0.03 | 0.985 ± 0.03 | 0.912 ± 0.0 | 0.912 ± 0.0 | 0.905 ± 0.01 | 0.905 ± 0.01 | 0.823 | 0.819 |
| SH3 | 8088 | 7 | 0.999 ± 0.0 | 0.999 ± 0.0 | 0.902 ± 0.0 | 0.902± 0.0 | 0.887 ± 0.0 | 0.887 ± 0.0 | 0.969 ± 0.0 | 0.980 ± 0.0 |
| CPF | 14135 | 8 | 0.987 ± 0.0 | 0.987 ± 0.0 | 0.982 ± 0.0 | 0.982 ± 0.0 | 0.976 ± 0.0 | 0.976 ± 0.0 | 0.963 ± 0.0 | 0.909 ± 0.0 |
---
### PLMs comparison:
| PLMs Classifier | PLM Parameters | Val Acc | Val F1 | Test Acc | Test F1 | Start (± 3) | End (± 3) | Training (s/iter) w/ batch = 16 | Test (s/iter) w/ batch = 16 |
|:---------------------------:|:--------------:|:-------:|:------:|:--------:|:-------:|:-----------:|:---------:|:-------------------------------:|:---------------------------:|
| ESM2-35M | 35M (Freezed) | 0.797 | 0.796 | 0.798 | 0.796 | 0.505 | 0.571 | 0.53 | 0.52 |
| ProtT5-XL-UR50-Half Encoder | 1.2B (Freezed) | 0.826 | 0.826 | 0.822 | 0.821 | 0.512 | 0.583 | 4.43 | 4.16 |
| Ankh-base Encoder | 450M (Freezed) | 0.815 | 0.813 | 0.822 | 0.820 | 0.476 | 0.556 | 3.90 | 3.82 |
## 🛠️ Usage
Get started with just a few steps:
......@@ -43,11 +52,22 @@ Get started with just a few steps:
### 3️⃣ Download pretrained models
**Protein Families:**
| Model | # Classes | # tokens | # Epoch | #Val F1 score | # Checkpoint |
|:---:|:---:|:---:|:---:|:---:|:---:|
| TRX model | 8 | 1024 | 7 | 0.92 | [🔗 Download](https://zenodo.org/records/17351600/files/trx_8class_model.tar?download=1) |
| SH3 model | 7 | 1024 | 10 | 0.91 | [🔗 Download](https://zenodo.org/records/17351600/files/sh3_7class_model.tar?download=1) |
| CPF model | 8 | 1024 | 10 | 0.99 | [🔗 Download](https://zenodo.org/records/17351600/files/cpf_8class_model.tar?download=1) |
| TRX model | 8 | 1024 | 7 | 0.92 | [🔗 Download](https://zenodo.org/records/17466839/files/trx_8class_model.tar?download=1) |
| SH3 model | 7 | 1024 | 10 | 0.91 | [🔗 Download](https://zenodo.org/records/17466839/files/sh3_7class_model.tar?download=1) |
| CPF model | 8 | 1024 | 10 | 0.99 | [🔗 Download](https://zenodo.org/records/17466839/files/cpf_8class_model.tar?download=1) |
**PLMs Comparison on TRX family:**
| Model | # Epoch | # Checkpoint |
|:---:|:---:|:---:|
| Ankh-base | 10 |[🔗 Download](https://zenodo.org/records/17466839/files/ankh_freezed_trx8.tar?download=1) |
| ESM2-35M | 7 |[🔗 Download](https://zenodo.org/records/17466839/files/esm_trx_freezed.tar?download=1) |
| ProtT5-XL | 5 |[🔗 Download](https://drive.google.com/file/d/1FNeI46XlfoTNDS-nst25-nWYFB2KxklU/view?usp=sharing) |
### 4️⃣ Create dataset from ProfileView tree
......@@ -65,6 +85,13 @@ Example of dataset.csv:
```bash
training.py -f path_to_csv --epochs 10 --batchsize 8 -v 2
```
#### Change backbone model:
Open config.py > edit 'version' instance attribute in Model_args class with:
- Ankh-base - 🤗 Model card: [ElnaggarLab/ankh-base](https://huggingface.co/ElnaggarLab/ankh-base)
- ProtT5-XL - 🤗 Model card: [Rostlab/prot_t5_xl_half_uniref50-enc](https://huggingface.co/Rostlab/prot_t5_xl_half_uniref50-enc)
### 7️⃣ Predict
```bash
......
......@@ -22,7 +22,7 @@ class TrainArgs:
class ModelArgs:
def __init__(self,
model_name: str = "",
version: str = "facebook/esm2_t12_35M_UR50D", #"Rostlab/prot_t5_xl_half_uniref50-enc", #"facebook/esm2_t12_35M_UR50D",
version: str = "facebook/esm2_t12_35M_UR50D", #"Rostlab/prot_t5_xl_half_uniref50-enc", "ElnaggarLab/ankh-base,
num_class: int = 0,
labels: List[str] = [],
freeze: bool = False,
......
......@@ -26,7 +26,7 @@ class PreprocessData:
print(self._data_input)
if not self._data_input.is_absolute():
self._data_input = BASE_PATH / self._data_input
self._data_input = self._base_dir/ self._data_input
if not self._data_input.exists():
raise Exception("path doesn't exist")
......@@ -43,7 +43,7 @@ class PreprocessData:
def _process_fasta(self):
with open(self._base_dir / self._data_input, 'r') as f:
with open(self._data_input, 'r') as f:
seqs = f.read().split('>')[1:]
fasta_id = [s.split()[0] for s in seqs]
......@@ -53,7 +53,7 @@ class PreprocessData:
def _process_csv(self):
return pd.read_csv(self._base_dir / self._data_input, sep=',')
return pd.read_csv(self._data_input, sep=',')
def _data_cleaning(self, data_df):
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
images/architecture.png

95.4 KB | W: | H:

images/architecture.png

436 KB | W: | H:

images/architecture.png
images/architecture.png
images/architecture.png
images/architecture.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -44,7 +44,7 @@ class DomainSpanESM(nn.Module):
hidd_size = self.t5.config.d_model
in_size = hidd_size
out_size = hidd_size #128
out_size = hidd_size
self.clf_head = nn.Sequential(
nn.Dropout(self.config.dropout),
......
......@@ -235,15 +235,4 @@ class TrainDomSpanESM:
log += f' F1 = [{metrics_train.f1score[epoch] :.4f}'
log += f',{metrics_val.f1score[epoch] :.4f}]' if metrics_val else ']'
print(log)
# print(
# f'Epoch: {epoch+1}'
# f' Lr: {lr :4f}'
# +' Train/Val:' if loss_val else 'Train:'
# + f' Loss = [{loss_train :.4f}]'
# + f',{loss_val :.4f}]' if loss_val else ''
# + f' Accuracy = [{metrics_train.accuracy[epoch] :.4f}]'
# + f',{metrics_val.accuracy[epoch] :.4f}]' if metrics_val else ''
# + f' F1 = [{metrics_train.f1score[epoch] :.4f}]'
# + f',{metrics_val.f1score[epoch] :.4f}]' if metrics_val else ''
# )
\ No newline at end of file
print(log)
\ No newline at end of file
......@@ -53,7 +53,6 @@ class TrainingPipeline:
dataset = EsmSpanDataset(dataframe)
dataset.split_data(self.seed, val_size=train_args.val_size)
# dataset.plot_distribution()
model_args = ModelArgs()
model_args.labels = dataset.labels
......@@ -100,7 +99,6 @@ class TrainingPipeline:
return result
if __name__ == "__main__":
# options for using from the command line
# EXAMPLE > training.py -f path_to_csv
parser = argparse.ArgumentParser(description='My parser')
......
......@@ -24,7 +24,7 @@ def make_splits(eval_size, targets, seed, stratify=True) -> Dict[str,List[int]]:
def make_plot_distribution(dataset_info, len_datasets, class2colors):
x = np.arange(len_datasets) # the label locations
x = np.arange(len_datasets)
width = 0.1
multiplier = 0
fig, ax = plt.subplots(layout='constrained')
......@@ -54,7 +54,7 @@ def make_plot_distribution(dataset_info, len_datasets, class2colors):
plt.show()
plt.clf()
def compute_dataset_info(labels, **datasets): #y_train, y_test, y_val):
def compute_dataset_info(labels, **datasets):
"""
Count number of class elements for each dataset
"""
......
......@@ -54,7 +54,7 @@ def load_model(filepath: Path|str, model_args=None):
if not filepath.is_absolute():
filepath = BASE_PATH / filepath
ckpt = torch.load(filepath,weights_only=False, map_location='cpu')
ckpt = torch.load(filepath, weights_only=False, map_location='cpu')
state_dict = ckpt['model_state_dict']
if ckpt.get('config') is None and model_args is None:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment