-
Notifications
You must be signed in to change notification settings - Fork 0
/
writeOutputFile.py
43 lines (27 loc) · 1.06 KB
/
writeOutputFile.py
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
#!/usr/bin/env python3
import pandas as pd
def writeOutputFile(results, filename):
"""
Parameters
----------
results: list or list of numpy arrays
predicted elemental compositions
filename: string
"""
if filename.lower().endswith(".csv"):
formatFile = ".csv"
elif filename.lower().endswith(".txt"):
formatFile = ".txt"
else:
print("Unsupported file format: " + filename)
return
output = pd.DataFrame(results[0], columns=["C", "H", "N", "O", "S", "calc_mass","input_neutral_mass"])
for n in range(1,len(results)):
if len(results[n]) != 0:
output = output.append(pd.DataFrame(results[n], columns=["C", "H", "N", "O", "S", "calc_mass", "input_neutral_mass"]), ignore_index= True)
file = open(filename,"w",newline='')
if formatFile == ".txt":
output.to_csv(file, sep="\t", index=False)
elif formatFile == ".csv":
output.to_csv(file, sep=",", index=False, line_terminator="")
file.close()