pyopenms#
Install pyopenms#
[1]:
!pip install pyopenms --quiet
[2]:
import requests
url = 'https://raw.githubusercontent.com/levitsky/pyteomics/master/tests/test.mzML'
file_name = 'test.mzML'
# # Send a GET request to the URL
response = requests.get(url)
# # Save the content of the response to a file
with open(file_name, 'wb') as file:
file.write(response.content)
print(f'File {file_name} downloaded successfully!')
File test.mzML downloaded successfully!
Load .mzML
file and convert to pd.DataFrame
#
[3]:
import pyopenms as oms
input_file = "./test.mzML"
# open mzML file
exp = oms.MSExperiment()
oms.MzMLFile().load(input_file, exp)
# convert to pd.DataFrame
df = exp.get_df(long=True)
df
[3]:
RT | mz | inty | |
---|---|---|---|
0 | 0.2961 | 200.000183 | 0.0 |
1 | 0.2961 | 200.000427 | 0.0 |
2 | 0.2961 | 200.000671 | 0.0 |
3 | 0.2961 | 200.000916 | 0.0 |
4 | 0.2961 | 202.605835 | 0.0 |
... | ... | ... | ... |
39823 | 0.3561 | 1999.913086 | 0.0 |
39824 | 0.3561 | 1999.937256 | 0.0 |
39825 | 0.3561 | 1999.961548 | 0.0 |
39826 | 0.3561 | 1999.985718 | 0.0 |
39827 | 0.3561 | 2000.009888 | 0.0 |
39828 rows × 3 columns
Convert a single Spectrum as a pd.DataFrame
#
This can be achieved by filtering the dataframe above to the desired spectrum or can be done with the pyopenms interface.
[4]:
spectrum = oms.MSSpectrum(exp.getSpectrum(0))
df = spectrum.get_df()
df
[4]:
mz | intensity | ion_mobility | ion_mobility_unit | ms_level | precursor_mz | precursor_charge | native_id | sequence | ion_annotation | base peak m/z | base peak intensity | total ion current | lowest observed m/z | highest observed m/z | filter string | preset scan configuration | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 200.000188 | 0.0 | NaN | <NONE> | 1 | 0.0 | 0 | controllerType=0 controllerNumber=1 scan=1 | 810 | 1471973 | 15245068 | 200 | 2000 | FTMS + p ESI Full ms [200.00-2000.00] | 1 | ||
1 | 200.000430 | 0.0 | NaN | <NONE> | 1 | 0.0 | 0 | controllerType=0 controllerNumber=1 scan=1 | 810 | 1471973 | 15245068 | 200 | 2000 | FTMS + p ESI Full ms [200.00-2000.00] | 1 | ||
2 | 200.000673 | 0.0 | NaN | <NONE> | 1 | 0.0 | 0 | controllerType=0 controllerNumber=1 scan=1 | 810 | 1471973 | 15245068 | 200 | 2000 | FTMS + p ESI Full ms [200.00-2000.00] | 1 | ||
3 | 200.000915 | 0.0 | NaN | <NONE> | 1 | 0.0 | 0 | controllerType=0 controllerNumber=1 scan=1 | 810 | 1471973 | 15245068 | 200 | 2000 | FTMS + p ESI Full ms [200.00-2000.00] | 1 | ||
4 | 202.605829 | 0.0 | NaN | <NONE> | 1 | 0.0 | 0 | controllerType=0 controllerNumber=1 scan=1 | 810 | 1471973 | 15245068 | 200 | 2000 | FTMS + p ESI Full ms [200.00-2000.00] | 1 | ||
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
19909 | 1999.913081 | 0.0 | NaN | <NONE> | 1 | 0.0 | 0 | controllerType=0 controllerNumber=1 scan=1 | 810 | 1471973 | 15245068 | 200 | 2000 | FTMS + p ESI Full ms [200.00-2000.00] | 1 | ||
19910 | 1999.937296 | 0.0 | NaN | <NONE> | 1 | 0.0 | 0 | controllerType=0 controllerNumber=1 scan=1 | 810 | 1471973 | 15245068 | 200 | 2000 | FTMS + p ESI Full ms [200.00-2000.00] | 1 | ||
19911 | 1999.961513 | 0.0 | NaN | <NONE> | 1 | 0.0 | 0 | controllerType=0 controllerNumber=1 scan=1 | 810 | 1471973 | 15245068 | 200 | 2000 | FTMS + p ESI Full ms [200.00-2000.00] | 1 | ||
19912 | 1999.985729 | 0.0 | NaN | <NONE> | 1 | 0.0 | 0 | controllerType=0 controllerNumber=1 scan=1 | 810 | 1471973 | 15245068 | 200 | 2000 | FTMS + p ESI Full ms [200.00-2000.00] | 1 | ||
19913 | 2000.009947 | 0.0 | NaN | <NONE> | 1 | 0.0 | 0 | controllerType=0 controllerNumber=1 scan=1 | 810 | 1471973 | 15245068 | 200 | 2000 | FTMS + p ESI Full ms [200.00-2000.00] | 1 |
19914 rows × 17 columns