Skip to content

Commit

Permalink
Merge pull request #461 from Proteobench/save_raw_input
Browse files Browse the repository at this point in the history
Change saving from intermediate to raw input
  • Loading branch information
RobbinBouwmeester authored Nov 29, 2024
2 parents 3421d5a + c31e3dd commit bc5e96c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
47 changes: 27 additions & 20 deletions proteobench/modules/quant_base/quant_base_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
import os
import shutil
from tempfile import TemporaryDirectory
from typing import Any, Optional

Expand All @@ -19,15 +20,17 @@
from proteobench.io.params.alphadia import extract_params as extract_params_alphadia
from proteobench.io.params.alphapept import extract_params as extract_params_alphapept
from proteobench.io.params.diann import extract_params as extract_params_diann
from proteobench.io.params.spectronaut import read_spectronaut_settings as extract_params_spectronaut
from proteobench.io.params.fragger import extract_params as extract_params_fragger
from proteobench.io.params.i2masschroq import (
extract_params as extract_params_i2masschroq,
)
from proteobench.io.params.maxquant import extract_params as extract_params_maxquant
from proteobench.io.params.msaid import extract_params as extract_params_msaid
from proteobench.io.params.proline import extract_params as extract_params_proline
from proteobench.io.params.sage import extract_params as extract_params_sage
from proteobench.io.params.msaid import extract_params as extract_params_msaid
from proteobench.io.params.spectronaut import (
read_spectronaut_settings as extract_params_spectronaut,
)
from proteobench.io.parsing.parse_ion import load_input_file
from proteobench.io.parsing.parse_settings_ion import ParseSettingsBuilder
from proteobench.score.quant.quantscores import QuantScores
Expand Down Expand Up @@ -161,8 +164,6 @@ def filter_data_point(all_datapoints: pd.DataFrame, default_val_slider: int = 3)
pd.DataFrame
All data points with the filtered data points.
"""
print(all_datapoints)

all_datapoints["median_abs_epsilon"] = [
filter_df_numquant_median_abs_epsilon(v, min_quant=default_val_slider) for v in all_datapoints["results"]
]
Expand Down Expand Up @@ -355,33 +356,42 @@ 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_df: pd.DataFrame, result_performance, param_loc):
def write_intermediate_raw(
self, dir: str, ident: str, input_file_path: str, result_performance: pd.DataFrame, param_loc
):
"""
Write intermediate and raw data to a directory.
Parameters
----------
dir
dir : str
Directory to write to.
ident
Intermediate hash of the submission.
input_df
Input DataFrame.
result_performance
Result performance DataFrame.
ident : str
Identifier (e.g., hash) to create a subdirectory for this submission.
input_file_path : str
Location to temp file of raw-input
result_performance : pd.DataFrame
Result performance DataFrame to be saved.
param_loc : list of str
List of paths to parameter files that need to be copied to the directory.
"""

# Create the target directory
path_write = os.path.join(dir, ident)
try:
os.mkdir(path_write)
except:
logging.warning(f"Could not make directory: {path_write}")
os.makedirs(path_write, exist_ok=True)
except Exception as e:
logging.warning(f"Could not create directory: {path_write}. Error: {e}")

try:
shutil.copy(input_file_path, dir)
except Exception as e:
logging.error(f"Failed to save input file to {input_file_path}. Error: {e}")

# TODO: save parameters file "locally" together with the raw and intermediate?
with open(os.path.join(path_write, "params.csv"), "w") as f:
with open(os.path.join(path_write, "params_without_extension"), "w") as f:
f.write(",\n".join(_file.getvalue().decode("utf-8") for _file in param_loc))

input_df.to_csv(os.path.join(path_write, "input_df.csv"))
result_performance.to_csv(os.path.join(path_write, "result_performance.csv"))

def load_params_file(self, input_file: list[str], input_format: str) -> ProteoBenchParameters:
Expand All @@ -400,9 +410,6 @@ def load_params_file(self, input_file: list[str], input_format: str) -> ProteoBe
ProteoBenchParameters
Parameters for the module.
"""

# ! adapted to be able to parse more than one file.
# ! how to ensure orrect order?
params = self.EXTRACT_PARAMS_DICT[input_format](*input_file)
params.software_name = input_format
return params
4 changes: 3 additions & 1 deletion webinterface/pages/base_pages/quant.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,13 @@ def save_intermediate_submission_data(self, pr_url: str) -> None:
].iloc[-1, :]["intermediate_hash"]
)

self.user_input["input_csv"].getbuffer()

if "storage" in st.secrets.keys():
self.ionmodule.write_intermediate_raw(
st.secrets["storage"]["dir"],
id,
st.session_state[self.variables_quant.input_df_submission],
self.user_input["input_csv"],
st.session_state[self.variables_quant.result_performance_submission],
self.user_input[self.variables_quant.meta_data],
)
Expand Down

0 comments on commit bc5e96c

Please sign in to comment.