Skip to content

Commit 0899b29

Browse files
authored
Merge pull request #37 from j-andrews7/36-in-app-catch-sample-column-name-not-being-whats-expected-in-uploaded-file
Improve error handling for batch queries
2 parents 1f0cf76 + 7a7a4ef commit 0899b29

File tree

2 files changed

+40
-34
lines changed

2 files changed

+40
-34
lines changed

Diff for: strprofiler/shiny_app/calc_functions.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,9 @@ def _batch_query(
235235
try:
236236
scores = sp.score_query(query=q, reference=r, use_amel=use_amel)
237237
except ZeroDivisionError:
238-
pass
238+
return "No shared markers between query and reference."
239239
except Exception:
240240
return False
241-
242241
# Create dict of scores for each sample comparison.
243242
samp_out = OrderedDict({"Sample": sa})
244243
samp_out.update(scores)

Diff for: strprofiler/shiny_app/shiny_app.py

+39-32
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,37 @@ def notify_modal(marker_list):
9797
)
9898

9999

100+
def notify_modal_malformed_input(marker_list=None):
101+
if marker_list is not None:
102+
message = (
103+
"There was a fatal error in the input file.<br><br>"
104+
"No marker(s) overlap with the loaded database.<br><br>"
105+
"Marker(s): {} are incompatible with the loaded database.<br><br>"
106+
"Adjust input file and retry upload/query.".format(str(marker_list)[1:-1])
107+
)
108+
else:
109+
message = (
110+
"There was a fatal error in the input file.<br><br>"
111+
"Ensure column header: 'Sample' was used.<br><br>"
112+
"Adjust input file and retry upload/query."
113+
)
114+
ui.modal_show(
115+
ui.modal(
116+
ui.div(
117+
{"style": "font-size: 18px"},
118+
ui.HTML(
119+
(
120+
message
121+
)
122+
),
123+
),
124+
title="Batch Query Error",
125+
easy_close=True,
126+
footer=None,
127+
)
128+
)
129+
130+
100131
def notify_non_int():
101132
ui.modal_show(
102133
ui.notification_show(
@@ -793,22 +824,7 @@ def out_batch_df():
793824
try:
794825
return render.DataTable(output_df())
795826
except Exception:
796-
m = ui.modal(
797-
ui.div(
798-
{"style": "font-size: 18px"},
799-
ui.HTML(
800-
(
801-
"There was a fatal error in the query.<br><br>"
802-
"Ensure marker names match expectation, and that"
803-
" no special characters (spaces, etc.) were used in sample names."
804-
)
805-
),
806-
),
807-
title="Batch Query Error",
808-
easy_close=True,
809-
footer=None,
810-
)
811-
ui.modal_show(m)
827+
notify_modal_malformed_input()
812828
return render.DataTable(pd.DataFrame({"Failed Query. Fix Input File": []}))
813829
elif input.search_type_batch() == "Cellosaurus Database (CLASTR)":
814830
with warnings.catch_warnings():
@@ -837,22 +853,7 @@ def batch_query_results():
837853
penta_fix=True,
838854
).to_dict(orient="index")
839855
except Exception:
840-
m = ui.modal(
841-
ui.div(
842-
{"style": "font-size: 18px"},
843-
ui.HTML(
844-
(
845-
"There was a fatal error in the input file.<br><br>"
846-
"Ensure column header: 'Sample' was used.<br><br>"
847-
"Adjust input file and retry upload/query."
848-
)
849-
),
850-
),
851-
title="Batch Query Error",
852-
easy_close=True,
853-
footer=None,
854-
)
855-
ui.modal_show(m)
856+
notify_modal_malformed_input()
856857
return pd.DataFrame({"Failed Query. Fix Input File": []})
857858

858859
ui.remove_ui("#result_selector")
@@ -887,6 +888,11 @@ def batch_query_results():
887888

888889
with reactive.isolate():
889890
if input.search_type_batch() == "STRprofiler Database":
891+
non_overlap_markers = set(query_df[next(iter(query_df))].keys()) - set(markers())
892+
if non_overlap_markers:
893+
notify_modal_malformed_input(non_overlap_markers)
894+
return pd.DataFrame({"Failed Query. Fix Input File": []})
895+
890896
results = _batch_query(
891897
query_df,
892898
str_database(),
@@ -896,6 +902,7 @@ def batch_query_results():
896902
input.mas_q_threshold_batch(),
897903
input.mas_r_threshold_batch(),
898904
)
905+
899906
elif input.search_type_batch() == "Cellosaurus Database (CLASTR)":
900907
clastr_query = [(lambda d: d.update(description=key) or d)(val) for (key, val) in query_df.items()]
901908
malformed_markers = utils.validate_api_markers(query_df[next(iter(query_df))].keys())

0 commit comments

Comments
 (0)