diff Marea/marea.py @ 28:e6831924df01 draft

small fixes (elbow plot and output managment)
author bimib
date Mon, 14 Oct 2019 05:01:08 -0400
parents c71ac0bb12de
children 944e15aa970a
line wrap: on
line diff
--- a/Marea/marea.py	Mon Oct 07 13:48:01 2019 -0400
+++ b/Marea/marea.py	Mon Oct 14 05:01:08 2019 -0400
@@ -50,7 +50,7 @@
                         help = 'your tool directory')
     parser.add_argument('-op', '--option', 
                         type = str, 
-                        choices = ['datasets', 'dataset_class'],
+                        choices = ['datasets', 'dataset_class', 'datasets_rasonly'],
                         help='dataset or dataset and class')
     parser.add_argument('-ol', '--out_log', 
                         help = "Output log")    
@@ -86,6 +86,10 @@
                         default = 'true',
                         choices = ['true', 'false'],
                         help = 'generate reaction activity score')
+    parser.add_argument('-sr', '--single_ras_file',  
+                         type = str,              
+                         help = 'file that will contain ras')
+    					
     args = parser.parse_args()
     return args
 
@@ -658,7 +662,7 @@
 
 ############################ create_ras #######################################
 
-def create_ras (resolve_rules, dataset_name):
+def create_ras (resolve_rules, dataset_name, single_ras):
 
     if resolve_rules == None:
         warning("Couldn't generate RAS for current dataset: " + dataset_name)
@@ -670,8 +674,13 @@
                 
     output_ras = pd.DataFrame.from_dict(resolve_rules)
     output_to_csv = pd.DataFrame.to_csv(output_ras, sep = '\t', index = False)
-                
-    text_file = open("ras/Reaction_Activity_Score_Of_" + dataset_name + ".tsv", "w")
+    
+    if (single_ras):
+        args = process_args(sys.argv)
+        text_file = open(args.single_ras_file, "w")
+    else:
+        text_file = open("ras/Reaction_Activity_Score_Of_" + dataset_name + ".tsv", "w")
+    
     text_file.write(output_to_csv)
     text_file.close()
 
@@ -749,7 +758,34 @@
     
     class_pat = {}
     
-    if args.option == 'datasets':
+    if args.option == 'datasets_rasonly':
+        name = "RAS Dataset"
+        dataset = read_dataset(args.input_datas[0],"dataset")
+
+        dataset.iloc[:, 0] = (dataset.iloc[:, 0]).astype(str)
+
+        type_gene = gene_type(dataset.iloc[0, 0], name) 
+            
+        if args.rules_selector != 'Custom':
+            genes = data_gene(dataset, type_gene, name, None)
+            ids, rules = load_id_rules(recon.get(type_gene))
+        elif args.rules_selector == 'Custom':
+            genes = data_gene(dataset, type_gene, name, gene_in_rule)
+                
+        resolve_rules, err = resolve(genes, rules, ids, resolve_none, name)
+
+        create_ras(resolve_rules, name, True)
+          
+        if err != None and err:
+            warning('Warning: gene\n' + str(err) + '\nnot found in class '
+                + name + ', the expression level for this gene ' +
+                'will be considered NaN\n')
+        
+        print('execution succeded')
+        return None
+    
+    
+    elif args.option == 'datasets':
         num = 1
         for i, j in zip(args.input_datas, args.names):
 
@@ -769,8 +805,7 @@
             resolve_rules, err = resolve(genes, rules, ids, resolve_none, name)
 
             if generate_ras:
-                create_ras(resolve_rules, name)
-                
+                create_ras(resolve_rules, name, False)
             
             if err != None and err:
                 warning('Warning: gene\n' + str(err) + '\nnot found in class '
@@ -801,7 +836,8 @@
                     'will be considered NaN\n')
         if resolve_rules != None:
             class_pat = split_class(classes, resolve_rules)
-            
+    
+    	
     if args.rules_selector == 'Custom':
         if args.yes_no == 'yes':
             try: