Commit 89237278 authored by Yan's avatar Yan
Browse files

Isotope predictor, minor bug fix

* Now prasopes can predict isotope pattern and plot it into parent
spectrum
* autozoom Y axis action double click in absence of the spectrum now
does not cause exception
parent 5f47af4b
......@@ -9,6 +9,7 @@ from PyQt5 import QtWidgets
from PyQt5 import QtGui
from rawprasslib import load_raw
from rawprasslib import rawprasslib
from prasopes.predictmz import predict as getmzpattern
import prasopes.graphtools as gt
import prasopes.filetools as ft
import prasopes.zcetools as zce
......@@ -81,12 +82,25 @@ def drag_entered(event):
event.accept()
def predictmz(form, chromatogram, spect, ds, ms, chrom):
text = form.text()
if text == "":
ms["predict"] = None
return
slims = [spect.get_xlim(), spect.get_ylim()]
ms["predict"] = getmzpattern(text)
gt.populate(chromatogram, spect, ds, ms, chrom)
spect.set_xlim(slims[0])
spect.set_ylim(slims[1])
spect.get_figure().canvas.draw()
def about(parent):
"""constructs window with "about" info"""
QtWidgets.QMessageBox.information(
parent, "About Prasopes",
"Prasopes Finnigan raw file viewer\n\n"
"Version: 0.0.8 (alpha)")
"Version: 0.0.9 (alpha)")
def main():
......@@ -94,7 +108,7 @@ def main():
ds = dict(chrom_dat=None, masses=None, matrix=None)
ms = dict(x=[0], y=[0], line=None, annotation=[],
name="Spectrum", xlabel="m/z", ylabel="ion count",
xtics=20, autoy=True)
xtics=20, autoy=True, predict=None)
chrom = dict(x=[0], y=[0], line=None, t_start=None, t_end=None,
name="Chromatogram", xlabel="time(min)",
ylabel="total ion count", timesarg=None)
......@@ -185,6 +199,10 @@ def main():
lambda: treedock.show() if filebrowseract.isChecked() == True
else treedock.hide())
predictform = QtWidgets.QLineEdit(maximumWidth=150)
predictform.editingFinished.connect(lambda: predictmz(
predictform, chromatogram, spectrum, ds, ms, chrom))
file_menu = QtWidgets.QMenu('&File', main_window)
main_window.menuBar().addMenu(file_menu)
file_menu.addAction(openact)
......@@ -219,6 +237,10 @@ def main():
toolBar.addAction(drlact)
toolBar.addSeparator()
toolBar.addAction(autozoomy)
toolBar.addSeparator()
toolBar.addWidget(QtWidgets.QLabel("Predict Formula:"))
toolBar.addWidget(predictform)
fileModel = QtWidgets.QFileSystemModel()
fileModel.setRootPath('')
......
......@@ -150,10 +150,11 @@ def autozoomy(state, ms_spec, msdata):
ms_spec.autoscale(True, 'y')
ymin = -0.01
argvis = dt.argsubselect(msdata['x'], *ms_spec.get_xlim())
ymax = max(msdata['y'][argvis])
ms_spec.set_ylim(ymax*ymin,
ymax*1.1)
ms_spec.figure.canvas.draw()
if msdata['y'] != [0]:
ymax = max(msdata['y'][argvis])
ms_spec.set_ylim(ymax*ymin,
ymax*1.1)
ms_spec.figure.canvas.draw()
else:
msdata['autoy'] = False
......@@ -234,6 +235,8 @@ def pop_plot(plot, plot_data):
def populate(mpl_chromatogram, mpl_spectrum, data_set,
mass_spect, chrom_spect):
"""populate the GUI plots with desired dataset"""
if isinstance(data_set['masses'], type(None)):
return
mass_spect['annotation'].clear()
mpl_spectrum.clear()
mpl_chromatogram.clear()
......@@ -241,6 +244,16 @@ def populate(mpl_chromatogram, mpl_spectrum, data_set,
mass_spect['x'] = data_set['masses']
mass_spect['y'] = np.mean(data_set['matrix'], axis=0)
pop_plot(mpl_spectrum, mass_spect)
if mass_spect['predict'] != None:
crudemasses = (np.arange(len(mass_spect['predict'][1]))
+mass_spect['predict'][0])
maxm = crudemasses[np.argmax(mass_spect['predict'][1])]
maxseek = dt.argsubselect(mass_spect['x'], maxm-.5, maxm+.5)
crudeints = mass_spect['predict'][1]*np.amax(mass_spect['y'][maxseek])
pmasses, pints = [], []
[pmasses.extend([np.nan,i,i]) for i in crudemasses]
[pints.extend([np.nan,0,i]) for i in crudeints]
mpl_spectrum.plot(pmasses,pints)
mpl_spectrum.figure.canvas.draw()
chrom_spect['x'] = data_set['chrom_dat'][0, :]
......
#!/usr/bin/env python3
#Part of code implemented from predictmz.py with approval of Andy Ohlin
import re
import numpy as np
pt={
'Ag': [107.0, [0.5184000000000001, 0, 0.4816]],
'Al': [27.0, [1.0]],
'Ar': [36.0, [0.0034000000000000002, 0, 0.00063, 0, 0, 0.996]],
'As': [75.0, [1.0]],
'Au': [197.0, [1.0]],
'B': [10.0, [0.198, 0.802]],
'Ba': [130.0, [0.0011, 0, 0.001, 0, 0, 0.0242, 0, 0, 0.0659, 0, 0, 0.0785, 0, 0, 0.11230000000000001, 0, 0, 0.7170000000000001]],
'Be': [9.0, [1.0]],
'Bi': [209.0, [1.0]],
'Br': [79.0, [0.5069, 0, 0.49310000000000004]],
'C': [12.0, [0.9890000000000001, 0.011000000000000001]],
'Ca': [40.0, [0.9695, 0, 0.006500000000000001, 0, 0.0014000000000000002, 0, 0.02086, 0, 0, 4e-05, 0, 0, 0, 0.0019]],
'Cd': [106.0, [0.0125, 0, 0.0089, 0, 0, 0.1249, 0, 0, 0.128, 0, 0, 0.2413, 0, 0, 0.1222, 0, 0, 0.2873, 0, 0, 0, 0.07490000000000001]],
'Ce': [136.0, [0.0019, 0, 0.0025, 0, 0, 0.8848, 0, 0, 0, 0.1108]],
'Cl': [35.0, [0.7576999999999999, 0, 0.24230000000000002]],
'Co': [59.0, [1.0]],
'Cr': [50.0, [0.0435, 0, 0.8379000000000001, 0, 0.095, 0, 0.0236]],
'Cs': [133.0, [1.0]],
'Cu': [63.0, [0.6917, 0, 0.30829999999999996]],
'Dy': [156.0, [0.0006, 0, 0.001, 0, 0, 0.023399999999999997, 0, 0, 0.18899999999999997, 0, 0, 0.255, 0, 0, 0.249, 0, 0, 0.282]],
'Er': [162.0, [0.0014000000000000002, 0, 0.0161, 0, 0, 0.336, 0, 0, 0.22949999999999998, 0, 0, 0.268, 0, 0, 0, 0.149]],
'Eu': [151.0, [0.478, 0, 0.522]],
'F': [19.0, [1.0]],
'Fe': [54.0, [0.057999999999999996, 0, 0.9172, 0, 0.022000000000000002, 0, 0.0028000000000000004]],
'Ga': [69.0, [0.601, 0, 0.39899999999999997]],
'Gd': [152.0, [0.002, 0, 0.0218, 0, 0.14800000000000002, 0, 0.2047, 0, 0.1565, 0, 0.2484, 0, 0, 0.2186]],
'Ge': [70.0, [0.205, 0, 0.27399999999999997, 0, 0.078, 0, 0.365, 0, 0, 0.078]],
'H': [1.0, [0.9998999999999999, 0.00015]],
'He': [3.0, [1e-06, 1.0]],
'Hf': [174.0, [0.0016, 0, 0.052000000000000005, 0, 0.18600000000000003, 0, 0.271, 0, 0.1374, 0, 0.35200000000000004]],
'Hg': [196.0, [0.0015, 0, 0.10099999999999999, 0, 0.17, 0, 0.231, 0, 0.132, 0, 0.2965, 0, 0, 0.068]],
'Ho': [165.0, [1.0]],
'I': [127.0, [1.0]],
'In': [113.0, [0.043, 0, 0.9570000000000001]],
'Ir': [191.0, [0.373, 0, 0.627]],
'K': [39.0, [0.932, 0.00012, 0.0673]],
'Kr': [78.0, [0.0034999999999999996, 0, 0.0225, 0, 0, 0.11599999999999999, 0, 0, 0.115, 0, 0, 0.57, 0, 0, 0, 0.17300000000000001]],
'La': [138.0, [0.0009, 0.9991]],
'Li': [6.0, [0.0742, 0.9258]],
'Lu': [175.0, [0.9740000000000001, 0.026000000000000002]],
'Mg': [24.0, [0.789, 0.1, 0.111]],
'Mn': [55.0, [1.0]],
'Mo': [92.0, [0.1484, 0, 0.0925, 0, 0.1592, 0, 0.1668, 0, 0.0955, 0, 0.2413, 0, 0, 0.09630000000000001]],
'N': [14.0, [0.9963, 0.0037]],
'Na': [23.0, [1.0]],
'Nb': [93.0, [1.0]],
'Nd': [142.0, [0.2713, 0.12179999999999999, 0.23800000000000002, 0.083, 0.17190000000000003, 0, 0.0576, 0, 0, 0.0564]],
'Ne': [20.0, [0.9059999999999999, 0.0026, 0.092]],
'Ni': [58.0, [0.6827, 0, 0.261, 0, 0.0113, 0, 0.0359, 0, 0, 0.0091]],
'O': [16.0, [0.9976, 0.00037999999999999997, 0.002]],
'Os': [184.0, [0.0002, 0, 0.0158, 0, 0.016, 0, 0.133, 0, 0.161, 0, 0.264, 0, 0, 0.41]],
'P': [31.0, [1.0]],
'Pb': [204.0, [0.013999999999999999, 0, 0.24100000000000002, 0, 0.221, 0, 0.524]],
'Pd': [102.0, [0.0102, 0, 0.1114, 0, 0.22329999999999997, 0, 0.2733, 0, 0, 0.2646, 0, 0, 0, 0.11720000000000001]],
'Pr': [141.0, [1.0]],
'Pt': [190.0, [0.0001, 0, 0.0079, 0, 0, 0.32899999999999996, 0, 0, 0.33799999999999997, 0, 0, 0.253, 0, 0, 0, 0.07200000000000001]],
'Rb': [85.0, [0.7217, 0, 0.2784]],
'Re': [185.0, [0.374, 0, 0.626]],
'Rh': [103.0, [1.0]],
'Ru': [96.0, [0.0552, 0, 0.018799999999999997, 0, 0.127, 0, 0.126, 0, 0.17, 0, 0.316, 0, 0, 0.187]],
'S': [32.0, [0.9501999999999999, 0.0075, 0.0421, 0, 0.0002]],
'Sb': [121.0, [0.573, 0, 0.42700000000000005]],
'Sc': [45.0, [1.0]],
'Se': [74.0, [0.009000000000000001, 0, 0.09, 0, 0.076, 0, 0.235, 0, 0, 0.496, 0, 0, 0, 0.094]],
'Si': [28.0, [0.9223, 0.0467, 0.031]],
'Sm': [144.0, [0.031, 0, 0, 0.15, 0, 0, 0.113, 0, 0, 0.138, 0, 0, 0.07400000000000001, 0, 0, 0, 0.267, 0, 0, 0, 0, 0.22699999999999998]],
'Sn': [112.0, [0.0097, 0, 0.006500000000000001, 0, 0.0036, 0, 0.147, 0, 0.077, 0, 0.243, 0, 0.086, 0, 0.324, 0, 0, 0.046, 0, 0, 0, 0.055999999999999994]],
'Sr': [84.0, [0.005600000000000001, 0, 0.0986, 0, 0.07, 0, 0.8258]],
'Ta': [180.0, [0.00012, 0.9998999999999999]],
'Tb': [159.0, [1.0]],
'Te': [120.0, [0.00096, 0, 0.026000000000000002, 0, 0.0091, 0, 0.0482, 0, 0.07139999999999999, 0, 0.1895, 0, 0, 0.3169, 0, 0, 0, 0.33799999999999997]],
'Th': [232.0, [1.0]],
'Ti': [46.0, [0.08, 0.073, 0.738, 0.055, 0.054000000000000006]],
'Tl': [203.0, [0.2952, 0, 0.7048000000000001]],
'Tm': [169.0, [1.0]],
'U': [234.0, [6e-05, 0.0072, 0, 0, 0.9926999999999999]],
'V': [50.0, [0.0025, 0.9975]],
'W': [180.0, [0.0013, 0, 0.263, 0, 0.14300000000000002, 0, 0.30670000000000003, 0, 0, 0.28600000000000003]],
'Xe': [124.0, [0.001, 0, 0.0009, 0, 0, 0.0191, 0, 0, 0.264, 0, 0, 0.040999999999999995, 0, 0, 0.212, 0, 0, 0.26899999999999996, 0, 0, 0, 0.10400000000000001, 0, 0, 0, 0, 0.08900000000000001]],
'Y': [89.0, [1.0]],
'Yb': [168.0, [0.0013, 0, 0.0305, 0, 0.14300000000000002, 0, 0.21899999999999997, 0, 0.1612, 0, 0.318, 0, 0, 0.127]],
'Zn': [64.0, [0.486, 0, 0.27899999999999997, 0, 0.040999999999999995, 0, 0.188, 0, 0, 0.006]],
'Zr': [90.0, [0.5145000000000001, 0.1127, 0.17170000000000002, 0, 0.17329999999999998, 0, 0, 0.0278]],
}
def formulaExpander(formula):
while len(re.findall('\(\w*\)',formula))>0:
parenthetical=re.findall('\(\w*\)[0-9]+',formula)
for i in parenthetical:
p=re.findall('[0-9]+',str(re.findall('\)[0-9]+',i)))
j=re.findall('[A-Z][a-z]*[0-9]*',i)
oldj=j
for n in range(0,len(j)):
numero=re.findall('[0-9]+',j[n])
if len(numero)!=0:
for k in numero:
nu=re.sub(k,str(int(int(k)*int(p[0]))),j[n])
else:
nu=re.sub(j[n],j[n]+p[0],j[n])
j[n]=nu
newphrase=""
for m in j:
newphrase+=str(m)
formula=formula.replace(i,newphrase)
if (len((re.findall('\(\w*\)[0-9]+',formula)))==0) and (len(re.findall('\(\w*\)',formula))!=0):
formula=formula.replace('(','')
formula=formula.replace(')','')
lopoff=re.findall('[A-Z][a-z]*0',formula)
if lopoff!=[]:
formula=formula.replace(lopoff[0],'')
formula = re.findall(r'([A-Z][a-z]*)([0-9]*)', formula)
return formula
def predict(text):
rawform = formulaExpander(text)
form = []
for element in rawform:
if element[0] in pt.keys():
if element[1] != "":
form+= ([element[0]]*int(element[1]))
else:
form+= ([element[0]])
else:
#TODO: Solve how to proceed
print("warning, element {} does not exist".format(element[0]))
pattern = [1]
smass = 0
for atom in form:
pattern = np.convolve(pattern, pt[atom][1])
smass+=pt[atom][0]
pattern = pattern/np.amax(pattern)
return smass, pattern
......@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
setup(
name="prasopes",
version="0.0.8",
version="0.0.9",
author="Jan Zelenka",
author_email="3yanyanyan@gmail.com",
description="Thermo/Finnigan .raw file viewer based on rawprasslib",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment