In [2]:
import sys
sys.path.append( '/Users/bpb/Data/programming/MetaboliteAtlas/metatlas2p0/metatlas/metatlas' )
import h5_query as h5q
import mzml_loader as mzml_loader
import numpy as np
import tables
import matplotlib.pyplot as plt
%matplotlib inline
%config InlineBackend.figure_format = 'svg'
In [3]:
mypath = '/Users/bpb/Downloads/20150326_BN6_BN7/'
# mypath = '/Users/bpb/Downloads/'
In [4]:
# import os
# for file in os.listdir(mypath):
# if file.endswith(".mzML"):
# filename = '%s%s' % (mypath,file)
# mzml_loader.mzml_to_hdf(filename)
# print filename
In [95]:
# myfile = '20141211_caj211_Ecoli_unlabelled_glucose_POS.h5'
# myfile = '2015326_pHILIC_ACN_POS_MSMS_BN7_1062_SAR11_media_WithPolyamines_PPLex_95_Run36.h5'
# myfile = '2015326_pHILIC_ACN_POS_MSMS_BN6_1062_SAR11_media_NoOsmolytes_PPLex_26_Run32.h5'
# myfile = '2015326_pHILIC_ACN_POS_MSMS_BN6_1062_SAR11_media_WithOsmolytes_PPLex_43_Run21.h5'
myfile = '2015326_pHILIC_ACN_POS_MSMS_BN6_7211_SAR11_media_WithOsmolytes_PPLex_53_Run22.h5'
# myfile = '2015326_pHILIC_ACN_NEG_MSMS_BN6_1062_SAR11_media_WithOsmolytes_PPLex_42_Run15.h5'
# myfile = '2015326_pHILIC_ACN_NEG_MSMS_BN6_7211_SAR11_media_WithOsmolytes_PPLex_53_Run22.h5'
filename = '%s%s' % (mypath,myfile)
fid = tables.open_file(filename)
In [134]:
# get total spectrum
min_rt = 12
max_rt = 14
ms_level = 2
polarity = 1
mz,intensity = h5q.get_spectrogram(fid, min_rt, max_rt, ms_level, polarity,bins=1e6)
In [140]:
idx = np.argsort(intensity)
for i in idx:
if intensity[i] > 1:
if mz[i] < 140:
print mz[i]
In [139]:
plt.plot(mz,intensity)
plt.xlim(0,140)
plt.show()
# print len(rt)
In [107]:
# get coarse 2d hist
mzEdges = np.linspace(80, 220,500)
rtEdges = np.linspace(2,15,500)
ms_level = 1
polarity = 1
hMap = h5q.get_HeatMapRTMZ(fid,mzEdges,rtEdges,ms_level,polarity)
h5q.plot_heatmap((hMap['arr']+1)**0.5,hMap['rt_bins'],hMap['mz_bins'],title='entire file')
plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
In [106]:
plt.plot(hMap['rt_bins'],np.max(hMap['arr'],axis=0))
plt.show
Out[106]:
In [146]:
# mz_theor = 89.0477 - 1.007276 # sarcosine minus proton
# mz_theor = 89.0477 + 59.013851 # sarcosine plus acetate anion
# mz_theor = 89.0477 + 1.007276 # sarcosine plus proton
# mz_theor = 105.0426 + 1.007276 # serine plus proton
# mz_theor = 105.0426 + 59.013851# serine plus acetate anion
# mz_theor = 149.051024 + 1.007276
# mz_theor = 202.033819322 - 1.007276 #5-hydroxy-2-oxo-4-ureido-2,5-dihydro-1H-imidazole-5-carboxylate
# mz_theor = 132.90533751
mz_theor = 132.904971 #bromomethane plus potassium
print mz_theor
In [147]:
polarity = 1
rt,intensity = h5q.get_XIC(fid, mz_theor - mz_theor*5/1e6, mz_theor + mz_theor*5/1e6, 1, polarity)
In [148]:
plt.plot(rt,intensity)
plt.xlim(10,15)
plt.show()
print len(rt)
In [145]:
ms_level=2
rt_min = 12
rt_max = 14
data = h5q.get_data(fid, ms_level, polarity,
min_mz=0,
max_mz=mz_theor+10,
min_rt=rt_min,
max_rt=rt_max,
min_precursor_MZ=mz_theor - mz_theor*100/1e6,
max_precursor_MZ=mz_theor + mz_theor*100/1e6)
# min_precursor_intensity=0,
# max_precursor_intensity=0,
# min_collision_energy=0,
# max_collision_energy=0)
plt.vlines(data['mz'],0,data['i'],color='k',linestyles='solid')
plt.xlabel('m/z')
plt.ylabel('intensity')
# plt.plot(data['mz'],data['i'])
plt.show()
idx = np.argsort(data['i'])
print data['mz'][idx]
In [161]:
mzEdges = np.linspace(mz_theor - 5.5, mz_theor + 5.1,100)
rtEdges = np.linspace(10,16,100)
ms_level = 1
polarity = 1
hMap = h5q.get_HeatMapRTMZ(fid,mzEdges,rtEdges,ms_level,polarity)
h5q.plot_heatmap(hMap['arr'],hMap['rt_bins'],hMap['mz_bins'],title='Maybe Methyl Bromide')
plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
In [150]:
mz_centroid = np.sum( np.multiply( np.sum(hMap['arr'],axis=1), hMap['mz_bins']) ) / np.sum( hMap['arr'] )
print "The measured centroid from this 2d hist is %5.5f" % mz_centroid
In [151]:
mzEdges = np.linspace(mz_theor - 0.05, mz_theor + 0.05, 100)
rtEdges = np.linspace(12,15,100)
ms_level = 1
polarity = 1
hMap = h5q.get_HeatMapRTMZ(fid,mzEdges,rtEdges,ms_level,polarity)
h5q.plot_heatmap(hMap['arr'],hMap['rt_bins'],hMap['mz_bins'],title='Methionine')
plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
In [152]:
mz_centroid = np.sum( np.multiply( np.sum(hMap['arr'],axis=1), hMap['mz_bins']) ) / np.sum( hMap['arr'] )
print "The measured centroid from this 2d hist is %5.5f" % mz_centroid
In [156]:
mzEdges = np.linspace(mz_theor - 0.001, mz_theor + 0.001,100)
rtEdges = np.linspace(11,15,100)
ms_level = 1
polarity = 1
hMap = h5q.get_HeatMapRTMZ(fid,mzEdges,rtEdges,ms_level,polarity)
h5q.plot_heatmap(hMap['arr'],hMap['rt_bins'],hMap['mz_bins'],title='Methionine')
plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
In [154]:
mz_centroid = np.sum( np.multiply( np.sum(hMap['arr'],axis=1), hMap['mz_bins']) ) / np.sum( hMap['arr'] )
print "The measured centroid from this 2d hist is %5.5f" % mz_centroid
In [17]:
print hMap['arr'].shape
print hMap['mz_bins'].shape
print hMap['rt_bins'].shape
In [ ]: