pyTDFSDK package¶
Submodules¶
pyTDFSDK.classes module¶
- class pyTDFSDK.classes.TdfData(bruker_d_folder_name: str, tdf_sdk, use_recalibrated_state=True, pressure_compensation_strategy=PressureCompensationStrategy.AnalyisGlobalPressureCompensation, sql_chunksize=1000)¶
Bases:
object
Class containing metadata from TDF files and methods from TDF-SDK library to work with TDF format data.
- Parameters:
bruker_d_folder_name (str) – Path to a Bruker .d directory containing analysis.tdf.
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
use_recalibrated_state (bool) – Whether to use recalibrated data (True) or not (False), defaults to True.
pressure_compensation_strategy (enum.Enum) – Pressure compensation when opening TDF data (pyTDFSDK.ctypes_data_structures.PressureCompensationStrategy.NoPressureCompensation = None, pyTDFSDK.ctypes_data_structures.PressureCompensationStrategy.AnalyisGlobalPressureCompensation = analysis global pressure compensation, pyTDFSDK.ctypes_data_structures.PressureCompensationStrategy.PerFramePressureCompensation = per frame pressure compensation), defaults to Global Pressure Compensation.
sql_chunksize (int) – Number of rows to read from SQL database query at once when reading tables/views from analysis.tdf.
- close_sql_connection()¶
Close the connection to analysis.tdf.
- get_db_tables(sql_chunksize=1000)¶
Get a dictionary of all tables found in the analysis.tdf SQLite database in which the table names act as keys and the tables as a pandas.DataFrame of values; this is stored in pyTDFSDK.classes.TdfData.analysis.
- Parameters:
sql_chunksize (int) – Number of rows to read from SQL database query at once when reading tables/views from analysis.tdf.
- class pyTDFSDK.classes.TdfSpectrum(tdf_data, frame: int, mode: str, precursor=0, diapasef_window=None, profile_bins=0, mz_encoding=64, intensity_encoding=64, mobility_encoding=64, exclude_mobility=False)¶
Bases:
object
Class for parsing and storing spectrum metadata and data arrays from TDF format data.
- Parameters:
tdf_data (pyTDFSDK.classes.TdfData) – TdfData object containing metadata from analysis.tdf database.
frame (int) – ID of the frame of interest.
mode (str) – Data array mode, either “profile”, “centroid”, or “raw”.
precursor (int) – ID of the precursor of interest for ddaPASEF data. If specified, overrides the frame ID during data parsing.
diapasef_window (dict) – Dictionary containing a row of metadata from the pyTDFSDK.classesTdfData.analysis[‘DiaFrameMsMsWindows’] table required for parsing diaPASEF data.
profile_bins (int) – Number of bins to bin spectrum to.
mz_encoding (int) – m/z encoding command line parameter, either “64” or “32”.
intensity_encoding (int) – Intensity encoding command line parameter, either “64” or “32”.
mobility_encoding (int) – Mobility encoding command line parameter, either “64” or “32”.
- get_ddapasef_precursor_data()¶
- get_lcms_tdf_data()¶
- get_maldi_tdf_data()¶
- class pyTDFSDK.classes.TsfData(bruker_d_folder_name: str, tdf_sdk, use_recalibrated_state=True, sql_chunksize=1000)¶
Bases:
object
Class containing metadata from TSF files and methods from TDF-SDK library to work with TSF format data.
- Parameters:
bruker_d_folder_name (str) – Path to a Bruker .d directory containing analysis.tsf.
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
use_recalibrated_state (bool) – Whether to use recalibrated data (True) or not (False), defaults to True.
sql_chunksize (int) – Number of rows to read from SQL database query at once when reading tables/views from analysis.tsf.
- close_sql_connection()¶
Close the connection to analysis.tsf.
- get_db_tables(sql_chunksize=1000)¶
Get a dictionary of all tables found in the analysis.tsf SQLite database in which the table names act as keys and the tables as a pandas.DataFrame of values; this is stored in pyTDFSDK.classes.TsfData.analysis.
- Parameters:
sql_chunksize (int) – Number of rows to read from SQL database query at once when reading tables/views from analysis.tsf.
- class pyTDFSDK.classes.TsfSpectrum(tsf_data, frame: int, mode: str, profile_bins=0, mz_encoding=64, intensity_encoding=64)¶
Bases:
object
Class for parsing and storing spectrum metadata and data arrays from TSF format data.
- Parameters:
tsf_data (pyTDFSDK.classes.TsfData) – TsfData object containing metadata from analysis.tsf database.
frame (int) – ID of the frame of interest.
mode (str) – Data array mode, either “profile”, “centroid”, or “raw”.
profile_bins (int) – Number of bins to bin spectrum to.
mz_encoding (int) – m/z encoding command line parameter, either “64” or “32”.
intensity_encoding (int) – Intensity encoding command line parameter, either “64” or “32”.
- get_lcms_tsf_data()¶
- get_maldi_tsf_data()¶
pyTDFSDK.ctypes_data_structures module¶
- class pyTDFSDK.ctypes_data_structures.ChromatogramJob¶
Bases:
Structure
ctypes.Structure to hold chromatogram job information.
- id¶
Structure/Union member
- mz_max¶
Structure/Union member
- mz_min¶
Structure/Union member
- ook0_max¶
Structure/Union member
- ook0_min¶
Structure/Union member
- time_begin¶
Structure/Union member
- time_end¶
Structure/Union member
- class pyTDFSDK.ctypes_data_structures.PressureCompensationStrategy(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
Enum
enum.Enum to determine pressure compensation strategy.
- AnalyisGlobalPressureCompensation = 1¶
- NoPressureCompensation = 0¶
- PerFramePressureCompensation = 2¶
- class pyTDFSDK.ctypes_data_structures.TimsVisExtractionFilter¶
Bases:
Structure
ctypes.Structure to hold visualization extraction filter information.
- mzLower¶
Structure/Union member
- mzUpper¶
Structure/Union member
- ook0Lower¶
Structure/Union member
- ook0Upper¶
Structure/Union member
- rtSecondsLower¶
Structure/Union member
- rtSecondsUpper¶
Structure/Union member
- class pyTDFSDK.ctypes_data_structures.TimsVisHeatmapSizes¶
Bases:
Structure
ctypes.Structure to hold heatmap size information.
- heightMobMz¶
Structure/Union member
- heightRtMob¶
Structure/Union member
- heightRtMz¶
Structure/Union member
- widthMobMz¶
Structure/Union member
- widthRtMob¶
Structure/Union member
- widthRtMz¶
Structure/Union member
pyTDFSDK.error module¶
- pyTDFSDK.error.throw_last_timsdata_error(tdf_sdk)¶
Return the last error as a string (thread-local) while throwing exception from TDF data.
- Parameters:
tdf_sdk (ctypes.CDLL) – Instance of TDF-SDK.
- Returns:
Runtime error.
- pyTDFSDK.error.throw_last_timsvis_error(tdf_sdk)¶
Return the last error as a string (thread-local) while throwing exception from TDF/TSF data.
- Parameters:
tdf_sdk (ctypes.CDLL) – Instance of TDF-SDK.
- Returns:
Runtime error.
- pyTDFSDK.error.throw_last_tsfdata_error(tdf_sdk)¶
Return the last error as a string (thread-local) while throwing exception from TSF data.
- Parameters:
tdf_sdk (ctypes.CDLL) – Instance of TDF-SDK.
- Returns:
Runtime error.
pyTDFSDK.init_tdf_sdk module¶
- pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api(bruker_api_file_name='')¶
Initialize functions from Bruker’s TDF-SDK library using ctypes.
- Parameters:
bruker_api_file_name (str) – Path to TDF-SDK library, defaults to packaged library paths if no custom paths are provided.
- Returns:
Handle for TDF-SDK library.
- Return type:
ctypes.CDLL
pyTDFSDK.tims module¶
- pyTDFSDK.tims.extract_2d_tdf_spectrum(tdf_data, frame, scan_begin, scan_end, mode, profile_bins=0, mz_encoding=64, intensity_encoding=64)¶
Extract spectrum from TDF data with m/z and intensity arrays. Spectrum can either be centroid or quasi-profile mode. “Raw” mode uses pyTDFSDK.tims.tims_read_scans_v2() method, while “centroid” mode uses pyTDFSDK.tims.tims_extract_centroided_spectrum_for_frame_v2() method. “Profile” mode uses pyTDFSDK.tims.tims_extract_profile_for_frame() to extrapolate a quasi-profile spectrum from centroid raw data.
- Parameters:
tdf_data (pyTDFSDK.classes.TdfData) – tdf_data object containing metadata from analysis.tdf database.
frame (int) – Frame ID from the Frames table in analysis.tdf/analysis.tsf database.
scan_begin (int) – Beginning scan number (corresponding to 1/K0 value) within frame.
scan_end (int) – Ending scan number (corresponding to 1/K0 value) within frame (non-inclusive).
mode (str) – Mode command line parameter, either “profile”, “centroid”, or “raw”.
profile_bins (int) – Number of bins to bin spectrum to.
mz_encoding (int) – m/z encoding command line parameter, either “64” or “32”.
intensity_encoding (int) – Intensity encoding command line parameter, either “64” or “32”.
- Returns:
Tuple of mz_array (np.array) and intensity_array (np.array) or (None, None) if spectra are empty.
- Return type:
tuple[numpy.array | None]
- pyTDFSDK.tims.extract_3d_tdf_spectrum(tdf_data, frame, scan_begin, scan_end)¶
Extract spectrum from TDF data with m/z and intensity arrays. Spectrum can either be centroid or quasi-profile mode. “Raw” and “centroid” modes uses pyTDFSDK.tims.tims_read_scans_v2(). “Profile” mode data is not available due to the resulting data size.
- Parameters:
tdf_data (pyTDFSDK.classes.TdfData) – tdf_data object containing metadata from analysis.tdf database.
frame (int) – Frame ID from the Frames table in analysis.tdf/analysis.tsf database.
scan_begin (int) – Beginning scan number (corresponding to 1/K0 value) within frame.
scan_end (int) – Ending scan number (corresponding to 1/K0 value) within frame (non-inclusive).
- Returns:
Tuple of mz_array (np.array), intensity_array (np.array), and mobility_array (np.array) or (None, None, None) if spectra are empty.
- Return type:
tuple[numpy.array | None]
- pyTDFSDK.tims.extract_ddapasef_precursor_spectrum(tdf_data, pasefframemsmsinfo_dicts, mode, profile_bins, mz_encoding, intensity_encoding)¶
Extract spectrum from TDF data with m/z and intensity arrays. Spectrum can either be centroid or quasi-profile mode. “Raw” mode uses pyTDFSDK.tims.tims_read_scans_v2() method, while “centroid” mode uses pyTDFSDK.tims.tims_extract_centroided_spectrum_for_frame_v2() method. “Profile” mode uses pyTDFSDK.tims.tims_extract_profile_for_frame() to extrapolate a quasi-profile spectrum from centroid raw data.
- Parameters:
tdf_data (pyTDFSDK.classes.TdfData) – tdf_data object containing metadata from analysis.tdf database.
pasefframemsmsinfo_dicts (dict) – A row from the PasefFrameMsmsInfo table in analysis.tdf database.
mode (str) – Mode command line parameter, either “profile”, “centroid”, or “raw”.
profile_bins (int) – Number of bins to bin spectrum to.
mz_encoding (int) – m/z encoding command line parameter, either “64” or “32”.
intensity_encoding (int) – Intensity encoding command line parameter, either “64” or “32”.
- Returns:
Tuple of mz_array (np.array) and intensity_array (np.array) or (None, None) if spectra are empty.
- Return type:
tuple[numpy.array | None
- pyTDFSDK.tims.tims_ccs_to_oneoverk0_for_mz(tdf_sdk, ccs, charge, mz)¶
Convert collisional cross section (CCS) values to 1/K0 values based on a feature’s m/z value and charge.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
ccs (float) – Collisional cross section (CCS) value of the feature.
charge (int) – Charge of the feature.
mz (float) – m/z value of the feature.
- Returns:
1/K0 value calculated from the provided feature.
- Return type:
float
- pyTDFSDK.tims.tims_close(tdf_sdk, handle, conn)¶
Close TDF dataset.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TDF dataset initialized using pyTDFSDK.tims.tims_open().
conn (sqlite3.Connection) – SQL database connection to analysis.tdf.
- Returns:
Tuple of the handle and connection.
- Return type:
tuple
- pyTDFSDK.tims.tims_extract_centroided_spectrum_for_frame_ext(tdf_sdk, handle, frame_id, scan_begin, scan_end, peak_picker_resolution)¶
Read peak picked spectra for a frame from a TIMS (TDF) dataset with a custom peak picker resolution. Same as pyTDFSDK.tims.tims_extract_centroided_spectrum_for_frame_v2() but with a user supplied resolution for the peak picker.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TDF dataset initialized using pyTDFSDK.tims.tims_open().
frame_id (int) – ID of the frame of interest.
scan_begin (int) – Beginning scan number (corresponding to 1/K0 value) within frame.
scan_end (int) – Ending scan number (corresponding to 1/K0 value) within frame (non-inclusive).
peak_picker_resolution (int) – User supplied resolution for peak picker.
- Returns:
Tuple containing an array of m/z values and an array of detector counts or 0 on error.
- Return type:
tuple[numpy.array] | int
- pyTDFSDK.tims.tims_extract_centroided_spectrum_for_frame_v2(tdf_sdk, handle, frame_id, scan_begin, scan_end)¶
Read peak picked spectra for a frame from a TIMS (TDF) dataset.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TDF dataset initialized using pyTDFSDK.tims.tims_open().
frame_id (int) – ID of the frame of interest.
scan_begin (int) – Beginning scan number (corresponding to 1/K0 value) within frame.
scan_end (int) – Ending scan number (corresponding to 1/K0 value) within frame (non-inclusive).
- Returns:
Tuple containing an array of m/z values and an array of detector counts or 0 on error.
- Return type:
tuple[numpy.array] | int
- pyTDFSDK.tims.tims_extract_chromatograms(tdf_sdk, handle, jobs, trace_sink)¶
Extract several (MS1-only) chromatograms from an analysis.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle – Handle value for TDF dataset initialized using pyTDFSDK.tims.tims_open().
jobs – Chromatogram definitions that will be iterated through using the generator function defined in this function.
trace_sink – Sink callback from TDF-SDK.
- pyTDFSDK.tims.tims_extract_profile_for_frame(tdf_sdk, handle, frame_id, scan_begin, scan_end)¶
Read quasi profile spectra for a frame from a TIMS (TDF) dataset. This function sums the corresponding scan number ranges into a synthetic profile spectrum.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TDF dataset initialized using pyTDFSDK.tims.tims_open().
frame_id (int) – ID of the frame of interest.
scan_begin (int) – Beginning scan number (corresponding to 1/K0 value) within frame.
scan_end (int) – Ending scan number (corresponding to 1/K0 value) within frame (non-inclusive).
- Returns:
Array of detector counts or 0 on error.
- Return type:
numpy.array | int
- pyTDFSDK.tims.tims_has_recalibrated_state(tdf_sdk, handle)¶
Check if the raw data has been recalibrated after acquisition (i.e. in the Bruker DataAnalysis software). Note that masses and 1/K0 values in the raw data SQLite files are always in the raw calibration state, not the recalibrated state.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TDF dataset initialized using pyTDFSDK.tims.tims_open().
- Returns:
1 if the raw data has been recalibrated after acquisition or 0 if not.
- Return type:
int
- pyTDFSDK.tims.tims_index_to_mz(tdf_sdk, handle, frame_id, indices)¶
Convert (possibly non-integer) index values for the mass dimension to m/z values.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TDF dataset initialized using pyTDFSDK.tims.tims_open().
frame_id (int) – ID of the frame of interest.
indices (numpy.array) – Array of index values to be converted to m/z values.
- Returns:
Array of m/z values.
- Return type:
numpy.array
- pyTDFSDK.tims.tims_mz_to_index(tdf_sdk, handle, frame_id, mzs)¶
Convert m/z values to (possibly non-integer) index values for the mass dimension.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TDF dataset initialized using pyTDFSDK.tims.tims_open().
frame_id (int) – ID of the frame of interest.
mzs (numpy.array) – Array of m/z values to be converted to index values.
- Returns:
Array of index values.
- Return type:
numpy.array
- pyTDFSDK.tims.tims_oneoverk0_to_ccs_for_mz(tdf_sdk, ook0, charge, mz)¶
Convert 1/K0 values to collisional cross section values (in Anstrom^2) using the Mason-Shamp equation.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
ook0 (float) – 1/K0 value of the feature to be converted.
charge (int) – Charge of the feature to be converted.
mz (float) – m/z value of the feature to be converted.
- Returns:
Collisional cross section value in Angstrom^2.
- Return type:
float
- pyTDFSDK.tims.tims_oneoverk0_to_scannum(tdf_sdk, handle, frame_id, mobilities)¶
Convert 1/K0 values to (possibly non-integer) scan numbers for the mobility dimension.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TDF dataset initialized using pyTDFSDK.tims.tims_open().
frame_id (int) – ID of the frame of interest.
mobilities (numpy.array) – Array of 1/K0 values to be converted to scan numbers.
- Returns:
Array of scan numbers.
- Return type:
numpy.array
- pyTDFSDK.tims.tims_open(tdf_sdk, bruker_d_folder_name, use_recalibrated_state=True)¶
Open TDF dataset and return a non-zero instance handle to be passed to subsequent API calls.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
bruker_d_folder_name (str) – Path to a Bruker .d file containing analysis.tdf.
use_recalibrated_state (bool) – Whether to use recalibrated data (True) or not (False), defaults to True.
- Returns:
Non-zero instance handle.
- Return type:
int
- pyTDFSDK.tims.tims_open_v2(tdf_sdk, bruker_d_folder_name, pressure_compensation_strategy, use_recalibrated_state=True)¶
Open TDF dataset while taking into account the pressure compensation strategy and return a non-zero instance handle to be passed to subsequent API calls.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
bruker_d_folder_name (str) – Path to a Bruker .d file containing analysis.tdf.
pressure_compensation_strategy (enum.Enum) – Pressure compensation strategy chosen from pyTDFSDK.ctypes_data_structures.PressureCompensationStrategy, either NoPressureCompensation, AnalysisGlobalPressureCompensation, or PerFramePressureCompensation.
use_recalibrated_state (bool) – Whether to use recalibrated data (True) or not (False), defaults to True.
- Returns:
Non-zero instance handle.
- Return type:
int
- pyTDFSDK.tims.tims_read_pasef_msms(tdf_sdk, handle, precursor_list)¶
Read peak picked MS/MS spectra for a list of PASEF precursors from a TIMS (TDF) dataset. This function reads all necessary PASEF frames, sums up the correspoonding scan number ranges into synthetic profile spectra for each precursor, performs centroiding using an algorithm and parameters suggested by Bruker, and returns the resulting MS/MS spectra (one for each precursor). The order of the returned MS/MS spectra does not necessarily match the order in the specified precursor list.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TDF dataset initialized using pyTDFSDK.tims.tims_open().
precursor_list (list[int] | numpy.array) – List of precursor IDs to obtain spectra for.
- Returns:
Dictionary in which the key corresponds to the precursor ID and the value is a tuple of an array of m/z values and an array of detector counts or 0 on error.
- Return type:
dict | int
- pyTDFSDK.tims.tims_read_pasef_msms_for_frame(tdf_sdk, handle, frame_id)¶
Read peak picked MS/MS spectra for all PASEF precursors in a given frame from a TIMS (TDF) dataset. This function reads all contained PASEF precursors for a frame from the necessary PASEF frames in the same way as pyTDFSDK.tims.tims_read_pasef_msms(). The order of the returned MS/MS does not necessarily match the order in the specified precursor ID list.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TDF dataset initialized using pyTDFSDK.tims.tims_open().
frame_id (int) – ID of the frame of interest.
- Returns:
Dictionary in which the key corresponds to the precursor ID and the value is a tuple of an array of m/z values and an array of detector counts or 0 on error.
- Return type:
dict | int
- pyTDFSDK.tims.tims_read_pasef_msms_for_frame_v2(tdf_sdk, handle, frame_id)¶
Read peak picked MS/MS spectra for all PASEF precursors in a given frame from a TIMS (TDF) dataset. This function reads all contained PASEF precursors for a frame from the necessary PASEF frames in the same way as pyTDFSDK.tims.tims_read_pasef_msms(). The order of the returned MS/MS does not necessarily match the order in the specified precursor ID list.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TDF dataset initialized using pyTDFSDK.tims.tims_open().
frame_id (int) – ID of the frame of interest.
- Returns:
Dictionary in which the key corresponds to the precursor ID and the value is a tuple of an array of m/z values and an array of detector counts or 0 on error.
- Return type:
dict | int
- pyTDFSDK.tims.tims_read_pasef_msms_v2(tdf_sdk, handle, precursor_list)¶
Read peak picked MS/MS spectra for a list of PASEF precursors from a TIMS (TDF) dataset. This function reads all necessary PASEF frames, sums up the correspoonding scan number ranges into synthetic profile spectra for each precursor, performs centroiding using an algorithm and parameters suggested by Bruker, and returns the resulting MS/MS spectra (one for each precursor). The order of the returned MS/MS spectra does not necessarily match the order in the specified precursor list.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TDF dataset initialized using pyTDFSDK.tims.tims_open().
precursor_list (list[int] | numpy.array) – List of precursor IDs to obtain spectra for.
- Returns:
Dictionary in which the key corresponds to the precursor ID and the value is a tuple of an array of m/z values and an array of detector counts or 0 on error.
- Return type:
dict | int
- pyTDFSDK.tims.tims_read_pasef_profile_msms(tdf_sdk, handle, precursor_list)¶
Read quasi profile MS/MS spectra for a list of PASEF precursors from a TIMS (TDF) dataset. This function reads all necessary PASEF frames, sums up the corresponding scan number ranges into synthetic profile spectra for each precursor and returns the resulting quasi profile MS/MS spectra (one for each precursor). The order of the returned MS/MS spectra does not necessarily match the order in the specified precursor ID list.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TDF dataset initialized using pyTDFSDK.tims.tims_open().
precursor_list (list[int] | numpy.array) – List of precursor IDs to obtain spectra for.
- Returns:
Dictionary in which the key corresponds to the precursor ID and the value an array of detector counts or 0 on error.
- Return type:
dict | int
- pyTDFSDK.tims.tims_read_pasef_profile_msms_for_frame(tdf_sdk, handle, frame_id)¶
Read quasi profile MS/MS spectra for all PASEF precursors in a given frame from a TIMS (TDF) dataset. This function reads all contained PASEF precursors for a frame from the necessary PASEF frames in the same way as pyTDFSDK.tims.tims_read_pasef_profile_msms(). The order of the returned MS/MS does not necessarily match the order in the specified precursor ID list.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TDF dataset initialized using pyTDFSDK.tims.tims_open().
frame_id (int) – ID of the frame of interest.
- Returns:
Dictionary in which the key corresponds to the precursor ID and the value an array of detector counts or 0 on error.
- Return type:
dict | int
- pyTDFSDK.tims.tims_read_pasef_profile_msms_for_frame_v2(tdf_sdk, handle, frame_id)¶
Read quasi profile MS/MS spectra for all PASEF precursors in a given frame from a TIMS (TDF) dataset. This function reads all contained PASEF precursors for a frame from the necessary PASEF frames in the same way as pyTDFSDK.tims.tims_read_pasef_profile_msms(). The order of the returned MS/MS does not necessarily match the order in the specified precursor ID list.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TDF dataset initialized using pyTDFSDK.tims.tims_open().
frame_id (int) – ID of the frame of interest.
- Returns:
Dictionary in which the key corresponds to the precursor ID and the value an array of detector counts or 0 on error.
- Return type:
dict | int
- pyTDFSDK.tims.tims_read_pasef_profile_msms_v2(tdf_sdk, handle, precursor_list)¶
Read quasi profile MS/MS spectra for a list of PASEF precursors from a TIMS (TDF) dataset. This function reads all necessary PASEF frames, sums up the corresponding scan number ranges into synthetic profile spectra for each precursor and returns the resulting quasi profile MS/MS spectra (one for each precursor). The order of the returned MS/MS spectra does not necessarily match the order in the specified precursor ID list.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TDF dataset initialized using pyTDFSDK.tims.tims_open().
precursor_list (list[int] | numpy.array) – List of precursor IDs to obtain spectra for.
- Returns:
Dictionary in which the key corresponds to the precursor ID and the value an array of detector counts or 0 on error.
- Return type:
dict | int
- pyTDFSDK.tims.tims_read_scans_v2(tdf_sdk, handle, frame_id, scan_begin, scan_end, initial_frame_buffer_size=128)¶
Read a range of scans from a single frame. The resulting arrays are equivalent to line spectra.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TDF dataset initialized using pyTDFSDK.tims.tims_open().
frame_id (int) – ID of the frame of interest.
scan_begin (int) – Beginning scan number (corresponding to 1/K0 value) within frame.
scan_end (int) – Ending scan number (corresponding to 1/K0 value) within frame (non-inclusive).
initial_frame_buffer_size (int) – Initial number of buffer bytes necessary for the output, defaults to 128.
- Returns:
List of tuples where each tuple contains an array of mass indices and array of detector counts or 0 on error.
- Return type:
list[tuple[numpy.array]] | int
- pyTDFSDK.tims.tims_scannum_to_oneoverk0(tdf_sdk, handle, frame_id, scan_nums)¶
Convert (possibly non-integer) scan numbers for the mobility dimension to 1/K0 values.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TDF dataset initialized using pyTDFSDK.tims.tims_open().
frame_id (int) – ID of the frame of interest.
scan_nums (numpy.array) – Array of scan numbers to be converted to 1/K0 values.
- Returns:
Array of 1/K0 values.
- Return type:
numpy.array
- pyTDFSDK.tims.tims_scannum_to_voltage(tdf_sdk, handle, frame_id, scan_nums)¶
Convert (possibly non-integer) scan numbers for the mobility dimension to TIMS voltages.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TDF dataset initialized using pyTDFSDK.tims.tims_open().
frame_id (int) – ID of the frame of interest.
scan_nums (numpy.array) – Array of scan numbers to be converted to voltages.
- Returns:
Array of TIMS voltages.
- Return type:
numpy.array
- pyTDFSDK.tims.tims_set_num_threads(tdf_sdk, num_threads)¶
Set the number of threads that this DLL is allowed to use internally. The index <-> m/z transformation is internally parallelized using OpenMP. This call is simply forwarded to omp_set_num_threads(). This function has no real effect on Linux.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
num_threads (int) – Number of threads to use (>= 1)
- pyTDFSDK.tims.tims_voltage_to_scannum(tdf_sdk, handle, frame_id, voltages)¶
Convert TIMS voltages to (possibly non-integer) scan numbers for the mobility dimension.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TDF dataset initialized using pyTDFSDK.tims.tims_open().
frame_id (int) – ID of the frame of interest.
voltages (numpy.array) – Array of voltages to be converted to scan numbers.
- Returns:
Array of scan numbers.
- Return type:
numpy.array
pyTDFSDK.tsf module¶
- pyTDFSDK.tsf.extract_tsf_spectrum(tsf_data, frame, mode, profile_bins=0, mz_encoding=64, intensity_encoding=64)¶
Extract spectrum from TSF data with m/z and intensity arrays. Spectrum can either be centroid or quasi-profile mode. If “raw” mode is chosen, centroid mode will automatically be used. “Centroid” mode uses pyTDFSDK.tsf.tsf_read_line_spectrum_v2() method. “Profile” mode uses pyTDFSDK.tsf.tsf_read_profile_spectrum_v2() to extrapolate a quasi-profile spectrum from centroid raw data.
- Parameters:
tsf_data (pyTDFSDK.classes.TsfData) – tsf_data object containing metadata from analysis.tsf database.
frame (int) – Frame ID from the Frames table in analysis.tdf/analysis.tsf database.
mode (str) – Mode command line parameter, either “profile”, “centroid”, or “raw”.
profile_bins (int) – Number of bins to bin spectrum to.
mz_encoding (int) – m/z encoding command line parameter, either “64” or “32”.
intensity_encoding (int) – Intensity encoding command line parameter, either “64” or “32”.
- Returns:
Tuple of mz_array (np.array) and intensity_array (np.array).
- Return type:
tuple[numpy.array]
- pyTDFSDK.tsf.tsf_close(tdf_sdk, handle, conn)¶
Close TSF dataset.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TSF dataset initialized using pyTDFSDK.tsf.tsf_open().
conn (sqlite3.Connection) – SQL database connection to analysis.tsf.
- Returns:
Tuple of the handle and connection.
- Return type:
tuple
- pyTDFSDK.tsf.tsf_has_recalibrated_state(tdf_sdk, handle)¶
Check if the raw data has been recalibrated after acquisition (i.e. in the Bruker DataAnalysis software). Note that masses and 1/K0 values in the raw data SQLite files are always in the raw calibration state, not the recalibrated state.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TSF dataset initialized using pyTDFSDK.tsf.tsf_open().
- Returns:
1 if the raw data has been recalibrated after acquisition or 0 if not.
- Return type:
int
- pyTDFSDK.tsf.tsf_index_to_mz(tdf_sdk, handle, frame_id, indices)¶
Convert (possibly non-integer) index values for the mass dimension to m/z values.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TSF dataset initialized using pyTDFSDK.tsf.tsf_open().
frame_id (int) – ID of the frame of interest.
indices (numpy.array) – Array of index values to be converted to m/z values.
- Returns:
Array of m/z values.
- Return type:
numpy.array
- pyTDFSDK.tsf.tsf_mz_to_index(tdf_sdk, handle, frame_id, mzs)¶
Convert m/z values to (possibly non-integer) index values for the mass dimension.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TSF dataset initialized using pyTDFSDK.tsf.tsf_open().
frame_id (int) – ID of the frame of interest.
mzs (numpy.array) – Array of m/z values to be converted to index values.
- Returns:
Array of index values.
- Return type:
numpy.array
- pyTDFSDK.tsf.tsf_open(tdf_sdk, bruker_d_folder_name, use_recalibrated_state=True)¶
Open TSF dataset and return a non-zero instance handle to be passed to subsequent API calls.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
bruker_d_folder_name (str) – Path to a Bruker .d file containing analysis.tsf.
use_recalibrated_state (bool) – Whether to use recalibrated data (True) or not (False), defaults to True.
- Returns:
Non-zero instance handle.
- Return type:
int
- pyTDFSDK.tsf.tsf_read_line_spectrum(tdf_sdk, handle, frame_id, profile_buffer_size=1024)¶
Read peak picked spectra for a frame from a non-TIMS (TSF) dataset.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TSF dataset initialized using pyTDFSDK.tsf.tsf_open().
frame_id (int) – ID of the frame of interest.
profile_buffer_size (int) – Initial number of buffer bytes necessary for the output, defaults to 1024.
- Returns:
Tuple containing an array of index values for the mass dimension and an array of detector counts or -1 on error.
- Return type:
tuple[numpy.array] | int
- pyTDFSDK.tsf.tsf_read_line_spectrum_v2(tdf_sdk, handle, frame_id, profile_buffer_size=1024)¶
Read peak picked spectra for a frame from a non-TIMS (TSF) dataset.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TSF dataset initialized using pyTDFSDK.tsf.tsf_open().
frame_id (int) – ID of the frame of interest.
profile_buffer_size (int) – Initial number of buffer bytes necessary for the output, defaults to 1024.
- Returns:
Tuple containing an array of index values for the mass dimension and an array of detector counts or -1 on error.
- Return type:
tuple[numpy.array] | int
- pyTDFSDK.tsf.tsf_read_line_spectrum_with_width_v2(tdf_sdk, handle, frame_id, profile_buffer_size=1024)¶
Read peak picked spectra with peak width for a frame from a non-TIMS (TSF) dataset.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TSF dataset initialized using pyTDFSDK.tsf.tsf_open().
frame_id (int) – ID of the frame of interest.
profile_buffer_size (int) – Initial number of buffer bytes necessary for the output, defaults to 1024.
- Returns:
Tuple containing an array of index values for the mass dimension, an array of detector counts, and an array of widths or -1 on error.
- Return type:
tuple[numpy.array] | int
- pyTDFSDK.tsf.tsf_read_profile_spectrum(tdf_sdk, handle, frame_id, profile_buffer_size=1024)¶
Read profile spectra for a frame from a non-TIMS (TSF) dataset.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TSF dataset initialized using pyTDFSDK.tsf.tsf_open().
frame_id (int) – ID of the frame of interest.
profile_buffer_size (int) – Initial number of buffer bytes necessary for the output, defaults to 1024.
- Returns:
Tuple containing an array of index values for the mass dimension and an array of detector counts or -1 on error.
- Return type:
tuple[numpy.array] | int
- pyTDFSDK.tsf.tsf_read_profile_spectrum_v2(tdf_sdk, handle, frame_id, profile_buffer_size=1024)¶
Read profile spectra for a frame from a non-TIMS (TSF) dataset.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
handle (int) – Handle value for TSF dataset initialized using pyTDFSDK.tsf.tsf_open().
frame_id (int) – ID of the frame of interest.
profile_buffer_size (int) – Initial number of buffer bytes necessary for the output, defaults to 1024.
- Returns:
Tuple containing an array of index values for the mass dimension and an array of detector counts or -1 on error.
- Return type:
tuple[numpy.array] | int
- pyTDFSDK.tsf.tsf_set_num_threads(tdf_sdk, num_threads)¶
Set the number of threads that this DLL is allowed to use internally. The index <-> m/z transformation is internally parallelized using OpenMP. This call is simply forwarded to omp_set_num_threads(). This function has no real effect on Linux.
- Parameters:
tdf_sdk (ctypes.CDLL) – Library initialized by pyTDFSDK.init_tdf_sdk.init_tdf_sdk_api().
num_threads (int) – Number of threads to use (>= 1)
pyTDFSDK.util module¶
- pyTDFSDK.util.bin_profile_spectrum(mz_array, intensity_array, profile_bins, mz_encoding)¶
Bin profile mode spectrum into N number of bins.
- Parameters:
mz_array (numpy.array) – Array containing m/z values.
intensity_array (numpy.array) – Array containing intensity values.
profile_bins (int) – Number of bins to bin spectrum to.
mz_encoding (int) – m/z encoding command line parameter, either “64” or “32”.
- Returns:
Tuple of binned_mz_array (np.array) and binned_intensity_array (np.array).
- Return type:
tuple[numpy.array]
- pyTDFSDK.util.call_conversion_func(tdf_sdk, handle, frame_id, input_data, func)¶
Decorator for other conversion related functions.
- Parameters:
tdf_sdk (ctypes.CDLL) – Instance of TDF-SDK.
handle (int) – Handle value for TDF/TSF dataset initialized using pyTDFSDK.tims.tims_open() or pyTDFSDK.tsf.tsf_open().
frame_id (int) – ID of the frame of interest.
input_data (numpy.array) – Array to be converted.
func (function) – Conversion function from TDF-SDK to pass through decorator.
- Returns:
Array of converted values equal in size to the input_data array.
- Return type:
numpy.array
- pyTDFSDK.util.get_centroid_status(mode, exclude_mobility=None)¶
Use “mode” command line parameter to determine whether output data is centroided in psims compatible format.
- Parameters:
mode (str) – Mode command line parameter, either “profile”, “centroid”, or “raw”.
exclude_mobility (bool | None) – Whether to include mobility data in the output files, defaults to None.
- Returns:
Dictionary containing standard spectrum data.
- Returns:
Tuple of (centroided status (bool), exclude_mobility status (bool))
- Return type:
tuple[bool]
- pyTDFSDK.util.get_encoding_dtype(encoding)¶
Use “encoding” command line parameter to determine numpy dtype.
- Parameters:
encoding (int) – Encoding command line parameter, either “64” or “32”.
- Returns:
Numpy dtype, either float64 or float32
- Return type:
numpy.dtype
- pyTDFSDK.util.get_maldi_coords(data, maldiframeinfo_dict)¶
Get tuple of MALDI coordinates from analysis.tsf/analysis.tdf metadata.
- Parameters:
data (pyTDFSDK.classes.TsfData | pyTDFSDK.classes.TdfData) – Object containing metadata from analysis.tsf/analysis.tdf database.
maldiframeinfo_dict (dict) – A row from the MaldiFrameInfo table in analysis.tsf/analysis.tdf database.
- Returns:
x-y (or x-y-z if available) coordinates for the current spectrum.
- Return type:
tuple[int]