wkumler / mzsql

A repository of data and code showing the efficiency of databases relative to existing mass-spectrometry database formats
0 stars 0 forks source link

mzML things #7

Open wkumler opened 6 days ago

wkumler commented 6 days ago

mzML tasks:

wkumler commented 6 days ago

Chromatogram extraction below:

import matplotlib.pyplot as plt
from pyteomics import mzml, mzmlb
import numpy as np
import pandas as pd

mzml_file = mzml.MzML('180205_Poo_TruePoo_Full1.mzML')

def get_chrom_mzml(file):
    scan_dfs = []
    for spectrum in mzml.MzML(file):
        if spectrum['ms level'] == 1:
            # print(spectrum["index"])
            mz_vals=spectrum['m/z array']
            int_vals = spectrum['intensity array']
            bet_mzs = mz_vals[abs(mz_vals-118.0865)<=0.001]
            bet_ints = int_vals[abs(mz_vals-118.0865)<=0.001]
            # print(bet_mzs)
            # print(bet_ints)
            rt_val = spectrum['scanList']['scan'][0]['scan start time']
            if(len(bet_mzs)>0):
                df_scan = pd.DataFrame({'mz':bet_mzs, 'int':bet_ints, 'rt':[rt_val]*len(bet_mzs)})
                scan_dfs.append(df_scan)    
    return(pd.concat(scan_dfs, ignore_index=True))
chrom_data = get_chrom_mzml('180205_Poo_TruePoo_Full1.mzML')
print(chrom_data)

plt.plot(chrom_data["rt"], chrom_data["int"])
plt.show()