-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoopedNormalization2.py
More file actions
80 lines (57 loc) · 1.96 KB
/
Copy pathLoopedNormalization2.py
File metadata and controls
80 lines (57 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
# coding: utf-8
# In[4]:
import os
import csv
import pandas as pd
import PySimpleGUI as sg
sg.theme('SandyBeach')
layout = [
[sg.Text('How many normalization columns would you like to add?')],
[sg.Text('Number of times', size =(15, 1)), sg.InputText()],
[sg.Submit(), sg.Cancel()]
]
window = sg.Window('Simple data entry window', layout)
event, values = window.read()
window.close()
numTimes=int(values[0])
counter=0
while counter<numTimes:
sg.theme('SandyBeach')
layout = [
[sg.Text('Please enter reference m/z, C13, and name for new column')],
[sg.Text('Reference m/z', size =(15, 1)), sg.InputText()],
[sg.Text('Column Name', size =(15, 1)), sg.InputText()],
[sg.Text('C13', size =(15, 1)), sg.InputText()],
[sg.Submit(), sg.Cancel()]
]
window = sg.Window('Simple data entry window', layout)
event, values = window.read()
window.close()
refNum=float(values[0])
newColumnHeader=values[1]
C13Value=int(values[2])
print("Using reference m/z of " + str(refNum))
print("New Column Name is "+ newColumnHeader)
for filename in os.scandir():
try:
if filename.path.endswith(".csv"):
df = pd.read_csv(filename.name)
#extracts denominator using refNum and 13C==0
denominator=df.loc[(df['Ref m/z'] == refNum) & (df["13C"]==C13Value)]["Corrected Intensity"].iloc[0]
#dividing everything and adding to column
addColumn=[]
numerators= df["Corrected Intensity"]
for num in numerators:
addColumn.append(num/denominator)
df[newColumnHeader]=addColumn
#overwrites to csv
df.to_csv(filename.name, index=False)
print("Done: "+ filename.name)
except:
print("Error: " +filename.name)
pass
counter+=1
# ###
# In[ ]:
# In[ ]: