Skip to content

Commit

Permalink
ruff lints
Browse files Browse the repository at this point in the history
  • Loading branch information
cgevans committed Oct 30, 2024
1 parent 4bdd28e commit df96149
Show file tree
Hide file tree
Showing 16 changed files with 222 additions and 248 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ indent-width = 4
fixable = ["ALL"]
select = ["E4", "E7", "E9", "F", "B", "A001", "A002", "C4", "ICN", "PIE", "PYI", "RSE",
"RET501", "SIM", "TID", "TCH", "INT", "PTH", "PD", "PLR", "PLW", "TRY",
"NPY", "PERF", "FURB", "RUF", "UP", "D"]
"NPY", "PERF", "FURB", "RUF", "UP", "D", "NPY201"]

# 2. Avoid enforcing line-length violations (`E501`)
ignore = ["E501", "TRY003", "D1", "UP007", "D205", "D401", "UP032", "UP", "PLR0913", "PLR2004", "PLR0912"]
Expand Down
12 changes: 6 additions & 6 deletions src/stickydesign/endclasses.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np
from typing_extensions import TypeAlias # noqa: UP035
from typing import Union, Literal, List, cast, Dict, Any # noqa: UP035
from typing_extensions import TypeAlias
from typing import Union, Literal, List, cast, Dict, Any
from collections.abc import Sequence
from abc import ABC, abstractmethod, abstractproperty
from abc import ABC, abstractmethod

__all__ = [
'Energetics',
Expand All @@ -17,7 +17,7 @@
'tops',
]

EndTypes: TypeAlias = Literal['DT', 'TD', 'S'] # noqa: UP040
EndTypes: TypeAlias = Literal['DT', 'TD', 'S']


class PairSeqA(np.ndarray):
Expand All @@ -28,7 +28,7 @@ def __new__(cls, array: np.ndarray):
def revcomp(self) -> 'PairSeqA':
return cast(PairSeqA, 4 * (3 - (self[:, ::-1] % 4)) + 3 - (self[:, ::-1] // 4))

def tolist(self) -> List[str]: # noqa: UP006
def tolist(self) -> List[str]:
st = ["a", "c", "g", "t"]
return [
"".join([st[x // 4] for x in y] + [st[y[-1] % 4]]) for y in self
Expand Down Expand Up @@ -159,7 +159,7 @@ def append(s1, s2: 'EndArray') -> 'EndArray':
def __repr__(self):
return f"<endarray ({len(self)}): type {self.endtype}; {self.tolist()!r}>"

def tolist(self) -> List[str]: # noqa: UP006
def tolist(self) -> List[str]:
st = ["a", "c", "g", "t"]
return ["".join([st[x] for x in y]) for y in self]

Expand Down
44 changes: 20 additions & 24 deletions src/stickydesign/energetics_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

def py_tightloop(ens, ltmm, rtmm, intmm, singlepair, looppenalty):
bindmax = np.zeros(ens.shape[0])
for e in range(0, ens.shape[0]):
for e in range(ens.shape[0]):
acc = 0
for i in range(ens.shape[1]):
if ens[e, i] != 0:
Expand All @@ -27,8 +27,7 @@ def py_tightloop(ens, ltmm, rtmm, intmm, singlepair, looppenalty):
# Update: we only want to do this if the last
# nnpair was bound, because otherwise, we
# can't have a "right" mismatch.
if acc + rtmm[e, i] > bindmax[e]:
bindmax[e] = acc + rtmm[e, i]
bindmax[e] = max(acc + rtmm[e, i], bindmax[e])
acc += intmm[e, i]
elif ltmm[e, i] != 0 and i < ens.shape[1] - 1:
# don't do this for the last pair we're mismatching on
Expand All @@ -40,9 +39,7 @@ def py_tightloop(ens, ltmm, rtmm, intmm, singlepair, looppenalty):
# mismatch.
if (not singlepair) and (ltmm[e, i] >
acc + intmm[e, i]) and (
ens[e, i + 1] > 0):
acc = ltmm[e, i]
elif (singlepair) and (ltmm[e, i] >
ens[e, i + 1] > 0) or (singlepair) and (ltmm[e, i] >
acc + intmm[e, i]):
acc = ltmm[e, i]
else:
Expand All @@ -54,22 +51,21 @@ def py_tightloop(ens, ltmm, rtmm, intmm, singlepair, looppenalty):


class EnergeticsBasic(Energetics):

"""Energy functions based on several sources, primarily SantaLucia's
2004 paper. This class uses the same parameters and algorithms
as EnergeticsDAOE, bet does not make DX-specific assumptions.
Instead, it assumes that each energy should simply be that of
two single strands attaching/detaching, without consideration
of nicks, stacking, or other effects related to the
beginning/end of each sequence. Dangles and tails are still
included in mismatched binding calculations when appropriate.
Relevant arguments:
2004 paper. This class uses the same parameters and algorithms
as EnergeticsDAOE, bet does not make DX-specific assumptions.
Instead, it assumes that each energy should simply be that of
two single strands attaching/detaching, without consideration
of nicks, stacking, or other effects related to the
beginning/end of each sequence. Dangles and tails are still
included in mismatched binding calculations when appropriate.
Relevant arguments:
singlepair (bool, default False) --- treat single base pair pairings
as possible.
temperature (float in degrees Celsius, default 37) --- temperature
to use for the model, in C.
singlepair (bool, default False) --- treat single base pair pairings
as possible.
temperature (float in degrees Celsius, default 37) --- temperature
to use for the model, in C.
"""

def __init__(self,
Expand Down Expand Up @@ -98,7 +94,7 @@ def __init__(self,
self._accel = _accel
self._allow_shifts = _allow_shifts
@property
def info(self) -> Dict[str, Any]: # noqa: F821
def info(self) -> Dict[str, Any]:
info = {'enclass': 'EnergeticsDAOE',
'temperature': self.temperature,
'coaxparams': self.coaxparaminfo,
Expand Down Expand Up @@ -158,9 +154,9 @@ def _setup_params(self, temperature=37):
self.intmmdG_5335 = np.zeros(256)

# Dumb setup. FIXME: do this cleverly
for i in range(0, 4):
for j in range(0, 4):
for k in range(0, 4):
for i in range(4):
for j in range(4):
for k in range(4):
self.ltmmdG_5335[
i * 64 + j * 16 + k * 4 +
j] = self.dangle5dG[i * 4
Expand Down
80 changes: 38 additions & 42 deletions src/stickydesign/energetics_daoe.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ def _setup_params(self, temperature=37):
self.intmmdG_5335 = np.zeros(256)

# Dumb setup. FIXME: do this cleverly
for i in range(0, 4):
for j in range(0, 4):
for k in range(0, 4):
for i in range(4):
for j in range(4):
for k in range(4):
self.ltmmdG_5335[
i * 64 + j * 16 + k * 4 +
j] = self.dangle5dG[i * 4
Expand Down Expand Up @@ -175,7 +175,7 @@ def uniform(self, seqs1, seqs2, debug=False):
s1.shape[0]) # store for max binding at any offset

if endtype == 'TD':
s1_end = s1[:, 0:-1] #
s1_end = s1[:, 0:-1]
s2_end_rc = s2r[:, 1:]
s1l = np.hstack(((4 * (s2r[:, 0] // 4) + s1[:, 0] // 4).reshape(
-1, 1), s1))
Expand Down Expand Up @@ -254,52 +254,50 @@ def uniform(self, seqs1, seqs2, debug=False):
ltmm = -self.ltmmdG_5335[s1_end[:, :] * 16 + s2_end_rc[:, :]]
rtmm = -self.rtmmdG_5335[s1_end[:, :] * 16 + s2_end_rc[:, :]]
intmm = -self.intmmdG_5335[s1_end[:, :] * 16 + s2_end_rc[:, :]]
else: # offset < 0
if endtype == 'TD':
ens = (s1_end[:, -offset:] == s2_end_rc[:, :offset]) * (
-self.nndG[s1_end[:, -offset:]])
ens[:, 0] += (ens[:, 0] != 0) * (
-self.nndG[s1[:, -1]] - p.tailcordG37 +
self.dangle5dG[s1[:, -1]]) # - for positive sign
ens[:, -1] += (ens[:, -1] != 0) * (
-self.nndG[s2[:, -1]] - p.tailcordG37 +
self.dangle5dG[s2[:, -1]]) # - for positive sign
ltmm = -self.ltmmdG_5335[s1_end[:, -offset:] * 16
+ s2_end_rc[:, :offset]]
rtmm = -self.rtmmdG_5335[s1_end[:, -offset:] * 16
+ s2_end_rc[:, :offset]]
intmm = -self.intmmdG_5335[s1_end[:, -offset:] * 16
+ s2_end_rc[:, :offset]]
elif endtype == 'DT':
ens = (s1_end[:, :offset] == s2_end_rc[:, -offset:]) * (
-self.nndG[s1_end[:, :offset]])
ens[:, 0] += (ens[:, 0] != 0) * (
-self.nndG[s1[:, 0]] - p.tailcordG37 +
self.dangle3dG[s1[:, 0]]) # - for positive sign
ens[:, -1] += (ens[:, -1] != 0) * (
-self.nndG[s2[:, 0]] - p.tailcordG37 +
self.dangle3dG[s2[:, 0]]) # - for positive sign
ltmm = -self.ltmmdG_5335[s1_end[:, :offset] * 16
+ s2_end_rc[:, -offset:]]
rtmm = -self.rtmmdG_5335[s1_end[:, :offset] * 16
+ s2_end_rc[:, -offset:]]
intmm = -self.intmmdG_5335[s1_end[:, :offset] * 16
+ s2_end_rc[:, -offset:]]
elif endtype == 'TD':
ens = (s1_end[:, -offset:] == s2_end_rc[:, :offset]) * (
-self.nndG[s1_end[:, -offset:]])
ens[:, 0] += (ens[:, 0] != 0) * (
-self.nndG[s1[:, -1]] - p.tailcordG37 +
self.dangle5dG[s1[:, -1]]) # - for positive sign
ens[:, -1] += (ens[:, -1] != 0) * (
-self.nndG[s2[:, -1]] - p.tailcordG37 +
self.dangle5dG[s2[:, -1]]) # - for positive sign
ltmm = -self.ltmmdG_5335[s1_end[:, -offset:] * 16
+ s2_end_rc[:, :offset]]
rtmm = -self.rtmmdG_5335[s1_end[:, -offset:] * 16
+ s2_end_rc[:, :offset]]
intmm = -self.intmmdG_5335[s1_end[:, -offset:] * 16
+ s2_end_rc[:, :offset]]
elif endtype == 'DT':
ens = (s1_end[:, :offset] == s2_end_rc[:, -offset:]) * (
-self.nndG[s1_end[:, :offset]])
ens[:, 0] += (ens[:, 0] != 0) * (
-self.nndG[s1[:, 0]] - p.tailcordG37 +
self.dangle3dG[s1[:, 0]]) # - for positive sign
ens[:, -1] += (ens[:, -1] != 0) * (
-self.nndG[s2[:, 0]] - p.tailcordG37 +
self.dangle3dG[s2[:, 0]]) # - for positive sign
ltmm = -self.ltmmdG_5335[s1_end[:, :offset] * 16
+ s2_end_rc[:, -offset:]]
rtmm = -self.rtmmdG_5335[s1_end[:, :offset] * 16
+ s2_end_rc[:, -offset:]]
intmm = -self.intmmdG_5335[s1_end[:, :offset] * 16
+ s2_end_rc[:, -offset:]]
bindmax = np.zeros(ens.shape[0])
if debug:
print(offset, ens.view(np.ndarray), ltmm, rtmm, intmm)
for e in range(0, ens.shape[0]):
for e in range(ens.shape[0]):
acc = 0
for i in range(0, ens.shape[1]):
for i in range(ens.shape[1]):
if ens[e, i] != 0:
# we're matching. add the pair to the accumulator
acc += ens[e, i]
elif rtmm[e, i] != 0 and i > 0 and ens[e, i-1] > 0:
# we're mismatching on the right: see if right-dangling
# is highest binding so far, and continue, adding intmm
# to accumulator.
if acc + rtmm[e, i] > bindmax[e]:
bindmax[e] = acc + rtmm[e, i]
bindmax[e] = max(acc + rtmm[e, i], bindmax[e])
acc += intmm[e, i]
elif ltmm[e, i] != 0 and i < ens.shape[1] - 1:
# don't do this for the last pair we're mismatching on
Expand All @@ -311,9 +309,7 @@ def uniform(self, seqs1, seqs2, debug=False):
# mismatch.
if (not self.singlepair) and (ltmm[e, i] >
acc + intmm[e, i]) and (
ens[e, i + 1] > 0):
acc = ltmm[e, i]
elif (self.singlepair) and (ltmm[e, i] >
ens[e, i + 1] > 0) or (self.singlepair) and (ltmm[e, i] >
acc + intmm[e, i]):
acc = ltmm[e, i]
else:
Expand Down
2 changes: 1 addition & 1 deletion src/stickydesign/multimodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def endchooser(currentends, availends, energetics):
0, max(1, ceil(init_wigglefraction * len(availends))))]
return availends[choice]
else:
if not target_vals: # NOQA
if not target_vals:
target_vals = [
en.matching_uniform(currentends[0:1])
for en in all_energetics
Expand Down
1 change: 0 additions & 1 deletion src/stickydesign/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def _multi_data_pandas(ends, all_energetics, energetics_names=None):
Returns
-------
match : pandas.DataFrame
matching energies
Expand Down
2 changes: 1 addition & 1 deletion src/stickydesign/stickydesign2/choosers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def choose(self, availends, currentends):
0, max(1, ceil(self._iwf * len(availends))))]
return availends[choice]
else:
if not self._tv: # NOQA
if not self._tv:
self._tv = [
en.gse(currentends[0:1])
for en in self._ae
Expand Down
4 changes: 1 addition & 3 deletions src/stickydesign/stickydesign2/design_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ def easyends(endtype, endlength, energetics=None, number=None,
curends = np.concatenate((curends, newend[None, :]),
0).view(newend.__class__)
availends = seqfilter.filterseqs(availends, newend[None, :])
if len(availends) == 0:
break
elif number and len(curends) >= number:
if len(availends) == 0 or number and len(curends) >= number:
break

return curends
39 changes: 18 additions & 21 deletions src/stickydesign/stickydesign2/energetics_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@

class EnergeticsBasic(object):
"""Energy functions based on several sources, primarily SantaLucia's
2004 paper. This class uses the same parameters and algorithms
as EnergeticsDAOE, bet does not make DX-specific assumptions.
Instead, it assumes that each energy should simply be that of
two single strands attaching/detaching, without consideration
of nicks, stacking, or other effects related to the
beginning/end of each sequence. Dangles and tails are still
included in mismatched binding calculations when appropriate.
2004 paper. This class uses the same parameters and algorithms
as EnergeticsDAOE, bet does not make DX-specific assumptions.
Instead, it assumes that each energy should simply be that of
two single strands attaching/detaching, without consideration
of nicks, stacking, or other effects related to the
beginning/end of each sequence. Dangles and tails are still
included in mismatched binding calculations when appropriate.
Relevant arguments:
Relevant arguments:
singlepair (bool, default False) --- treat single base pair pairings
as possible.
temperature (float in degrees Celsius, default 37) --- temperature
to use for the model, in C.
singlepair (bool, default False) --- treat single base pair pairings
as possible.
temperature (float in degrees Celsius, default 37) --- temperature
to use for the model, in C.
"""

def __init__(self,
Expand Down Expand Up @@ -97,9 +97,9 @@ def _setup_params(self, temperature=37):
self.intmmdG_5335 = np.zeros(256)

# Dumb setup. FIXME: do this cleverly
for i in range(0, 4):
for j in range(0, 4):
for k in range(0, 4):
for i in range(4):
for j in range(4):
for k in range(4):
self.ltmmdG_5335[
i * 64 + j * 16 + k * 4 +
j] = self.dangle5dG[i * 4
Expand Down Expand Up @@ -184,7 +184,7 @@ def gse_all(self, seqs1, seqs2, forcemulti=False, debug=False):
print(offset, ens.view(np.ndarray), ltmm, rtmm, intmm)
for endi in np.ndindex(ens.shape[:-1]):
acc = 0
for i in range(0, ens.shape[-1]):
for i in range(ens.shape[-1]):
if ens[endi][i] != 0:
# we're matching. add the pair to the accumulator
acc += ens[endi][i]
Expand All @@ -195,8 +195,7 @@ def gse_all(self, seqs1, seqs2, forcemulti=False, debug=False):
# Update: we only want to do this if the last
# nnpair was bound, because otherwise, we
# can't have a "right" mismatch.
if acc + rtmm[endi][i] > bindmax[endi]:
bindmax[endi] = acc + rtmm[endi][i]
bindmax[endi] = max(acc + rtmm[endi][i], bindmax[endi])
acc += intmm[endi][i]
elif ltmm[endi][i] != 0 and i < ens.shape[-1] - 1:
# don't do this for the last pair we're mismatching on
Expand All @@ -208,9 +207,7 @@ def gse_all(self, seqs1, seqs2, forcemulti=False, debug=False):
# mismatch.
if (not self.singlepair) and (
ltmm[endi][i] > acc + intmm[endi][i]) and (
ens[endi][i + 1] > 0):
acc = ltmm[endi][i]
elif (self.singlepair) and (ltmm[endi][i] >
ens[endi][i + 1] > 0) or (self.singlepair) and (ltmm[endi][i] >
acc + intmm[endi][i]):
acc = ltmm[endi][i]
else:
Expand Down
Loading

0 comments on commit df96149

Please sign in to comment.