changeset 94:e844f7dab6fe draft

Uploaded
author luca_milaz
date Sun, 13 Oct 2024 11:43:08 +0000
parents 7e703e546998
children 45574f99a807
files COBRAxy/ras_to_bounds.py
diffstat 1 files changed, 16 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/COBRAxy/ras_to_bounds.py	Sun Oct 13 11:41:34 2024 +0000
+++ b/COBRAxy/ras_to_bounds.py	Sun Oct 13 11:43:08 2024 +0000
@@ -54,20 +54,20 @@
                         required = False,
                         help = 'input ras')
     
+    parser.add_argument('-rn', '--names',
+                type=str,
+                help = 'ras class names')
+    
     parser.add_argument('-rs', '--ras_selector',
                         required = True,
                         type=utils.Bool("using_RAS"),
                         help = 'ras selector')
-    
-    parser.add_argument('-c', '--classes',
-                    type = str,
-                    required = False,
-                    help = 'input classes')
 
     parser.add_argument('-cc', '--cell_class',
                     type = str,
                     help = 'output of cell class')
     
+    
     ARGS = parser.parse_args()
     return ARGS
 
@@ -128,6 +128,7 @@
             scaling_factor = ras_row[reaction]
             lower_bound=model.reactions.get_by_id(reaction).lower_bound
             upper_bound=model.reactions.get_by_id(reaction).upper_bound
+            #warning("Reaction: "+reaction+" Lower Bound: "+str(lower_bound)+" Upper Bound: "+str(upper_bound)+" Scaling Factor: "+str(scaling_factor))
             valMax=float((upper_bound)*scaling_factor)
             valMin=float((lower_bound)*scaling_factor)
             if upper_bound!=0 and lower_bound==0:
@@ -190,6 +191,8 @@
 
     if ras is not None:
         Parallel(n_jobs=cpu_count())(delayed(process_ras_cell)(cellName, ras_row, model, rxns_ids, output_folder) for cellName, ras_row in ras.iterrows())
+         #for cellName, ras_row in ras.iterrows():
+            #process_ras_cell(cellName, ras_row, model, rxns_ids, output_folder) 
     else:
         model_new = model.copy()
         apply_ras_bounds(model_new, pd.Series([1]*len(rxns_ids), index=rxns_ids), rxns_ids)
@@ -218,10 +221,10 @@
 
     if(ARGS.ras_selector == True):
         ras_file_list = ARGS.input_ras.split(",")
-        if(len(ras_file_list)>1):
-            ras_class_names = [cls.strip() for cls in ARGS.classes.split(',')]
-        else:
-            ras_class_names = ["placeHolder"]
+        ras_file_names = ARGS.names.split(",")
+        ras_class_names = []
+        for file in ras_file_names:
+            ras_class_names.append(file.split(".")[0])
         ras_list = []
         class_assignments = pd.DataFrame(columns=["Patient_ID", "Class"])
         for ras_matrix, ras_class_name in zip(ras_file_list, ras_class_names):
@@ -232,10 +235,11 @@
             ras = ras.astype(float)
             ras_list.append(ras)
             for patient_id in ras.index:
-                class_assignments = class_assignments.append({"Patient_ID": patient_id, "Class": ras_class_name}, ignore_index=True)
+                class_assignments.loc[class_assignments.shape[0]] = [patient_id, ras_class_name]
+        
         
         # Concatenate all ras DataFrames into a single DataFrame
-        ras_combined = pd.concat(ras_list, axis=1)
+        ras_combined = pd.concat(ras_list, axis=0)
         # Normalize the RAS values by max RAS
         ras_combined = ras_combined.div(ras_combined.max(axis=0))
         ras_combined = ras_combined.fillna(0)
@@ -261,8 +265,7 @@
 
     if(ARGS.ras_selector == True):
         generate_bounds(model, medium, ras = ras_combined, output_folder=ARGS.output_folder)
-        if(len(ras_list)>1):
-            class_assignments.to_csv(ARGS.cell_class, sep = '\t', index = False)
+        class_assignments.to_csv(ARGS.cell_class, sep = '\t', index = False)
     else:
         generate_bounds(model, medium, output_folder=ARGS.output_folder)