|
@@ -32,24 +32,28 @@ selected_mask_names_with_dilations = {
|
|
|
"CST_MOp-int-py_ipsilesional_CCcut": 2,
|
|
|
"OT_och-lgn_lgncut": 2,
|
|
|
"TC_DORsm-SSp_ll+SSp_ul_ipsilesional_END+higherstepsize_": 0,
|
|
|
- "TC_DORsm-SSp+SSs_contralesional_END+CCcut": 0
|
|
|
+ "TC_DORsm-SSp+SSs_contralesional_END+CCcut": 0,
|
|
|
+ "L_cst_784_AMBA":0,
|
|
|
+ "L_cc_776_AMBA":0,
|
|
|
+ "L_VIS_669_AMBA":0
|
|
|
} # Set mask names and their specific dilation amounts for Qtype 'fa'
|
|
|
|
|
|
-# Define simple anatomical names for the masks
|
|
|
+# Define simple anatomical names for the masks (this is not correct)
|
|
|
mask_name_mapping = {
|
|
|
- "CRuT_MOp-RN_ipsilesional_CCcut": "Rubropsinal (Ipsilesional)",
|
|
|
- "CRuT_MOp-RN_contralesional_mirrored_CCcut": "Rubropsinal (Contralesional)",
|
|
|
- "CReT_MOp-TRN_ipsilesional_CCcut": "Reticulospinal (Ipsilesional)",
|
|
|
- "CReT_MOp-TRN_contralesional_CCcut": "Reticulospinal (Contralesional)",
|
|
|
- "CST_MOp-int-py_ipsilesional_selfdrawnROA+CCcut": "Corticospinal (Ipsilesional)",
|
|
|
- "CST_MOp-int-py_contralesional_selfdrawnROA+CCcut": "Corticospinal (Contralesional)",
|
|
|
- "CC_MOp-MOp_cut": "Corpus Callosum",
|
|
|
- "OT_och-lgn_lgncut": "Optic"
|
|
|
+ "CRusdT_MOp-RN_ipsilesional_CCcut": "Rubropsisdnal (Ipsilesional)",
|
|
|
+ "CRuT_MOp-RN_contralesional_sdmirrored_CCcut": "Rubsdropsinal (Contralesional)",
|
|
|
+ "CReT_MOp-TRN_ipsilesionalsd_CCcut": "Reticulsdospinal (Ipsilesional)",
|
|
|
+ "CReT_MOp-TRN_contralesionsdal_CCcut": "Reticulosdspinal (Contralesional)",
|
|
|
+ "CST_MOp-int-py_ipsilesional_selfdrawnROA+CsdCcut": "Csdorticospinal (Ipsilesional)",
|
|
|
+ "CST_MOp-int-py_contralesional_selfdrawsdnROA+CCcut": "Csdorticospinal (Contralesional)",
|
|
|
+ "CC_MOp-MOp_cusdt": "Corpus Calsdlosum",
|
|
|
+ "OT_och-lgn_lsdgncut": "Optisdc"
|
|
|
}
|
|
|
|
|
|
# Define the PlotBoxplot function
|
|
|
|
|
|
-# Define the PlotBoxplot function
|
|
|
+import numpy as np
|
|
|
+from pandas.api.types import CategoricalDtype
|
|
|
|
|
|
def PlotBoxplot(filtered_df_stroke, filtered_df_sham, qq, mm, dd, output_folder):
|
|
|
"""
|
|
@@ -69,6 +73,14 @@ def PlotBoxplot(filtered_df_stroke, filtered_df_sham, qq, mm, dd, output_folder)
|
|
|
# Set font to Calibri
|
|
|
plt.rcParams['font.family'] = 'Calibri'
|
|
|
|
|
|
+ # Define the categorical order for merged_timepoint
|
|
|
+ timepoint_order = ["0", "3", "7", "14", "21", "28"]
|
|
|
+ cat_type = CategoricalDtype(categories=timepoint_order, ordered=True)
|
|
|
+
|
|
|
+ # Convert merged_timepoint to categorical with the defined order to align with categorical boxplot positions
|
|
|
+ filtered_df_stroke["merged_timepoint"] = filtered_df_stroke["merged_timepoint"].astype(str).astype(cat_type)
|
|
|
+ filtered_df_sham["merged_timepoint"] = filtered_df_sham["merged_timepoint"].astype(str).astype(cat_type)
|
|
|
+
|
|
|
# Create the figure with subplots
|
|
|
fig, axes = plt.subplots(1, 2, figsize=(18 / 2.54, 8 / 2.54)) # Convert cm to inches
|
|
|
|
|
@@ -79,11 +91,7 @@ def PlotBoxplot(filtered_df_stroke, filtered_df_sham, qq, mm, dd, output_folder)
|
|
|
whiskerprops={'color': 'black', 'linewidth': 0.8},
|
|
|
fliersize=0, linewidth=1.0, boxprops={'linewidth': 0.8}
|
|
|
)
|
|
|
- sns.stripplot(
|
|
|
- data=filtered_df_stroke, hue="Group", y="Value", x="merged_timepoint",
|
|
|
- ax=axes[0], dodge=True, palette=custom_colors,
|
|
|
- alpha=1.0, size=2, jitter=True, marker='o', legend=False
|
|
|
- )
|
|
|
+
|
|
|
sns.despine(ax=axes[0], right=True, top=True)
|
|
|
axes[0].set_title(f'Stroke - {qq}\n{mask_name_mapping.get(mm, mm)}\nd={dd}', fontsize=12)
|
|
|
axes[0].set_xlabel('Timepoint', fontsize=12)
|
|
@@ -92,6 +100,17 @@ def PlotBoxplot(filtered_df_stroke, filtered_df_sham, qq, mm, dd, output_folder)
|
|
|
axes[0].tick_params(axis='y', labelsize=10)
|
|
|
axes[0].legend_.remove() # Remove the legend from the Stroke plot
|
|
|
|
|
|
+ # Plot median line for Stroke group using matplotlib to ensure alignment
|
|
|
+ median_stroke = filtered_df_stroke.groupby("merged_timepoint")["Value"].median().reset_index()
|
|
|
+ axes[0].plot(median_stroke["merged_timepoint"], median_stroke["Value"], color='black', linewidth=1.0, marker='o', markersize=3)
|
|
|
+
|
|
|
+ # Plot strip plot for Stroke group last to make sure dots are on top
|
|
|
+ sns.stripplot(
|
|
|
+ data=filtered_df_stroke, hue="Group", y="Value", x="merged_timepoint",
|
|
|
+ ax=axes[0], dodge=True, palette={"Stroke": '#8b0000'}, # Darker red color for Stroke dots
|
|
|
+ alpha=1.0, size=2, jitter=True, marker='o', legend=False
|
|
|
+ )
|
|
|
+
|
|
|
# Plot Sham group
|
|
|
sns.boxplot(
|
|
|
data=filtered_df_sham, hue="Group", y="Value", x="merged_timepoint",
|
|
@@ -99,11 +118,7 @@ def PlotBoxplot(filtered_df_stroke, filtered_df_sham, qq, mm, dd, output_folder)
|
|
|
whiskerprops={'color': 'black', 'linewidth': 0.8},
|
|
|
fliersize=0, linewidth=1.0, boxprops={'linewidth': 0.8}
|
|
|
)
|
|
|
- sns.stripplot(
|
|
|
- data=filtered_df_sham, hue="Group", y="Value", x="merged_timepoint",
|
|
|
- ax=axes[1], dodge=True, palette=custom_colors,
|
|
|
- alpha=1.0, size=2, jitter=True, marker='o', legend=False
|
|
|
- )
|
|
|
+
|
|
|
sns.despine(ax=axes[1], right=True, top=True)
|
|
|
axes[1].set_title(f'Sham - {qq}\n{mask_name_mapping.get(mm, mm)}\nd={dd}', fontsize=12)
|
|
|
axes[1].set_xlabel('Timepoint', fontsize=12)
|
|
@@ -112,6 +127,17 @@ def PlotBoxplot(filtered_df_stroke, filtered_df_sham, qq, mm, dd, output_folder)
|
|
|
axes[1].tick_params(axis='y', labelsize=10)
|
|
|
axes[1].legend_.remove() # Remove the legend from the Sham plot
|
|
|
|
|
|
+ # Plot median line for Sham group using matplotlib to ensure alignment
|
|
|
+ median_sham = filtered_df_sham.groupby("merged_timepoint")["Value"].median().reset_index()
|
|
|
+ axes[1].plot(median_sham["merged_timepoint"], median_sham["Value"], color='black', linewidth=1.0, marker='o', markersize=3)
|
|
|
+
|
|
|
+ # Plot strip plot for Sham group last to make sure dots are on top
|
|
|
+ sns.stripplot(
|
|
|
+ data=filtered_df_sham, hue="Group", y="Value", x="merged_timepoint",
|
|
|
+ ax=axes[1], dodge=True, palette={"Sham": '#4f4f4f'}, # Darker gray color for Sham dots
|
|
|
+ alpha=1.0, size=2, jitter=True, marker='o', legend=False
|
|
|
+ )
|
|
|
+
|
|
|
plt.tight_layout()
|
|
|
|
|
|
# Save the plot as an image
|
|
@@ -125,6 +151,11 @@ def PlotBoxplot(filtered_df_stroke, filtered_df_sham, qq, mm, dd, output_folder)
|
|
|
plt.show()
|
|
|
plt.close()
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
# Get the directory where the code file is located
|
|
|
code_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|