Skip to content

Commit

Permalink
Fix #68
Browse files Browse the repository at this point in the history
  • Loading branch information
veghp committed Jun 3, 2023
1 parent e551fce commit a060a9e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ DNA Chisel requires Python 3, and can be installed via a pip command:
The full installation using ``dnachisel[reports]`` downloads heavier libraries
(Matplotlib, PDF reports, sequenticon) for report generation, but is highly
recommended to use DNA Chisel interactively via Python scripts. Also install
`Geneblocks<https://edinburgh-genome-foundry.github.io/Geneblocks>`_ and its
`GeneBlocks <https://edinburgh-genome-foundry.github.io/Geneblocks>`_ and its
dependencies if you wish to include a plot of sequence edits in the report.

Alternatively, you can unzip the sources in a folder and type
Expand Down
30 changes: 13 additions & 17 deletions dnachisel/SequencePattern/SequencePattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


class SequencePattern:
"""Pattern/ that will be looked for in a DNA sequence.
"""Pattern that will be looked for in a DNA sequence.
Use this class for matching regular expression patterns, and
DnaNotationPattern for matching explicit sequences or sequences using Ns
Expand All @@ -32,22 +32,21 @@ class SequencePattern:
----------
expression
Any string or regular expression for matching ATGC nucleotides.
Note that multi-nucleotides symbols such as "N" (for A-T-G-C), or "K"
Any string or regular expression (regex) for matching ATGC nucleotides.
Note that multi-nucleotide symbols such as "N" (for A-T-G-C), or "K"
are not supported by this class, see DnaNotationPattern instead.
size
Size of the pattern, in number of characters (if none provided, the size
of the ``pattern`` string is used).
The ``size`` is used to determine the size of windows when performing
local optimization and constraint solving.
It can be important to provide the size when the
Size of the pattern, in number of characters. The ``size`` is used to
determine the size of windows when performing local optimization and
constraint solving. It can be important to provide the size when the
``pattern`` string provided represents a complex regular expression whose
maximal matching size cannot be easily evaluated.
For example, if a regex is used to actively remove sites, then a size
should be provided to inform DNA Chisel during optimization.
name
Name of the pattern (will be displayed e.g. when the pattern is printed)
Name of the pattern (will be displayed e.g. when the pattern is printed).
"""

registered_string_pattern_classes = []
Expand Down Expand Up @@ -100,11 +99,10 @@ def find_matches(self, sequence, location=None, forced_strand=None):

# THE FUNCTION HAS BEEN CALLED WITH A LOCATION AND A FORCED STRAND
if forced_strand is not None:
subsequence = sequence[location.start: location.end]
subsequence = sequence[location.start : location.end]
if forced_strand == 1:
return [
(loc + location.start)
for loc in self.find_matches(subsequence)
(loc + location.start) for loc in self.find_matches(subsequence)
]
if forced_strand == -1:
subsequence = reverse_complement(subsequence)
Expand All @@ -129,7 +127,7 @@ def find_matches(self, sequence, location=None, forced_strand=None):
else:
return self.find_matches(sequence, location, -1)
if strand == 0:
matches = self.find_matches(sequence, location, 1)
matches = self.find_matches(sequence, location, 1)
if not self.is_palyndromic:
matches += self.find_matches(sequence, location, -1)
return matches
Expand Down Expand Up @@ -158,9 +156,7 @@ def find_matches_in_string(self, sequence):
]

def __str__(self):
return self.expression + (
"" if self.name is None else " (%s)" % self.name
)
return self.expression + ("" if self.name is None else " (%s)" % self.name)

@classmethod
def from_string(cls, string):
Expand Down
4 changes: 2 additions & 2 deletions dnachisel/biotools/genbank_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def annotate_differences(record, reference, feature_type="misc_feature", prefix=
else:
locations.append([ind, ind])
new_record = deepcopy(record)
for (start, end) in locations:
for start, end in locations:
annotate_record(
new_record,
location=(start, end + 1),
Expand All @@ -144,7 +144,7 @@ def annotate_pattern_occurrences(
A Biopython record.
pattern
A DnaChisel SequencePattern object (such as DnaPAttern).
A DNA Chisel SequencePattern object. See SequencePattern documentation.
feature_type
Type of the annotations in the returned record.
Expand Down
4 changes: 3 additions & 1 deletion dnachisel/builtin_specifications/AvoidPattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class AvoidPattern(Specification):
----------
pattern
A SequencePattern or DnaNotationPattern
A SequencePattern or DnaNotationPattern. If a ``str`` is given, it will
be converted. Note that providing ``size`` may be necessary for certain
patterns. See SequencePattern documentation for more details.
location
Location of the DNA segment on which to enforce the pattern e.g.
Expand Down
7 changes: 5 additions & 2 deletions dnachisel/builtin_specifications/EnforcePatternOccurence.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class EnforcePatternOccurence(Specification):
----------
pattern
A SequencePattern or DnaNotationPattern or a string such as "AATTG",
"BsmBI_site", etc.
"BsmBI_site", etc. See SequencePattern documentation for more details.
occurences
Desired number of occurrences of the pattern.
Expand Down Expand Up @@ -87,7 +87,10 @@ def initialized_on_problem(self, problem, role=None):

def evaluate(self, problem):
"""Score the difference between expected and observed n_occurences."""
matches = self.pattern.find_matches(problem.sequence, self.location,)
matches = self.pattern.find_matches(
problem.sequence,
self.location,
)
score = -abs(len(matches) - self.occurences)

if score == 0:
Expand Down

0 comments on commit a060a9e

Please sign in to comment.