pymzml#
Install pymzml#
[1]:
!pip install pymzml --quiet
[2]:
import pandas as pd
import pymzml
Download the test file#
[3]:
# # Download test file
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
#
[4]:
input_file = "./test.mzML"
run = pymzml.run.Reader(input_file)
# Get the first spec
spec = run.next()
# Convert to Pandas DataFrame
df = pd.DataFrame(spec.centroidedPeaks).rename(columns={0:'mz', 1:'int'})
df
[4]:
mz | int | |
---|---|---|
0 | 204.760065 | 3901.930681 |
1 | 204.778823 | 3431.441349 |
2 | 204.790975 | 3703.068912 |
3 | 204.795946 | 4317.227255 |
4 | 204.797708 | 4267.166873 |
... | ... | ... |
1735 | 1998.647154 | 2567.956920 |
1736 | 1998.908241 | 5539.517009 |
1737 | 1999.254369 | 14109.211636 |
1738 | 1999.510959 | 8432.185933 |
1739 | 1999.782814 | 1875.846606 |
1740 rows × 2 columns