Skip to content

Commit

Permalink
bugfix: ligoPWM instantiate motif fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlovicmilena committed Jul 23, 2024
1 parent 152b38e commit abb29e7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ligo/environment/Constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Constants:

VERSION = "1.0.8"
VERSION = "1.0.9"

# encoding constants
FEATURE_DELIMITER = "-"
Expand Down
13 changes: 8 additions & 5 deletions ligo/simulation/implants/LigoPWM.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from ligo.environment.EnvironmentSettings import EnvironmentSettings
from ligo.environment.SequenceType import SequenceType
from ligo.simulation.implants.Motif import Motif
from ligo.simulation.implants.MotifInstance import MotifInstance


@dataclass
Expand Down Expand Up @@ -57,11 +58,13 @@ def get_alphabet(self) -> List[str]:
return list(self.pwm_matrix.alphabet)

def instantiate_motif(self, sequence_type: SequenceType = SequenceType.AMINO_ACID):
if len(EnvironmentSettings.get_sequence_alphabet(sequence_type)) != self.pwm_matrix.alphabet:
raise RuntimeError(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}.")
if EnvironmentSettings.get_sequence_alphabet(sequence_type) != sorted(list(self.pwm_matrix.alphabet)):
raise RuntimeError(
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])

return "".join([random.choices(list(self.pwm_matrix.alphabet), weights=counts_per_position[:, position])[0]
for position in range(self.pwm_matrix.window_size)])
return MotifInstance(
"".join([random.choices(list(self.pwm_matrix.alphabet), weights=counts_per_position[:, position])[0]
for position in range(self.pwm_matrix.window_size)]), gap=0)

0 comments on commit abb29e7

Please sign in to comment.