timspy package

Submodules

timspy.df module

class timspy.df.TimsPyDF(analysis_directory)

Bases: opentimspy.opentims.OpenTIMS

TimsData that uses info about Frames.

intensity_given_mz_inv_ion_mobility(frames=None, mz_bin_borders=array([500., 502., 504., ..., 2496., 2498., 2500.]), inv_ion_mobility_bin_borders=array([0.8, 0.809, 0.818, 0.827, 0.836, 0.845, 0.854, 0.863, 0.872, 0.881, 0.89, 0.899, 0.908, 0.917, 0.926, 0.935, 0.944, 0.953, 0.962, 0.971, 0.98, 0.989, 0.998, 1.007, 1.016, 1.025, 1.034, 1.043, 1.052, 1.061, 1.07, 1.079, 1.088, 1.097, 1.106, 1.115, 1.124, 1.133, 1.142, 1.151, 1.16, 1.169, 1.178, 1.187, 1.196, 1.205, 1.214, 1.223, 1.232, 1.241, 1.25, 1.259, 1.268, 1.277, 1.286, 1.295, 1.304, 1.313, 1.322, 1.331, 1.34, 1.349, 1.358, 1.367, 1.376, 1.385, 1.394, 1.403, 1.412, 1.421, 1.43, 1.439, 1.448, 1.457, 1.466, 1.475, 1.484, 1.493, 1.502, 1.511, 1.52, 1.529, 1.538, 1.547, 1.556, 1.565, 1.574, 1.583, 1.592, 1.601, 1.61, 1.619, 1.628, 1.637, 1.646, 1.655, 1.664, 1.673, 1.682, 1.691, 1.7]))

Sum intensity over m/z-inverse ion mobility rectangles.

Typically it does not make too much sense to mix MS1 intensities with the others here.

Parameters
  • frames (iterable) – Frames to consider. Defaults to all ms1_frames.

  • mz_bin_borders (np.array) – Positions of bin borders for mass over charge ratios.

  • inv_ion_mobility_bin_borders (np.array) – Positions of bin borders for inverse ion mobilities.

Returns

np.array with intensities, the positions of bin borders for mass over charge ratios and inverse ion mobilities.

Return type

tuple

intensity_per_frame(recalibrated=True)

Get sum of intensity per each frame (retention time).

Parameters

recalibrated (bool) – Use Bruker recalibrated total intensities or calculate them from scratch with OpenTIMS?

Returns

sums of intensities per frame.

Return type

np.array

plot_TIC(recalibrated=True, show=True)

Plot peak counts per frame.

Parameters
  • recalibrated (bool) – Use Bruker recalibrated total intensities or calculate them from scratch with OpenTIMS?

  • show (bool) – Show the plot immediately, or just add it to the canvas?

plot_intensity_given_mz_inv_ion_mobility(summed_intensity_matrix, mz_bin_borders, inv_ion_mobility_bin_borders, intensity_transformation=<ufunc 'log2'>, interpolation='lanczos', aspect='auto', cmap='inferno', origin='lower', show=True, **kwds)

Sum intensity over m/z-inverse ion mobility rectangles.

Plot a transformation of the sum of intensities. Usually, plotting the square root of summed intensities looks best.

Parameters
  • summed_intensity_matrix (np.array) – 2D array with intensities, as produced by ‘intensity_given_mz_inv_ion_mobility’.

  • mz_bin_borders (np.array) – Positions of bin borders for mass over charge ratios.

  • inv_ion_mobility_bin_borders (np.array) – Positions of bin borders for inverse ion mobilities.

  • intensity_transformation (np.ufunc) – Function that transforms intensities. Default to logarithm with base 2.

  • interpolation (str) – Type of interpolation used in ‘matplotlib.pyplot.imshow’.

  • aspect (str) – Aspect ratio in ‘matplotlib.pyplot.imshow’.

  • cmap (str) – Color scheme for the ‘matplotlib.pyplot.imshow’.

  • origin (str) – Where should the origin of the coordinate system start? Defaults to bottom-left. Check ‘matplotlib.pyplot.imshow’.

  • show (bool) – Show the plot immediately, or just add it to the canvas?

  • **kwds – Keyword arguments for ‘matplotlib.pyplot.imshow’ function.

plot_peak_counts(show=True)

Plot peak counts per frame.

Parameters

show (bool) – Show the plot immediately, or just add it to the canvas.

query(frames, columns=('frame', 'scan', 'tof', 'intensity', 'mz', 'inv_ion_mobility', 'retention_time'))

Get data from a selection of frames.

Parameters
  • frames (int, iterable) – Frames to choose. Passing an integer results in extracting that one frame.

  • columns (tuple) – which columns to extract? Defaults to all possible columns.

Returns

Data frame filled with columns with raw data.

Return type

pd.DataFrame

summary()

Print a short summary of the data content.

Includes the number of peaks, the minimal and the maximal frame numbers.

table2df(name)

Retrieve a table with SQLite connection from a data base.

Parameters

name (str) – Name of the table to extract.

Returns

required data frame.

Return type

pd.DataFrame

tables_names()

List names of tables in the SQLite db.

Returns

table with names of tables one can get with ‘table2df’.

Return type

pd.DataTable

to_hdf(target_path, columns=('frame', 'scan', 'tof', 'intensity', 'mz', 'inv_ion_mobility', 'retention_time'), compression='gzip', compression_level=9, shuffle=True, chunks=True, silent=True, **kwds)

Convert the data set to HDF5 compatible with ‘vaex’.

Most of the arguments are documented on the h5py website.

Parameters
  • target_path (str) – Where to write the file (folder will be automatically created). Cannot point to an already existing file.

  • columns (tuple) – Names of columns to export to HDF5.

  • compression (str) – Compression strategy.

  • compression_level (str) – Parameters for compression filter.

  • shuffle (bool) – Enable shuffle filter.

  • chunks (int) – Chunk shape, or True to enable auto-chunking.

  • silent (bool) – Skip progress bar

timspy.dia module

class timspy.dia.TimsPyDIA(analysis_directory)

Bases: timspy.df.TimsPyDF

frames_meta()

Return meta information on every frame.

Returns

Information on every frame, including which window it belongs to.

Return type

pd.DataFrame

timspy.plot module

Basic plotting procedures.

timspy.plot.plot2d(X, x_axis, x_i, x_l, y_axis, y_i, y_l, show=True, **kwds)
timspy.plot.plot3d(x, y, z, show=True, **kwds)

Make a 3D plot of data.

timspy.plot.plot_spectrum(mz, intensity, show=True, **kwds)

A simple stem-plot stick spectrum.

You need to have matplotlib installed for this method to work.

Parameters
  • MZ (iterable) – mass over charge values.

  • I (iterable) – intensities corresponding to mass over charge ratios.

  • show (bool) – show the plot

timspy.sql module

timspy.sql.table2df(path, name)

Retrieve a table with SQLite connection from a data base.

This function is simply great for injection attacks (: Don’t do that.

Parameters

name (str) – Name of the table to extract.

Returns

required data frame.

Return type

pd.DataFrame

timspy.sql.tables_names(path)

List names of tables in the SQLite db.

Parameters

path (str) – Path to the sqlite db.

Returns

table with names of tables one can get with ‘table2df’.

Return type

pd.DataTable

timspy.vaex module

Log: TimsVaex cannot be a subclass vaex.dataset.HDF5MappableStorage because of potential clashes between column names and methods.

class timspy.vaex.TimsVaex(path2hdf, path2tdf)

Bases: object

intensity_given_mz_inv_ion_mobility(frames=None, mz_bin_borders=array([500., 502., 504., ..., 2496., 2498., 2500.]), inv_ion_mobility_bin_borders=array([0.8, 0.809, 0.818, 0.827, 0.836, 0.845, 0.854, 0.863, 0.872, 0.881, 0.89, 0.899, 0.908, 0.917, 0.926, 0.935, 0.944, 0.953, 0.962, 0.971, 0.98, 0.989, 0.998, 1.007, 1.016, 1.025, 1.034, 1.043, 1.052, 1.061, 1.07, 1.079, 1.088, 1.097, 1.106, 1.115, 1.124, 1.133, 1.142, 1.151, 1.16, 1.169, 1.178, 1.187, 1.196, 1.205, 1.214, 1.223, 1.232, 1.241, 1.25, 1.259, 1.268, 1.277, 1.286, 1.295, 1.304, 1.313, 1.322, 1.331, 1.34, 1.349, 1.358, 1.367, 1.376, 1.385, 1.394, 1.403, 1.412, 1.421, 1.43, 1.439, 1.448, 1.457, 1.466, 1.475, 1.484, 1.493, 1.502, 1.511, 1.52, 1.529, 1.538, 1.547, 1.556, 1.565, 1.574, 1.583, 1.592, 1.601, 1.61, 1.619, 1.628, 1.637, 1.646, 1.655, 1.664, 1.673, 1.682, 1.691, 1.7]))
intensity_per_frame(recalibrated=True)
max(column)
min(column)
minmax(column)
plot_TIC(recalibrated=True, show=True)

Plot peak counts per frame.

Parameters
  • recalibrated (bool) – Use Bruker recalibrated total intensities or calculate them from scratch with OpenTIMS?

  • show (bool) – Show the plot immediately, or just add it to the canvas?

table2df(name)

Retrieve a table with SQLite connection from a data base.

Parameters

name (str) – Name of the table to extract.

Returns

required data frame.

Return type

pd.DataFrame

tables_names()

List names of tables in the SQLite db.

Returns

table with names of tables one can get with ‘table2df’.

Return type

pd.DataTable

timspy.vaex.round10(x)

Module contents