-
Notifications
You must be signed in to change notification settings - Fork 0
/
final.py
173 lines (128 loc) · 6.44 KB
/
final.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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import subprocess
import pandas as pd
import os
import glob
df=pd.read_csv('muscle_atlas_clean.csv')
#### Partie HE ##########
#### Préparation des listes pour les images######
df_HE=df[(df['Staining method'].str.contains( 'HE',na=False))]
images_HE = list(df_HE["Number"])
for images in images_HE:
chemin = "Images/" + images
myoquant= subprocess.run(['myoquant', "he-analysis", chemin,'--output-path', '/Users/afaf/stage-afaf/data'])
#Mes fonctions
def conversion_pix_µm(im, data_frame,muscle_atlas):
'Convertion du diamètre en µm'
barre_echelle= muscle_atlas.loc[(df['Number']== im), 'Calibration (um/px)']
data_frame['diameter_µm']=(data_frame['feret_diameter_max'].values)*barre_echelle.values
def count_atrophic_cells (data_frame,min_size, max_size):
"""
Comptes le nombre de cellules normales, hyper ou hypo atrophique. min_size et max_size peuvent être changer ici on a pris les tailles trouvés dans la littéature
"""
hyper='Hypertrophy'
hypo= 'Hypotrophy'
norm= 'Normal'
data_frame["State_cell"] = ''
for index in data_frame.index:
a=data_frame['diameter_µm'][index]
if a > max_size:
data_frame["State_cell"][index]=hyper
elif a < min_size:
data_frame["State_cell"][index]=hypo
else:
data_frame["State_cell"][index]= norm
#J'applique les fonctions sur les données
ath = os.getcwd()
csv_files = []
for folder, subs, files in os.walk("data"):
for filename in files:
if filename.endswith(('_cell_details.csv')):
csv_files .append(os.path.abspath(os.path.join(folder, filename)))
for f in csv_files:
df_cell_details = pd.read_csv(f)
for images in images_HE:
conversion_pix_µm(images,df_cell_details,df )
count_atrophic_cells (df_cell_details, 30, 80)
#print('Location:', f)
#print('File Name:', f.split("//")[-1])
#display(df_cell_details)
df_cell_details.to_csv(f,sep=",", index=False)
def pourcentage_state_cell (im,data_frame,muscle_atlas):
"""
Calcul du pourcentage des cellules normales, hypo et hyper atrophique
"""
data = {'Number':[],'Hypertrophy': [],'Normal':[],'Hypotrophy': []} # Ici on créer un dataframe pour mettre ensuite les valeurs des pourcentages
df_state_cell = pd.DataFrame(data)
percentage= (data_frame['State_cell'].value_counts()/data_frame['State_cell'].count())*100
df_state_cell.loc[len(df_state_cell.index)] = percentage
muscle_atlas.loc[(muscle_atlas['Number']== im),"Hypertrophic_cell_%"]=df_state_cell['Hypertrophy'].values
muscle_atlas.loc[(muscle_atlas['Number']== im),"Normal_cell_%"]=df_state_cell['Normal'].values
muscle_atlas.loc[(muscle_atlas['Number']== im),"Hypotrophic_cell_%"]=df_state_cell['Hypotrophy'].values
def diameter_mean_std (im,data_frame,muscle_atlas):
"""
Calcul du diamètre moyen, ainsi que de l'écart type du diamètre
"""
cell_mean=data_frame['diameter_µm'].mean()
cell_std=data_frame['diameter_µm'].std()
muscle_atlas.loc[(muscle_atlas['Number']== im),"diameter_mean"]=cell_mean
muscle_atlas.loc[(muscle_atlas['Number']== im),"diameter_std"]=cell_std
for f,images in zip(csv_files,images_HE):
df_cell_details = pd.read_csv(f)
pourcentage_state_cell (images,df_cell_details,df)
#display(df.head(10))
diameter_mean_std(images,df_cell_details,df)
fichier = []
for folder, subs, files in os.walk("data"):
for filename in files:
if filename.endswith(('_results_summary.csv',)):
fichier.append(os.path.abspath(os.path.join(folder, filename)))
def ajout_He (im,dataframe,muscle_atlas):
"""
Ajout des données générées par Myoquant dans l'atlas du muscle
"""
muscle_atlas.loc[(muscle_atlas['Number']== im),"Proportion_nuclei"]=dataframe.loc['Proportion (%)','N° Nuclei']
muscle_atlas.loc[(muscle_atlas['Number']== im),"Number_nuclei"]=dataframe.iloc[0,0]
muscle_atlas.loc[(muscle_atlas['Number']== im),"Proportion_intern_nuclei"]=dataframe.loc['Proportion (%)','N° Intern. Nuclei']
muscle_atlas.loc[(muscle_atlas['Number']== im),"Number_intern_nuclei"]=dataframe.iloc[0,1]
muscle_atlas.loc[(muscle_atlas['Number']== im),"Number_Periph_nuclei"]=dataframe.iloc[0,2]
muscle_atlas.loc[(muscle_atlas['Number']== im),"Proportion_Periph_nuclei"]=dataframe.loc['Proportion (%)','N° Periph. Nuclei']
muscle_atlas.loc[(muscle_atlas['Number']== im),"Number_Cells with 1+ intern.nuc"]=dataframe.iloc[0,3]
muscle_atlas.loc[(muscle_atlas['Number']== im),"Proportion_Cells with 1+ intern. nuc"]=dataframe.loc['Proportion (%)','N° Cells with 1+ intern. nuc.']
for i ,images in zip(fichier,images_HE):
df_results_summary=pd.read_csv(i)
df3=df_results_summary.set_index('Feature')
df4=df3.transpose()
ajout_He(images,df4,df)
#########Partie SDH ##########
####Préparation des listes pour les images######
df_SDH=df[(df['Staining method'].str.contains( 'SDH',na=False))]
images_SDH= list(df_SDH["Number"])
for chemin_image in images_SDH:
myoquant_sdh= subprocess.run(['myoquant', "sdh-analysis",chemin_image ,'--output-path', '/Users/afaf/stage-afaf/data'])
fichier_sdh = []
for folder, subs, files in os.walk("data"):
for filename_sdh in files:
if filename_sdh.endswith(('_results.csv')):
fichier_sdh.append(os.path.abspath(os.path.join(folder, filename_sdh)))
#import glob
#glob("Users/afaf/stage-afaf/Images_sdh/*.jpg")
def ajout_SDH (im,dataframe,muscle_atlas):
""" Ajout des données générées par myoquant dans l'atlas du muscle """
muscle_atlas.loc[(muscle_atlas['Number']== im),"Total cells (%)"]=dataframe.iloc[1,0]
muscle_atlas.loc[(muscle_atlas['Number']== im),"Number_cells"]=dataframe.iloc[0,0]
muscle_atlas.loc[(muscle_atlas['Number']== im),"normals_cells (%)"]=dataframe.iloc[1,1]
muscle_atlas.loc[(muscle_atlas['Number']== im),"normals_cells"]=dataframe.iloc[0,1]
muscle_atlas.loc[(muscle_atlas['Number']== im),"sick_cells"]=dataframe.iloc[0,2]
muscle_atlas.loc[(muscle_atlas['Number']== im),"sick_cells (%)"]=dataframe.iloc[1,2]
for j ,images1 in zip(fichier_sdh,images_SDH):
df_results_sdh=pd.read_csv(j)
df_sdh=df_results_sdh.set_index('Feature')
df_sdh1=df_sdh.transpose()
data_sdh = {'Muscle Fibers': [],'control':[],'sick': []}
df_sdh2 = pd.DataFrame(data_sdh)
df_sdh3 = df_sdh2.append(df_sdh1,ignore_index = True)
#display(df_sdh3)
df_sdh3.to_csv(j,sep=",", index=False)
for j ,images1 in zip(fichier_sdh,images_SDH):
df_sdh_final=pd.read_csv(j)
ajout_SDH(images1,df_sdh_final,df)