Skip to content

Commit

Permalink
apply unsafe auto-fixes for ruff rule SIM
Browse files Browse the repository at this point in the history
  • Loading branch information
mschwoer committed Sep 20, 2024
1 parent 7bcc4d4 commit 30bfcdd
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repos:
hooks:
- id: ruff-format
- id: ruff
args: ['--fix']
args: ['--unsafe-fixes', '--fix']
- repo: https://github.com/Yelp/detect-secrets
rev: v1.5.0
hooks:
Expand Down
7 changes: 3 additions & 4 deletions alphastats/DataSet_Preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ def _remove_na_values(self, cut_off):
count = column.isna().sum()
try:
count = count.item()
if isinstance(count, int):
if count < limit:
keep_list += [column_name]
if isinstance(count, int) and count < limit:
keep_list += [column_name]

except ValueError:
invalid += 1
Expand Down Expand Up @@ -402,7 +401,7 @@ def preprocess(
imputation (str, optional): method to impute data: either "mean", "median", "knn" or "randomforest". Defaults to None.
subset (bool, optional): filter matrix so only samples that are described in metadata found in matrix. Defaults to False.
"""
for k in kwargs.keys():
for k in kwargs:
if k not in [
"batch",
]:
Expand Down
4 changes: 2 additions & 2 deletions alphastats/gui/pages/04_Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ def select_analysis():
with c1:
method = select_analysis()

if method in st.session_state.plotting_options.keys():
if method in st.session_state.plotting_options:
analysis_result = get_analysis(
method=method, options_dict=st.session_state.plotting_options
)
plot_to_display = True

elif method in st.session_state.statistic_options.keys():
elif method in st.session_state.statistic_options:
analysis_result = get_analysis(
method=method, options_dict=st.session_state.statistic_options
)
Expand Down
5 changes: 2 additions & 3 deletions alphastats/gui/pages/05_GPT.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextlib
import os

import pandas as pd
Expand Down Expand Up @@ -105,10 +106,8 @@ def select_analysis():

try_to_set_api_key(api_key)

try:
with contextlib.suppress(OpenAIError):
client = OpenAI(api_key=st.secrets["openai_api_key"])
except OpenAIError:
pass
method = st.selectbox(
"Differential Analysis using:",
options=["ttest", "anova", "wald", "sam", "paired-ttest", "welch-ttest"],
Expand Down
6 changes: 3 additions & 3 deletions alphastats/gui/utils/analysis_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def st_general(method_dict):
for parameter in settings_dict:
parameter_dict = settings_dict[parameter]

if "options" in parameter_dict.keys():
if "options" in parameter_dict:
chosen_parameter = st.selectbox(
parameter_dict.get("label"), options=parameter_dict.get("options")
)
Expand Down Expand Up @@ -200,7 +200,7 @@ def get_analysis_options_from_dict(method, options_dict):
elif method == "UMAP Plot":
return st_plot_umap(method_dict)

elif "settings" not in method_dict.keys():
elif "settings" not in method_dict:
if st.session_state.dataset.mat.isna().values.any() == True:
st.error(
"Data contains missing values impute your data before plotting (Preprocessing - Imputation)."
Expand Down Expand Up @@ -342,7 +342,7 @@ def helper_compare_two_groups():


def get_analysis(method, options_dict):
if method in options_dict.keys():
if method in options_dict:
obj = get_analysis_options_from_dict(method, options_dict=options_dict)
return obj

Expand Down
2 changes: 1 addition & 1 deletion alphastats/gui/utils/ui_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def empty_session_state():
"""
remove all variables to avoid conflicts
"""
for key in st.session_state.keys():
for key in st.session_state:
del st.session_state[key]
st.empty()

Expand Down
5 changes: 1 addition & 4 deletions alphastats/loader/AlphaPeptLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ def standardize_protein_group_column(entry: str) -> str:
protein_id_list = []
for protein in proteins:
# 'sp|P0DMV9|HS71B_HUMAN,sp|P0DMV8|HS71A_HUMAN',
if "|" in protein:
fasta_header_split = protein.split("|")
else:
fasta_header_split = protein
fasta_header_split = protein.split("|") if "|" in protein else protein
if isinstance(fasta_header_split, str):
# 'ENSEMBL:ENSBTAP00000007350',
if "ENSEMBL:" in fasta_header_split:
Expand Down
12 changes: 4 additions & 8 deletions alphastats/multicova/multicova.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,7 @@ def get_tstat_cutoff(res_real, t_perm_avg, delta):
# between the observed and average random t-stat is
# larger than the selected delta.
t_max = t_real_abs[t_diff > delta]
if t_max.shape[0] == 0:
t_max = np.ceil(np.max(t_real_abs))
else:
t_max = np.min(t_max)
t_max = np.ceil(np.max(t_real_abs)) if t_max.shape[0] == 0 else np.min(t_max)
return t_max


Expand Down Expand Up @@ -329,10 +326,9 @@ def get_fdr_line(
for i in np.arange(0, len(fc_s)):
for j in np.arange(0, len(s_s)):
res_s = perform_ttest_getMaxS(fc=fc_s[i], s=s_s[j], s0=s0, n_x=n_x, n_y=n_y)
if res_s[3] >= t_limit:
if svals[i] < s_s[j]:
svals[i] = s_s[j]
pvals[i] = res_s[2]
if res_s[3] >= t_limit and svals[i] < s_s[j]:
svals[i] = s_s[j]
pvals[i] = res_s[2]

s_df = pd.DataFrame(
np.array([fc_s, svals, pvals]).T, columns=["fc_s", "svals", "pvals"]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_DataSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def test_plot_sampledistribution_group(self):
# check if there are two groups control and disease
self.assertEqual(plot_dict.get("data")[0].get("legendgroup"), "control")
#  check that it is boxplot and not violinplot
is_boxplot = "boxmode" in plot_dict.get("layout").keys()
is_boxplot = "boxmode" in plot_dict.get("layout")
self.assertTrue(is_boxplot)

def test_plot_correlation_matrix(self):
Expand Down Expand Up @@ -826,7 +826,7 @@ def test_plot_intensity_box(self):
plot_dict = plot.to_plotly_json()
#  log scale
self.assertEqual(plot_dict.get("layout").get("yaxis").get("type"), "log")
is_boxplot = "boxmode" in plot_dict.get("layout").keys()
is_boxplot = "boxmode" in plot_dict.get("layout")
self.assertTrue(is_boxplot)

def test_plot_intensity_scatter(self):
Expand Down

0 comments on commit 30bfcdd

Please sign in to comment.