EnforcePatternOccurence raises IndexError (in some specific parameters)
See original GitHub issuerelated to #51
from dnachisel import *
from Bio.SeqFeature import FeatureLocation
seq="ATGCAGAGCAAGGTGCTGCTGGCCGTCGCCCTGTGGCTCTGCGTGGAGACCCGGGCCGCC"
problem = DnaOptimizationProblem(
sequence=seq,
constraints=[
EnforcePatternOccurence( pattern='CTG',occurences=2,strand=-1,location=FeatureLocation(start=0,end=50))
],
)
print(problem.constraints_text_summary())
===> FAILURE: 1 constraints evaluations failed
FAIL ┍ EnforcePatternOccurence[0-50(-)](CTG, occurence, 2)
│ Failed. Pattern found 1 times instead of 2 wanted, at locations [3-6(-)]
problem.resolve_constraints()
/usr/local/lib/python3.8/site-packages/dnachisel/DnaOptimizationProblem/mixins/ConstraintsSolverMixin.py in resolve_constraints(self, final_check, cst_filter)
355 ):
356 try:
--> 357 self.resolve_constraint(constraint=constraint)
358 except NoSolutionError as error:
359 self.logger(constraint__index=len(constraints))
/usr/local/lib/python3.8/site-packages/dnachisel/DnaOptimizationProblem/mixins/ConstraintsSolverMixin.py in resolve_constraint(self, constraint)
301 try:
302 if hasattr(constraint, "resolution_heuristic"):
--> 303 constraint.resolution_heuristic(local_problem)
304 else:
305 local_problem.resolve_constraints_locally()
/usr/local/lib/python3.8/site-packages/dnachisel/builtin_specifications/EnforcePatternOccurence.py in resolution_heuristic(self, problem)
183 mutation_space=problem.mutation_space,
184 )
--> 185 new_occurence_cst.insert_pattern_in_problem(new_problem)
186 problem.sequence = new_problem.sequence
187 return
constraint: 0%| | 0/1 [00:00<?, ?it/s, now=EnforcePatternOccurence[0...]
/usr/local/lib/python3.8/site-packages/dnachisel/builtin_specifications/EnforcePatternOccurence.py in insert_pattern_in_problem(self, problem, reverse)
132 sequence=sequence_to_insert, location=new_location
133 )
--> 134 new_space = MutationSpace.from_optimization_problem(
135 problem, new_constraints=[new_constraint]
136 )
/usr/local/lib/python3.8/site-packages/dnachisel/MutationSpace/MutationSpace.py in from_optimization_problem(problem, new_constraints)
184 constraints = new_constraints
185 mutation_choices = sorted(
--> 186 [
187 MutationChoice(segment=choice[0], variants=set(choice[1]))
188 for cst in constraints
/usr/local/lib/python3.8/site-packages/dnachisel/MutationSpace/MutationSpace.py in <listcomp>(.0)
187 MutationChoice(segment=choice[0], variants=set(choice[1]))
188 for cst in constraints
--> 189 for choice in cst.restrict_nucleotides(sequence)
190 ],
191 key=lambda choice: (choice.end - choice.start, choice.start),
/usr/local/lib/python3.8/site-packages/dnachisel/builtin_specifications/EnforceSequence.py in restrict_nucleotides(self, sequence, location)
107 if self.location.strand == -1:
108 lend = self.location.end
--> 109 return [(i, set(reverse_complement(n) for n in
110 IUPAC_NOTATION[self.sequence[lend - i]]))
111 for i in range(start, end)]
/usr/local/lib/python3.8/site-packages/dnachisel/builtin_specifications/EnforceSequence.py in <listcomp>(.0)
108 lend = self.location.end
109 return [(i, set(reverse_complement(n) for n in
--> 110 IUPAC_NOTATION[self.sequence[lend - i]]))
111 for i in range(start, end)]
112 else:
IndexError: string index out of range
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
How to raise an IndexError when slice indices are out of range?
So when should an exception be raised? When both indices are out of bounds? For any indices that result in an empty slice?...
Read more >How to Fix IndexError in Python - Rollbar
The IndexError in Python occurs when an item from a list is attempted to be accessed that is outside the index range of...
Read more >List Index Out of Range – Python Error Message Solved
You'll get the Indexerror: list index out of range error when you try and access an item using a value that is out...
Read more >Python IndexError: List Index Out of Range Error Explained
How to raise an IndexError with a For Loop a_list = ['welcome', 'to', 'datagy'] for i in range(len(a_list) + 1): print(a_list[i]) # Returns: ......
Read more >RuntimeError: Cannot run the event loop while ... - IssueHint
Issue Title Created Date Comment Count Updated Date
Missing Authorization Header 7 2021‑12‑27 2022‑07‑18
library messes with millis() function 1 2021‑05‑11 2022‑04‑24
Error if location not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Solution now committed to the
dev
branch and will be in the next release. If urgent, install withpip install --upgrade git+https://github.com/Edinburgh-Genome-Foundry/DnaChisel.git@dev
.Thanks! That solves the problem apparently, but I will have to review the logic flow to make sure everything is okay. This is a separate issue but for example if I specify no location, then there is error because in https://github.com/Edinburgh-Genome-Foundry/DnaChisel/blob/9c72428ae822c1e5afba480232158e604c355699/dnachisel/builtin_specifications/EnforcePatternOccurence.py#L67 from_data() returns a
None
as location, and a value is assigned to its attribute in: https://github.com/Edinburgh-Genome-Foundry/DnaChisel/blob/9c72428ae822c1e5afba480232158e604c355699/dnachisel/builtin_specifications/EnforcePatternOccurence.py#L73