Skip to content

Commit

Permalink
Fix typing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
PauAndrio committed Oct 23, 2024
1 parent a8f052c commit 6849e0a
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 44 deletions.
4 changes: 2 additions & 2 deletions biobb_dna/dna/dna_averages.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ def launch(self) -> int:
for i in self.seqpos]

# rename duplicated subunits
while any(ser_data.columns.duplicated()):
while any(pd.Index(ser_data.columns).duplicated()):
ser_data.columns = [
name if not duplicated else name + "_dup"
for duplicated, name
in zip(ser_data.columns.duplicated(), ser_data.columns)]
in zip(pd.Index(ser_data.columns).duplicated(), ser_data.columns)]

# write output files for all selected bases
means = ser_data.mean(axis=0).iloc[:len(xlabels)]
Expand Down
13 changes: 6 additions & 7 deletions biobb_dna/dna/dna_bimodality.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.mixture import GaussianMixture

from sklearn.mixture import GaussianMixture # type: ignore
from biobb_dna.utils import constants
from biobb_common.generic.biobb_object import BiobbObject
from biobb_common.configuration import settings
Expand Down Expand Up @@ -210,12 +209,12 @@ def launch(self) -> int:
label1 = "Single State"
out = plt.hist(
synth1, bins=bins, alpha=alpha, density=True, label=label1)
ylim = max(out[0])
ylim = max(out[0]) # type: ignore
plt.vlines(info['mean1'], 0, ylim, colors="r", linestyles="dashed")
if binormal:
out = plt.hist(
synth2, bins=bins, alpha=alpha, density=True, label="high state")
ylim = max(out[0])
ylim = max(out[0]) # type: ignore
plt.vlines(info['mean2'], 0, ylim, colors="r", linestyles="dashed")
plt.legend()
plt.ylabel("Density")
Expand Down Expand Up @@ -255,10 +254,10 @@ def fit_to_model(self, data):
max_iter=self.max_iter,
tol=self.tol)
gmm = gmm.fit(data)
m = gmm.means_.flatten()
v = gmm.covariances_.flatten()
m = gmm.means_.flatten() # type: ignore
v = gmm.covariances_.flatten() # type: ignore
b = gmm.bic(data)
w = gmm.weights_.flatten()
w = gmm.weights_.flatten() # type: ignore
means.append(m)
variances.append(v)
bics.append(b)
Expand Down
4 changes: 2 additions & 2 deletions biobb_dna/dna/dna_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ def launch(self) -> int:
# get removed items
removed_items = [s for s in subunits if not pattern.fullmatch(s)]
# get indices of removed items (in integer format and starting from 0)
removed_numbers = [re.match(r'\d+', item).group() for item in removed_items]
removed_numbers = [int(match.group()) for item in removed_items if (match := re.match(r'\d+', item))]
removed_numbers = list(map(int, removed_numbers))
removed_numbers = [i-1 for i in removed_numbers]
removed_numbers = [int(i)-1 for i in removed_numbers]
# remove non basepairs from subunits and indices
subunits = [s for s in subunits if pattern.fullmatch(s)]
indices = [i for i in indices if i not in removed_numbers]
Expand Down
8 changes: 4 additions & 4 deletions biobb_dna/interbp_correlations/interbpcorr.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ def launch(self) -> int:
):
method = self.circlineal
else:
method = "pearson"
method = "pearson" # type: ignore
corr_data = ser1.corrwith(ser2_shifted, method=method)
corr_data.index = corr_index
results[f"{ser1.name}/{ser2.name}"] = corr_data
result_df = pd.DataFrame.from_dict(results)
result_df.index = corr_index
result_df.index = corr_index # type: ignore

# save csv data
result_df.to_csv(self.stage_io_dict["out"]["output_csv_path"])
Expand All @@ -199,7 +199,7 @@ def launch(self) -> int:
cmap = plt.get_cmap("bwr").copy()
bounds = [-1, -.8, -.6, -.4, -.2, .2, .4, .6, .8, 1]
num = cmap.N
norm = mpl.colors.BoundaryNorm(bounds, num)
norm = mpl.colors.BoundaryNorm(bounds, num) # type: ignore
cmap.set_bad(color="gainsboro")
fig, ax = plt.subplots(
1,
Expand All @@ -217,7 +217,7 @@ def launch(self) -> int:

ylocs = np.arange(len(result_df.index))
_ = ax.set_yticks(ylocs)
_ = ax.set_yticklabels(result_df.index.to_list())
_ = ax.set_yticklabels(result_df.index.to_list()) # type: ignore

ax.set_title(
"Correlation for neighboring basepairs "
Expand Down
24 changes: 12 additions & 12 deletions biobb_dna/interbp_correlations/interhpcorr.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ def launch(self) -> int:
# corr_matrix["shift"]["rise"] = shift.corrwith(rise, method="pearson")
corr_matrix.loc["rise", "shift"] = shift.corrwith(rise, method="pearson").values[0]
# corr_matrix["shift"]["tilt"] = shift.corrwith(tilt, method=self.circlineal)
corr_matrix.loc["tilt", "shift"] = shift.corrwith(tilt, method=self.circlineal).values[0]
corr_matrix.loc["tilt", "shift"] = shift.corrwith(tilt, method=self.circlineal).values[0] # type: ignore
# corr_matrix["shift"]["roll"] = shift.corrwith(roll, method=self.circlineal)
corr_matrix.loc["roll", "shift"] = shift.corrwith(roll, method=self.circlineal).values[0]
corr_matrix.loc["roll", "shift"] = shift.corrwith(roll, method=self.circlineal).values[0] # type: ignore
# corr_matrix["shift"]["twist"] = shift.corrwith(twist, method=self.circlineal)
corr_matrix.loc["twist", "shift"] = shift.corrwith(twist, method=self.circlineal).values[0]
corr_matrix.loc["twist", "shift"] = shift.corrwith(twist, method=self.circlineal).values[0] # type: ignore
# symmetric values
# corr_matrix["slide"]["shift"] = corr_matrix["shift"]["slide"]
corr_matrix.loc["shift", "slide"] = corr_matrix.loc["slide", "shift"]
Expand All @@ -151,11 +151,11 @@ def launch(self) -> int:
# corr_matrix["slide"]["rise"] = slide.corrwith(rise, method="pearson")
corr_matrix.loc["rise", "slide"] = slide.corrwith(rise, method="pearson").values[0]
# corr_matrix["slide"]["tilt"] = slide.corrwith(tilt, method=self.circlineal)
corr_matrix.loc["tilt", "slide"] = slide.corrwith(tilt, method=self.circlineal).values[0]
corr_matrix.loc["tilt", "slide"] = slide.corrwith(tilt, method=self.circlineal).values[0] # type: ignore
# corr_matrix["slide"]["roll"] = slide.corrwith(roll, method=self.circlineal)
corr_matrix.loc["roll", "slide"] = slide.corrwith(roll, method=self.circlineal).values[0]
corr_matrix.loc["roll", "slide"] = slide.corrwith(roll, method=self.circlineal).values[0] # type: ignore
# corr_matrix["slide"]["twist"] = slide.corrwith(twist, method=self.circlineal)
corr_matrix.loc["twist", "slide"] = slide.corrwith(twist, method=self.circlineal).values[0]
corr_matrix.loc["twist", "slide"] = slide.corrwith(twist, method=self.circlineal).values[0] # type: ignore
# symmetric values
# corr_matrix["rise"]["slide"] = corr_matrix["slide"]["rise"]
corr_matrix.loc["slide", "rise"] = corr_matrix.loc["rise", "slide"]
Expand All @@ -168,11 +168,11 @@ def launch(self) -> int:

# rise
# corr_matrix["rise"]["tilt"] = rise.corrwith(tilt, method=self.circlineal)
corr_matrix.loc["tilt", "rise"] = rise.corrwith(tilt, method=self.circlineal).values[0]
corr_matrix.loc["tilt", "rise"] = rise.corrwith(tilt, method=self.circlineal).values[0] # type: ignore
# corr_matrix["rise"]["roll"] = rise.corrwith(roll, method=self.circlineal)
corr_matrix.loc["roll", "rise"] = rise.corrwith(roll, method=self.circlineal).values[0]
corr_matrix.loc["roll", "rise"] = rise.corrwith(roll, method=self.circlineal).values[0] # type: ignore
# corr_matrix["rise"]["twist"] = rise.corrwith(twist, method=self.circlineal)
corr_matrix.loc["twist", "rise"] = rise.corrwith(twist, method=self.circlineal).values[0]
corr_matrix.loc["twist", "rise"] = rise.corrwith(twist, method=self.circlineal).values[0] # type: ignore
# symmetric values
# corr_matrix["tilt"]["rise"] = corr_matrix["rise"]["tilt"]
corr_matrix.loc["rise", "tilt"] = corr_matrix.loc["tilt", "rise"]
Expand All @@ -183,9 +183,9 @@ def launch(self) -> int:

# tilt
# corr_matrix["tilt"]["roll"] = tilt.corrwith(roll, method=self.circular)
corr_matrix.loc["roll", "tilt"] = tilt.corrwith(roll, method=self.circular).values[0]
corr_matrix.loc["roll", "tilt"] = tilt.corrwith(roll, method=self.circular).values[0] # type: ignore
# corr_matrix["tilt"]["twist"] = tilt.corrwith(twist, method=self.circular)
corr_matrix.loc["twist", "tilt"] = tilt.corrwith(twist, method=self.circular).values[0]
corr_matrix.loc["twist", "tilt"] = tilt.corrwith(twist, method=self.circular).values[0] # type: ignore
# symmetric values
# corr_matrix["roll"]["tilt"] = corr_matrix["tilt"]["roll"]
corr_matrix.loc["tilt", "roll"] = corr_matrix.loc["roll", "tilt"]
Expand All @@ -194,7 +194,7 @@ def launch(self) -> int:

# roll
# corr_matrix["roll"]["twist"] = roll.corrwith(twist, method=self.circular)
corr_matrix.loc["twist", "roll"] = roll.corrwith(twist, method=self.circular).values[0]
corr_matrix.loc["twist", "roll"] = roll.corrwith(twist, method=self.circular).values[0] # type: ignore
# symmetric values
# corr_matrix["twist"]["roll"] = corr_matrix["roll"]["twist"]
corr_matrix.loc["roll", "twist"] = corr_matrix.loc["twist", "roll"]
Expand Down
8 changes: 4 additions & 4 deletions biobb_dna/intrabp_correlations/intrabpcorr.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ def launch(self) -> int:
):
method = self.circlineal
else:
method = "pearson"
method = "pearson" # type: ignore
corr_data = ser1.corrwith(ser2_shifted, method=method)
corr_data.index = corr_index
results[f"{ser1.name}/{ser2.name}"] = corr_data
result_df = pd.DataFrame.from_dict(results)
result_df.index = corr_index
result_df.index = corr_index # type: ignore

# save csv data
result_df.to_csv(self.stage_io_dict["out"]["output_csv_path"])
Expand All @@ -199,7 +199,7 @@ def launch(self) -> int:
cmap = plt.get_cmap("bwr").copy()
bounds = [-1, -.8, -.6, -.4, -.2, .2, .4, .6, .8, 1]
num = cmap.N
norm = mpl.colors.BoundaryNorm(bounds, num)
norm = mpl.colors.BoundaryNorm(bounds, num) # type: ignore
cmap.set_bad(color="gainsboro")
fig, ax = plt.subplots(
1,
Expand All @@ -217,7 +217,7 @@ def launch(self) -> int:

ylocs = np.arange(len(result_df.index))
_ = ax.set_yticks(ylocs)
_ = ax.set_yticklabels(result_df.index.to_list())
_ = ax.set_yticklabels(result_df.index.to_list()) # type: ignore

ax.set_title(
"Correlation for neighboring basepairs "
Expand Down
24 changes: 12 additions & 12 deletions biobb_dna/intrabp_correlations/intrahpcorr.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ def launch(self) -> int:
# corr_matrix["shear"]["stagger"] = shear.corrwith(stagger, method="pearson")
corr_matrix.loc["stagger", "shear"] = shear.corrwith(stagger, method="pearson").values[0]
# corr_matrix["shear"]["buckle"] = shear.corrwith(buckle, method=self.circlineal)
corr_matrix.loc["buckle", "shear"] = shear.corrwith(buckle, method=self.circlineal).values[0]
corr_matrix.loc["buckle", "shear"] = shear.corrwith(buckle, method=self.circlineal).values[0] # type: ignore
# corr_matrix["shear"]["propel"] = shear.corrwith(propel, method=self.circlineal)
corr_matrix.loc["propel", "shear"] = shear.corrwith(propel, method=self.circlineal).values[0]
corr_matrix.loc["propel", "shear"] = shear.corrwith(propel, method=self.circlineal).values[0] # type: ignore
# corr_matrix["shear"]["opening"] = shear.corrwith(opening, method=self.circlineal)
corr_matrix.loc["opening", "shear"] = shear.corrwith(opening, method=self.circlineal).values[0]
corr_matrix.loc["opening", "shear"] = shear.corrwith(opening, method=self.circlineal).values[0] # type: ignore
# symmetric values
# corr_matrix["stretch"]["shear"] = corr_matrix["shear"]["stretch"]
corr_matrix.loc["shear", "stretch"] = corr_matrix.loc["stretch", "shear"]
Expand All @@ -153,11 +153,11 @@ def launch(self) -> int:
# corr_matrix["stretch"]["stagger"] = stretch.corrwith(stagger, method="pearson")
corr_matrix.loc["stagger", "stretch"] = stretch.corrwith(stagger, method="pearson").values[0]
# corr_matrix["stretch"]["buckle"] = stretch.corrwith(buckle, method=self.circlineal)
corr_matrix.loc["buckle", "stretch"] = stretch.corrwith(buckle, method=self.circlineal).values[0]
corr_matrix.loc["buckle", "stretch"] = stretch.corrwith(buckle, method=self.circlineal).values[0] # type: ignore
# corr_matrix["stretch"]["propel"] = stretch.corrwith(propel, method=self.circlineal)
corr_matrix.loc["propel", "stretch"] = stretch.corrwith(propel, method=self.circlineal).values[0]
corr_matrix.loc["propel", "stretch"] = stretch.corrwith(propel, method=self.circlineal).values[0] # type: ignore
# corr_matrix["stretch"]["opening"] = stretch.corrwith(opening, method=self.circlineal)
corr_matrix.loc["opening", "stretch"] = stretch.corrwith(opening, method=self.circlineal).values[0]
corr_matrix.loc["opening", "stretch"] = stretch.corrwith(opening, method=self.circlineal).values[0] # type: ignore
# symmetric values
# corr_matrix["stagger"]["stretch"] = corr_matrix["stretch"]["stagger"]
corr_matrix.loc["stretch", "stagger"] = corr_matrix.loc["stagger", "stretch"]
Expand All @@ -170,11 +170,11 @@ def launch(self) -> int:

# stagger
# corr_matrix["stagger"]["buckle"] = stagger.corrwith(buckle, method=self.circlineal)
corr_matrix.loc["buckle", "stagger"] = stagger.corrwith(buckle, method=self.circlineal).values[0]
corr_matrix.loc["buckle", "stagger"] = stagger.corrwith(buckle, method=self.circlineal).values[0] # type: ignore
# corr_matrix["stagger"]["propel"] = stagger.corrwith(propel, method=self.circlineal)
corr_matrix.loc["propel", "stagger"] = stagger.corrwith(propel, method=self.circlineal).values[0]
corr_matrix.loc["propel", "stagger"] = stagger.corrwith(propel, method=self.circlineal).values[0] # type: ignore
# corr_matrix["stagger"]["opening"] = stagger.corrwith(opening, method=self.circlineal)
corr_matrix.loc["opening", "stagger"] = stagger.corrwith(opening, method=self.circlineal).values[0]
corr_matrix.loc["opening", "stagger"] = stagger.corrwith(opening, method=self.circlineal).values[0] # type: ignore
# symmetric values
# corr_matrix["buckle"]["stagger"] = corr_matrix["stagger"]["buckle"]
corr_matrix.loc["stagger", "buckle"] = corr_matrix.loc["buckle", "stagger"]
Expand All @@ -185,9 +185,9 @@ def launch(self) -> int:

# buckle
# corr_matrix["buckle"]["propel"] = buckle.corrwith(propel, method=self.circular)
corr_matrix.loc["propel", "buckle"] = buckle.corrwith(propel, method=self.circular).values[0]
corr_matrix.loc["propel", "buckle"] = buckle.corrwith(propel, method=self.circular).values[0] # type: ignore
# corr_matrix["buckle"]["opening"] = buckle.corrwith(opening, method=self.circular)
corr_matrix.loc["opening", "buckle"] = buckle.corrwith(opening, method=self.circular).values[0]
corr_matrix.loc["opening", "buckle"] = buckle.corrwith(opening, method=self.circular).values[0] # type: ignore
# symmetric values
# corr_matrix["propel"]["buckle"] = corr_matrix["buckle"]["propel"]
corr_matrix.loc["buckle", "propel"] = corr_matrix.loc["propel", "buckle"]
Expand All @@ -196,7 +196,7 @@ def launch(self) -> int:

# propel
# corr_matrix["propel"]["opening"] = propel.corrwith(opening, method=self.circular)
corr_matrix.loc["opening", "propel"] = propel.corrwith(opening, method=self.circular).values[0]
corr_matrix.loc["opening", "propel"] = propel.corrwith(opening, method=self.circular).values[0] # type: ignore
# symmetric values
# corr_matrix["opening"]["propel"] = corr_matrix["propel"]["opening"]
corr_matrix.loc["propel", "opening"] = corr_matrix.loc["opening", "propel"]
Expand Down
2 changes: 1 addition & 1 deletion biobb_dna/utils/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def read_series(input_serfile, usecols=None):
header=None,
sep='\\s+',
index_col=0)
ser_data = pd.read_csv(input_serfile, **extra_kwargs)
ser_data = pd.read_csv(input_serfile, **extra_kwargs) # type: ignore
if usecols is not None:
if 0 in usecols:
usecols.pop(usecols.index(0))
Expand Down

0 comments on commit 6849e0a

Please sign in to comment.