pulsatrix 1.1.0
Loading...
Searching...
No Matches
pulsatrix::VariantScorer Class Reference

Scores variants with a masked language model and its tokenizer, the way ProteinGym scores ESM models. A higher score means the model finds the variant more plausible. More...

#include <variant_scoring.hpp>

Public Member Functions

 VariantScorer (EncoderLM &model, const TextTokenizer &tokenizer, DeviceBackend *backend, VariantScoringOptions options={})
 
ResidueLogProbs masked_marginals (std::string_view sequence)
 Each residue's distribution with that residue masked.
 
ResidueLogProbs wild_type_marginals (std::string_view sequence)
 Each residue's distribution from one pass over the unmasked sequence.
 
double pseudo_log_likelihood (std::string_view sequence)
 The sum over residues of log p(residue) with it masked. Every residue is scored.
 
double score (const ResidueLogProbs &marginals, std::string_view sequence, const std::vector< Mutation > &mutations, int64_t offset=1) const
 The summed log-ratio of mutations in marginals computed on sequence.
 
std::vector< float > single_mutant_scan (const ResidueLogProbs &marginals, std::string_view sequence) const
 Every single substitution: row i, column j is log p(kAminoAcids[j]) - log p(wild type) at residue i, row-major, length x 20. The wild type's own column is 0.
 
int64_t token_of (char residue) const
 

Detailed Description

Scores variants with a masked language model and its tokenizer, the way ProteinGym scores ESM models. A higher score means the model finds the variant more plausible.

  • Masked marginals (ProteinGym's choice for ESM-2) mask each residue in turn. A substitution scores log p(mutant) - log p(wild type) at its masked position, and a multiple mutant the sum of its substitutions. The cost is one forward pass per residue, whatever the number of variants.
  • Wild-type marginals read the same log-ratio from one unmasked pass. They are faster but less accurate.
  • Pseudo-log-likelihood sums log p(residue) with each residue masked in turn: one pass per residue, for each sequence scored.

Constructor & Destructor Documentation

◆ VariantScorer()

pulsatrix::VariantScorer::VariantScorer ( EncoderLM &  model,
const TextTokenizer &  tokenizer,
DeviceBackend *  backend,
VariantScoringOptions  options = {} 
)
Parameters
backendWhere the model runs. The model, tokenizer and backend must outlive this.

Member Function Documentation

◆ masked_marginals()

ResidueLogProbs pulsatrix::VariantScorer::masked_marginals ( std::string_view  sequence)

Each residue's distribution with that residue masked.

Exceptions
std::invalid_argumentfor an empty sequence or a character the tokenizer doesn't know.

◆ pseudo_log_likelihood()

double pulsatrix::VariantScorer::pseudo_log_likelihood ( std::string_view  sequence)

The sum over residues of log p(residue) with it masked. Every residue is scored.

◆ score()

double pulsatrix::VariantScorer::score ( const ResidueLogProbs &  marginals,
std::string_view  sequence,
const std::vector< Mutation > &  mutations,
int64_t  offset = 1 
) const

The summed log-ratio of mutations in marginals computed on sequence.

Exceptions
std::invalid_argumentif a mutation doesn't match the sequence, or names a residue that isn't a single vocabulary token.

◆ single_mutant_scan()

std::vector< float > pulsatrix::VariantScorer::single_mutant_scan ( const ResidueLogProbs &  marginals,
std::string_view  sequence 
) const

Every single substitution: row i, column j is log p(kAminoAcids[j]) - log p(wild type) at residue i, row-major, length x 20. The wild type's own column is 0.

◆ token_of()

int64_t pulsatrix::VariantScorer::token_of ( char  residue) const

◆ wild_type_marginals()

ResidueLogProbs pulsatrix::VariantScorer::wild_type_marginals ( std::string_view  sequence)

Each residue's distribution from one pass over the unmasked sequence.


The documentation for this class was generated from the following file: