diff Marea/marea.py @ 48:e4235b5231e4 draft

Uploaded
author bimib
date Sun, 23 Feb 2020 09:41:14 -0500
parents 3af9d394367c
children 7b57a93ac594
line wrap: on
line diff
--- a/Marea/marea.py	Wed Feb 19 10:44:52 2020 -0500
+++ b/Marea/marea.py	Sun Feb 23 09:41:14 2020 -0500
@@ -18,14 +18,17 @@
     parser = argparse.ArgumentParser(usage = '%(prog)s [options]',
                                      description = 'process some value\'s'+
                                      ' genes to create a comparison\'s map.')
-    parser.add_argument('-rs', '--rules_selector', 
+    parser.add_argument('-cr', '--custom_rules', 
                         type = str,
-                        default = 'HMRcore',
-                        choices = ['HMRcore', 'Recon', 'Custom'], 
-                        help = 'chose which type of dataset you want use')
-    parser.add_argument('-cr', '--custom',
+                        default = 'false',
+                        choices = ['true', 'false'],
+                        help = 'choose whether to use custom rules')
+    parser.add_argument('-cc', '--custom_rule',
                         type = str,
-                        help='your dataset if you want custom rules')
+                        help='custom rules to use')
+    parser.add_argument('-cm', '--custom_map',
+                        type = str,
+                        help='custom map to use')
     parser.add_argument('-n', '--none',
                         type = str,
                         default = 'true',
@@ -55,13 +58,6 @@
     parser.add_argument('-ic', '--input_class', 
                         type = str, 
                         help = 'sample group specification')
-    parser.add_argument('-cm', '--custom_map', 
-                        type = str, 
-                        help = 'custom map')
-    parser.add_argument('-yn', '--yes_no', 
-                        type = str,
-                        choices = ['yes', 'no'],
-                        help = 'if make or not custom map')
     parser.add_argument('-gs', '--generate_svg',
                         type = str,
                         default = 'true',
@@ -551,7 +547,7 @@
         react = recon.reactions
         rules = [react[i].gene_reaction_rule for i in range(len(react))]
         ids = [react[i].id for i in range(len(react))]
-    except cb.io.sbml3.CobraSBMLError:
+    except cb.io.sbml.CobraSBMLError:
         try:
             data = (pd.read_csv(data, sep = '\t', dtype = str, engine='python')).fillna('')
             if len(data.columns) < 2:
@@ -693,8 +689,8 @@
             tmp_csv.to_csv(tab, sep = '\t', index = False, header = header)
             
             if create_svg or create_pdf:
-                if args.rules_selector == 'HMRcore' or (args.rules_selector == 'Custom'
-                                                        and args.yes_no == 'yes'):
+                if args.custom_rules == 'false' or (args.custom_rules == 'true'
+                                                        and args.custom_map != ''):
                     fix_map(tmp, core_map, threshold_P_V, threshold_F_C, max_F_C)
                     file_svg = 'result/' + i + '_vs_' + j + ' (SVG Map).svg'
                     with open(file_svg, 'wb') as new_map:
@@ -760,13 +756,6 @@
                         
     elif comparison == "onevsmany":
         for i, j in it.combinations(class_pat.keys(), 2):
-
-            if i != control and j != control:
-                print(str(control) + " " + str(i) + " " + str(j))
-                #Se รจ un confronto fra elementi diversi dal controllo, skippo
-                continue
-            
-            print('vado')
             tmp = {}
             count = 0
             max_F_C = 0
@@ -823,13 +812,9 @@
 
     if os.path.isdir('result') == False:
         os.makedirs('result')
-    
-    if args.rules_selector == 'HMRcore':        
-        recon = pk.load(open(args.tool_dir + '/local/HMRcore_rules.p', 'rb'))
-    elif args.rules_selector == 'Recon':
-        recon = pk.load(open(args.tool_dir + '/local/Recon_rules.p', 'rb'))
-    elif args.rules_selector == 'Custom':
-        ids, rules, gene_in_rule = make_recon(args.custom)
+        
+    if args.custom_rules == 'true':
+        ids, rules, gene_in_rule = make_recon(args.custom_rule)
 
     class_pat = {}
     
@@ -885,15 +870,13 @@
         if resolve_rules_float != None:
             class_pat = split_class(classes, resolve_rules_float)
     	
-    if args.rules_selector == 'Custom':
-        if args.yes_no == 'yes':
-            try:
-                core_map = ET.parse(args.custom_map)
-            except (ET.XMLSyntaxError, ET.XMLSchemaParseError):
-                sys.exit('Execution aborted: custom map in wrong format')
-        elif args.yes_no == 'no':
-            core_map = ET.parse(args.tool_dir + '/local/HMRcoreMap.svg')
-    else:       
+       
+    if args.custom_rules == 'true':
+        try:
+            core_map = ET.parse(args.custom_map)
+        except (ET.XMLSyntaxError, ET.XMLSchemaParseError):
+            sys.exit('Execution aborted: custom map in wrong format')
+    else:
         core_map = ET.parse(args.tool_dir+'/local/HMRcoreMap.svg')
         
     maps(core_map, class_pat, ids, args.pValue, args.fChange, create_svg, create_pdf, args.comparison, args.control)