alphatims#

Launch on Binder

Install alphatims#

[1]:
!pip install alphatims --quiet

Download test data#

[2]:
import requests
import zipfile
import os

# # Define the URL and file name
url = 'https://github.com/MannLabs/alphatims/releases/download/0.1.210317/20201207_tims03_Evo03_PS_SA_HeLa_200ng_EvoSep_prot_DDA_21min_8cm_S1-C10_1_22476.d.zip'
file_name = '20201207_tims03_Evo03_PS_SA_HeLa_200ng_EvoSep_prot_DDA_21min_8cm_S1-C10_1_22476.d.zip'
extract_dir = './'  # Directory to extract the contents

# # Download the file
response = requests.get(url)
with open(file_name, 'wb') as file:
    file.write(response.content)

print(f'File {file_name} downloaded successfully!')

# Unzip the file
with zipfile.ZipFile(file_name, 'r') as zip_ref:
    zip_ref.extractall(extract_dir)

print(f'File extracted to {extract_dir}!')

# Optionally, remove the zip file after extraction
os.remove(file_name)
print(f'Zip file {file_name} removed.')
File 20201207_tims03_Evo03_PS_SA_HeLa_200ng_EvoSep_prot_DDA_21min_8cm_S1-C10_1_22476.d.zip downloaded successfully!
File extracted to ./!
Zip file 20201207_tims03_Evo03_PS_SA_HeLa_200ng_EvoSep_prot_DDA_21min_8cm_S1-C10_1_22476.d.zip removed.

Load .d File and Extra a section of it as a pd.DataFrame#

[3]:
import alphatims.bruker

bruker_dia_d_folder_name = "./20201207_tims03_Evo03_PS_SA_HeLa_200ng_EvoSep_prot_DDA_21min_8cm_S1-C10_1_22476.d"
dda_data = alphatims.bruker.TimsTOF(bruker_dia_d_folder_name)

# Slice the resulting object to return a pandas dataframe
# for full details see https://github.com/MannLabs/alphatims/blob/master/nbs/tutorial.ipynb
dda_data[1] # returns the first spectrum
/opt/hostedtoolcache/Python/3.12.8/x64/lib/python3.12/site-packages/alphatims/bruker.py:237: FutureWarning: ChainedAssignmentError: behaviour will change in pandas 3.0!
You are setting values through chained assignment. Currently this works in certain cases, but when using Copy-on-Write (which will become the default behaviour in pandas 3.0) this will never work to update the original DataFrame or Series, because the intermediate object on which we are setting values will behave as a copy.
A typical example is when you are setting values in a column of a DataFrame, like:

df["col"][row_indexer] = value

Use `df.loc[row_indexer, "col"] = values` instead, to perform the assignment in a single step and ensure this keeps updating the original `df`.

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy

  frames.Id[0] = 0
/opt/hostedtoolcache/Python/3.12.8/x64/lib/python3.12/site-packages/alphatims/bruker.py:238: FutureWarning: ChainedAssignmentError: behaviour will change in pandas 3.0!
You are setting values through chained assignment. Currently this works in certain cases, but when using Copy-on-Write (which will become the default behaviour in pandas 3.0) this will never work to update the original DataFrame or Series, because the intermediate object on which we are setting values will behave as a copy.
A typical example is when you are setting values in a column of a DataFrame, like:

df["col"][row_indexer] = value

Use `df.loc[row_indexer, "col"] = values` instead, to perform the assignment in a single step and ensure this keeps updating the original `df`.

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy

  frames.Time[0] = 0
/opt/hostedtoolcache/Python/3.12.8/x64/lib/python3.12/site-packages/alphatims/bruker.py:239: FutureWarning: ChainedAssignmentError: behaviour will change in pandas 3.0!
You are setting values through chained assignment. Currently this works in certain cases, but when using Copy-on-Write (which will become the default behaviour in pandas 3.0) this will never work to update the original DataFrame or Series, because the intermediate object on which we are setting values will behave as a copy.
A typical example is when you are setting values in a column of a DataFrame, like:

df["col"][row_indexer] = value

Use `df.loc[row_indexer, "col"] = values` instead, to perform the assignment in a single step and ensure this keeps updating the original `df`.

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy

  frames.MaxIntensity[0] = 0
/opt/hostedtoolcache/Python/3.12.8/x64/lib/python3.12/site-packages/alphatims/bruker.py:240: FutureWarning: ChainedAssignmentError: behaviour will change in pandas 3.0!
You are setting values through chained assignment. Currently this works in certain cases, but when using Copy-on-Write (which will become the default behaviour in pandas 3.0) this will never work to update the original DataFrame or Series, because the intermediate object on which we are setting values will behave as a copy.
A typical example is when you are setting values in a column of a DataFrame, like:

df["col"][row_indexer] = value

Use `df.loc[row_indexer, "col"] = values` instead, to perform the assignment in a single step and ensure this keeps updating the original `df`.

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy

  frames.SummedIntensities[0] = 0
/opt/hostedtoolcache/Python/3.12.8/x64/lib/python3.12/site-packages/alphatims/bruker.py:241: FutureWarning: ChainedAssignmentError: behaviour will change in pandas 3.0!
You are setting values through chained assignment. Currently this works in certain cases, but when using Copy-on-Write (which will become the default behaviour in pandas 3.0) this will never work to update the original DataFrame or Series, because the intermediate object on which we are setting values will behave as a copy.
A typical example is when you are setting values in a column of a DataFrame, like:

df["col"][row_indexer] = value

Use `df.loc[row_indexer, "col"] = values` instead, to perform the assignment in a single step and ensure this keeps updating the original `df`.

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy

  frames.NumPeaks[0] = 0
/opt/hostedtoolcache/Python/3.12.8/x64/lib/python3.12/site-packages/alphatims/bruker.py:242: FutureWarning: ChainedAssignmentError: behaviour will change in pandas 3.0!
You are setting values through chained assignment. Currently this works in certain cases, but when using Copy-on-Write (which will become the default behaviour in pandas 3.0) this will never work to update the original DataFrame or Series, because the intermediate object on which we are setting values will behave as a copy.
A typical example is when you are setting values in a column of a DataFrame, like:

df["col"][row_indexer] = value

Use `df.loc[row_indexer, "col"] = values` instead, to perform the assignment in a single step and ensure this keeps updating the original `df`.

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy

  frames.MsMsType[0] = 0
100%|██████████| 11886/11886 [00:03<00:00, 3014.40it/s]
[3]:
raw_indices frame_indices scan_indices precursor_indices push_indices tof_indices rt_values rt_values_min mobility_values quad_low_mz_values quad_high_mz_values mz_values intensity_values corrected_intensity_values
0 0 1 52 0 980 255431 0.564402 0.009407 1.580692 -1.0 -1.0 913.250345 10 10
1 1 1 63 0 991 308595 0.564402 0.009407 1.568660 -1.0 -1.0 1185.318098 86 86
2 2 1 69 0 997 160184 0.564402 0.009407 1.562095 -1.0 -1.0 514.400704 159 159
3 3 1 77 0 1005 375561 0.564402 0.009407 1.553337 -1.0 -1.0 1578.430403 53 53
4 4 1 78 0 1006 248580 0.564402 0.009407 1.552242 -1.0 -1.0 880.766749 47 47
... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
17036 17036 1 919 0 1847 74875 0.564402 0.009407 0.609185 -1.0 -1.0 253.681834 81 81
17037 17037 1 919 0 1847 112482 0.564402 0.009407 0.609185 -1.0 -1.0 357.374903 253 253
17038 17038 1 919 0 1847 143231 0.564402 0.009407 0.609185 -1.0 -1.0 455.328372 130 130
17039 17039 1 923 0 1851 160022 0.564402 0.009407 0.604592 -1.0 -1.0 513.819175 154 154
17040 17040 1 923 0 1851 167506 0.564402 0.009407 0.604592 -1.0 -1.0 541.027761 174 174

17041 rows × 14 columns