Skip to content

Commit

Permalink
pairwise for old python
Browse files Browse the repository at this point in the history
  • Loading branch information
BjornFJohansson committed Jan 24, 2025
1 parent 69d8af2 commit bde52b2
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/pydna/dseq.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"""
import math as _math
import copy as _copy
import itertools as _itertools
import re as _re
import inspect as _inspect

Expand Down Expand Up @@ -48,6 +47,18 @@
from Bio.Restriction import RestrictionBatch as _RestrictionBatch
from Bio.Restriction import CommOnly

try:
from itertools import pairwise as _pairwise
except ImportError:

def _pairwise(iterable):
# pairwise('ABCDEFG') → AB BC CD DE EF FG
iterator = iter(iterable)
a = next(iterator, None)
for b in iterator:
yield a, b
a = b

pos_w_enz = _namedtuple("enzpos", "position enzyme recsite")

from typing import (
Expand Down Expand Up @@ -1421,7 +1432,7 @@ def __repr__(self):

cutpairs = []

for (w1, e1, s1), (w2, e2, s2) in _itertools.pairwise(cutsites):
for (w1, e1, s1), (w2, e2, s2) in _pairwise(cutsites):

table1 = {True: to_5tail_table, False: to_3tail_table}[e1.is_3overhang()]
table2 = {True: to_5tail_table, False: to_3tail_table}[e2.is_5overhang()]
Expand Down

0 comments on commit bde52b2

Please sign in to comment.