Skip to content

Commit

Permalink
flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
BjornFJohansson committed Jan 25, 2025
1 parent c42932a commit 21f831f
Show file tree
Hide file tree
Showing 10 changed files with 1,081 additions and 915 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ select = B,C,E,F,W,T4,B9
exclude =
tests,
scripts,
docs*
docs
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ repos:
- id: mixed-line-ending
# Code formatting
- repo: https://github.com/ambv/black
rev: 24.2.0
rev: 24.10.0
hooks:
- id: black
exclude: tests
# Further linting (e.g. module imported but not used)
- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
hooks:
- id: flake8
args:
- --exclude=tests,scripts,docs
exclude: ^(tests/|scripts/|docs/)
# Verify that requirements.txt is up to date with poetry dependencies every commit
- repo: https://github.com/python-poetry/poetry
rev: 1.8.3
Expand Down
1,934 changes: 1,044 additions & 890 deletions requirements.txt

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion scripts/guess_alphabet.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def guess_alphabet(sequence):
else:
if not isinstance(sequence, str):
warnings.warn(
("Input is {}, expected string, " "unicode string, Seq or SeqRecord " "objects!").format(type(sequence))
("Input is {}, expected string, " "unicode string, Seq or SeqRecord " "objects!").format(
type(sequence)
)
)
sequence = str(sequence)

Expand Down
6 changes: 3 additions & 3 deletions src/pydna/amplicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ def figure(self):
fzc = tp.seq.crick[::-1][fp.position - fp._fp : fp.position]
rzc = tp.seq.crick[::-1][rp.position : rp.position + rp._fp]
f = f"""
{" " *ft}5{faz}...{raz}3
{" " * ft}5{faz}...{raz}3
{sp3}{"|" * rp._fp}
{sp3}3{rp.seq[::-1]}5
5{fp.seq}3
{"|" *fp._fp:>{len(fp)}}
{" " *ft}3{fzc}...{rzc}5
{"|" * fp._fp:>{len(fp)}}
{" " * ft}3{fzc}...{rzc}5
"""
# breakpoint()
return _pretty_str(_textwrap.dedent(f).strip("\n"))
Expand Down
5 changes: 3 additions & 2 deletions src/pydna/amplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from pydna.utils import flatten as _flatten

from pydna.utils import iupac_compl_regex as _iupac_compl_regex
from pydna.utils import rc as _rc, shift_feature as _shift_feature
from pydna.utils import shift_feature as _shift_feature
from pydna.utils import anneal_from_left as _anneal_from_left
from pydna.amplicon import Amplicon as _Amplicon
from pydna.primer import Primer as _Primer
Expand All @@ -27,7 +27,8 @@
from Bio.SeqFeature import SimpleLocation as _SimpleLocation
from Bio.SeqFeature import CompoundLocation as _CompoundLocation
from pydna.seq import Seq as _Seq
import itertools as _itertools

# import itertools as _itertools
import re as _re
import copy as _copy
import operator as _operator
Expand Down
20 changes: 10 additions & 10 deletions src/pydna/dseq.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@
from Bio.Restriction import RestrictionBatch as _RestrictionBatch
from Bio.Restriction import CommOnly

from typing import (
TYPE_CHECKING,
List as _List,
Tuple as _Tuple,
Union as _Union,
TypeVar as _TypeVar,
Iterable as _Iterable,
)

try:
from itertools import pairwise as _pairwise
except ImportError:
Expand All @@ -59,16 +68,8 @@ def _pairwise(iterable):
yield a, b
a = b

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

from typing import (
TYPE_CHECKING,
List as _List,
Tuple as _Tuple,
Union as _Union,
TypeVar as _TypeVar,
Iterable as _Iterable,
)
pos_w_enz = _namedtuple("enzpos", "position enzyme recsite")


if TYPE_CHECKING:
Expand Down Expand Up @@ -1413,7 +1414,6 @@ def __repr__(self):
if overlaps := _cuts_overlap(cutsites):
raise ValueError(f"Enzyme pairs with cut overlap: {overlaps}")


if not cutsites:
return tuple(), tuple(), None, None

Expand Down
7 changes: 5 additions & 2 deletions src/pydna/dseqrecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@
from pydna._pretty import pretty_str as _pretty_str
from pydna.utils import flatten as _flatten, location_boundaries as _location_boundaries
from pydna.utils import unfold_feature as _unfold_feature
from pydna.utils import rc as _rc

# from pydna.utils import rc as _rc
from pydna.utils import shift_location as _shift_location
from pydna.utils import shift_feature as _shift_feature
from pydna.common_sub_strings import common_sub_strings as _common_sub_strings
from Bio import SeqIO
from Bio.SeqFeature import SeqFeature as _SeqFeature
from Bio.SeqFeature import CompoundLocation as _CompoundLocation
from Bio.SeqFeature import SimpleLocation as _SimpleLocation
from Bio.SeqFeature import ExactPosition as _ExactPosition

# from Bio.SeqFeature import ExactPosition as _ExactPosition
from pydna.seqrecord import SeqRecord as _SeqRecord
from Bio.Seq import translate as _translate
from pydna.utils import identifier_from_string as _identifier_from_string
Expand Down Expand Up @@ -517,6 +519,7 @@ def write(self, filename=None, f="gb"):
# The filename alread exists in current directory
# We assume it contains a sequence
from pydna.readers import read

old = read(filename)
if self == old:
# The sequence object to be saved is identical to the on disk.
Expand Down
5 changes: 3 additions & 2 deletions src/pydna/seqrecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
from pydna._pretty import PrettyTable as _PrettyTable

import re as _re
import pickle as _pickle

# import pickle as _pickle
from copy import copy as _copy

from pydna import _PydnaWarning
Expand Down Expand Up @@ -627,7 +628,7 @@ def removeprefix(text, prefix):

if format == "pydnafasta":
return _pretty_str(
f">{self.id} {len(self)} bp {dict(((True,'circular'),(False,'linear')))[self.seq.circular]}\n{str(self.seq)}\n"
f">{self.id} {len(self)} bp {dict(((True, 'circular'), (False, 'linear')))[self.seq.circular]}\n{str(self.seq)}\n"
)
if format == "primer":
return _pretty_str(
Expand Down
7 changes: 6 additions & 1 deletion src/pydna/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def _pairwise(iterable):
yield a, b
a = b


# For functions that take str or bytes as input and return str or bytes as output, matching the input type
StrOrBytes = _TypeVar("StrOrBytes", str, bytes)

Expand Down Expand Up @@ -1511,11 +1512,15 @@ def eq(*args, **kwargs):
# y = sorted([right_watson, right_crick])
# return (x[1] > y[0]) != (y[1] < x[0])


def cuts_overlap(cutsites):

srt_pos = [(tuple(sorted((ep.position, ep.position - ep.enzyme.ovhg))), ep) for ep in cutsites]

combs = {(ep1.enzyme, x, ep2.enzyme, y): (x[1] > y[0]) != (y[1] < x[0]) for ((x, ep1), (y, ep2)) in _itertools.combinations(srt_pos, 2)}
combs = {
(ep1.enzyme, x, ep2.enzyme, y): (x[1] > y[0]) != (y[1] < x[0])
for ((x, ep1), (y, ep2)) in _itertools.combinations(srt_pos, 2)
}

return [comb for comb, val in combs.items() if val]

Expand Down

0 comments on commit 21f831f

Please sign in to comment.