Skip to content

Commit

Permalink
Merge pull request #462 from Proteobench/save_raw_input
Browse files Browse the repository at this point in the history
Update quant_base_module.py
  • Loading branch information
RobbinBouwmeester authored Nov 29, 2024
2 parents bc5e96c + 07a4bc5 commit 2b328c2
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions proteobench/modules/quant_base/quant_base_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,7 @@ def write_json_local_development(self, temporary_datapoints: pd.DataFrame, datap

return os.path.join(self.t_dir_pr, "results.json")

def write_intermediate_raw(
self, dir: str, ident: str, input_file_path: str, result_performance: pd.DataFrame, param_loc
):
def write_intermediate_raw(self, dir: str, ident: str, input_file_obj, result_performance: pd.DataFrame, param_loc):
"""
Write intermediate and raw data to a directory.
Expand All @@ -368,8 +366,8 @@ def write_intermediate_raw(
Directory to write to.
ident : str
Identifier (e.g., hash) to create a subdirectory for this submission.
input_file_path : str
Location to temp file of raw-input
input_file_obj : file-like object
File-like object representing the raw input file (e.g., from Streamlit).
result_performance : pd.DataFrame
Result performance DataFrame to be saved.
param_loc : list of str
Expand All @@ -383,8 +381,13 @@ def write_intermediate_raw(
except Exception as e:
logging.warning(f"Could not create directory: {path_write}. Error: {e}")

# Save the input file-like object content to disk
input_file_path = os.path.join(path_write, "input_file_without_extension")
try:
shutil.copy(input_file_path, dir)
input_file_obj.seek(0) # Reset file pointer to the beginning
with open(input_file_path, "wb") as f:
f.write(input_file_obj.read()) # Read the content and write it to a file
logging.info(f"Input file saved to {input_file_path}")
except Exception as e:
logging.error(f"Failed to save input file to {input_file_path}. Error: {e}")

Expand Down

0 comments on commit 2b328c2

Please sign in to comment.