changeset 64:53b4fca5bdf9 draft

Uploaded
author bimib
date Mon, 16 Mar 2020 07:47:12 -0400
parents b8cbc2122d55
children a61733753aec
files Marea/marea.py
diffstat 1 files changed, 46 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/Marea/marea.py	Mon Mar 16 07:45:59 2020 -0400
+++ b/Marea/marea.py	Mon Mar 16 07:47:12 2020 -0400
@@ -537,6 +537,36 @@
         warning('Warning: wrong format rule in ' + str(err_rules) + '\n')
     return (split_rules, list(set(tmp_gene_in_rule)))
 
+def make_recon(data):
+    try:
+        import cobra as cb
+        import warnings
+        with warnings.catch_warnings():
+            warnings.simplefilter('ignore')
+            recon = cb.io.read_sbml_model(data)
+        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.sbml.CobraSBMLError:
+        try:
+            data = (pd.read_csv(data, sep = '\t', dtype = str, engine='python')).fillna('')
+            if len(data.columns) < 2:
+                sys.exit('Execution aborted: wrong format of '+
+                         'custom datarules\n')
+            if not len(data.columns) == 2:
+                warning('Warning: more than 2 columns in custom datarules.\n' +
+                        'Extra columns have been disregarded\n')
+            ids = list(data.iloc[:, 0])
+            rules = list(data.iloc[:, 1])
+        except pd.errors.EmptyDataError:
+            sys.exit('Execution aborted: wrong format of custom datarules\n')
+        except pd.errors.ParserError:
+            sys.exit('Execution aborted: wrong format of custom datarules\n')            
+    split_rules, tmp_genes = do_rules(rules)
+    gene_in_rule = {}
+    for i in tmp_genes:
+        gene_in_rule[i] = 'ok'
+    return (ids, split_rules, gene_in_rule)
 
 ############################ gene #############################################
 
@@ -636,6 +666,7 @@
 
     if comparison == "manyvsmany":
         for i, j in it.combinations(class_pat.keys(), 2):
+            
             tmp = {}
             count = 0
             max_F_C = 0
@@ -671,6 +702,10 @@
                         renderPDF.drawToFile(svg2rlg(file_svg), file_pdf)
                     
                     if not create_svg:
+                        #Ho utilizzato il file svg per generare il pdf, 
+                        #ma l'utente non ne ha richiesto il ritorno, quindi
+                        #lo elimino
+                        
                         os.remove('result/' + i + '_vs_' + j + ' (SVG Map).svg')
     elif comparison == "onevsrest":
         for single_cluster in class_pat.keys():
@@ -704,8 +739,8 @@
             tmp_csv.to_csv(tab, sep = '\t', index = False, header = header)
             
             if create_svg or create_pdf:
-                if args.custom_rules == 'false' or (args.custom_rules == 'true'
-                                                        and args.custom_map != ''):
+                if args.rules_selector == 'HMRcore' or (args.rules_selector == 'Custom'
+                                                        and args.yes_no == 'yes'):
                     fix_map(tmp, core_map, threshold_P_V, threshold_F_C, max_F_C)
                     file_svg = 'result/' + single_cluster + '_vs_ rest (SVG Map).svg'
                     with open(file_svg, 'wb') as new_map:
@@ -721,10 +756,6 @@
                         
     elif comparison == "onevsmany":
         for i, j in it.combinations(class_pat.keys(), 2):
-            if i != control and j != control:
-                continue
-            if i == control and j == control:
-                continue
             tmp = {}
             count = 0
             max_F_C = 0
@@ -747,8 +778,8 @@
             tmp_csv.to_csv(tab, sep = '\t', index = False, header = header)
             
             if create_svg or create_pdf:
-                if args.custom_rules == 'false' or (args.custom_rules == 'true'
-                                                        and args.custom_map != ''):
+                if args.rules_selector == 'HMRcore' or (args.rules_selector == 'Custom'
+                                                        and args.yes_no == 'yes'):
                     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,6 +791,10 @@
                         renderPDF.drawToFile(svg2rlg(file_svg), file_pdf)
                     
                     if not create_svg:
+                        #Ho utilizzato il file svg per generare il pdf, 
+                        #ma l'utente non ne ha richiesto il ritorno, quindi
+                        #lo elimino
+                        
                         os.remove('result/' + i + '_vs_' + j + ' (SVG Map).svg')
         
         
@@ -777,6 +812,9 @@
 
     if os.path.isdir('result') == False:
         os.makedirs('result')
+        
+    if args.custom_rules == 'true':
+        ids, rules, gene_in_rule = make_recon(args.custom_rule)
 
     class_pat = {}