This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Sage-Bionetworks-Workflows/bwmac/ORCA-222/…
…scoring_step [ORCA-222] Adds Rudimentary Scoring Step
- Loading branch information
Showing
6 changed files
with
97 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import json | ||
import os | ||
import sys | ||
|
||
|
||
def score_submission(predictions_path: str, status: str) -> dict: | ||
"""Determine the score of a submission. This is a placeholder function. | ||
Args: | ||
predictions_path (str): path to the predictions file | ||
status (str): current submission status | ||
Returns: | ||
result (dict): dictionary containing score, status and errors | ||
""" | ||
if status == "INVALID": | ||
score_status = "INVALID" | ||
score = None | ||
else: | ||
# placeholder file reading | ||
with open(predictions_path, "r") as sub_file: | ||
predictions_contents = sub_file.read() | ||
try: | ||
# placeholder scoring | ||
score = 1 + 1 | ||
score_status = "SCORED" | ||
message = "" | ||
except Exception as e: | ||
message = f"Error {e} occurred while scoring" | ||
score = None | ||
score_status = "INVALID" | ||
result = { | ||
"score": { | ||
"score_category": "auc", | ||
"score": score, | ||
"status": score_status, | ||
"errors": message, | ||
} | ||
} | ||
return score_status, result | ||
|
||
|
||
def update_json(results_path: str, result: dict) -> None: | ||
"""Update the results.json file with the current score and status | ||
Args: | ||
results_path (str): path to the results.json file | ||
result (dict): dictionary containing score, status and errors | ||
""" | ||
file_size = os.path.getsize(results_path) | ||
with open(results_path, "r") as o: | ||
data = json.load(o) if file_size else {} | ||
data.update(result) | ||
with open(results_path, "w") as o: | ||
o.write(json.dumps(data)) | ||
|
||
|
||
if __name__ == "__main__": | ||
predictions_path = sys.argv[1] | ||
results_path = sys.argv[2] | ||
status = sys.argv[3] | ||
score_status, result = score_submission(predictions_path, status) | ||
update_json(results_path, result) | ||
print(score_status) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// validate submission results | ||
process SCORE { | ||
secret "SYNAPSE_AUTH_TOKEN" | ||
container "python:3.12.0rc1" | ||
|
||
input: | ||
tuple val(submission_id), path(predictions), val(status), path(results) | ||
|
||
output: | ||
tuple val(submission_id), path(predictions), stdout, path("results.json") | ||
|
||
script: | ||
""" | ||
score.py '${predictions}' '${results}' '${status}' | ||
""" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters