<commit_before>#! /usr/bin/env python

##############################################################################
##  pyvolve: Python platform for simulating evolutionary sequences.
##
##  Written by <NAME> (<EMAIL>) 
##############################################################################


'''
    This module defines evolutionary model objects, EvoModel() and its child classes Model() and CodonModel().
    All evolutionary models contain information about the substitution process (rate matrix) and information about rate heterogeneity.
    The Model() class uses a single rate matrix, and heterogeneity is modeled using discrete scaling factors and associated probabilities.
    The CodonModel() class is used specifically in cases of codon model (dN/dS or omega) rate heterogeneity. Rate heterogeneity is implemented using a set of matrices with distinct dN/dS values, and each matrix has an associated probability. 
'''

import numpy as np
from copy import deepcopy
from matrix_builder import *


class EvoModels(object):
    ''' 
        Parent class for child classes Model() and CodonModel(). 
    '''
    
    def __init__(self, model_type, **kwargs):
        '''
            The EvoModel class will construct an evolutionary model object which will be used to evolve sequence data.            
            Instantiation requires a single positional argument:
                
                1. **model_type** is type of model (matrix) that is being used. These matrices are described explicitly in the matrix_builder module. Options include the following:
                                
                                    
                    +------------+-----------------------------------------------------------+
                    | model_type |                         Notes                             | 
                    +============+===========================================================+
                    | nucleotide | Arbitrary GTR                                             | 
                    +------------+-----------------------------------------------------------+
                    | JTT        | Jones, Taylor, and Thornton 1994 (amino acids)            |
                    +------------+-----------------------------------------------------------+
                    | WAG        | Whelan and Goldman 2002      (amino acids)                |
                    +------------+-----------------------------------------------------------+
                    | LG         | Le and Gascuel 2008        (amino acids)                  |
                    +------------+-----------------------------------------------------------+
                    | amino_acid | Defaults to LG                                            |
                    +------------+-----------------------------------------------------------+
                    | GY94       | Goldman and Yang 1994, Nielsen and Yang 1998              | 
                    +------------+-----------------------------------------------------------+
                    | MG94       | Muse and Gaut 1994                                        | 
                    +------------+-----------------------------------------------------------+
                    | codon      | Defaults to GY94                                          | 
                    +------------+-----------------------------------------------------------+
                    | ECM        | Kosiol et al. 2007                                        |   
                    +------------+-----------------------------------------------------------+
                    | mutsel     | Halpern and Bruno 2008 (may also be used for nucleotides) |  
                    +------------+-----------------------------------------------------------+
                    
            
            Optional keyword arguments include, 
                1. **params** is a dictionary of parameters pertaining to substitution process. For all models, this includes a vector of stationary frequencies. Each individual evolutionary model will have its own additional parameters. Note that if this argument is not provided, default parameters for your selected model will be assigned.
                
                2. **scale_matrix** = <'yang', 'neutral', 'False/None'>. This argument determines how rate matrices should be scaled. By default, all matrices are scaled according to Ziheng Yang's approach, in which the mean substitution rate is equal to 1. However, for codon models (GY94, MG94), this scaling approach effectively causes sites under purifying selection to evolve at the same rate as sites under positive selection, which may not be desired. Thus, the 'neutral' scaling option will allow for codon matrices to be scaled such that the mean rate of *neutral* subsitution is 1. You may also opt out of scaling by providing either False or None to this argument, although this is not recommended.
                
       '''
    
        
        self.model_type   = model_type.upper()
        self.params       = kwargs.get('params', {})
        self.scale_matrix = kwargs.get('scale_matrix', 'yang') # 'Yang', 'neutral', or False/None

        accepted_models = ['NUCLEOTIDE', 'AMINO_ACID', 'JTT', 'WAG', 'LG', 'CODON', 'GY94', 'MG94', 'MUTSEL']
        assert( self.model_type in accepted_models), "Inappropriate model type specified."
        assert( type(self.params) is dict ), "params argument must be a dictionary."
        
        # Default codon, aa models
        if self.model_type == 'CODON':
            self.model_type = 'GY94'
        if self.model_type == 'AMINO_ACID':
            self.model_type = 'LG'
        self.name = None
          

    def construct_model(self):
        '''
            Construct EvoModel. Setup substitution matrix(ces) and rate heterogeneity probabilities.
            Calls _assign_matrix and _assign_rate_probs, as needed.
            
            Parent class method. Not executed.
        '''
        print "Parent class method. Not executed."

  
    def assign_name(self, name):
        '''
            Assign name to an EvoModel instance. 
            In cases of branch/temporal homogeneity, names are unneeded.
            However, in cases of **branch heterogeneity, each model must be named**. Names are used to map to model flags given in the phylogeny.

        '''
        self.name = name<commit_msg>ecm is an accepted mdoel<commit_after>#! /usr/bin/env python

##############################################################################
##  pyvolve: Python platform for simulating evolutionary sequences.
##
##  Written by <NAME> (<EMAIL>) 
##############################################################################


'''
    This module defines evolutionary model objects, EvoModel() and its child classes Model() and CodonModel().
    All evolutionary models contain information about the substitution process (rate matrix) and information about rate heterogeneity.
    The Model() class uses a single rate matrix, and heterogeneity is modeled using discrete scaling factors and associated probabilities.
    The CodonModel() class is used specifically in cases of codon model (dN/dS or omega) rate heterogeneity. Rate heterogeneity is implemented using a set of matrices with distinct dN/dS values, and each matrix has an associated probability. 
'''

import numpy as np
from copy import deepcopy
from matrix_builder import *


class EvoModels(object):
    ''' 
        Parent class for child classes Model() and CodonModel(). 
    '''
    
    def __init__(self, model_type, **kwargs):
        '''
            The EvoModel class will construct an evolutionary model object which will be used to evolve sequence data.            
            Instantiation requires a single positional argument:
                
                1. **model_type** is type of model (matrix) that is being used. These matrices are described explicitly in the matrix_builder module. Options include the following:
                                
                                    
                    +------------+-----------------------------------------------------------+
                    | model_type |                         Notes                             | 
                    +============+===========================================================+
                    | nucleotide | Arbitrary GTR                                             | 
                    +------------+-----------------------------------------------------------+
                    | JTT        | Jones, Taylor, and Thornton 1994 (amino acids)            |
                    +------------+-----------------------------------------------------------+
                    | WAG        | Whelan and Goldman 2002      (amino acids)                |
                    +------------+-----------------------------------------------------------+
                    | LG         | Le and Gascuel 2008        (amino acids)                  |
                    +------------+-----------------------------------------------------------+
                    | amino_acid | Defaults to LG                                            |
                    +------------+-----------------------------------------------------------+
                    | GY94       | Goldman and Yang 1994, Nielsen and Yang 1998              | 
                    +------------+-----------------------------------------------------------+
                    | MG94       | Muse and Gaut 1994                                        | 
                    +------------+-----------------------------------------------------------+
                    | codon      | Defaults to GY94                                          | 
                    +------------+-----------------------------------------------------------+
                    | ECM        | Kosiol et al. 2007                                        |   
                    +------------+-----------------------------------------------------------+
                    | mutsel     | Halpern and Bruno 2008 (may also be used for nucleotides) |  
                    +------------+-----------------------------------------------------------+
                    
            
            Optional keyword arguments include, 
                1. **params** is a dictionary of parameters pertaining to substitution process. For all models, this includes a vector of stationary frequencies. Each individual evolutionary model will have its own additional parameters. Note that if this argument is not provided, default parameters for your selected model will be assigned.
                
                2. **scale_matrix** = <'yang', 'neutral', 'False/None'>. This argument determines how rate matrices should be scaled. By default, all matrices are scaled according to Ziheng Yang's approach, in which the mean substitution rate is equal to 1. However, for codon models (GY94, MG94), this scaling approach effectively causes sites under purifying selection to evolve at the same rate as sites under positive selection, which may not be desired. Thus, the 'neutral' scaling option will allow for codon matrices to be scaled such that the mean rate of *neutral* subsitution is 1. You may also opt out of scaling by providing either False or None to this argument, although this is not recommended.
                
       '''
    
        
        self.model_type   = model_type.upper()
        self.params       = kwargs.get('params', {})
        self.scale_matrix = kwargs.get('scale_matrix', 'yang') # 'Yang', 'neutral', or False/None

        accepted_models = ['NUCLEOTIDE', 'AMINO_ACID', 'JTT', 'WAG', 'LG', 'CODON', 'GY94', 'MG94', 'MUTSEL', 'ECM']
        assert( self.model_type in accepted_models), "Inappropriate model type specified."
        assert( type(self.params) is dict ), "params argument must be a dictionary."
        
        # Default codon, aa models
        if self.model_type == 'CODON':
            self.model_type = 'GY94'
        if self.model_type == 'AMINO_ACID':
            self.model_type = 'LG'
        self.name = None
          

    def construct_model(self):
        '''
            Construct EvoModel. Setup substitution matrix(ces) and rate heterogeneity probabilities.
            Calls _assign_matrix and _assign_rate_probs, as needed.
            
            Parent class method. Not executed.
        '''
        print "Parent class method. Not executed."

  
    def assign_name(self, name):
        '''
            Assign name to an EvoModel instance. 
            In cases of branch/temporal homogeneity, names are unneeded.
            However, in cases of **branch heterogeneity, each model must be named**. Names are used to map to model flags given in the phylogeny.

        '''
        self.name = name
{'fraction_non_alphanumeric': 0.21311602039239919, 'fraction_numerical': 0.008187857253205623, 'mean_word_length': 1.2307029634734665, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2039641', 'n_tokens_mistral': 2780, 'n_tokens_neox': 2369, 'n_words': 1050}