1- import matplotlib .pyplot as plt
2- import matplotlib .gridspec as gridspec
3- from matplotlib_venn import venn3_unweighted
4- import seaborn as sns
5- import numpy as np
6- import pandas as pd
71from DataSet import *
82
93colours = {'NC' :'#CA8151' ,'MC' :'#FFE1B3' ,'SC' :'#307CA1' ,'NC+MC' :'#999999' ,'NC+SC' :'#797979' ,'MC+SC' :'#898989' ,'NC+MC+SC' :'#696969' ,'Mixed' :'#595959' , 'Mixed/MC' : '#494949' }
104
11- def Plot_Patients (Sim_df_lastFrame ,Pat_df_7classes ,Pat_df_3classes , Title = False , FigName = None ):
5+ def plot_Patients (Sim_df_lastFrame ,Pat_df_7classes ,Pat_df_3classes , Title = False , FigName = None ):
126 fig , (ax1 ,ax2 ,ax3 ) = plt .subplots (1 ,3 ,figsize = (16 , 6 ))
137 Sim_sizes = Sim_df_lastFrame ['label' ].value_counts ()
148 Pat_7classes_sizes = Pat_df_7classes ['label' ].value_counts ()
@@ -30,59 +24,71 @@ def Plot_Patients(Sim_df_lastFrame,Pat_df_7classes,Pat_df_3classes, Title=False,
3024 if (FigName ): plt .savefig (FigName )
3125 else : plt .show ()
3226
33- def Plot_Parameters (df_input_min_max_scaled , FigName = None ):
27+ def plot_Parameters (df_input_min_max_scaled , FigName = None ):
3428 df_SC_NC_min_max_scaled = df_input_min_max_scaled .loc [(df_input_min_max_scaled ["label" ] == 'NC' ) | (df_input_min_max_scaled ["label" ] == 'SC' )]
3529 data_plot = pd .melt (df_SC_NC_min_max_scaled , id_vars = ['sample' ,'label' ], value_vars = NameParameters )
3630 plt .figure (figsize = (16 , 6 ))
3731 ax = sns .boxplot (x = "variable" , y = "value" , hue = "label" , data = data_plot , palette = colours , saturation = 1 )
38- ax .set_xticklabels ([r"$r_{recruit}[M ]$" ,r"$\rho_{min}[M ]$" ,r"$\rho_{sat}[M ]$" ,r"$r_{recruit}[D ]$" ,r"$\rho_{min}[D ]$" ,r"$\rho_{sat}[D ]$" ,r"$P_ {leave}[D] $" ,r"$\delta_C$" ,r"$\kappa_{T}$" ,r"$\delta_{DM}$" ],fontsize = 14 )
32+ ax .set_xticklabels ([r"$r_{recruit}[MP ]$" ,r"$\rho_{min}[MP ]$" ,r"$\rho_{sat}[MP ]$" ,r"$r_{recruit}[DC ]$" ,r"$\rho_{min}[DC ]$" ,r"$\rho_{sat}[DC ]$" ,r"$r_ {leave}$" ,r"$\delta_C$" ,r"$\kappa_{T}$" ,r"$\delta_{DM}$" ],fontsize = 14 )
3933 ax .set (xlabel = None )
4034 ax .set_ylabel ('Normalized parameters' ,fontsize = 14 )
4135 ax .legend (loc = 'upper right' , bbox_to_anchor = (1.1 , 1 ),fontsize = 14 )
4236 if (FigName ): plt .savefig (FigName )
4337 else : plt .show ()
4438
45- def Plot_PatientAnalysis (PlotPatientPoint = False , FigName = None ):
39+ def plot_PatientAnalysis (PlotPatientPoint = False , FigName = None ):
4640 df_PatientVariation = PatientsAnalysis ()
47- fig = plt .figure (figsize = (12 , 8 ))
48- G = gridspec .GridSpec (4 , 6 , width_ratios = [1 ,1 ,1 ,1 ,1 ,0.3 ])
41+ fig = plt .figure (figsize = (12 , 10 ))
42+ G = gridspec .GridSpec (4 , 2 , width_ratios = [1 ,0.05 ],height_ratios = [0.01 ,1 ,0.01 ,1 ])
43+ # Patient classified as marginal control
44+ ax_title_1 = plt .subplot (G [0 , 0 ])
45+ ax_title_1 .axis ('off' )
46+ ax_title_1 .set_title ('Ten virtual patients initially classified as marginal control (MC)' )
47+ G0 = gridspec .GridSpecFromSubplotSpec (2 , 5 , subplot_spec = G [1 ,0 ])
48+ # Patient classified as no control
49+ ax_title_2 = plt .subplot (G [2 , 0 ])
50+ ax_title_2 .axis ('off' )
51+ ax_title_2 .set_title ('Ten virtual patients initially classified as no control (NC)' )
52+ G1 = gridspec .GridSpecFromSubplotSpec (2 , 5 , subplot_spec = G [3 ,0 ])
4953 # Axes color bar
50- axcb = plt .subplot (G [:, 5 ])
54+ axcb = plt .subplot (G [:, 1 ])
5155 NewColours = {'NC' : colours ['NC' ], 'Mixed/MC' : colours ['Mixed/MC' ], 'SC' : colours ['SC' ]}
5256 customPalette = sns .color_palette (NewColours .values (),len (NewColours ))
5357
5458 for ind , patientID in enumerate (MC_Patients_samples ):
55- ax = plt .subplot (G [int (ind / 5 ), ind % 5 ])
59+ ax = plt .subplot (G0 [int (ind / 5 ), ind % 5 ])
5660 df = df_PatientVariation .loc [df_PatientVariation ['patientID' ] == patientID ]
61+ df ["label" ] = pd .to_numeric (df ["label" ])
5762 df_wide = df .pivot_table ( index = 'DC_recruit' , columns = 'Mac_recruit' , values = 'label' )
5863 g1 = sns .heatmap (df_wide ,cmap = customPalette ,vmin = 0 ,vmax = 2 ,cbar = False ,ax = ax ,linewidths = .5 )#,annot=True)
5964 g1 .invert_yaxis ()
6065 g1 .set (xlabel = ('' ), ylabel = ('' ), xticks = ([]), yticks = ([]))
61- g1 .set_title ('Patient ' + str (patientID ),color = "#4783af" )
66+ g1 .set_title ('Patient ' + str (patientID )) # ,color="#4783af")
6267 if ( ind % 5 == 0 ): g1 .set_yticks (ticks = [0.01 ,1.5 ,2.99 ],labels = ['0' ,'0.5' ,'1' ])
6368 if (PlotPatientPoint ):
6469 MAC_rec_value = df_input .loc [df_input ['sample' ] == patientID ]['macrophage_max_recruitment_rate' ].values [0 ]
6570 DC_rec_value = df_input .loc [df_input ['sample' ] == patientID ]['DC_max_recruitment_rate' ].values [0 ]
6671 ax .scatter (3 * MAC_rec_value / 8e-9 ,3 * DC_rec_value / 4e-9 , color = colours ['MC' ], edgecolors = 'k' )
6772
6873 for ind , patientID in enumerate (NC_Patients_samples ):
69- ax = plt .subplot (G [ 2 + int ((ind )/ 5 ), ind % 5 ])
74+ ax = plt .subplot (G1 [ int ((ind )/ 5 ), ind % 5 ])
7075 df = df_PatientVariation .loc [df_PatientVariation ['patientID' ] == patientID ]
76+ df ["label" ] = pd .to_numeric (df ["label" ])
7177 df_wide = df .pivot_table ( index = 'DC_recruit' , columns = 'Mac_recruit' , values = 'label' )
7278 if (ind == 9 ): g1 = sns .heatmap (df_wide ,cmap = customPalette ,vmin = 0 ,vmax = 2 ,ax = ax ,linewidths = .5 ,cbar_ax = axcb )#,annot=True)
7379 else : g1 = sns .heatmap (df_wide ,cmap = customPalette ,vmin = 0 ,vmax = 2 ,cbar = False ,ax = ax ,linewidths = .5 )#,annot=True)
7480 g1 .invert_yaxis ()
7581 g1 .set (xlabel = ('' ), ylabel = ('' ), xticks = ([]), yticks = ([]))
76- g1 .set_title ('Patient ' + str (patientID ),color = "#ff7f7f" )
82+ g1 .set_title ('Patient ' + str (patientID )) # ,color="#ff7f7f")
7783 if ( int (ind / 5 ) == 1 ): g1 .set_xticks (ticks = [0.02 ,1.5 ,2.98 ],labels = ['0' ,'0.5' ,'1' ])
7884 if ( ind % 5 == 0 ): g1 .set_yticks (ticks = [0.01 ,1.5 ,2.99 ],labels = ['0' ,'0.5' ,'1' ])
7985 if (PlotPatientPoint ):
8086 MAC_rec_value = df_input .loc [df_input ['sample' ] == patientID ]['macrophage_max_recruitment_rate' ].values [0 ]
8187 DC_rec_value = df_input .loc [df_input ['sample' ] == patientID ]['DC_max_recruitment_rate' ].values [0 ]
8288 ax .scatter (3 * MAC_rec_value / 8e-9 ,3 * DC_rec_value / 4e-9 , color = colours ['NC' ], edgecolors = 'k' )
8389
84- fig .supxlabel (r'$r_{recruit}[M ]$' )
85- fig .supylabel (r'$r_{recruit}[D ]$' )
90+ fig .supxlabel (r'$r_{recruit}[MP ]$' )
91+ fig .supylabel (r'$r_{recruit}[DC ]$' )
8692 # modify colorbar:
8793 colorbar = ax .collections [0 ].colorbar
8894 r = colorbar .vmax - colorbar .vmin
@@ -93,11 +99,22 @@ def Plot_PatientAnalysis(PlotPatientPoint = False, FigName=None):
9399 if (FigName ): plt .savefig (FigName )
94100 else : plt .show ()
95101
96- def Plot_UMAP (Sim_df_lastFrame , FigName = None ):
97- fig = plt .figure (figsize = (8 , 7 ))
98- df_UMAP , df = Loading_UMAP ()
102+ def plot_UMAP (Sim_df_lastFrame , FigName = None , NumSamples = None ):
103+ fig , ax = plt .subplots (nrows = 1 , ncols = 1 ,figsize = (8 , 7 ))
104+ df_UMAP = Loading_UMAP_traj ()
105+ print (df_UMAP )
99106 df_UMAP ['label' ] = Sim_df_lastFrame ['label' ]
100- ax = sns .scatterplot (data = df_UMAP ,x = 'UMAP1' ,y = 'UMAP2' ,hue = 'label' ,palette = [colours ['NC' ],colours ['MC' ],colours ['SC' ]], hue_order = ['NC' ,'MC' ,'SC' ])
107+ if NumSamples :
108+ cluster1 = df_UMAP .loc [ (df_UMAP ['UMAP1' ] < 10 ) & (df_UMAP ['label' ] == 'NC' ) ].sample (n = NumSamples , random_state = 42 ).index .to_numpy ()
109+ cluster2 = df_UMAP .loc [ (df_UMAP ['UMAP1' ] >= 10 ) & (df_UMAP ['label' ] == 'NC' )].sample (n = NumSamples , random_state = 42 ).index .to_numpy ()
110+ df_UMAP ['label' ] = ['NC1' if temp_s in cluster1 else temp_label for temp_s , temp_label in zip (df_UMAP .index .to_numpy (),df_UMAP ['label' ])]
111+ df_UMAP ['label' ] = ['NC2' if temp_s in cluster2 else temp_label for temp_s , temp_label in zip (df_UMAP .index .to_numpy (),df_UMAP ['label' ])]
112+ print (df_UMAP .loc [df_UMAP ['label' ] == 'NC1' ] )
113+ print (df_UMAP .loc [df_UMAP ['label' ] == 'NC2' ] )
114+ hue_order = ['NC' ,'MC' ,'SC' ,'NC1' ,'NC2' ]
115+ sns .scatterplot (data = df_UMAP .sort_values ('label' , key = np .vectorize (hue_order .index )),x = 'UMAP1' ,y = 'UMAP2' ,hue = 'label' ,palette = [[0.79216 , 0.50588 , 0.31765 , 0.1 ],[1.0 , 0.88235 , 0.70196 , 0.1 ],[0.18823 , 0.48627 , 0.63137 , 0.1 ],[0 , 0 , 0 , 1.0 ],[1.0 , 0.0 , 0.0 , 1.0 ]], hue_order = hue_order , ax = ax )
116+ else :
117+ sns .scatterplot (data = df_UMAP ,x = 'UMAP1' ,y = 'UMAP2' ,hue = 'label' ,palette = [colours ['NC' ],colours ['MC' ],colours ['SC' ]], hue_order = ['NC' ,'MC' ,'SC' ], ax = ax )
101118 ax .legend (markerscale = 2.0 , fontsize = 14 )
102119 ax .set_xlabel ('UMAP 1' , fontsize = 14 )
103120 ax .set_ylabel ('UMAP 2' , fontsize = 14 )
@@ -106,11 +123,11 @@ def Plot_UMAP(Sim_df_lastFrame, FigName=None):
106123 if (FigName ): plt .savefig (FigName )
107124 else : plt .show ()
108125
109- def Plot_UMAP_MeanPatients (Pat_df_7classes , FigName = None ):
110- fig = plt .figure ( figsize = (8 , 7 ))
111- df , df_UMAP = Loading_UMAP ()
126+ def plot_UMAP_MeanPatients (Pat_df_7classes , FigName = None ):
127+ fig , ax = plt .subplots ( nrows = 1 , ncols = 1 , figsize = (8 , 7 ))
128+ df_UMAP = Loading_UMAP_avg ()
112129 df_UMAP ['label' ] = Pat_df_7classes ['label' ]
113- ax = sns .scatterplot (data = df_UMAP ,x = 'UMAP1' ,y = 'UMAP2' ,hue = 'label' ,palette = [colours ['NC' ],colours ['MC' ],colours ['SC' ],colours ['NC+MC' ],colours ['NC+SC' ],colours ['MC+SC' ],colours ['NC+MC+SC' ]], hue_order = ['NC' ,'MC' ,'SC' ,'NC+MC' ,'NC+SC' ,'MC+SC' ,'NC+MC+SC' ])
130+ sns .scatterplot (data = df_UMAP ,x = 'UMAP1' ,y = 'UMAP2' ,hue = 'label' ,palette = [colours ['NC' ],colours ['MC' ],colours ['SC' ],colours ['NC+MC' ],colours ['NC+SC' ],colours ['MC+SC' ],colours ['NC+MC+SC' ]], hue_order = ['NC' ,'MC' ,'SC' ,'NC+MC' ,'NC+SC' ,'MC+SC' ,'NC+MC+SC' ], ax = ax )
114131 ax .legend (markerscale = 2.0 , fontsize = 14 )
115132 ax .set_xlabel ('UMAP 1' , fontsize = 14 )
116133 ax .set_ylabel ('UMAP 2' , fontsize = 14 )
@@ -122,12 +139,19 @@ def Plot_UMAP_MeanPatients(Pat_df_7classes, FigName=None):
122139if __name__ == '__main__' :
123140 df_input , df_output = Loading_dataset ()
124141 Sim_df_lastFrame = Classifier_Simulations (df_output )
142+ print ("DataFrame info (UMAP trajectories):" )
143+ print (Sim_df_lastFrame .info ())
144+ # plot_UMAP(Sim_df_lastFrame,FigName='Figure5_B.svg') # Plot UMAP of the trajectories
145+ plot_UMAP (Sim_df_lastFrame ,NumSamples = 4 ,FigName = 'Figure5_B_analysis.png' )
146+ exit ()
147+ print ("DataFrame info (UMAP trajectories): " ,Sim_df_lastFrame .info ())
125148 Pat_df_7classes , Pat_df_3classes = Classifier_Patients (Sim_df_lastFrame )
126- Plot_UMAP (Sim_df_lastFrame ,FigName = 'Figure4_B.svg' ) # Plot UMAP of the trajectories
127- Plot_UMAP_MeanPatients (Pat_df_7classes ,FigName = 'Figure4_D.svg' ) # Plot UMAP of the trajectory averages
128- Plot_Patients (Sim_df_lastFrame ,Pat_df_7classes ,Pat_df_3classes , FigName = 'Figure4_AC.svg' ) # Patient statistics
149+ plot_UMAP_MeanPatients (Pat_df_7classes ,FigName = 'Figure5_D.svg' ) # Plot UMAP of the trajectory averages
150+ print ("DataFrame info (UMAP trajectory averages): " ,Pat_df_7classes .info ())
151+ exit ()
152+ plot_Patients (Sim_df_lastFrame ,Pat_df_7classes ,Pat_df_3classes , FigName = 'Figure5_AC.svg' ) # Patient statistics
129153 # Plot the quartiles of patient features
130154 df_input_min_max_scaled = Normalize_Parameters (df_input , Pat_df_3classes )
131- Plot_Parameters (df_input_min_max_scaled , FigName = 'Figure6_A .svg' )
155+ plot_Parameters (df_input_min_max_scaled , FigName = 'Figure4_A .svg' )
132156 # Plot the analysis of 20 patients
133- Plot_PatientAnalysis (FigName = 'Figure6_B .svg' )
157+ plot_PatientAnalysis (FigName = 'Figure4_B .svg' )
0 commit comments