From 7083ed481bb294666d22635c4f290282ad852d6b Mon Sep 17 00:00:00 2001 From: theGreatHerrLebert Date: Sun, 12 Nov 2023 15:39:31 +0100 Subject: [PATCH 01/15] renaming columns for clear join operations --- imspy/imspy/dda.py | 62 +++++++++++++++++++++++++++++++++++++++++-- imspy/imspy/handle.py | 38 -------------------------- 2 files changed, 60 insertions(+), 40 deletions(-) diff --git a/imspy/imspy/dda.py b/imspy/imspy/dda.py index e420fbe5..3ac3734d 100644 --- a/imspy/imspy/dda.py +++ b/imspy/imspy/dda.py @@ -1,11 +1,69 @@ -import numpy as np +from .handle import TimsDataset import pandas as pd import imspy_connector as pims - from imspy.frame import TimsFrame +class TimsDatasetDDA(TimsDataset): + + def __init__(self, data_path: str): + super().__init__(data_path=data_path) + self.__dataset = pims.PyTimsDatasetDDA(self.data_path, self.binary_path) + self.meta_data = self.meta_data.rename(columns={"Id": "frame_id"}) + self.fragmented_precursors = self._load_selected_precursors().rename( + columns={ + 'Id': 'precursor_id', + 'LargestPeakMz': 'largest_peak_mz', + 'AverageMz': 'average_mz', + 'MonoisotopicMz': 'monoisotopic_mz', + 'Charge': 'charge', + 'ScanNumber': 'average_scan', + 'Intensity': 'intensity', + 'Parent': 'frame_id', + } + ) + self.pasef_meta_data = self._load_pasef_meta_data().rename( + columns={ + 'Frame': 'frame_id', + 'ScanNumBegin': 'scan_begin', + 'ScanNumEnd': 'scan_end', + 'IsolationMz': 'isolation_mz', + 'IsolationWidth': 'isolation_width', + 'CollisionEnergy': 'collision_energy', + 'Precursor': 'precursor_id' + } + ) + + def _load_selected_precursors(self): + """Get precursors selected for fragmentation. + + Returns: + pd.DataFrame: Precursors selected for fragmentation. + """ + return pd.read_sql_query("SELECT * from Precursors", sqlite3.connect(self.data_path + "/analysis.tdf")) + + def _load_pasef_meta_data(self): + """Get PASEF meta data for DDA. + + Returns: + pd.DataFrame: PASEF meta data. + """ + return pd.read_sql_query("SELECT * from PasefFrameMsMsInfo", + sqlite3.connect(self.data_path + "/analysis.tdf")) + + def get_pasef_fragments(self) -> pd.DataFrame: + """Get PASEF fragments. + + Args: + num_threads (int, optional): Number of threads. Defaults to 4. + + Returns: + List[FragmentDDA]: List of PASEF fragments. + """ + pasef_fragments = [FragmentDDA.from_py_tims_fragment_dda(fragment) + for fragment in self.__dataset.get_pasef_fragments(1)] + class FragmentDDA: def __init__(self, frame_id: int, precursor_id: int, selected_fragment: TimsFrame): self._fragment_ptr = pims.PyTimsFragmentDDA(frame_id, precursor_id, selected_fragment.get_fragment_ptr()) diff --git a/imspy/imspy/handle.py b/imspy/imspy/handle.py index d5ee7bd6..953d77af 100644 --- a/imspy/imspy/handle.py +++ b/imspy/imspy/handle.py @@ -122,44 +122,6 @@ def __getitem__(self, index): return self.get_tims_frame(index) -class TimsDatasetDDA(TimsDataset): - - def __init__(self, data_path: str): - super().__init__(data_path=data_path) - self.__dataset = pims.PyTimsDatasetDDA(self.data_path, self.binary_path) - - @property - def selected_precursors(self): - """Get precursors selected for fragmentation. - - Returns: - pd.DataFrame: Precursors selected for fragmentation. - """ - return pd.read_sql_query("SELECT * from Precursors", sqlite3.connect(self.data_path + "/analysis.tdf")) - - @property - def pasef_meta_data(self): - """Get PASEF meta data for DDA. - - Returns: - pd.DataFrame: PASEF meta data. - """ - return pd.read_sql_query("SELECT * from PasefFrameMsMsInfo", - sqlite3.connect(self.data_path + "/analysis.tdf")) - - def get_pasef_fragments(self): - """Get PASEF fragments. - - Args: - num_threads (int, optional): Number of threads. Defaults to 4. - - Returns: - List[FragmentDDA]: List of PASEF fragments. - """ - pasef_fragments = self.__dataset.get_pasef_fragments(1) - return [FragmentDDA.from_py_tims_fragment_dda(fragment) for fragment in pasef_fragments] - - class TimsDatasetDIA(TimsDataset): def __init__(self, data_path: str): super().__init__(data_path=data_path) From b0507688b223c26d7bbd327bcecd2dfaef2e9779 Mon Sep 17 00:00:00 2001 From: theGreatHerrLebert Date: Sun, 12 Nov 2023 15:42:33 +0100 Subject: [PATCH 02/15] fixing export --- imspy/imspy/data.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/imspy/imspy/data.py b/imspy/imspy/data.py index d2674bc8..2c5fc2bc 100644 --- a/imspy/imspy/data.py +++ b/imspy/imspy/data.py @@ -1,4 +1,5 @@ from .frame import TimsFrame from .spectrum import TimsSpectrum, MzSpectrum -from .handle import TimsDataset, TimsDatasetDDA, TimsDatasetDIA +from .handle import TimsDataset, TimsDatasetDIA from .slice import TimsSlice, TimsSliceVectorized +from .dda import TimsDatasetDDA, FragmentDDA From b44b03a32fd2d6a3347cb40105e7cdee30871eb2 Mon Sep 17 00:00:00 2001 From: theGreatHerrLebert Date: Sun, 12 Nov 2023 15:46:40 +0100 Subject: [PATCH 03/15] fixing name space clash --- imspy/imspy/core.py | 6 ++ imspy/imspy/data.py | 127 ++++++++++++++++++++++++++++++++++++-- imspy/imspy/dda.py | 2 +- imspy/imspy/dia.py | 20 ++++++ imspy/imspy/handle.py | 138 ------------------------------------------ 5 files changed, 149 insertions(+), 144 deletions(-) create mode 100644 imspy/imspy/core.py create mode 100644 imspy/imspy/dia.py delete mode 100644 imspy/imspy/handle.py diff --git a/imspy/imspy/core.py b/imspy/imspy/core.py new file mode 100644 index 00000000..12828afd --- /dev/null +++ b/imspy/imspy/core.py @@ -0,0 +1,6 @@ +from imspy.frame import TimsFrame +from imspy.spectrum import TimsSpectrum, MzSpectrum +from imspy.data import TimsDataset +from imspy.dia import TimsDatasetDIA +from imspy.slice import TimsSlice, TimsSliceVectorized +from imspy.dda import TimsDatasetDDA, FragmentDDA diff --git a/imspy/imspy/data.py b/imspy/imspy/data.py index 2c5fc2bc..ac66e775 100644 --- a/imspy/imspy/data.py +++ b/imspy/imspy/data.py @@ -1,5 +1,122 @@ -from .frame import TimsFrame -from .spectrum import TimsSpectrum, MzSpectrum -from .handle import TimsDataset, TimsDatasetDIA -from .slice import TimsSlice, TimsSliceVectorized -from .dda import TimsDatasetDDA, FragmentDDA +from typing import List + +import numpy as np +import pandas as pd +import sqlite3 +from numpy.typing import NDArray + +import imspy_connector as pims +import opentims_bruker_bridge as obb + +from abc import ABC + +from imspy.dda import FragmentDDA +from imspy.frame import TimsFrame +from imspy.slice import TimsSlice + + +class TimsDataset(ABC): + def __init__(self, data_path: str): + """TimsDataHandle class. + + Args: + data_path (str): Path to the data. + """ + self.__dataset = None + self.binary_path = None + + self.data_path = data_path + self.meta_data = self.__load_meta_data() + self.precursor_frames = self.meta_data[self.meta_data["MsMsType"] == 0].Id.values.astype(np.int32) + self.fragment_frames = self.meta_data[self.meta_data["MsMsType"] > 0].Id.values.astype(np.int32) + self.__current_index = 1 + + # Try to load the data with the first binary found + appropriate_found = False + for so_path in obb.get_so_paths(): + try: + self.__dataset = pims.PyTimsDataset(self.data_path, so_path) + self.binary_path = so_path + appropriate_found = True + break + except Exception: + continue + assert appropriate_found is True, ("No appropriate bruker binary could be found, please check if your " + "operating system is supported by open-tims-bruker-bridge.") + + @property + def acquisition_mode(self) -> str: + """Get the acquisition mode. + + Returns: + str: Acquisition mode. + """ + return self.__dataset.get_acquisition_mode_as_string() + + @property + def acquisition_mode_numerical(self) -> int: + """Get the acquisition mode as a numerical value. + + Returns: + int: Acquisition mode as a numerical value. + """ + return self.__dataset.get_acquisition_mode() + + @property + def frame_count(self) -> int: + """Get the number of frames. + + Returns: + int: Number of frames. + """ + return self.__dataset.frame_count + + def __load_meta_data(self) -> pd.DataFrame: + """Get the meta data. + + Returns: + pd.DataFrame: Meta data. + """ + return pd.read_sql_query("SELECT * from Frames", sqlite3.connect(self.data_path + "/analysis.tdf")) + + def get_tims_frame(self, frame_id: int) -> TimsFrame: + """Get a TimsFrame. + + Args: + frame_id (int): Frame ID. + + Returns: + TimsFrame: TimsFrame. + """ + return TimsFrame.from_py_tims_frame(self.__dataset.get_frame(frame_id)) + + def get_tims_slice(self, frame_ids: NDArray[np.int32]) -> TimsSlice: + """Get a TimsFrame. + + Args: + frame_ids (int): Frame ID. + + Returns: + TimsFrame: TimsFrame. + """ + return TimsSlice.from_py_tims_slice(self.__dataset.get_slice(frame_ids)) + + def __iter__(self): + return self + + def __next__(self): + if self.__current_index <= self.frame_count: + frame_ptr = self.__dataset.get_frame(self.__current_index) + self.__current_index += 1 + if frame_ptr is not None: + return TimsFrame.from_py_tims_frame(frame_ptr) + else: + raise ValueError(f"Frame pointer is None for valid index: {self.__current_index}") + else: + self.__current_index = 1 # Reset for next iteration + raise StopIteration + + def __getitem__(self, index): + if isinstance(index, slice): + return self.get_tims_slice(np.arange(index.start, index.stop, index.step).astype(np.int32)) + return self.get_tims_frame(index) diff --git a/imspy/imspy/dda.py b/imspy/imspy/dda.py index 3ac3734d..8c99a4a8 100644 --- a/imspy/imspy/dda.py +++ b/imspy/imspy/dda.py @@ -1,4 +1,4 @@ -from .handle import TimsDataset +from .data import TimsDataset import pandas as pd import imspy_connector as pims diff --git a/imspy/imspy/dia.py b/imspy/imspy/dia.py new file mode 100644 index 00000000..5a2f940d --- /dev/null +++ b/imspy/imspy/dia.py @@ -0,0 +1,20 @@ +from .data import TimsDataset +import pandas as pd + +import imspy_connector as pims + + +class TimsDatasetDIA(TimsDataset): + def __init__(self, data_path: str): + super().__init__(data_path=data_path) + self.__dataset = pims.PyTimsDatasetDIA(self.data_path, self.binary_path) + + @property + def pasef_meta_data(self): + """Get PASEF meta data for DIA. + + Returns: + pd.DataFrame: PASEF meta data. + """ + return pd.read_sql_query("SELECT * from DiaFrameMsMsWindows", + sqlite3.connect(self.data_path + "/analysis.tdf")) diff --git a/imspy/imspy/handle.py b/imspy/imspy/handle.py deleted file mode 100644 index 953d77af..00000000 --- a/imspy/imspy/handle.py +++ /dev/null @@ -1,138 +0,0 @@ -from typing import List - -import numpy as np -import pandas as pd -import sqlite3 -from numpy.typing import NDArray - -import imspy_connector as pims -import opentims_bruker_bridge as obb - -from abc import ABC - -from imspy.dda import FragmentDDA -from imspy.frame import TimsFrame -from imspy.slice import TimsSlice - - -class TimsDataset(ABC): - def __init__(self, data_path: str): - """TimsDataHandle class. - - Args: - data_path (str): Path to the data. - """ - self.__dataset = None - self.binary_path = None - - self.data_path = data_path - self.meta_data = self.__load_meta_data() - self.precursor_frames = self.meta_data[self.meta_data["MsMsType"] == 0].Id.values.astype(np.int32) - self.fragment_frames = self.meta_data[self.meta_data["MsMsType"] > 0].Id.values.astype(np.int32) - self.__current_index = 1 - - # Try to load the data with the first binary found - appropriate_found = False - for so_path in obb.get_so_paths(): - try: - self.__dataset = pims.PyTimsDataset(self.data_path, so_path) - self.binary_path = so_path - appropriate_found = True - break - except Exception: - continue - assert appropriate_found is True, ("No appropriate bruker binary could be found, please check if your " - "operating system is supported by open-tims-bruker-bridge.") - - @property - def acquisition_mode(self) -> str: - """Get the acquisition mode. - - Returns: - str: Acquisition mode. - """ - return self.__dataset.get_acquisition_mode_as_string() - - @property - def acquisition_mode_numerical(self) -> int: - """Get the acquisition mode as a numerical value. - - Returns: - int: Acquisition mode as a numerical value. - """ - return self.__dataset.get_acquisition_mode() - - @property - def frame_count(self) -> int: - """Get the number of frames. - - Returns: - int: Number of frames. - """ - return self.__dataset.frame_count - - def __load_meta_data(self) -> pd.DataFrame: - """Get the meta data. - - Returns: - pd.DataFrame: Meta data. - """ - return pd.read_sql_query("SELECT * from Frames", sqlite3.connect(self.data_path + "/analysis.tdf")) - - def get_tims_frame(self, frame_id: int) -> TimsFrame: - """Get a TimsFrame. - - Args: - frame_id (int): Frame ID. - - Returns: - TimsFrame: TimsFrame. - """ - return TimsFrame.from_py_tims_frame(self.__dataset.get_frame(frame_id)) - - def get_tims_slice(self, frame_ids: NDArray[np.int32]) -> TimsSlice: - """Get a TimsFrame. - - Args: - frame_ids (int): Frame ID. - - Returns: - TimsFrame: TimsFrame. - """ - return TimsSlice.from_py_tims_slice(self.__dataset.get_slice(frame_ids)) - - def __iter__(self): - return self - - def __next__(self): - if self.__current_index <= self.frame_count: - frame_ptr = self.__dataset.get_frame(self.__current_index) - self.__current_index += 1 - if frame_ptr is not None: - return TimsFrame.from_py_tims_frame(frame_ptr) - else: - raise ValueError(f"Frame pointer is None for valid index: {self.__current_index}") - else: - self.__current_index = 1 # Reset for next iteration - raise StopIteration - - def __getitem__(self, index): - if isinstance(index, slice): - return self.get_tims_slice(np.arange(index.start, index.stop, index.step).astype(np.int32)) - return self.get_tims_frame(index) - - -class TimsDatasetDIA(TimsDataset): - def __init__(self, data_path: str): - super().__init__(data_path=data_path) - self.__dataset = pims.PyTimsDatasetDIA(self.data_path, self.binary_path) - - @property - def pasef_meta_data(self): - """Get PASEF meta data for DIA. - - Returns: - pd.DataFrame: PASEF meta data. - """ - return pd.read_sql_query("SELECT * from DiaFrameMsMsWindows", - sqlite3.connect(self.data_path + "/analysis.tdf")) From 3e7e12a5776ebf56f259e3d624251bd197ef3666 Mon Sep 17 00:00:00 2001 From: theGreatHerrLebert Date: Sun, 12 Nov 2023 15:48:47 +0100 Subject: [PATCH 04/15] fixing circular deps --- imspy/imspy/data.py | 1 - imspy/imspy/dda.py | 2 +- imspy/imspy/dia.py | 2 +- imspy/imspy/mixture.py | 3 --- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/imspy/imspy/data.py b/imspy/imspy/data.py index ac66e775..fa7e2f3b 100644 --- a/imspy/imspy/data.py +++ b/imspy/imspy/data.py @@ -10,7 +10,6 @@ from abc import ABC -from imspy.dda import FragmentDDA from imspy.frame import TimsFrame from imspy.slice import TimsSlice diff --git a/imspy/imspy/dda.py b/imspy/imspy/dda.py index 8c99a4a8..ff5d095e 100644 --- a/imspy/imspy/dda.py +++ b/imspy/imspy/dda.py @@ -1,4 +1,4 @@ -from .data import TimsDataset +from imspy.data import TimsDataset import pandas as pd import imspy_connector as pims diff --git a/imspy/imspy/dia.py b/imspy/imspy/dia.py index 5a2f940d..df74969e 100644 --- a/imspy/imspy/dia.py +++ b/imspy/imspy/dia.py @@ -1,4 +1,4 @@ -from .data import TimsDataset +from imspy.data import TimsDataset import pandas as pd import imspy_connector as pims diff --git a/imspy/imspy/mixture.py b/imspy/imspy/mixture.py index a2e82e68..7942a8f9 100644 --- a/imspy/imspy/mixture.py +++ b/imspy/imspy/mixture.py @@ -1,6 +1,3 @@ -import os -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf import numpy as np import tensorflow_probability as tfp From e4119188bf53a39969b4cf549a1da1e19a41d78e Mon Sep 17 00:00:00 2001 From: theGreatHerrLebert Date: Sun, 12 Nov 2023 15:51:02 +0100 Subject: [PATCH 05/15] fixing --- imspy/imspy/data.py | 2 -- imspy/imspy/dda.py | 1 + imspy/imspy/dia.py | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/imspy/imspy/data.py b/imspy/imspy/data.py index fa7e2f3b..2e5b1e96 100644 --- a/imspy/imspy/data.py +++ b/imspy/imspy/data.py @@ -1,5 +1,3 @@ -from typing import List - import numpy as np import pandas as pd import sqlite3 diff --git a/imspy/imspy/dda.py b/imspy/imspy/dda.py index ff5d095e..b9dd2143 100644 --- a/imspy/imspy/dda.py +++ b/imspy/imspy/dda.py @@ -1,3 +1,4 @@ +import sqlite3 from imspy.data import TimsDataset import pandas as pd diff --git a/imspy/imspy/dia.py b/imspy/imspy/dia.py index df74969e..2d376f84 100644 --- a/imspy/imspy/dia.py +++ b/imspy/imspy/dia.py @@ -1,3 +1,4 @@ +import sqlite3 from imspy.data import TimsDataset import pandas as pd From cb4e11a6b7854ead47c8a211a6ae8d8e57129588 Mon Sep 17 00:00:00 2001 From: theGreatHerrLebert Date: Sun, 12 Nov 2023 16:05:58 +0100 Subject: [PATCH 06/15] adding meta data to return of pasef fragments --- imspy/imspy/dda.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/imspy/imspy/dda.py b/imspy/imspy/dda.py index b9dd2143..aff7a432 100644 --- a/imspy/imspy/dda.py +++ b/imspy/imspy/dda.py @@ -62,9 +62,29 @@ def get_pasef_fragments(self) -> pd.DataFrame: Returns: List[FragmentDDA]: List of PASEF fragments. """ + + time = self.meta_data[['frame_id']] + time.insert(time.shape[1], "time", self.meta_data['Time'] / 60) + pasef_fragments = [FragmentDDA.from_py_tims_fragment_dda(fragment) for fragment in self.__dataset.get_pasef_fragments(1)] + pasef_fragments = pd.DataFrame({ + 'frame_id': [s.frame_id for s in pasef_fragments], + 'precursor_id': [s.precursor_id for s in pasef_fragments], + 'raw_data': [s.selected_fragment for s in pasef_fragments] + }) + + tmp = pd.merge( + pasef_fragments, self.pasef_meta_data, + left_on=['precursor_id', 'frame_id'], + right_on=['precursor_id', 'frame_id'], + how='inner', + ) + tmp = pd.merge(tmp, self.precursor_frames, left_on=['precursor_id'], right_on=['precursor_id'], how='inner') + return pd.merge(time, tmp, left_on=['frame_id'], right_on=['frame_id'], how='inner') + + class FragmentDDA: def __init__(self, frame_id: int, precursor_id: int, selected_fragment: TimsFrame): self._fragment_ptr = pims.PyTimsFragmentDDA(frame_id, precursor_id, selected_fragment.get_fragment_ptr()) From 1515fb93ec3ff0664ccd595033c773b49caa6696 Mon Sep 17 00:00:00 2001 From: theGreatHerrLebert Date: Sun, 12 Nov 2023 16:08:23 +0100 Subject: [PATCH 07/15] adding meta data to return of pasef fragments --- imspy/imspy/dda.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imspy/imspy/dda.py b/imspy/imspy/dda.py index aff7a432..aec8a71b 100644 --- a/imspy/imspy/dda.py +++ b/imspy/imspy/dda.py @@ -81,7 +81,7 @@ def get_pasef_fragments(self) -> pd.DataFrame: right_on=['precursor_id', 'frame_id'], how='inner', ) - tmp = pd.merge(tmp, self.precursor_frames, left_on=['precursor_id'], right_on=['precursor_id'], how='inner') + tmp = pd.merge(tmp, self.fragmented_precursors, left_on=['precursor_id'], right_on=['precursor_id'], how='inner') return pd.merge(time, tmp, left_on=['frame_id'], right_on=['frame_id'], how='inner') From 6ac93c77e72ac2a5927097da4595d35d5101232a Mon Sep 17 00:00:00 2001 From: theGreatHerrLebert Date: Sun, 12 Nov 2023 16:14:25 +0100 Subject: [PATCH 08/15] adding meta data to return of pasef fragments --- imspy/imspy/dda.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/imspy/imspy/dda.py b/imspy/imspy/dda.py index aec8a71b..6ac26322 100644 --- a/imspy/imspy/dda.py +++ b/imspy/imspy/dda.py @@ -62,10 +62,6 @@ def get_pasef_fragments(self) -> pd.DataFrame: Returns: List[FragmentDDA]: List of PASEF fragments. """ - - time = self.meta_data[['frame_id']] - time.insert(time.shape[1], "time", self.meta_data['Time'] / 60) - pasef_fragments = [FragmentDDA.from_py_tims_fragment_dda(fragment) for fragment in self.__dataset.get_pasef_fragments(1)] @@ -81,7 +77,17 @@ def get_pasef_fragments(self) -> pd.DataFrame: right_on=['precursor_id', 'frame_id'], how='inner', ) - tmp = pd.merge(tmp, self.fragmented_precursors, left_on=['precursor_id'], right_on=['precursor_id'], how='inner') + + tmp = pd.merge( + tmp, self.fragmented_precursors, + left_on=['precursor_id', 'frame_id'], + right_on=['precursor_id', 'frame_id'], + how='inner' + ) + + time = self.meta_data[['frame_id']] + time.insert(time.shape[1], "time", self.meta_data['Time'] / 60) + return pd.merge(time, tmp, left_on=['frame_id'], right_on=['frame_id'], how='inner') From 8a7b8d313cb84e3bf87979be1767c0fcfde9ccb2 Mon Sep 17 00:00:00 2001 From: theGreatHerrLebert Date: Sun, 12 Nov 2023 16:17:52 +0100 Subject: [PATCH 09/15] adding meta data to return of pasef fragments --- imspy/imspy/dda.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/imspy/imspy/dda.py b/imspy/imspy/dda.py index 6ac26322..36eb6013 100644 --- a/imspy/imspy/dda.py +++ b/imspy/imspy/dda.py @@ -71,6 +71,9 @@ def get_pasef_fragments(self) -> pd.DataFrame: 'raw_data': [s.selected_fragment for s in pasef_fragments] }) + return pasef_fragments + + """ tmp = pd.merge( pasef_fragments, self.pasef_meta_data, left_on=['precursor_id', 'frame_id'], @@ -89,6 +92,7 @@ def get_pasef_fragments(self) -> pd.DataFrame: time.insert(time.shape[1], "time", self.meta_data['Time'] / 60) return pd.merge(time, tmp, left_on=['frame_id'], right_on=['frame_id'], how='inner') + """ class FragmentDDA: From 11e4077f86d4bb1313dfa730616f83ac05c465d7 Mon Sep 17 00:00:00 2001 From: theGreatHerrLebert Date: Sun, 12 Nov 2023 16:24:46 +0100 Subject: [PATCH 10/15] adding meta data to return of pasef fragments --- imspy/imspy/dda.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/imspy/imspy/dda.py b/imspy/imspy/dda.py index 36eb6013..957d14fd 100644 --- a/imspy/imspy/dda.py +++ b/imspy/imspy/dda.py @@ -71,9 +71,6 @@ def get_pasef_fragments(self) -> pd.DataFrame: 'raw_data': [s.selected_fragment for s in pasef_fragments] }) - return pasef_fragments - - """ tmp = pd.merge( pasef_fragments, self.pasef_meta_data, left_on=['precursor_id', 'frame_id'], @@ -81,7 +78,7 @@ def get_pasef_fragments(self) -> pd.DataFrame: how='inner', ) - tmp = pd.merge( + tmp2 = pd.merge( tmp, self.fragmented_precursors, left_on=['precursor_id', 'frame_id'], right_on=['precursor_id', 'frame_id'], @@ -91,8 +88,7 @@ def get_pasef_fragments(self) -> pd.DataFrame: time = self.meta_data[['frame_id']] time.insert(time.shape[1], "time", self.meta_data['Time'] / 60) - return pd.merge(time, tmp, left_on=['frame_id'], right_on=['frame_id'], how='inner') - """ + return pd.merge(time, tmp2, left_on=['frame_id'], right_on=['frame_id'], how='inner') class FragmentDDA: From 6cf3a7683ab65a82253abb5a7a9866093193980e Mon Sep 17 00:00:00 2001 From: theGreatHerrLebert Date: Sun, 12 Nov 2023 16:26:31 +0100 Subject: [PATCH 11/15] adding meta data to return of pasef fragments --- imspy/imspy/dda.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/imspy/imspy/dda.py b/imspy/imspy/dda.py index 957d14fd..9dc88a84 100644 --- a/imspy/imspy/dda.py +++ b/imspy/imspy/dda.py @@ -71,6 +71,9 @@ def get_pasef_fragments(self) -> pd.DataFrame: 'raw_data': [s.selected_fragment for s in pasef_fragments] }) + return pasef_fragments + + """ tmp = pd.merge( pasef_fragments, self.pasef_meta_data, left_on=['precursor_id', 'frame_id'], @@ -89,7 +92,8 @@ def get_pasef_fragments(self) -> pd.DataFrame: time.insert(time.shape[1], "time", self.meta_data['Time'] / 60) return pd.merge(time, tmp2, left_on=['frame_id'], right_on=['frame_id'], how='inner') - + """ + class FragmentDDA: def __init__(self, frame_id: int, precursor_id: int, selected_fragment: TimsFrame): From f494ea3a727249d5040da62a92c51ba3e132c0c5 Mon Sep 17 00:00:00 2001 From: theGreatHerrLebert Date: Sun, 12 Nov 2023 16:31:07 +0100 Subject: [PATCH 12/15] adding meta data to return of pasef fragments --- imspy/imspy/dda.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imspy/imspy/dda.py b/imspy/imspy/dda.py index 9dc88a84..e11408ab 100644 --- a/imspy/imspy/dda.py +++ b/imspy/imspy/dda.py @@ -21,7 +21,7 @@ def __init__(self, data_path: str): 'Charge': 'charge', 'ScanNumber': 'average_scan', 'Intensity': 'intensity', - 'Parent': 'frame_id', + 'Parent': 'parent_id', } ) self.pasef_meta_data = self._load_pasef_meta_data().rename( @@ -93,7 +93,7 @@ def get_pasef_fragments(self) -> pd.DataFrame: return pd.merge(time, tmp2, left_on=['frame_id'], right_on=['frame_id'], how='inner') """ - + class FragmentDDA: def __init__(self, frame_id: int, precursor_id: int, selected_fragment: TimsFrame): From 7c4c184e7ed7aff52716443e4110b4a0cbffa6b3 Mon Sep 17 00:00:00 2001 From: theGreatHerrLebert Date: Sun, 12 Nov 2023 16:34:58 +0100 Subject: [PATCH 13/15] adding meta data to return of pasef fragments --- imspy/imspy/dda.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/imspy/imspy/dda.py b/imspy/imspy/dda.py index e11408ab..09978e66 100644 --- a/imspy/imspy/dda.py +++ b/imspy/imspy/dda.py @@ -71,28 +71,24 @@ def get_pasef_fragments(self) -> pd.DataFrame: 'raw_data': [s.selected_fragment for s in pasef_fragments] }) - return pasef_fragments - - """ - tmp = pd.merge( + A = pd.merge( pasef_fragments, self.pasef_meta_data, left_on=['precursor_id', 'frame_id'], right_on=['precursor_id', 'frame_id'], how='inner', ) - tmp2 = pd.merge( - tmp, self.fragmented_precursors, - left_on=['precursor_id', 'frame_id'], - right_on=['precursor_id', 'frame_id'], + B = pd.merge( + A, self.fragmented_precursors, + left_on=['precursor_id'], + right_on=['precursor_id'], how='inner' ) time = self.meta_data[['frame_id']] time.insert(time.shape[1], "time", self.meta_data['Time'] / 60) - return pd.merge(time, tmp2, left_on=['frame_id'], right_on=['frame_id'], how='inner') - """ + return pd.merge(time, B, left_on=['frame_id'], right_on=['frame_id'], how='inner') class FragmentDDA: From 2ba0d98bfbe694a175ba16f408c4fd2fe9153b13 Mon Sep 17 00:00:00 2001 From: theGreatHerrLebert Date: Sun, 12 Nov 2023 17:31:42 +0100 Subject: [PATCH 14/15] off by one on scan select in PASEF data --- rustdf/src/data/dda.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rustdf/src/data/dda.rs b/rustdf/src/data/dda.rs index 19a5f181..9521f099 100644 --- a/rustdf/src/data/dda.rs +++ b/rustdf/src/data/dda.rs @@ -51,7 +51,8 @@ impl TimsDatasetDDA { 0.0, 2000.0, pasef_info.scan_num_begin as i32, - pasef_info.scan_num_end as i32, + // TODO: +1? + pasef_info.scan_num_end as i32 + 1, 0.0, 5.0, 0.0, From 0b56957071906fc425cfed576f6b8d684e2cc240 Mon Sep 17 00:00:00 2001 From: theGreatHerrLebert Date: Sun, 12 Nov 2023 17:37:01 +0100 Subject: [PATCH 15/15] checking plus one on scan --- rustdf/src/data/dda.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rustdf/src/data/dda.rs b/rustdf/src/data/dda.rs index 9521f099..45519d40 100644 --- a/rustdf/src/data/dda.rs +++ b/rustdf/src/data/dda.rs @@ -51,7 +51,7 @@ impl TimsDatasetDDA { 0.0, 2000.0, pasef_info.scan_num_begin as i32, - // TODO: +1? + // TODO: check if this is correct pasef_info.scan_num_end as i32 + 1, 0.0, 5.0,