<commit_before>import numpy as np
from gpmap.gpm import GenotypePhenotypeMap
from gpmap import utils
from epistasis.mapping import EpistasisMap, assert_epistasis

class BaseSimulation(GenotypePhenotypeMap):
    """ Base class for simulating genotype-phenotype maps built from epistatic
    interactions.

    Parameters
    ----------
    wildtype : str
        wildtype sequence.
    mutations : dict
        dictionary mapping each site the possible mutations
    """
    def __init__(self, wildtype, mutations,
        log_transform=False,
        logbase=np.log10,
        model_type="global",
        **kwargs
        ):
        genotypes = np.array(utils.mutations_to_genotypes(wildtype, mutations))
        phenotypes = np.ones(len(genotypes))
        # Initialize a genotype-phenotype map
        super(BaseSimulation, self).__init__(
            wildtype,
            genotypes,
            phenotypes,
            log_transform=log_transform,
            logbase=logbase,
            mutations=mutations,
            **kwargs
        )

    def set_coefs_order(self, order):
        """Set coefs from an epistatic order."""
        # Attach an epistasis model.
        self.epistasis = EpistasisMap.from_mutations(self.mutations, order)

    def set_coefs_sites(self, sites):
        """Set coefs from list of coefs sites.
        """
        order = max([len(s) for s in sites])
        self.epistasis = EpistasisMap(sites, order=order, model_type="global")

    @assert_epistasis
    def set_coefs(self, sites, values):
        """Set the epistatic coefs

        Parameters
        ----------<commit_msg>assert epistasis too early in mapping<commit_after>import numpy as np
from gpmap.gpm import GenotypePhenotypeMap
from gpmap import utils
from epistasis.mapping import EpistasisMap, assert_epistasis

class BaseSimulation(GenotypePhenotypeMap):
    """ Base class for simulating genotype-phenotype maps built from epistatic
    interactions.

    Parameters
    ----------
    wildtype : str
        wildtype sequence.
    mutations : dict
        dictionary mapping each site the possible mutations
    """
    def __init__(self, wildtype, mutations,
        log_transform=False,
        logbase=np.log10,
        model_type="global",
        **kwargs
        ):
        genotypes = np.array(utils.mutations_to_genotypes(wildtype, mutations))
        phenotypes = np.ones(len(genotypes))
        # Initialize a genotype-phenotype map
        super(BaseSimulation, self).__init__(
            wildtype,
            genotypes,
            phenotypes,
            log_transform=log_transform,
            logbase=logbase,
            mutations=mutations,
            **kwargs
        )

    def set_coefs_order(self, order):
        """Set coefs from an epistatic order."""
        # Attach an epistasis model.
        self.epistasis = EpistasisMap.from_mutations(self.mutations, order)

    def set_coefs_sites(self, sites):
        """Set coefs from list of coefs sites.
        """
        order = max([len(s) for s in sites])
        self.epistasis = EpistasisMap(sites, order=order, model_type="global")

    def set_coefs(self, sites, values):
        """Set the epistatic coefs

        Parameters
        ----------
{'fraction_non_alphanumeric': 0.09054388133498145, 'fraction_numerical': 0.0012360939431396785, 'mean_word_length': 2.3544041450777202, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1750335', 'n_tokens_mistral': 958, 'n_tokens_neox': 892, 'n_words': 234}