aegis_sim.submodels.genetics.modifying.architecture
1import numpy as np 2 3from aegis_sim import constants 4from aegis_sim import variables 5from aegis_sim import parameterization 6 7from aegis_sim.submodels.genetics.modifying.gpm_decoder import GPM_decoder 8from aegis_sim.submodels.genetics.modifying.gpm import GPM 9from aegis_sim.submodels.genetics import ploider 10from aegis_sim.dataclasses.phenotypes import Phenotypes 11 12 13class ModifyingArchitecture: 14 """ 15 16 GUI 17 - when pleiotropy is needed 18 - when all bits are 0, the phenotypic values are the ones set from parameters (baseline set in parameters); 19 vs composite where it would be 0. 20 - ... dev still required 21 """ 22 23 def __init__(self, PHENOMAP, AGE_LIMIT, MODIF_GENOME_SIZE): 24 self.PHENOMAP = PHENOMAP 25 26 self.gpm_decoder = GPM_decoder(PHENOMAP) 27 28 self.length = MODIF_GENOME_SIZE 29 30 phenolist = self.gpm_decoder.get_total_phenolist() 31 self.phenomap = GPM( 32 phenomatrix=None, 33 phenolist=phenolist, 34 ) 35 36 # self.n_phenotypic_values = AGE_LIMIT * constants.TRAIT_N 37 38 self.AGE_LIMIT = AGE_LIMIT 39 40 def get_number_of_bits(self): 41 return self.length * ploider.ploider.y 42 43 def get_shape(self): 44 return (ploider.ploider.y, self.length, 1) 45 46 def init_genome_array(self, popsize): 47 array = variables.rng.random(size=(popsize, *self.get_shape())) 48 49 # Only neut (G_neut_initgeno) matters here 50 for trait in parameterization.traits.values(): 51 array[:, :, trait.slice] = array[:, :, trait.slice] < trait.initgeno 52 53 return array 54 55 # def init_phenotype_array(self, popsize): 56 # return np.zeros(shape=(popsize, self.n_phenotypic_values)) 57 58 def compute(self, genomes): 59 60 if genomes.shape[1] == 1: # Do not calculate mean if genomes are haploid 61 genomes = genomes[:, 0] 62 else: 63 genomes = ploider.ploider.diploid_to_haploid(genomes) 64 65 # TODO yuck! 66 67 # Apply phenomap 68 phenomapped = self.phenomap( 69 interpretome=genomes.reshape(len(genomes), -1), 70 zeropheno=Phenotypes.init_phenotype_array(popsize=len(genomes)).array, 71 ) 72 73 # TODO damn ugly! 74 75 # Add background values 76 for traitname, trait in parameterization.traits.items(): 77 start = constants.starting_site(trait.name) * self.AGE_LIMIT 78 end = start + self.AGE_LIMIT 79 phenomapped[:, slice(start, end)] += trait.initpheno 80 81 # Check that phenotype values are within [0,1]: 82 p = phenomapped[:, slice(start, end)] 83 p[p > 1] = 1 84 p[p < 0] = 0 85 phenomapped[:, slice(start, end)] = p 86 87 return phenomapped
class
ModifyingArchitecture:
14class ModifyingArchitecture: 15 """ 16 17 GUI 18 - when pleiotropy is needed 19 - when all bits are 0, the phenotypic values are the ones set from parameters (baseline set in parameters); 20 vs composite where it would be 0. 21 - ... dev still required 22 """ 23 24 def __init__(self, PHENOMAP, AGE_LIMIT, MODIF_GENOME_SIZE): 25 self.PHENOMAP = PHENOMAP 26 27 self.gpm_decoder = GPM_decoder(PHENOMAP) 28 29 self.length = MODIF_GENOME_SIZE 30 31 phenolist = self.gpm_decoder.get_total_phenolist() 32 self.phenomap = GPM( 33 phenomatrix=None, 34 phenolist=phenolist, 35 ) 36 37 # self.n_phenotypic_values = AGE_LIMIT * constants.TRAIT_N 38 39 self.AGE_LIMIT = AGE_LIMIT 40 41 def get_number_of_bits(self): 42 return self.length * ploider.ploider.y 43 44 def get_shape(self): 45 return (ploider.ploider.y, self.length, 1) 46 47 def init_genome_array(self, popsize): 48 array = variables.rng.random(size=(popsize, *self.get_shape())) 49 50 # Only neut (G_neut_initgeno) matters here 51 for trait in parameterization.traits.values(): 52 array[:, :, trait.slice] = array[:, :, trait.slice] < trait.initgeno 53 54 return array 55 56 # def init_phenotype_array(self, popsize): 57 # return np.zeros(shape=(popsize, self.n_phenotypic_values)) 58 59 def compute(self, genomes): 60 61 if genomes.shape[1] == 1: # Do not calculate mean if genomes are haploid 62 genomes = genomes[:, 0] 63 else: 64 genomes = ploider.ploider.diploid_to_haploid(genomes) 65 66 # TODO yuck! 67 68 # Apply phenomap 69 phenomapped = self.phenomap( 70 interpretome=genomes.reshape(len(genomes), -1), 71 zeropheno=Phenotypes.init_phenotype_array(popsize=len(genomes)).array, 72 ) 73 74 # TODO damn ugly! 75 76 # Add background values 77 for traitname, trait in parameterization.traits.items(): 78 start = constants.starting_site(trait.name) * self.AGE_LIMIT 79 end = start + self.AGE_LIMIT 80 phenomapped[:, slice(start, end)] += trait.initpheno 81 82 # Check that phenotype values are within [0,1]: 83 p = phenomapped[:, slice(start, end)] 84 p[p > 1] = 1 85 p[p < 0] = 0 86 phenomapped[:, slice(start, end)] = p 87 88 return phenomapped
GUI
- when pleiotropy is needed
- when all bits are 0, the phenotypic values are the ones set from parameters (baseline set in parameters); vs composite where it would be 0.
- ... dev still required
ModifyingArchitecture(PHENOMAP, AGE_LIMIT, MODIF_GENOME_SIZE)
24 def __init__(self, PHENOMAP, AGE_LIMIT, MODIF_GENOME_SIZE): 25 self.PHENOMAP = PHENOMAP 26 27 self.gpm_decoder = GPM_decoder(PHENOMAP) 28 29 self.length = MODIF_GENOME_SIZE 30 31 phenolist = self.gpm_decoder.get_total_phenolist() 32 self.phenomap = GPM( 33 phenomatrix=None, 34 phenolist=phenolist, 35 ) 36 37 # self.n_phenotypic_values = AGE_LIMIT * constants.TRAIT_N 38 39 self.AGE_LIMIT = AGE_LIMIT
def
compute(self, genomes):
59 def compute(self, genomes): 60 61 if genomes.shape[1] == 1: # Do not calculate mean if genomes are haploid 62 genomes = genomes[:, 0] 63 else: 64 genomes = ploider.ploider.diploid_to_haploid(genomes) 65 66 # TODO yuck! 67 68 # Apply phenomap 69 phenomapped = self.phenomap( 70 interpretome=genomes.reshape(len(genomes), -1), 71 zeropheno=Phenotypes.init_phenotype_array(popsize=len(genomes)).array, 72 ) 73 74 # TODO damn ugly! 75 76 # Add background values 77 for traitname, trait in parameterization.traits.items(): 78 start = constants.starting_site(trait.name) * self.AGE_LIMIT 79 end = start + self.AGE_LIMIT 80 phenomapped[:, slice(start, end)] += trait.initpheno 81 82 # Check that phenotype values are within [0,1]: 83 p = phenomapped[:, slice(start, end)] 84 p[p > 1] = 1 85 p[p < 0] = 0 86 phenomapped[:, slice(start, end)] = p 87 88 return phenomapped