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

Closed wkumler closed 2 days ago

wkumler commented 3 weeks ago

mzML tasks:

wkumler commented 3 weeks ago

Chromatogram extraction below:

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

def pmppm(mass, ppm=4):
    return(mass*(1-ppm/1000000), mass*(1+ppm/1000000))

def get_chrom_mzml(file, mz, ppm):
    scan_dfs = []
    for spectrum in mzml.MzML(file):
        if spectrum['ms level'] == 1:
            rt_val = spectrum['scanList']['scan'][0]['scan start time']
            mz_vals=spectrum['m/z array']
            int_vals = spectrum['intensity array']

            mzmin, mzmax = pmppm(mz, ppm)
            bet_idxs = (spectrum["m/z array"]>mzmin) & (spectrum["m/z array"]<mzmax)
            if(sum(bet_idxs)>0):
                df_scan = pd.DataFrame({'mz':mz_vals[bet_idxs], 'int':int_vals[bet_idxs], 'rt':[rt_val]*sum(bet_idxs)})
                scan_dfs.append(df_scan)    
    return(pd.concat(scan_dfs, ignore_index=True))

chrom_data = get_chrom_mzml('180205_Poo_TruePoo_Full1.mzML', 118.0865, 10)

plt.plot(chrom_data["rt"], chrom_data["int"])
plt.show()
wkumler commented 2 days ago

Also added multiple packages for mzML extraction!