-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnewDataDebug.py
More file actions
120 lines (94 loc) · 3.75 KB
/
Copy pathnewDataDebug.py
File metadata and controls
120 lines (94 loc) · 3.75 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
import pickle
import sys
import altair as alt
from ClumPyCells.Analysis.decisionTree import *
from ClumPyCells.Analysis.markcorrResult import *
from ClumPyCells.Analysis.metadata import *
from ClumPyCells.Analysis.survivalAnalysis import *
IMAGEFOLDER = HOMEDIR + "Result/images/AML/"
sys.path.append(HOMEDIR + "altairThemes.py")
if True: # In order to bypass isort when saving
import altairThemes
# register the custom theme under a chosen name
alt.themes.register("publishTheme", altairThemes.publishTheme)
# enable the newly registered theme
alt.themes.enable("publishTheme")
def get_CD34_count():
AML_file = pd.read_csv(HOMEDIR + "Data/output/AML.csv")
NBM_file = pd.read_csv(HOMEDIR + "Data/output/Normal.csv")
AML_file_old = pd.read_csv(HOMEDIR + "Data/output/AML_old.csv")
NBM_file_old = pd.read_csv(HOMEDIR + "Data/output/Normal_old.csv")
AML_counts = (
AML_file[AML_file["CellType"] == "CD34"]
.groupby(["ImageNumber", "CellType"])
.size()
.reset_index(name="CD34_Count")
)
NBM_counts = (
NBM_file[NBM_file["CellType"] == "CD34"]
.groupby(["ImageNumber", "CellType"])
.size()
.reset_index(name="CD34_Count")
)
AML_counts_old = (
AML_file_old[AML_file_old["CellType"] == "CD34"]
.groupby(["ImageNumber", "CellType"])
.size()
.reset_index(name="CD34_Count")
)
NBM_counts_old = (
NBM_file_old[NBM_file_old["CellType"] == "CD34"]
.groupby(["ImageNumber", "CellType"])
.size()
.reset_index(name="CD34_Count")
)
print("AML CD34 counts:")
print(AML_counts)
print("\nAML CD34 counts (old):")
print(AML_counts_old)
print("\nNBM CD34 counts:")
print(NBM_counts)
print("\nNBM CD34 counts (old):")
print(NBM_counts_old)
def combine_pickle_to_csv():
base_dir = "/Users/leo/ClumPyCells/Result/AML/intensity_withSize2"
for i in range(51):
folder_name = os.path.join(base_dir, f"image_{i}")
iso_file_path = os.path.join(folder_name, "iso.csv")
data = {}
if os.path.exists(folder_name):
for filename in os.listdir(folder_name):
if filename.endswith(".pkl"):
file_path = os.path.join(folder_name, filename)
# Load the pickle data
with open(file_path, "rb") as file:
try:
file_data = pickle.load(file)
except Exception as e:
print(f"Error loading {file_path}: {e}")
exit(1)
data[filename[:-4]] = file_data
if len(data) == 121:
iso = {key: val[0] for key, val in data.items()}
df = pd.DataFrame(iso)
if len(df.columns) not in [36, 49, 64, 81, 100, 121]:
logging.error(
f"image_{i} contains unfinished data (wrong column count: {len(df.columns)})"
)
else:
df.to_csv(os.path.join(folder_name, "iso.csv"))
print(f"saved at {os.path.join(folder_name, 'iso.csv')}")
# print(i, end=" ")
def plot_heatmap_individual_image(image_index):
imageGroup = {f"image_{image_index}": [image_index]}
a = AMLResult(
groups=imageGroup,
sizeCorrection=True,
intensity=True,
resultFolder="/Users/leo/ClumPyCells/Result/AML/intensity_withSize2/",
)
_, plots = a.getAUC(plot=True)
image_auc_plot = a.displayImages(plots, order=[[f"image_{image_index}"]])
image_auc_plot.save(f"{IMAGEFOLDER}image_{image_index}_auc.html")
print(f"Heatmap for image_{image_index} saved.")
plot_heatmap_individual_image(37)