-
Notifications
You must be signed in to change notification settings - Fork 1
/
ParserToTsv.py
57 lines (43 loc) · 1.92 KB
/
ParserToTsv.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
44
45
46
47
48
49
50
51
52
53
54
55
# Sebastien Galvagno 06/2023
import csv
from tools import eprint
from tools import copy_to_file, create_folder
class ParserToTsv:
def __init__(self, project):
self._model = project
self._tsv = self._model.init_tsv()
def read_csv_file(self, file_name, dest_path):
print ("processing: " + file_name)
with open(file_name,"r") as roiFile:
reader = csv.reader( roiFile )
#for data in reader:
line = -1
while True:
line +=1
try:
data = next(reader)
except StopIteration:
break
except csv.Error:
eprint("Cannot read file \"" + file_name + "\" at line " + str(line))
continue
except IOError:
continue
else:
# to filtering the commented line,
# in the sample data we have a file named 20191202.roicoordswithheader.txt
# that contain the header
if data[0][0] == "#" or data[0][0] == "^@":
continue
imageName = data[2]
folder = self._model.define_folders(imageName)
create_folder(folder['destFolder'])
additionaldata = self._model.additionnal_process(folder['imageName']) #TODO change function name
status = copy_to_file( folder['imageName'], folder['destFolder'])
#print("status:" + str(status) )
if status:
tsvrow = self._model.data_to_tsv_format(data)
self._tsv.addData(tsvrow)
#tsvName = self.id(name) + ".tsv"
tsvName = self._tsv.tsv_format_name( folder['tsvName'] )
self._tsv.generate_tsv(folder['destFolder'] / tsvName)