-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSIU_CV_Correction.py
More file actions
108 lines (89 loc) · 3.4 KB
/
SIU_CV_Correction.py
File metadata and controls
108 lines (89 loc) · 3.4 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import csv
import tkinter
from tkinter import filedialog
from tkinter import simpledialog
import pandas as pd
import numpy as np
# set up Tkinter
root = tkinter.Tk()
root.withdraw()
def CV_modification(exp_file, outdir):
print(f"Input = {exp_file}")
df = pd.read_csv(filepath_or_buffer=exp_file, sep=',', header=1)
# column names
columns = df.keys()
trapCVrows = df.loc[0]
trapCVrows = trapCVrows[1:].astype('int') - 10
print(f"columns = {columns}")
print(f"trapCVrows = {trapCVrows}")
# Set outputpath
expfilesplits = exp_file.split('/')
outfile = expfilesplits[-1]
outfile = outfile.replace(".csv", f"_SIU_CVcorrected_raw.csv")
outputpath = outdir + '/' + outfile
print(f"output = {outputpath}")
#adding back the trap cvs
df.loc[0] = trapCVrows
#Convert data frame to csv
df.to_csv(outputpath, index=False)
def CV_correction_main():
txtraw_files = filedialog.askopenfilenames(title='Choose _raw.csv vendor specific Files',
filetypes=[('TWIM_Extract files', '.txt_raw.csv')])
# Where to save results
outputdir = filedialog.askdirectory(title='Choose Output Folder')
for file_index, file in enumerate(txtraw_files):
print('Processing file {} of {}...'.format(file_index + 1, len(txtraw_files)))
if file.endswith(".csv"):
CV_modification(file, outputdir)
# filename = filedialog.askopenfilename(title='Choose _raw.csv input file', filetypes=[("CSV Files", "*.csv")])
# print('filename:', filename)
# csvpath = r"C:/Desktop/Research/CIUSuite/CIUSuite3dev"
# Define the input and output file paths
#input_file = '2022_0204_BSA_CIU_4220mz_500WV_27WH_1.txt_raw.csv'
# output_file = "output.csv"
# Read the input file and extract the columns
# cols = []
# with open(exp_file, "r") as f:
# reader = csv.reader(f)
# #headers = next(reader) # Extract the header row
# for column in reader:
# cols.append(column)
# return cols, filename
#
#
#
# def cv_subtraction(columns):
# indices = []
# for i in range(len(columns)):
# for j in range(len(columns[i])):
# if i == 2 and j >= 1:
# print(columns[i][j])
# columns[i][j] = float(columns[i][j]) - 10
#
# if columns[i][j] < 0:
# print("column_neg =", i, j)
# indices.append(j)
# print("indices:", indices)
# for i in range(len(columns)):
# for j in range(len(indices)):
# del columns[i][indices[j]]
# # Write the updated columns to the output file with the same format as the input file
# return columns
#
# def write_csv(columns, outfile):
# with open(outfile, "w", newline="") as f:
# writer = csv.writer(f)
# #writer.writerow(headers) # Write the header row
# writer.writerows(columns)
#
# def CV_correction_main():
# columns, fpath = read_from_csv()
# fname = fpath.split("/")[-1]
# # fname_list = fname.split(".")
# # fname_list[-2] = "SIU_raw"
# outfile = fname.replace(".csv", f"_SIU_CVcorrected_raw.csv")
# print(outfile)
# columns_corrected = cv_subtraction(columns)
# write_csv(columns_corrected, outfile)
if __name__ == '__main__':
CV_correction_main()