aegis_sim.parameterization.trait
1class Trait: 2 """Genetic trait 3 4 Contains data on traits encoded in the genome. 5 """ 6 7 def __init__(self, name, cnf, genarch_type, MODIF_GENOME_SIZE, start_position): 8 def get(key): 9 return getattr(cnf, f"G_{name}_{key}") 10 11 self.name = name 12 self.start = start_position 13 14 # Relevant if genetic architecture is composite 15 self.evolvable = get("evolvable") 16 self.agespecific = get("agespecific") 17 self.interpreter = get("interpreter") 18 self.initgeno = get("initgeno") 19 # Per-trait dominance coefficient h for diploid-to-haploid collapse. 20 # None means "inherit global DOMINANCE_FACTOR". The architecture builds 21 # a per-locus array from these values at init time. 22 self.dominance = get("dominance") 23 24 # Relevant if genetic architecture is modifying 25 self.initpheno = get("initpheno") 26 27 # Relevant under any genetic architecture 28 self.lo = get("lo") 29 self.hi = get("hi") 30 31 assert genarch_type in ("modifying", "composite") 32 33 if genarch_type == "composite": 34 35 # Determine the number of loci encoding the trait 36 if self.evolvable: 37 if self.agespecific is True: # one locus per age 38 self.length = cnf.AGE_LIMIT 39 elif self.agespecific is False: # one locus for all ages 40 self.length = 1 41 else: # custom number of loci 42 self.length = self.agespecific 43 else: # no loci for a constant trait 44 self.length = 0 45 46 self._validate() 47 48 # Infer positions in the genome 49 # self.start = start 50 # self.end = self.start + self.length 51 # self.slice = slice(self.start, self.end) 52 53 # self.start = cnf.AGE_LIMIT * constants.starting_site(self.name) 54 # self.end = self.start_position + cnf.AGE_LIMIT 55 56 elif genarch_type == "modifying": 57 if name == "neut": 58 self.length = MODIF_GENOME_SIZE 59 else: 60 self.length = 0 61 62 self.end = self.start + self.length 63 64 self.slice = slice(self.start, self.end) 65 66 def _validate(self): 67 """Check whether input parameters are legal.""" 68 if not isinstance(self.evolvable, bool): 69 raise TypeError 70 71 if not 0 <= self.initgeno <= 1: 72 raise ValueError 73 74 if self.evolvable: 75 # if not isinstance(self.agespecific, bool): 76 # raise TypeError 77 78 if self.interpreter not in ( 79 "uniform", 80 "exp", 81 "binary", 82 "binary_exp", 83 "binary_switch", 84 "switch", 85 "linear", 86 "single_bit", 87 "const1", 88 "threshold", 89 ): 90 raise ValueError(f"{self.interpreter} is not a valid interpreter type") 91 92 if not 0 <= self.lo <= 1: 93 raise ValueError 94 95 if not 0 <= self.hi <= 1: 96 raise ValueError 97 98 def __len__(self): 99 """Return number of loci used to encode the trait.""" 100 return self.length 101 102 def __str__(self): 103 return self.name
class
Trait:
2class Trait: 3 """Genetic trait 4 5 Contains data on traits encoded in the genome. 6 """ 7 8 def __init__(self, name, cnf, genarch_type, MODIF_GENOME_SIZE, start_position): 9 def get(key): 10 return getattr(cnf, f"G_{name}_{key}") 11 12 self.name = name 13 self.start = start_position 14 15 # Relevant if genetic architecture is composite 16 self.evolvable = get("evolvable") 17 self.agespecific = get("agespecific") 18 self.interpreter = get("interpreter") 19 self.initgeno = get("initgeno") 20 # Per-trait dominance coefficient h for diploid-to-haploid collapse. 21 # None means "inherit global DOMINANCE_FACTOR". The architecture builds 22 # a per-locus array from these values at init time. 23 self.dominance = get("dominance") 24 25 # Relevant if genetic architecture is modifying 26 self.initpheno = get("initpheno") 27 28 # Relevant under any genetic architecture 29 self.lo = get("lo") 30 self.hi = get("hi") 31 32 assert genarch_type in ("modifying", "composite") 33 34 if genarch_type == "composite": 35 36 # Determine the number of loci encoding the trait 37 if self.evolvable: 38 if self.agespecific is True: # one locus per age 39 self.length = cnf.AGE_LIMIT 40 elif self.agespecific is False: # one locus for all ages 41 self.length = 1 42 else: # custom number of loci 43 self.length = self.agespecific 44 else: # no loci for a constant trait 45 self.length = 0 46 47 self._validate() 48 49 # Infer positions in the genome 50 # self.start = start 51 # self.end = self.start + self.length 52 # self.slice = slice(self.start, self.end) 53 54 # self.start = cnf.AGE_LIMIT * constants.starting_site(self.name) 55 # self.end = self.start_position + cnf.AGE_LIMIT 56 57 elif genarch_type == "modifying": 58 if name == "neut": 59 self.length = MODIF_GENOME_SIZE 60 else: 61 self.length = 0 62 63 self.end = self.start + self.length 64 65 self.slice = slice(self.start, self.end) 66 67 def _validate(self): 68 """Check whether input parameters are legal.""" 69 if not isinstance(self.evolvable, bool): 70 raise TypeError 71 72 if not 0 <= self.initgeno <= 1: 73 raise ValueError 74 75 if self.evolvable: 76 # if not isinstance(self.agespecific, bool): 77 # raise TypeError 78 79 if self.interpreter not in ( 80 "uniform", 81 "exp", 82 "binary", 83 "binary_exp", 84 "binary_switch", 85 "switch", 86 "linear", 87 "single_bit", 88 "const1", 89 "threshold", 90 ): 91 raise ValueError(f"{self.interpreter} is not a valid interpreter type") 92 93 if not 0 <= self.lo <= 1: 94 raise ValueError 95 96 if not 0 <= self.hi <= 1: 97 raise ValueError 98 99 def __len__(self): 100 """Return number of loci used to encode the trait.""" 101 return self.length 102 103 def __str__(self): 104 return self.name
Genetic trait
Contains data on traits encoded in the genome.
Trait(name, cnf, genarch_type, MODIF_GENOME_SIZE, start_position)
8 def __init__(self, name, cnf, genarch_type, MODIF_GENOME_SIZE, start_position): 9 def get(key): 10 return getattr(cnf, f"G_{name}_{key}") 11 12 self.name = name 13 self.start = start_position 14 15 # Relevant if genetic architecture is composite 16 self.evolvable = get("evolvable") 17 self.agespecific = get("agespecific") 18 self.interpreter = get("interpreter") 19 self.initgeno = get("initgeno") 20 # Per-trait dominance coefficient h for diploid-to-haploid collapse. 21 # None means "inherit global DOMINANCE_FACTOR". The architecture builds 22 # a per-locus array from these values at init time. 23 self.dominance = get("dominance") 24 25 # Relevant if genetic architecture is modifying 26 self.initpheno = get("initpheno") 27 28 # Relevant under any genetic architecture 29 self.lo = get("lo") 30 self.hi = get("hi") 31 32 assert genarch_type in ("modifying", "composite") 33 34 if genarch_type == "composite": 35 36 # Determine the number of loci encoding the trait 37 if self.evolvable: 38 if self.agespecific is True: # one locus per age 39 self.length = cnf.AGE_LIMIT 40 elif self.agespecific is False: # one locus for all ages 41 self.length = 1 42 else: # custom number of loci 43 self.length = self.agespecific 44 else: # no loci for a constant trait 45 self.length = 0 46 47 self._validate() 48 49 # Infer positions in the genome 50 # self.start = start 51 # self.end = self.start + self.length 52 # self.slice = slice(self.start, self.end) 53 54 # self.start = cnf.AGE_LIMIT * constants.starting_site(self.name) 55 # self.end = self.start_position + cnf.AGE_LIMIT 56 57 elif genarch_type == "modifying": 58 if name == "neut": 59 self.length = MODIF_GENOME_SIZE 60 else: 61 self.length = 0 62 63 self.end = self.start + self.length 64 65 self.slice = slice(self.start, self.end)