[docs]@dataclassclassLigoPWM(Motif):""" Motifs defined by a positional weight matrix and using bionumpy's PWM internally. For more details on bionumpy's implementation of PWM, as well as for supported formats, see the documentation at https://bionumpy.github.io/bionumpy/tutorials/position_weight_matrix.html. **Specification arguments:** - file_path: path to the file where the PWM is stored - threshold (float): when matching PWM to a sequence, this is the threshold to consider the sequence as containing the motif **YAML specification:** .. indent with spaces .. code-block:: yaml definitions: motifs: my_custom_pwm: # this will be the identifier of the motif file_path: my_pwm_1.csv threshold: 2 """file_path:Pathpwm_matrix:bnp_PWM# with log-likelihoodthreshold:float
[docs]definstantiate_motif(self,sequence_type:SequenceType=SequenceType.AMINO_ACID):ifEnvironmentSettings.get_sequence_alphabet(sequence_type)!=sorted(list(self.pwm_matrix.alphabet)):raiseRuntimeError(f"{LigoPWM.__name__}: could not instantiate motif for sequence type {sequence_type.name},"f" check if the motif sequence type is a match at {self.file_path}.")counts_per_position=np.exp(self.pwm_matrix._matrix+np.log([0.25])[:,np.newaxis])returnMotifInstance("".join([random.choices(list(self.pwm_matrix.alphabet),weights=counts_per_position[:,position])[0]forpositioninrange(self.pwm_matrix.window_size)]),gap=0)