forked from ant-trullo/SegmentTrack_v4.0
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalysisConverter.py
More file actions
128 lines (97 loc) · 5.68 KB
/
AnalysisConverter.py
File metadata and controls
128 lines (97 loc) · 5.68 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"""This function converts analysis run with version 3.3 into analysis done with version 4.0.
It works only on the bulk analysis, no spatial or similar.
"""
import numpy as np
import xlrd
import xlsxwriter
from openpyxl import load_workbook
import AnalysisLoader
import SpotsDetectionChopper
import ParametersExtraction
import SpotsConnection
def converjj_xls2xlsx(foldername):
"""This func converts xls file in xlsx"""
book = xlrd.open_workbook(foldername + '/journal.xls')
book2wrt = xlsxwriter.Workbook(foldername + "/journal.xlsx") # write results
sh_cr = book.sheet_by_index(0)
sheet1_wr = book2wrt.add_worksheet()
for k_vr in range(sh_cr.ncols):
for k_ho in range(sh_cr.nrows):
sheet1_wr.write(k_ho, k_vr, sh_cr.cell(k_ho, k_vr).value)
sheet1_wr.write(22, 1, "SegmentTrackSingleCycleGUI_v4.0")
sheet1_wr.write(16, 1, 0.5)
sheet1_wr.write(16, 0, "Pixel Size Z")
sheet1_wr.write(17, 0, "Frames Pre-Track")
sheet1_wr.write(17, 1, sh_cr.cell(16, 1).value)
book2wrt.close()
def converspts_dvd_bkg_xls2xlsx(foldername):
"""This func converts xls file in xlsx"""
book = xlrd.open_workbook(foldername + '/SpotsIntensityDividedByBackground.xls')
book2wrt = xlsxwriter.Workbook(foldername + "/SpotsIntensityDividedByBackground.xlsx") # write results
for nn in book.sheet_names():
sh_cr = book.sheet_by_name(nn)
sheet1_wr = book2wrt.add_worksheet(nn)
for k_vr in range(sh_cr.ncols):
for k_ho in range(sh_cr.nrows):
sheet1_wr.write(k_ho, k_vr, sh_cr.cell(k_ho, k_vr).value)
book2wrt.close()
def convers_burst_xls2xlsx(foldername):
"""This func converts xls file in xlsx"""
book = xlrd.open_workbook(foldername + '/Bursts_Statistics.xls')
book2wrt = xlsxwriter.Workbook(foldername + "/Bursts_Statistics.xlsx") # write results
for nn in book.sheet_names():
sh_cr = book.sheet_by_name(nn)
sheet1_wr = book2wrt.add_worksheet(nn)
for k_vr in range(sh_cr.ncols):
for k_ho in range(sh_cr.nrows):
sheet1_wr.write(k_ho, k_vr, sh_cr.cell(k_ho, k_vr).value)
book2wrt.close()
class AnalysisConverter:
"""Only class, does all the job"""
def __init__(self, analysis_folder):
nuclei_tracked = np.fromfile(analysis_folder + '/nuclei_tracked.bin', 'uint16')
nuclei_tracked = nuclei_tracked[3:].reshape((nuclei_tracked[2], nuclei_tracked[1], nuclei_tracked[0]))
np.save(analysis_folder + '/nuclei_tracked.npy', nuclei_tracked)
spots_tracked = np.fromfile(analysis_folder + '/spots_tracked.bin', 'uint16')
spots_tracked = spots_tracked[3:].reshape((spots_tracked[2], spots_tracked[1], spots_tracked[0]))
np.save(analysis_folder + '/spots_tracked.npy', spots_tracked)
converjj_xls2xlsx(analysis_folder)
converspts_dvd_bkg_xls2xlsx(analysis_folder)
convers_burst_xls2xlsx(analysis_folder)
green4D = AnalysisLoader.RawData(analysis_folder).green4D
wb = load_workbook(analysis_folder + '/journal.xlsx')
spots_thr_value = wb.active["B7"].value
volume_thr_value = wb.active["B8"].value
max_dist = wb.active["B11"].value
spots_3D = SpotsDetectionChopper.SpotsDetectionChopper(green4D, spots_thr_value, volume_thr_value)
spots_tracked_3D = SpotsConnection.SpotsConnection(nuclei_tracked, np.sign(spots_3D.spots_vol), max_dist).spots_tracked
features_3D = ParametersExtraction.ParametersExtraction(spots_3D.spots_ints, spots_tracked_3D, spots_3D.spots_vol) # spots_3D.spots_vol * np.sign(self.spots_tracked_3D))
np.save(analysis_folder + '/spots_3D_tzxy.npy', spots_3D.spots_tzxy.astype("uint16"))
np.save(analysis_folder + '/spots_3D_vol.npy', spots_3D.spots_vol.astype("uint16"))
np.save(analysis_folder + '/spots_3D_coords.npy', spots_3D.spots_coords.astype("uint16"))
np.save(analysis_folder + '/spots_3D_ints.npy', spots_3D.spots_ints.astype("uint16"))
np.save(analysis_folder + '/spots_features3D.npy', features_3D.statistics_info.astype(float))
# def converjj_xls2xlsx(foldername):
# """This func converts xls file in xlsx"""
# book = xlrd.open_workbook(foldername + '/journal.xls')
# book2wrt = xlsxwriter.Workbook(foldername + "/journal.xlsx") # write results
#
# for nn in book.sheet_names():
# sh_cr = book.sheet_by_name(nn)
# sheet1_wr = book2wrt.add_worksheet(nn)
# for k_vr in range(sh_cr.ncols):
# for k_ho in range(sh_cr.nrows):
# if nn == "Sheet 1" and k_ho == 22 and k_vr == 1:
# sheet1_wr.write(k_ho, k_vr, "SegmentTrackSingleCycleGUI_v4.0")
# if nn == "Sheet 1" and k_ho == 16 and k_vr == 1:
# sheet1_wr.write(k_ho, k_vr, 0.5)
# if nn == "Sheet 1" and k_ho == 16 and k_vr == 0:
# sheet1_wr.write(k_ho, k_vr, "Pixel Size Z")
# # if nn == "Sheet 1" and k_ho == 17 and k_vr == 0:
# # sheet1_wr.write(k_ho, k_vr, "Frames Pre-Track")
# # if nn == "Sheet 1" and k_ho == 17 and k_vr == 1:
# # sheet1_wr.write(k_ho, k_vr, sh_cr.cell(k_ho - 1, k_vr).value)
# else:
# sheet1_wr.write(k_ho, k_vr, sh_cr.cell(k_ho, k_vr).value)
#
# book2wrt.close()