From 1b4e47c9d9c2d2f4bf7a4f28f17a78f9f25bc070 Mon Sep 17 00:00:00 2001 From: Mario Picciani Date: Mon, 2 Oct 2023 14:21:13 +0200 Subject: [PATCH] support reading from csv --- oktoberfest/data/spectra.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/oktoberfest/data/spectra.py b/oktoberfest/data/spectra.py index 28b03c77..1566180d 100644 --- a/oktoberfest/data/spectra.py +++ b/oktoberfest/data/spectra.py @@ -211,9 +211,22 @@ def from_hdf5(cls: Type[SpectraT], input_file: Union[str, Path]) -> SpectraT: """ input_file = str(input_file) spectra = cls() - spectra.spectra_data spectra.add_columns(hdf5.read_file(input_file, hdf5.META_DATA_KEY)) spectra.add_matrix_from_hdf5(hdf5.read_file(input_file, f"sparse_{hdf5.INTENSITY_RAW_KEY}"), FragmentType.RAW) spectra.add_matrix_from_hdf5(hdf5.read_file(input_file, f"sparse_{hdf5.MZ_RAW_KEY}"), FragmentType.MZ) return spectra + + @classmethod + def from_csv(cls: Type[SpectraT], input_file: Union[str, Path]) -> SpectraT: + """ + Read from hdf5 file. + + :param input_file: path to input file + :return: a spectra instance + """ + input_file = str(input_file) + spectra = cls() + spectra.spectra_data = pd.read_csv(input_file) + + return spectra