Views
No views yet

1import torch
2from transformers import AutoTokenizer, BigBirdForMaskedLM
3from CodonTransformer.CodonPrediction import predict_dna_sequence
4from CodonTransformer.CodonJupyter import format_model_output
5device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
6
7
8# Load model and tokenizer
9tokenizer = AutoTokenizer.from_pretrained("adibvafa/CodonTransformer")
10model = BigBirdForMaskedLM.from_pretrained("adibvafa/CodonTransformer-base").to(device)
11
12
13# Set your input data
14protein = "MALWMRLLPLLALLALWGPDPAAAFVNQHLCGSHLVEALYLVCGERGFFYTPKTRREAEDLQVGQVELGG"
15organism = "Escherichia coli general"
16
17
18# Predict with CodonTransformer
19output = predict_dna_sequence(
20 protein=protein,
21 organism=organism,
22 device=device,
23 tokenizer=tokenizer,
24 model=model,
25 attention_type="original_full",
26 deterministic=True
27)
28print(format_model_output(output))1-----------------------------
2| Organism |
3-----------------------------
4Escherichia coli general
5
6-----------------------------
7| Input Protein |
8-----------------------------
9MALWMRLLPLLALLALWGPDPAAAFVNQHLCGSHLVEALYLVCGERGFFYTPKTRREAEDLQVGQVELGG
10
11-----------------------------
12| Processed Input |
13-----------------------------
14M_UNK A_UNK L_UNK W_UNK M_UNK R_UNK L_UNK L_UNK P_UNK L_UNK L_UNK A_UNK L_UNK L_UNK A_UNK L_UNK W_UNK G_UNK P_UNK D_UNK P_UNK A_UNK A_UNK A_UNK F_UNK V_UNK N_UNK Q_UNK H_UNK L_UNK C_UNK G_UNK S_UNK H_UNK L_UNK V_UNK E_UNK A_UNK L_UNK Y_UNK L_UNK V_UNK C_UNK G_UNK E_UNK R_UNK G_UNK F_UNK F_UNK Y_UNK T_UNK P_UNK K_UNK T_UNK R_UNK R_UNK E_UNK A_UNK E_UNK D_UNK L_UNK Q_UNK V_UNK G_UNK Q_UNK V_UNK E_UNK L_UNK G_UNK G_UNK __UNK
15
16-----------------------------
17| Predicted DNA |
18-----------------------------
19ATGGCTTTATGGATGCGTCTGCTGCCGCTGCTGGCGCTGCTGGCGCTGTGGGGCCCGGACCCGGCGGCGGCGTTTGTGAATCAGCACCTGTGCGGCAGCCACCTGGTGGAAGCGCTGTATCTGGTGTGCGGTGAGCGCGGCTTCTTCTACACGCCCAAAACCCGCCGCGAAGCGGAAGATCTGCAGGTGGGCCAGGTGGAGCTGGGCGGCTAA@article{Fallahpour_Gureghian_Filion_Lindner_Pandi_2025,
title={CodonTransformer: a multispecies codon optimizer using context-aware neural networks},
volume={16},
ISSN={2041-1723},
url={https://www.nature.com/articles/s41467-025-58588-7},
DOI={10.1038/s41467-025-58588-7},
number={1},
journal={Nature Communications},
author={Fallahpour, Adibvafa and Gureghian, Vincent and Filion, Guillaume J. and Lindner, Ariel B. and Pandi, Amir},
year={2025},
month=apr,
pages={3205},
language={en}
}