Skip to content

Commit

Permalink
release MixTcpred_v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
GiancarloCroce committed Mar 11, 2024
1 parent 2b64bac commit 950313a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
3 changes: 2 additions & 1 deletion MixTCRpred.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import configparser
import pandas as pd

path_pretrained_models = './pretrained_models'
path_pretrained_models = '/home/giancarlo/Documents/lab_work/MixTCRpred/pretrained_models'
#path_pretrained_models = './pretrained_models'

if __name__ == '__main__':

Expand Down
2 changes: 2 additions & 0 deletions src/imgt_ref_seq/get_CDR12_fromVgene.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
name = seq_record.id
vgene = name.split("|")[1]
seq = seq_record.seq
break
cdr1 = str(seq[26:38]).replace("-","")
cdr2 = str(seq[55:65]).replace("-","")
all_cdr1.append(cdr1)
Expand Down Expand Up @@ -62,6 +63,7 @@
name = seq_record.id
vgene = name.split("|")[1]
seq = seq_record.seq
print(len(seq))
cdr1 = str(seq[26:38]).replace("-","")
cdr2 = str(seq[55:65]).replace("-","")
all_cdr1.append(cdr1)
Expand Down
43 changes: 22 additions & 21 deletions src/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, vocab_size, embedding_dim, hidden_dim, num_heads, num_layers
self.scale = torch.sqrt(torch.FloatTensor([self.embedding_dim]))
self.embedding_pos_epi = PositionWiseEmbedding(self.vocab_size, self.embedding_dim, self.padding[0])
self.embedding_pos_TRA = PositionWiseEmbedding(self.vocab_size, self.embedding_dim, self.padding[1] + 2*self.padding[-1])
self.embedding_pos_TRB = PositionWiseEmbedding(self.vocab_size, self.embedding_dim, self.padding[1] + 2*self.padding[-1])
self.embedding_pos_TRB = PositionWiseEmbedding(self.vocab_size, self.embedding_dim, self.padding[2] + 2*self.padding[-1])
# Transformer - Encoder
self.transformer_encoder = TransformerEncoder(num_layers=num_layers, input_dim=embedding_dim, dim_feedforward=hidden_dim, num_heads=num_heads, dropout=dropout)
### Output classifier
Expand Down Expand Up @@ -131,23 +131,23 @@ def training_step(self, batch, batch_idx):
preds = self.forward(inp_data, mask = True)
loss = self.loss_function(preds, labels)
self.log('train_loss', loss)
#compute auc
fpr, tpr, threshold = metrics.roc_curve(labels.cpu().numpy(), preds.data[:,1].cpu().numpy())
AUC = metrics.auc(fpr, tpr)
#print("AUC_train:{0}".format(AUC))
self.log('train_auc', AUC)
##compute auc
#fpr, tpr, threshold = metrics.roc_curve(labels.cpu().numpy(), preds.data[:,1].cpu().numpy())
#AUC = metrics.auc(fpr, tpr)
##print("AUC_train:{0}".format(AUC))
#self.log('train_auc', AUC)
return loss
def validation_step(self, batch, batch_idx):
inp_data = batch[1]
labels = batch[2]
preds = self.forward(inp_data, mask = True)
loss = self.loss_function(preds, labels)
self.log('val_loss', loss)
#compute auc
fpr, tpr, threshold = metrics.roc_curve(labels.cpu().numpy(), preds.data[:,1].cpu().numpy())
AUC = metrics.auc(fpr, tpr)
#print("AUC_train:{0}".format(AUC))
self.log('val_auc', AUC)
##compute auc
#fpr, tpr, threshold = metrics.roc_curve(labels.cpu().numpy(), preds.data[:,1].cpu().numpy())
#AUC = metrics.auc(fpr, tpr)
##print("AUC_train:{0}".format(AUC))
#self.log('val_auc', AUC)
return loss
def test_step(self, batch, batch_idx):
test_seq = batch[0]
Expand All @@ -156,6 +156,7 @@ def test_step(self, batch, batch_idx):
preds = self.forward(inp_data, mask = True)
loss = self.loss_function(preds, labels)
self.prob.extend(preds.data[:,1].cpu().numpy())
#self.prob.extend(preds.data.cpu().numpy())
self.test_tp.extend(labels.cpu().numpy())
self.test_seq.extend(test_seq)

Expand Down Expand Up @@ -188,7 +189,7 @@ def __init__(self, vocab_size, embedding_dim, hidden_dim, num_heads, num_layers
self.embedding_pos_cdr12= PositionWiseEmbedding(self.vocab_size, self.embedding_dim, 4*self.padding[-1])
########## TEST ############3
self.embedding_pos_TRA = PositionWiseEmbedding(self.vocab_size, self.embedding_dim, self.padding[1] + 2*self.padding[-1])
self.embedding_pos_TRB = PositionWiseEmbedding(self.vocab_size, self.embedding_dim, self.padding[1] + 2*self.padding[-1])
self.embedding_pos_TRB = PositionWiseEmbedding(self.vocab_size, self.embedding_dim, self.padding[2] + 2*self.padding[-1])
# Transformer - Encoder
self.transformer_encoder = TransformerEncoder(num_layers=num_layers,
input_dim=embedding_dim,
Expand Down Expand Up @@ -344,22 +345,22 @@ def training_step(self, batch, batch_idx):
loss = self.loss_function(preds, labels)
self.log('train_loss', loss)
#compute auc
fpr, tpr, threshold = metrics.roc_curve(labels.cpu().numpy(), preds.data[:,1].cpu().numpy())
AUC = metrics.auc(fpr, tpr)
#print("AUC_train:{0}".format(AUC))
self.log('train_auc', AUC)
#fpr, tpr, threshold = metrics.roc_curve(labels.cpu().numpy(), preds.data[:,1].cpu().numpy())
#AUC = metrics.auc(fpr, tpr)
##print("AUC_train:{0}".format(AUC))
#self.log('train_auc', AUC)
return loss
def validation_step(self, batch, batch_idx):
inp_data = batch[1]
labels = batch[2]
preds = self.forward(inp_data, mask = True)
loss = self.loss_function(preds, labels)
self.log('val_loss', loss)
#compute auc
fpr, tpr, threshold = metrics.roc_curve(labels.cpu().numpy(), preds.data[:,1].cpu().numpy())
AUC = metrics.auc(fpr, tpr)
#print("AUC_train:{0}".format(AUC))
self.log('val_auc', AUC)
##compute auc
#fpr, tpr, threshold = metrics.roc_curve(labels.cpu().numpy(), preds.data[:,1].cpu().numpy())
#AUC = metrics.auc(fpr, tpr)
##print("AUC_train:{0}".format(AUC))
#self.log('val_auc', AUC)
return loss
def test_step(self, batch, batch_idx):
test_seq = batch[0]
Expand Down

0 comments on commit 950313a

Please sign in to comment.