diff COBRAxy/marea.py @ 293:7b8d9de81a86 draft

Uploaded
author francesco_lapi
date Thu, 15 May 2025 18:23:52 +0000
parents 7f3e66dd46fa
children 1402c2beb8f2
line wrap: on
line diff
--- a/COBRAxy/marea.py	Thu May 15 18:21:58 2025 +0000
+++ b/COBRAxy/marea.py	Thu May 15 18:23:52 2025 +0000
@@ -50,6 +50,13 @@
         type = str, 
         default = 'manyvsmany',
         choices = ['manyvsmany', 'onevsrest', 'onevsmany'])
+
+    parser.add_argument(
+        '-te' ,'--test',
+        type = str, 
+        default = 'ks', 
+        choices = ['ks', 'ttest_p', 'ttest_ind', 'wilcoxon', 'mw'],
+        help = 'Statistical test to use (default: %(default)s)')
     
     parser.add_argument(
         '-pv' ,'--pValue',
@@ -503,7 +510,7 @@
             continue
         
         width = Arrow.MAX_W
-        if not math.isinf(foldChange):
+        if not math.isinf(z_score):
             try: width = min(
                 max(abs(z_score * Arrow.MAX_W) / maxNumericZScore, Arrow.MIN_W),
                 Arrow.MAX_W)
@@ -690,11 +697,25 @@
 
     Returns:
         tuple: (P-value, Z-score)
-            - P-value from a Kolmogorov-Smirnov test on the provided data.
+            - P-value from the selected test on the provided data.
             - Z-score of the difference between means of the two datasets.
     """
-    # Perform Kolmogorov-Smirnov test
-    ks_statistic, p_value = st.ks_2samp(dataset1Data, dataset2Data)
+    match ARGS.test:
+        case "ks":
+            # Perform Kolmogorov-Smirnov test
+            _, p_value = st.ks_2samp(dataset1Data, dataset2Data)
+        case "ttest_p":
+            # Perform t-test for paired samples
+            _, p_value = st.ttest_rel(dataset1Data, dataset2Data)
+        case "ttest_ind":
+            # Perform t-test for independent samples
+            _, p_value = st.ttest_ind(dataset1Data, dataset2Data)
+        case "wilcoxon":
+            # Perform Wilcoxon signed-rank test
+            _, p_value = st.wilcoxon(dataset1Data, dataset2Data)
+        case "mw":
+            # Perform Mann-Whitney U test
+            _, p_value = st.mannwhitneyu(dataset1Data, dataset2Data)
     
     # Calculate means and standard deviations
     mean1 = np.mean(dataset1Data)