<commit_before>__doc__ = """
Base class for epistasis models. This is meant to be called in a subclass.
"""
import numpy as np
import itertools as it
from collections import OrderedDict

# imports from seqspace dependency
from seqspace.utils import farthest_genotype, binary_mutations_map

# Local imports
from epistasis.utils import epistatic_order_indices
from epistasis.mapping.epistasis import EpistasisMap

class BaseModel(EpistasisMap):
    
    def __init__(self, wildtype, genotypes, phenotypes, errors=None, log_transform=False, mutations=None):
        """ Populate an Epistasis mapping object. 
        
            __Arguments__:
            
            `wildtype` [str] : Wildtype genotype. Wildtype phenotype will be used as reference state.
            
            `genotypes` [array-like, dtype=str] : Genotypes in map. Can be binary strings, or not.
            
            `phenotypes` [array-like] : Quantitative phenotype values
            
            `errors` [array-like] : List of phenotype errors.
            
            `log_transform` [bool] : If True, log transform the phenotypes.
            
            `mutations` [dict]: Mapping dictionary for mutations at each site.
            
        """
        # Defaults to binary mapping if not specific mutations are named
        if mutations is None:
            mutant = farthest_genotype(wildtype, genotypes)
            mutations = binary_mutations_map(wildtype, mutant)
            
        super(BaseModel, self).__init__(wildtype, genotypes, phenotypes, errors=errors, log_transform=log_transform, mutations=mutations)
        
        # Construct a binary representation of the map (method inherited from parent class)
        # and make it a subclass of the model.
        self._construct_binary()
      
        # Model error if given. 
        if errors is not None:
            self.errors = errors
            
    # ---------------------------------------------------------------------------------
    # Loading method
    # ---------------------------------------------------------------------------------
        
    @classmethod    
    def from_gpm(cls, gpm, **kwargs):
        """ Initialize an epistasis model from a Genotype-phenotype map object """
        # Grab each property from map
        model = cls(gpm.wildtype, 
                    gpm.genotypes, 
                    gpm.phenotypes, 
                    mutations = gpm.mutations,
                    log_transform= False,
                    **kwargs)
        
        # Set errors outside init to handle log transform
        model._errors = gpm.errors
        
        # Might need to change this later (kind of a hack)
        model._log_transform = gpm.log_transform
        
        return model
        
    # ---------------------------------------------------------------------------------
    # Other methods
    # ---------------------------------------------------------------------------------        
        
    def get_order(self, order, errors=False, label="genotype"):
        """ Return a dict of interactions to values of a given order. """<commit_msg>update basemap for changes in error map from seqspace<commit_after>__doc__ = """
Base class for epistasis models. This is meant to be called in a subclass.
"""
import numpy as np
import itertools as it
from collections import OrderedDict

# imports from seqspace dependency
from seqspace.utils import farthest_genotype, binary_mutations_map

# Local imports
from epistasis.utils import epistatic_order_indices
from epistasis.mapping.epistasis import EpistasisMap

class BaseModel(EpistasisMap):
    
    def __init__(self, wildtype, genotypes, phenotypes, errors=None, log_transform=False, mutations=None):
        """ Populate an Epistasis mapping object. 
        
            __Arguments__:
            
            `wildtype` [str] : Wildtype genotype. Wildtype phenotype will be used as reference state.
            
            `genotypes` [array-like, dtype=str] : Genotypes in map. Can be binary strings, or not.
            
            `phenotypes` [array-like] : Quantitative phenotype values
            
            `errors` [array-like] : List of phenotype errors.
            
            `log_transform` [bool] : If True, log transform the phenotypes.
            
            `mutations` [dict]: Mapping dictionary for mutations at each site.
            
        """
        # Defaults to binary mapping if not specific mutations are named
        if mutations is None:
            mutant = farthest_genotype(wildtype, genotypes)
            mutations = binary_mutations_map(wildtype, mutant)
            
        super(BaseModel, self).__init__(wildtype, genotypes, phenotypes, errors=errors, log_transform=log_transform, mutations=mutations)
        
        # Construct a binary representation of the map (method inherited from parent class)
        # and make it a subclass of the model.
        self._construct_binary()
      
        # Model error if given. 
        if errors is not None:
            self.errors = errors
            
    # ---------------------------------------------------------------------------------
    # Loading method
    # ---------------------------------------------------------------------------------
        
    @classmethod    
    def from_gpm(cls, gpm, **kwargs):
        """ Initialize an epistasis model from a Genotype-phenotype map object """
        # Grab each property from map
        model = cls(gpm.wildtype, 
                    gpm.genotypes, 
                    gpm.Raw.phenotypes, 
                    errors = gpm.Raw.errors,
                    mutations = gpm.mutations,
                    log_transform= gpm.log_transform,
                    **kwargs)
        
        return model
        
    # ---------------------------------------------------------------------------------
    # Other methods
    # ---------------------------------------------------------------------------------        
        
    def get_order(self, order, errors=False, label="genotype"):
        """ Return a dict of interactions to values of a given order. """
{'fraction_non_alphanumeric': 0.1654769630110318, 'fraction_numerical': 0.0, 'mean_word_length': 1.4640287769784173, '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': '2938849', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1377, 'n_words': 478}