From a6f4f72b96dce403ca7d1bff648d9462e65bccce Mon Sep 17 00:00:00 2001
From: George Marchment <georgemarchment@yahoo.fr>
Date: Fri, 24 Jan 2025 11:32:52 +0100
Subject: [PATCH] Add method to automatically generate random relevant
 processes

---
 src/workflow.py | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/src/workflow.py b/src/workflow.py
index b9ae98f..570f005 100644
--- a/src/workflow.py
+++ b/src/workflow.py
@@ -879,6 +879,38 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
         self.__init__(str(temp_file), display_info = False, duplicate=True)
         self.initialise(create_rocrate=False)
 
+    def generate_random_relevant_processes(self, alpha = -1):
+        import random
+
+        #Random value between 0 and 1, centered at 0.5
+        def get_value():
+            check = True
+            val = -1
+            while(check):
+                check = False
+                val = random.gauss(0.5, 0.1)
+                if(val<0 or val>1):
+                    check = True
+            return val
+
+        if(self.duplicate):
+            if(alpha == -1):
+                alpha = get_value()
+            else:
+                if(0<=alpha and alpha<=1):
+                    None
+                else:
+                    raise BioFlowInsightError("alpha is not in the interval [0; 1]")
+            
+            processes_called = self.get_processes_called()
+            nb_2_select = int(alpha*len(processes_called))
+            sampled = random.sample(set(processes_called), nb_2_select)
+            name_select = []
+            for p in sampled:
+                name_select.append(p.get_alias())
+            return name_select
+        else:
+            raise BioFlowInsightError("Trying to generate random relevant processes however option 'duplicate' is not activated.")
 
 
     #Conert workflow to user_view only makes sense when the option duplicate is activated -> otherwise is doesn't make sense + it makes the analysis way more complicated
@@ -948,7 +980,6 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
                 return broken_subworkflows
 
             broken_subworkflows = get_workflows_broken(subworkflow_2_executors, set_clusters_with_calls)
-            print(broken_subworkflows)
             #Rewrite broken subworkflows
             for sub in broken_subworkflows:
                 code = self.rewrite_subworkflow_call(code, sub)
@@ -1195,7 +1226,7 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
             #Putting || back
             code = code.replace("$OR$", "||")
 
-            print(remove_extra_jumps(format_with_tabs(code)))
+            return remove_extra_jumps(format_with_tabs(code))
             
 
             #So basically when retriving a thing (process or subworkflow)
-- 
GitLab