Skip to content

Commit

Permalink
Handle EnforcePatternOccurence parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
veghp committed Sep 6, 2021
1 parent 8a2b0d2 commit 776d8cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
22 changes: 14 additions & 8 deletions dnachisel/builtin_specifications/EnforcePatternOccurence.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,25 @@ def __init__(
pattern = SequencePattern.from_string(pattern)
self.pattern = pattern
self.location = Location.from_data(location)
if strand != "from_location":
if strand == "both":
strand = 0
if strand not in [-1, 0, 1]:
raise ValueError("unknown strand: %s" % strand)
self.location.strand = strand
self.strand = strand
if strand == "from_location":
if self.location is None:
self.strand = 0
else:
self.strand = self.location.strand
elif strand == "both":
self.strand = 0
elif strand in [-1, 0, 1]:
self.strand = strand
else:
raise ValueError("unknown strand: %s" % strand)
self.occurences = occurences
self.center = center
self.boost = boost

def initialized_on_problem(self, problem, role=None):
return self._copy_with_full_span_if_no_location(problem)
copy_of_constraint = self._copy_with_full_span_if_no_location(problem)
copy_of_constraint.location.strand = self.strand
return copy_of_constraint

def evaluate(self, problem):
"""Score the difference between expected and observed n_occurences."""
Expand Down
4 changes: 1 addition & 3 deletions tests/builtin_specifications/test_EnforcePatternOccurence.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def test_enforce_pattern_basics():
constraints = [
EnforceTranslation(location=Location(1000, 2500)),
EnforceTranslation(location=Location(3000, 4500)),
EnforcePatternOccurence(
"ANANANANTT", location=Location(1100, 2150)
),
EnforcePatternOccurence("ANANANANTT", location=Location(1100, 2150)),
]

problem = DnaOptimizationProblem(
Expand Down

0 comments on commit 776d8cd

Please sign in to comment.