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 20 # Relevant if genetic architecture is modifying 21 self.initpheno = get("initpheno") 22 23 # Relevant under any genetic architecture 24 self.lo = get("lo") 25 self.hi = get("hi") 26 27 assert genarch_type in ("modifying", "composite") 28 29 if genarch_type == "composite": 30 31 # Determine the number of loci encoding the trait 32 if self.evolvable: 33 if self.agespecific is True: # one locus per age 34 self.length = cnf.AGE_LIMIT 35 elif self.agespecific is False: # one locus for all ages 36 self.length = 1 37 else: # custom number of loci 38 self.length = self.agespecific 39 else: # no loci for a constant trait 40 self.length = 0 41 42 self._validate() 43 44 # Infer positions in the genome 45 # self.start = start 46 # self.end = self.start + self.length 47 # self.slice = slice(self.start, self.end) 48 49 # self.start = cnf.AGE_LIMIT * constants.starting_site(self.name) 50 # self.end = self.start_position + cnf.AGE_LIMIT 51 52 elif genarch_type == "modifying": 53 if name == "neut": 54 self.length = MODIF_GENOME_SIZE 55 else: 56 self.length = 0 57 58 self.end = self.start + self.length 59 60 self.slice = slice(self.start, self.end) 61 62 def _validate(self): 63 """Check whether input parameters are legal.""" 64 if not isinstance(self.evolvable, bool): 65 raise TypeError 66 67 if not 0 <= self.initgeno <= 1: 68 raise ValueError 69 70 if self.evolvable: 71 # if not isinstance(self.agespecific, bool): 72 # raise TypeError 73 74 if self.interpreter not in ( 75 "uniform", 76 "exp", 77 "binary", 78 "binary_exp", 79 "binary_switch", 80 "switch", 81 "linear", 82 "single_bit", 83 "const1", 84 "threshold", 85 ): 86 raise ValueError(f"{self.interpreter} is not a valid interpreter type") 87 88 if not 0 <= self.lo <= 1: 89 raise ValueError 90 91 if not 0 <= self.hi <= 1: 92 raise ValueError 93 94 def __len__(self): 95 """Return number of loci used to encode the trait.""" 96 return self.length 97 98 def __str__(self): 99 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 21 # Relevant if genetic architecture is modifying 22 self.initpheno = get("initpheno") 23 24 # Relevant under any genetic architecture 25 self.lo = get("lo") 26 self.hi = get("hi") 27 28 assert genarch_type in ("modifying", "composite") 29 30 if genarch_type == "composite": 31 32 # Determine the number of loci encoding the trait 33 if self.evolvable: 34 if self.agespecific is True: # one locus per age 35 self.length = cnf.AGE_LIMIT 36 elif self.agespecific is False: # one locus for all ages 37 self.length = 1 38 else: # custom number of loci 39 self.length = self.agespecific 40 else: # no loci for a constant trait 41 self.length = 0 42 43 self._validate() 44 45 # Infer positions in the genome 46 # self.start = start 47 # self.end = self.start + self.length 48 # self.slice = slice(self.start, self.end) 49 50 # self.start = cnf.AGE_LIMIT * constants.starting_site(self.name) 51 # self.end = self.start_position + cnf.AGE_LIMIT 52 53 elif genarch_type == "modifying": 54 if name == "neut": 55 self.length = MODIF_GENOME_SIZE 56 else: 57 self.length = 0 58 59 self.end = self.start + self.length 60 61 self.slice = slice(self.start, self.end) 62 63 def _validate(self): 64 """Check whether input parameters are legal.""" 65 if not isinstance(self.evolvable, bool): 66 raise TypeError 67 68 if not 0 <= self.initgeno <= 1: 69 raise ValueError 70 71 if self.evolvable: 72 # if not isinstance(self.agespecific, bool): 73 # raise TypeError 74 75 if self.interpreter not in ( 76 "uniform", 77 "exp", 78 "binary", 79 "binary_exp", 80 "binary_switch", 81 "switch", 82 "linear", 83 "single_bit", 84 "const1", 85 "threshold", 86 ): 87 raise ValueError(f"{self.interpreter} is not a valid interpreter type") 88 89 if not 0 <= self.lo <= 1: 90 raise ValueError 91 92 if not 0 <= self.hi <= 1: 93 raise ValueError 94 95 def __len__(self): 96 """Return number of loci used to encode the trait.""" 97 return self.length 98 99 def __str__(self): 100 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 21 # Relevant if genetic architecture is modifying 22 self.initpheno = get("initpheno") 23 24 # Relevant under any genetic architecture 25 self.lo = get("lo") 26 self.hi = get("hi") 27 28 assert genarch_type in ("modifying", "composite") 29 30 if genarch_type == "composite": 31 32 # Determine the number of loci encoding the trait 33 if self.evolvable: 34 if self.agespecific is True: # one locus per age 35 self.length = cnf.AGE_LIMIT 36 elif self.agespecific is False: # one locus for all ages 37 self.length = 1 38 else: # custom number of loci 39 self.length = self.agespecific 40 else: # no loci for a constant trait 41 self.length = 0 42 43 self._validate() 44 45 # Infer positions in the genome 46 # self.start = start 47 # self.end = self.start + self.length 48 # self.slice = slice(self.start, self.end) 49 50 # self.start = cnf.AGE_LIMIT * constants.starting_site(self.name) 51 # self.end = self.start_position + cnf.AGE_LIMIT 52 53 elif genarch_type == "modifying": 54 if name == "neut": 55 self.length = MODIF_GENOME_SIZE 56 else: 57 self.length = 0 58 59 self.end = self.start + self.length 60 61 self.slice = slice(self.start, self.end)