Skip to content
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
13 changes: 9 additions & 4 deletions src/mavedb/routers/score_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,10 +648,15 @@ async def upload_score_set_variant_data(
assert_permission(user_data, item, Action.UPDATE)
assert_permission(user_data, item, Action.SET_SCORES)

scores_df = csv_data_to_df(scores_file.file)
counts_df = None
if counts_file and counts_file.filename:
counts_df = csv_data_to_df(counts_file.file)
try:
scores_df = csv_data_to_df(scores_file.file)
counts_df = None
if counts_file and counts_file.filename:
counts_df = csv_data_to_df(counts_file.file)
# Handle non-utf8 file problem.
except UnicodeDecodeError as e:
raise HTTPException(status_code=400, detail=f"Error decoding file: {e}. Ensure the file has correct values.")


if scores_file:
# Although this is also updated within the variant creation job, update it here
Expand Down
12 changes: 0 additions & 12 deletions tests/routers/counts.csv

This file was deleted.

12 changes: 0 additions & 12 deletions tests/routers/counts_with_different_variants.csv

This file was deleted.

3 changes: 0 additions & 3 deletions tests/routers/counts_with_hgvs_nt_and_pro.csv

This file was deleted.

12 changes: 0 additions & 12 deletions tests/routers/counts_with_score.csv

This file was deleted.

Binary file added tests/routers/data/scores_non_utf8_encoded.csv
Binary file not shown.
12 changes: 0 additions & 12 deletions tests/routers/scores.csv

This file was deleted.

3 changes: 0 additions & 3 deletions tests/routers/scores_hgvs_nt_not_match_pro.csv

This file was deleted.

12 changes: 0 additions & 12 deletions tests/routers/scores_hgvs_pro_has_same_values.csv

This file was deleted.

12 changes: 0 additions & 12 deletions tests/routers/scores_with_duplicate_columns.csv

This file was deleted.

3 changes: 0 additions & 3 deletions tests/routers/scores_with_hgvs_nt_and_pro.csv

This file was deleted.

12 changes: 0 additions & 12 deletions tests/routers/scores_with_invalid_hgvs_nt_prefix.csv

This file was deleted.

12 changes: 0 additions & 12 deletions tests/routers/scores_with_invalid_hgvs_pro_prefix.csv

This file was deleted.

12 changes: 0 additions & 12 deletions tests/routers/scores_with_nan_column_name.csv

This file was deleted.

12 changes: 0 additions & 12 deletions tests/routers/scores_with_string.csv

This file was deleted.

5 changes: 0 additions & 5 deletions tests/routers/scores_without_hgvs_column.csv

This file was deleted.

3 changes: 0 additions & 3 deletions tests/routers/scores_without_score_column.csv

This file was deleted.

20 changes: 20 additions & 0 deletions tests/routers/test_score_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -2089,6 +2089,26 @@ def test_score_set_not_found_for_non_existent_score_set_when_adding_score_calibr
assert "score_calibrations" not in response_data


########################################################################################################################
# Score set upload files
########################################################################################################################

# Not sure why scores_non_utf8_encoded.csv file has a wrong encoding problem, but it's good for this test.
def test_upload_a_non_utf8_file(session, client, setup_router_db, data_files):
experiment = create_experiment(client)
score_set = create_seq_score_set(client, experiment["urn"])
scores_csv_path = data_files / "scores_non_utf8_encoded.csv"
with open(scores_csv_path, "rb") as scores_file:
response = client.post(
f"/api/v1/score-sets/{score_set['urn']}/variants/data",
files={"scores_file": (scores_csv_path.name, scores_file, "text/csv")},
)
assert response.status_code == 400
response_data = response.json()
assert "Error decoding file: 'utf-8' codec can't decode byte 0xdd in position 10: invalid continuation byte. " \
"Ensure the file has correct values." in response_data["detail"]


########################################################################################################################
# Score set download files
########################################################################################################################
Expand Down
Loading