Skip to content

Commit abb29e7

Browse files
bugfix: ligoPWM instantiate motif fix
1 parent 152b38e commit abb29e7

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

ligo/environment/Constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Constants:
22

3-
VERSION = "1.0.8"
3+
VERSION = "1.0.9"
44

55
# encoding constants
66
FEATURE_DELIMITER = "-"

ligo/simulation/implants/LigoPWM.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from ligo.environment.EnvironmentSettings import EnvironmentSettings
1111
from ligo.environment.SequenceType import SequenceType
1212
from ligo.simulation.implants.Motif import Motif
13+
from ligo.simulation.implants.MotifInstance import MotifInstance
1314

1415

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

5960
def instantiate_motif(self, sequence_type: SequenceType = SequenceType.AMINO_ACID):
60-
if len(EnvironmentSettings.get_sequence_alphabet(sequence_type)) != self.pwm_matrix.alphabet:
61-
raise RuntimeError(f"{LigoPWM.__name__}: could not instantiate motif for sequence type {sequence_type.name},"
62-
f" check if the motif sequence type is a match at {self.file_path}.")
61+
if EnvironmentSettings.get_sequence_alphabet(sequence_type) != sorted(list(self.pwm_matrix.alphabet)):
62+
raise RuntimeError(
63+
f"{LigoPWM.__name__}: could not instantiate motif for sequence type {sequence_type.name},"
64+
f" check if the motif sequence type is a match at {self.file_path}.")
6365

6466
counts_per_position = np.exp(self.pwm_matrix._matrix + np.log([0.25])[:, np.newaxis])
6567

66-
return "".join([random.choices(list(self.pwm_matrix.alphabet), weights=counts_per_position[:, position])[0]
67-
for position in range(self.pwm_matrix.window_size)])
68+
return MotifInstance(
69+
"".join([random.choices(list(self.pwm_matrix.alphabet), weights=counts_per_position[:, position])[0]
70+
for position in range(self.pwm_matrix.window_size)]), gap=0)

0 commit comments

Comments
 (0)