From a5c2a361a7574651f56f58be036b3a70b5ce5038 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bertrand=20N=C3=A9ron?= <bneron@pasteur.fr>
Date: Mon, 18 Mar 2019 08:16:31 +0100
Subject: [PATCH] add2nd implementation for one_enz_all_binding_sites

---
 source/_static/code/restriction.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/source/_static/code/restriction.py b/source/_static/code/restriction.py
index f160bfa..4966eaf 100644
--- a/source/_static/code/restriction.py
+++ b/source/_static/code/restriction.py
@@ -30,6 +30,28 @@ def one_enz_all_binding_sites(dna, enzyme):
     return positions
 
 
+def one_enz_all_binding_sites2(dna, enzyme):
+    """
+    :param dna: the dna sequence to search enzyme binding sites
+    :type dna: str
+    :param enzyme: the enzyme to looking for
+    :type enzyme:  a namedtuple RestrictEnzyme
+    :return: all positions of enzyme binding sites in dna
+    :rtype: list of int
+    """
+    positions = []
+    pos = dna.find(enzyme.sequence)
+    while pos != -1:
+        if positions:
+            positions.append(pos)
+        else:
+            positions = pos + positions[-1]
+        new_seq = dna[pos + 1:]
+        pos = new_seq.find(enzyme.sequence)
+        pos = pos
+    return positions
+
+
 def binding_sites(dna, enzymes):
     """
     return all positions of all enzymes binding sites present in dna
-- 
GitLab