arefks 2 tygodni temu
rodzic
commit
3321dce0e3
49 zmienionych plików z 82895 dodań i 2560 usunięć
  1. 7 6
      code/plotting_quantitative_dti_values.py
  2. 1 1
      code/ttest_group_differences.py
  3. 140 0
      code/volcano_plot.py
  4. 0 2533
      output/Figures/fa_behavior_correlation_CST_MOp-int-py_ipsilesional_CCcut_groups_comparison.svg
  5. 0 20
      output/Figures/fa_behavior_correlation_CST_MOp-int-py_ipsilesional_CCcut_groups_correlation_results.txt
  6. BIN
      output/Figures/fa_over_time_plots/CC_MOp-MOp_cut.png
  7. BIN
      output/Figures/fa_over_time_plots/CReT_MOp-TRN_contralesional_CCcut.png
  8. BIN
      output/Figures/fa_over_time_plots/CReT_MOp-TRN_ipsilesional_CCcut.png
  9. BIN
      output/Figures/fa_over_time_plots/CRuT_MOp-RN_contralesional_mirrored_CCcut.png
  10. BIN
      output/Figures/fa_over_time_plots/CRuT_MOp-RN_ipsilesional_CCcut.png
  11. BIN
      output/Figures/fa_over_time_plots/CST_MOp-int-py_contralesional_selfdrawnROA+CCcut.png
  12. BIN
      output/Figures/fa_over_time_plots/CST_MOp-int-py_ipsilesional_selfdrawnROA+CCcut.png
  13. BIN
      output/Figures/fa_over_time_plots/L_cst_784_AMBA.png
  14. BIN
      output/Figures/fa_over_time_plots/OT_och-lgn_lgncut.png
  15. BIN
      output/Figures/fa_over_time_plots/TC_DORsm-SSp_ll+SSp_ul_contralesional_END+higherstepsize.png
  16. BIN
      output/Figures/fa_over_time_plots/TC_DORsm-SSp_ll+SSp_ul_ipsilesional_END+higherstepsize_.png
  17. 2646 0
      output/Figures/pythonFigs/volcano_plot_0.svg
  18. 2374 0
      output/Figures/pythonFigs/volcano_plot_0_ad.svg
  19. 2323 0
      output/Figures/pythonFigs/volcano_plot_0_fa.svg
  20. 2361 0
      output/Figures/pythonFigs/volcano_plot_0_fa_dilation_0.svg
  21. 2331 0
      output/Figures/pythonFigs/volcano_plot_0_fa_dilation_1.svg
  22. 2562 0
      output/Figures/pythonFigs/volcano_plot_0_fa_dilation_2.svg
  23. 2376 0
      output/Figures/pythonFigs/volcano_plot_0_md.svg
  24. 2438 0
      output/Figures/pythonFigs/volcano_plot_0_rd.svg
  25. 2756 0
      output/Figures/pythonFigs/volcano_plot_14.svg
  26. 2474 0
      output/Figures/pythonFigs/volcano_plot_14_ad.svg
  27. 2453 0
      output/Figures/pythonFigs/volcano_plot_14_fa.svg
  28. 2468 0
      output/Figures/pythonFigs/volcano_plot_14_md.svg
  29. 2443 0
      output/Figures/pythonFigs/volcano_plot_14_rd.svg
  30. 2726 0
      output/Figures/pythonFigs/volcano_plot_21.svg
  31. 2451 0
      output/Figures/pythonFigs/volcano_plot_21_ad.svg
  32. 2484 0
      output/Figures/pythonFigs/volcano_plot_21_fa.svg
  33. 2477 0
      output/Figures/pythonFigs/volcano_plot_21_md.svg
  34. 2473 0
      output/Figures/pythonFigs/volcano_plot_21_rd.svg
  35. 2769 0
      output/Figures/pythonFigs/volcano_plot_28.svg
  36. 2539 0
      output/Figures/pythonFigs/volcano_plot_28_ad.svg
  37. 2512 0
      output/Figures/pythonFigs/volcano_plot_28_fa.svg
  38. 2594 0
      output/Figures/pythonFigs/volcano_plot_28_md.svg
  39. 2540 0
      output/Figures/pythonFigs/volcano_plot_28_rd.svg
  40. 2712 0
      output/Figures/pythonFigs/volcano_plot_3.svg
  41. 2534 0
      output/Figures/pythonFigs/volcano_plot_3_ad.svg
  42. 2429 0
      output/Figures/pythonFigs/volcano_plot_3_fa.svg
  43. 2489 0
      output/Figures/pythonFigs/volcano_plot_3_md.svg
  44. 2560 0
      output/Figures/pythonFigs/volcano_plot_3_rd.svg
  45. 2641 0
      output/Figures/pythonFigs/volcano_plot_7.svg
  46. 2581 0
      output/Figures/pythonFigs/volcano_plot_7_ad.svg
  47. 2356 0
      output/Figures/pythonFigs/volcano_plot_7_fa.svg
  48. 2440 0
      output/Figures/pythonFigs/volcano_plot_7_md.svg
  49. 2435 0
      output/Figures/pythonFigs/volcano_plot_7_rd.svg

+ 7 - 6
code/plotting_quantitative_dti_values.py

@@ -21,9 +21,9 @@ import warnings
 warnings.simplefilter(action='ignore')
 
 # Define user settings for the analysis
-selected_dialation_amount = 2  # Set dilation amount
+selected_dialation_amount = 3  # Set dilation amount
 selected_qtype = "fa"  # Set Qtype value
-selected_mask_names = [
+selected_mask_names = ["L_cst_784_AMBA",
     "CRuT_MOp-RN_ipsilesional_CCcut",
     "CRuT_MOp-RN_contralesional_mirrored_CCcut",
     "CReT_MOp-TRN_ipsilesional_CCcut",
@@ -68,8 +68,8 @@ def PlotBoxplot(filtered_df, qq, mm, dd, output_folder, sig):
     plt.figure(figsize=(18/2.54, 4))  # Convert 18 cm to inches
     
     # Create a boxplot
-    sns.boxplot(data=filtered_df, x="Group", y="Value", hue="merged_timepoint",
-                fliersize=3, flierprops={"marker": "o"}, palette="rocket_r")
+    sns.boxplot(data=filtered_df, hue="Group", y="Value", x="merged_timepoint",
+                fliersize=3, flierprops={"marker": "o"}, palette="rocket")
     
     
     # Set title and labels
@@ -100,7 +100,7 @@ code_dir = os.path.dirname(os.path.abspath(__file__))
 parent_dir = os.path.dirname(code_dir)
 
 # Define the path for the input CSV file
-input_file_path = os.path.join(parent_dir, 'output', "Quantitative_outputs", 'Quantitative_results_from_dwi_processing.csv')
+input_file_path = os.path.join(parent_dir, 'output', "Quantitative_outputs","old", 'Quantitative_results_from_dwi_processing.csv')
 
 # Define the path for the output folder to save plots
 plots_output_dir = os.path.join(parent_dir, 'output', 'Figures', 'pythonFigs')
@@ -110,8 +110,9 @@ os.makedirs(plots_output_dir, exist_ok=True)
 
 # Load the CSV file into a dataframe
 df = pd.read_csv(input_file_path)
+#df = df[df["cluster ii"]=="High ii"]
 df = df.drop_duplicates()
-df = df[df["merged_timepoint"].isin([3,7,14,21, 28])]
+df = df[df["merged_timepoint"].isin([0,3,7,14,21, 28])]
 
 
 # Create lists to store results and terminal output

+ 1 - 1
code/ttest_group_differences.py

@@ -106,7 +106,7 @@ with ThreadPoolExecutor(max_workers=6) as executor:
 results_df = pd.DataFrame(results)
 
 # Define output path for the new CSV
-output_file_path = os.path.join(parent_dir, 'output', "Quantitative_outputs", 'Significance_stroke_vs_sham_difference.csv')
+output_file_path = os.path.join(parent_dir, 'output', "Quantitative_outputs", 'Significance_stroke_vs_sham_difference_withoutWMmask.csv')
 
 # Save results to CSV
 results_df.to_csv(output_file_path, index=False)

+ 140 - 0
code/volcano_plot.py

@@ -0,0 +1,140 @@
+import os
+import pandas as pd
+import numpy as np
+import matplotlib.pyplot as plt
+from tqdm import tqdm
+
+# Define cm for converting cm to inches
+cm = 1 / 2.54
+
+# Get the directory where the code file is located
+code_dir = os.path.dirname(os.path.abspath(__file__))
+
+# Get the parent directory of the code directory
+parent_dir = os.path.dirname(code_dir)
+
+# Define the path for the input CSV files
+original_file_path = os.path.join(parent_dir, 'output', 'Quantitative_outputs', 'old', 'Quantitative_results_from_dwi_processing.csv')
+results_file_path = os.path.join(parent_dir, 'output', 'Quantitative_outputs', 'Significance_stroke_vs_sham_difference.csv')
+
+# Define the path for the output folders to save plots
+plots_output_dir = os.path.join(parent_dir, 'output', 'Figures', 'pythonFigs')
+fa_over_time_plots_dir = os.path.join(parent_dir, 'output', 'Figures', 'fa_over_time_plots')
+os.makedirs(fa_over_time_plots_dir, exist_ok=True)
+os.makedirs(plots_output_dir, exist_ok=True)
+
+# Load the original dataset for analysis
+df = pd.read_csv(original_file_path, low_memory=False)
+
+# Load the results CSV
+results_df = pd.read_csv(results_file_path)
+
+# Filter results to exclude those with "AMBA" in the mask name
+results_df = results_df[~results_df['mask_name'].str.contains("AMBA")]
+
+# Define functions to map abbreviations and locations
+def map_abbreviation(mask_name):
+    if mask_name.startswith("CC"):
+        return "CC"
+    elif mask_name.startswith("CRuT"):
+        return "RS"
+    elif mask_name.startswith("CReT"):
+        return "RetS"
+    elif mask_name.startswith("CST"):
+        return "CST"
+    elif mask_name.startswith("TC"):
+        return "TC"
+    elif mask_name.startswith("OT"):
+        return "OT"
+    else:
+        return "Unknown"
+
+def map_location(mask_name):
+    if "ipsi" in mask_name:
+        return "Ips"
+    elif "contra" in mask_name:
+        return "Con"
+    else:
+        return "None"
+
+# Add new columns to the dataframe for abbreviation and location
+results_df['abbreviation'] = results_df['mask_name'].apply(map_abbreviation)
+results_df['location'] = results_df['mask_name'].apply(map_location)
+
+# Get unique time points and qtypes
+timepoints = results_df['merged_timepoint'].unique()
+qtypes = results_df['Qtype'].unique()
+
+# Define different marker shapes for each unique abbreviation
+unique_abbreviations = results_df['abbreviation'].unique()
+markers = ['o', 's', '^', 'D', 'v', '<', '>', 'p', '*', 'X', 'h']
+marker_mapping = {abbr: markers[i % len(markers)] for i, abbr in enumerate(unique_abbreviations)}
+
+# Iterate over each time point and Qtype to create individual volcano plots
+for timepoint in timepoints:
+    for qtype in qtypes:
+        subset_df = results_df[(results_df['merged_timepoint'] == timepoint) & (results_df['Qtype'] == qtype)]
+
+        # Skip if there is no data for the specific subset
+        if subset_df.empty:
+            continue
+
+        # Calculate mean difference for the current subset
+        mean_diff = []
+        with tqdm(total=len(subset_df), desc=f"Calculating mean differences for {timepoint}, Qtype: {qtype}") as pbar:
+            for _, row in subset_df.iterrows():
+                mask = row['mask_name']
+
+                # Filter original data for Stroke and Sham
+                stroke_values = df[(df['Group'] == 'Stroke') &
+                                   (df['mask_name'] == mask) &
+                                   (df['merged_timepoint'] == timepoint) &
+                                   (df['dialation_amount'] == row['dialation_amount']) &
+                                   (df['Qtype'] == qtype)]['Value'].dropna()
+
+                sham_values = df[(df['Group'] == 'Sham') &
+                                 (df['mask_name'] == mask) &
+                                 (df['merged_timepoint'] == timepoint) &
+                                 (df['dialation_amount'] == row['dialation_amount']) &
+                                 (df['Qtype'] == qtype)]['Value'].dropna()
+
+                # Calculate mean difference
+                if len(stroke_values) > 0 and len(sham_values) > 0:
+                    mean_diff.append(stroke_values.mean() - sham_values.mean())
+                else:
+                    mean_diff.append(np.nan)
+                
+                # Update progress bar
+                pbar.update(1)
+
+        subset_df['Mean_Difference'] = mean_diff
+        subset_df['-log10(Pvalue)'] = -np.log10(subset_df['Pvalue'])
+
+        # Plot the volcano plot for the current time point and Qtype
+        plt.figure(figsize=(8 * cm, 8 * cm), dpi=300)  # 8 cm by 8 cm in inches, with high DPI for better quality
+
+        # Plot each mask using its corresponding marker shape and location suffix
+        for abbr in unique_abbreviations:
+            abbr_subset = subset_df[subset_df['abbreviation'] == abbr]
+            for location in abbr_subset['location'].unique():
+                loc_subset = abbr_subset[abbr_subset['location'] == location]
+                label = f"{abbr} ({location})" if location != "None" else abbr
+                plt.scatter(loc_subset['Mean_Difference'], loc_subset['-log10(Pvalue)'],
+                            alpha=0.7, s=10, marker=marker_mapping[abbr], label=label)
+
+        # Labels and title for each plot
+        plt.axhline(y=-np.log10(0.05), color='blue', linestyle='--')
+        plt.xlabel('Mean Difference (Stroke - Sham)', fontsize=12, fontname='Calibri')
+        plt.ylabel('-log10(Pvalue)', fontsize=12, fontname='Calibri')
+        plt.title(f'Volcano Plot: {qtype} for {timepoint}', fontsize=12, fontname='Calibri')
+        plt.grid(False)
+
+        # Create the legend with marker shapes
+        plt.legend(loc='best', fontsize=6, frameon=False)
+
+        # Save the plot as an SVG file
+        plot_file_name = f'volcano_plot_{timepoint}_{qtype}.svg'
+        plot_file_path = os.path.join(plots_output_dir, plot_file_name)
+        plt.savefig(plot_file_path, format='svg', bbox_inches='tight')
+
+        plt.show()

Plik diff jest za duży
+ 0 - 2533
output/Figures/fa_behavior_correlation_CST_MOp-int-py_ipsilesional_CCcut_groups_comparison.svg


+ 0 - 20
output/Figures/fa_behavior_correlation_CST_MOp-int-py_ipsilesional_CCcut_groups_correlation_results.txt

@@ -1,20 +0,0 @@
-Group: Sham
-Correlation Coefficient (uncorrected): 0.3333
-P-Value (uncorrected): 4.1975e-01
-P-Value (corrected): 4.1975e-01
-----------------------------------------
-Group: Stroke
-Correlation Coefficient (uncorrected): 0.3333
-P-Value (uncorrected): 4.1975e-01
-P-Value (corrected): 4.1975e-01
-----------------------------------------
-Group: Sham
-Correlation Coefficient (uncorrected): 0.3333
-P-Value (uncorrected): 4.1975e-01
-P-Value (corrected): 4.1975e-01
-----------------------------------------
-Group: Stroke
-Correlation Coefficient (uncorrected): 0.3333
-P-Value (uncorrected): 4.1975e-01
-P-Value (corrected): 4.1975e-01
-----------------------------------------

BIN
output/Figures/fa_over_time_plots/CC_MOp-MOp_cut.png


BIN
output/Figures/fa_over_time_plots/CReT_MOp-TRN_contralesional_CCcut.png


BIN
output/Figures/fa_over_time_plots/CReT_MOp-TRN_ipsilesional_CCcut.png


BIN
output/Figures/fa_over_time_plots/CRuT_MOp-RN_contralesional_mirrored_CCcut.png


BIN
output/Figures/fa_over_time_plots/CRuT_MOp-RN_ipsilesional_CCcut.png


BIN
output/Figures/fa_over_time_plots/CST_MOp-int-py_contralesional_selfdrawnROA+CCcut.png


BIN
output/Figures/fa_over_time_plots/CST_MOp-int-py_ipsilesional_selfdrawnROA+CCcut.png


BIN
output/Figures/fa_over_time_plots/L_cst_784_AMBA.png


BIN
output/Figures/fa_over_time_plots/OT_och-lgn_lgncut.png


BIN
output/Figures/fa_over_time_plots/TC_DORsm-SSp_ll+SSp_ul_contralesional_END+higherstepsize.png


BIN
output/Figures/fa_over_time_plots/TC_DORsm-SSp_ll+SSp_ul_ipsilesional_END+higherstepsize_.png


Plik diff jest za duży
+ 2646 - 0
output/Figures/pythonFigs/volcano_plot_0.svg


Plik diff jest za duży
+ 2374 - 0
output/Figures/pythonFigs/volcano_plot_0_ad.svg


Plik diff jest za duży
+ 2323 - 0
output/Figures/pythonFigs/volcano_plot_0_fa.svg


Plik diff jest za duży
+ 2361 - 0
output/Figures/pythonFigs/volcano_plot_0_fa_dilation_0.svg


Plik diff jest za duży
+ 2331 - 0
output/Figures/pythonFigs/volcano_plot_0_fa_dilation_1.svg


Plik diff jest za duży
+ 2562 - 0
output/Figures/pythonFigs/volcano_plot_0_fa_dilation_2.svg


Plik diff jest za duży
+ 2376 - 0
output/Figures/pythonFigs/volcano_plot_0_md.svg


Plik diff jest za duży
+ 2438 - 0
output/Figures/pythonFigs/volcano_plot_0_rd.svg


Plik diff jest za duży
+ 2756 - 0
output/Figures/pythonFigs/volcano_plot_14.svg


Plik diff jest za duży
+ 2474 - 0
output/Figures/pythonFigs/volcano_plot_14_ad.svg


Plik diff jest za duży
+ 2453 - 0
output/Figures/pythonFigs/volcano_plot_14_fa.svg


Plik diff jest za duży
+ 2468 - 0
output/Figures/pythonFigs/volcano_plot_14_md.svg


Plik diff jest za duży
+ 2443 - 0
output/Figures/pythonFigs/volcano_plot_14_rd.svg


Plik diff jest za duży
+ 2726 - 0
output/Figures/pythonFigs/volcano_plot_21.svg


Plik diff jest za duży
+ 2451 - 0
output/Figures/pythonFigs/volcano_plot_21_ad.svg


Plik diff jest za duży
+ 2484 - 0
output/Figures/pythonFigs/volcano_plot_21_fa.svg


Plik diff jest za duży
+ 2477 - 0
output/Figures/pythonFigs/volcano_plot_21_md.svg


Plik diff jest za duży
+ 2473 - 0
output/Figures/pythonFigs/volcano_plot_21_rd.svg


Plik diff jest za duży
+ 2769 - 0
output/Figures/pythonFigs/volcano_plot_28.svg


Plik diff jest za duży
+ 2539 - 0
output/Figures/pythonFigs/volcano_plot_28_ad.svg


Plik diff jest za duży
+ 2512 - 0
output/Figures/pythonFigs/volcano_plot_28_fa.svg


Plik diff jest za duży
+ 2594 - 0
output/Figures/pythonFigs/volcano_plot_28_md.svg


Plik diff jest za duży
+ 2540 - 0
output/Figures/pythonFigs/volcano_plot_28_rd.svg


Plik diff jest za duży
+ 2712 - 0
output/Figures/pythonFigs/volcano_plot_3.svg


Plik diff jest za duży
+ 2534 - 0
output/Figures/pythonFigs/volcano_plot_3_ad.svg


Plik diff jest za duży
+ 2429 - 0
output/Figures/pythonFigs/volcano_plot_3_fa.svg


Plik diff jest za duży
+ 2489 - 0
output/Figures/pythonFigs/volcano_plot_3_md.svg


Plik diff jest za duży
+ 2560 - 0
output/Figures/pythonFigs/volcano_plot_3_rd.svg


Plik diff jest za duży
+ 2641 - 0
output/Figures/pythonFigs/volcano_plot_7.svg


Plik diff jest za duży
+ 2581 - 0
output/Figures/pythonFigs/volcano_plot_7_ad.svg


Plik diff jest za duży
+ 2356 - 0
output/Figures/pythonFigs/volcano_plot_7_fa.svg


Plik diff jest za duży
+ 2440 - 0
output/Figures/pythonFigs/volcano_plot_7_md.svg


Plik diff jest za duży
+ 2435 - 0
output/Figures/pythonFigs/volcano_plot_7_rd.svg