Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linitin rule sim #335

Merged
merged 7 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -414,7 +413,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 @@ -65,13 +65,13 @@ def select_analysis():
with c1:
method = select_analysis()

if method in st.session_state[StateKeys.PLOTTING_OPTIONS].keys():
if method in st.session_state[StateKeys.PLOTTING_OPTIONS]:
analysis_result = get_analysis(
method=method, options_dict=st.session_state[StateKeys.PLOTTING_OPTIONS]
)
plot_to_display = True

elif method in st.session_state[StateKeys.STATISTIC_OPTIONS].keys():
elif method in st.session_state[StateKeys.STATISTIC_OPTIONS]:
analysis_result = get_analysis(
method=method,
options_dict=st.session_state[StateKeys.STATISTIC_OPTIONS],
Expand Down
Empty file added alphastats/gui/pages/05_GPT.py
Empty file.
6 changes: 3 additions & 3 deletions alphastats/gui/utils/analysis_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,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 @@ -202,7 +202,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[StateKeys.DATASET].mat.isna().values.any() == True:
st.error(
"Data contains missing values impute your data before plotting (Preprocessing - Imputation)."
Expand Down Expand Up @@ -346,7 +346,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/gpt_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def get_assistant_functions(
"properties": {
"protein_id": {
"type": "string",
"enum": [i for i in gene_to_prot_id_dict.keys()],
"enum": [i for i in gene_to_prot_id_dict],
"description": "Identifier for the protein of interest",
},
"group": {
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
4 changes: 2 additions & 2 deletions alphastats/gui/utils/uniprot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ def extract_data(data: Dict) -> Dict:
extracted = {}

# 1. Entry Type
extracted["entryType"] = data.get("entryType", None)
extracted["entryType"] = data.get("entryType")

# 2. Primary Accession
extracted["primaryAccession"] = data.get("primaryAccession", None)
extracted["primaryAccession"] = data.get("primaryAccession")

# 3. Organism Details
organism = data.get("organism", {})
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
24 changes: 9 additions & 15 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 @@ -226,16 +223,14 @@ def get_fdr(n_pos, n_false_pos, pi0):
proportion of true null (unaffected) genes in the data set.
"""
n = n_false_pos * pi0

fdr = 0
if n != 0:
if n_pos != 0:
fdr = n / n_pos
else:
fdr = 0
else:
if n_pos > 0:
fdr = 0
else:
fdr = np.nan
elif n_pos <= 0:
fdr = np.nan

return fdr


Expand Down Expand Up @@ -329,10 +324,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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extend-exclude = [".bumpversion.cfg", ".secrets.baseline"]
# # flake8-bugbear
# "B",
# # flake8-simplify
# "SIM",
"SIM",
# isort
"I",
]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_DataSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,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 @@ -827,7 +827,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
Loading