Package: antiberty
AntiBERTyOfficial repository for AntiBERTy, an antibody-specific transformer language model pre-trained on 558M natural antibody sequences, as described inDeciphering antibody affinity maturation with language models and weakly supervised learning.SetupTo use AntiBERTy, install via pip:pipinstallantibertyAlternatively, you can clone this repository and install the package locally:$gitclonegit@github.com:jeffreyruffolo/AntiBERTy.git$pipinstallAntiBERTyUsageEmbeddingsTo use AntiBERTy to generate sequence embeddings, use theembedfunction. The output is a list of embedding tensors, where each tensor is the embedding for the corresponding sequence. Each embedding has dimension[(Length + 2) x 512].fromantibertyimportAntiBERTyRunnerantiberty=AntiBERTyRunner()sequences=["EVQLVQSGPEVKKPGTSVKVSCKASGFTFMSSAVQWVRQARGQRLEWIGWIVIGSGNTNYAQKFQERVTITRDMSTSTAYMELSSLRSEDTAVYYCAAPYCSSISCNDGFDIWGQGTMVTVS","DVVMTQTPFSLPVSLGDQASISCRSSQSLVHSNGNTYLHWYLQKPGQSPKLLIYKVSNRFSGVPDRFSGSGSGTDFTLKISRVEAEDLGVYFCSQSTHVPYTFGGGTKLEIK",]embeddings=antiberty.embed(sequences)To access the attention matrices, pass thereturn_attentionflag to theembedfunction. The output is a list of attention matrices, where each matrix is the attention matrix for the corresponding sequence. Each attention matrix has dimension[Layer x Heads x (Length + 2) x (Length + 2)].fromantibertyimportAntiBERTyRunnerantiberty=AntiBERTyRunner()sequences=["EVQLVQSGPEVKKPGTSVKVSCKASGFTFMSSAVQWVRQARGQRLEWIGWIVIGSGNTNYAQKFQERVTITRDMSTSTAYMELSSLRSEDTAVYYCAAPYCSSISCNDGFDIWGQGTMVTVS","DVVMTQTPFSLPVSLGDQASISCRSSQSLVHSNGNTYLHWYLQKPGQSPKLLIYKVSNRFSGVPDRFSGSGSGTDFTLKISRVEAEDLGVYFCSQSTHVPYTFGGGTKLEIK",]embeddings,attentions=antiberty.embed(sequences,return_attention=True)Theembedfunction can also be used with masked sequences. Masked residues should be indicated with underscores.ClassificationTo use AntiBERTy to predict the species and chain type of sequences, use theclassifyfunction. The output is two lists of classifications for each sequences.fromantibertyimportAntiBERTyRunnerantiberty=AntiBERTyRunner()sequences=["EVQLVQSGPEVKKPGTSVKVSCKASGFTFMSSAVQWVRQARGQRLEWIGWIVIGSGNTNYAQKFQERVTITRDMSTSTAYMELSSLRSEDTAVYYCAAPYCSSISCNDGFDIWGQGTMVTVS","DVVMTQTPFSLPVSLGDQASISCRSSQSLVHSNGNTYLHWYLQKPGQSPKLLIYKVSNRFSGVPDRFSGSGSGTDFTLKISRVEAEDLGVYFCSQSTHVPYTFGGGTKLEIK",]species_preds,chain_preds=antiberty.classify(sequences)Theclassifyfunction can also be used with masked sequences. Masked residues should be indicated with underscores.Mask predictionTo use AntiBERTy to predict the identity of masked residues, use thefill_masksfunction. Masked residues should be indicated with underscores. The output is a list of filled sequences, corresponding to the input masked sequences.fromantibertyimportAntiBERTyRunnerantiberty=AntiBERTyRunner()sequences=["____VQSGPEVKKPGTSVKVSCKASGFTFMSSAVQWVRQARGQRLEWIGWIVIGSGN_NYAQKFQERVTITRDM__STAYMELSSLRSEDTAVYYCAAPYCSSISCNDGFD____GTMVTVS","DVVMTQTPFSLPV__GDQASISCRSSQSLVHSNGNTY_HWYLQKPGQSPKLLIYKVSNRFSGVPDRFSG_GSGTDFTLKISRVEAEDLGVYFCSQSTHVPYTFGG__KLEIK",]filled_sequences=antiberty.fill_masks(sequences)Pseudo log-likelihoodTo use AntiBERTy to calculate the pseudo log-likelihood of a sequence, use thepseudo_log_likelihoodfunction. The pseudo log-likelihood of a sequence is calculated as the average of per-residue masked log-likelihoods. The output is a list of pseudo log-likelihoods, corresponding to the input sequences.fromantibertyimportAntiBERTyRunnerantiberty=AntiBERTyRunner()sequences=["EVQLVQSGPEVKKPGTSVKVSCKASGFTFMSSAVQWVRQARGQRLEWIGWIVIGSGNTNYAQKFQERVTITRDMSTSTAYMELSSLRSEDTAVYYCAAPYCSSISCNDGFDIWGQGTMVTVS","DVVMTQSSTPFSLPVSLGDQASISCRSSQSLVHSNGNTYLHWYLQKPGQSPKLLIYKVSNRFSGVPDRFSGSGSGTDFTLKISRVEAEDLGVYFCSQSTHVPYTFGGGTKLEIK",]pll=antiberty.pseudo_log_likelihood(sequences,batch_size=16)Citing this work@article{ruffolo2021deciphering,title={Deciphering antibody affinity maturation with language models and weakly supervised learning},author={Ruffolo, Jeffrey A and Gray, Jeffrey J and Sulam, Jeremias},journal={arXiv preprint arXiv:2112.07782},year={2021}}