Repository 'marea'
hg clone https://toolshed.g2.bx.psu.edu/repos/bimib/marea

Changeset 46:5d5d01ef1d68 (2020-01-22)
Previous changeset 45:7aa966c488a4 (2020-01-22) Next changeset 47:3af9d394367c (2020-02-19)
Commit message:
Uploaded
added:
Marea/ras_generator.py
b
diff -r 7aa966c488a4 -r 5d5d01ef1d68 Marea/ras_generator.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Marea/ras_generator.py Wed Jan 22 11:50:54 2020 -0500
[
b'@@ -0,0 +1,869 @@\n+from __future__ import division\n+import sys\n+import pandas as pd\n+import itertools as it\n+import scipy.stats as st\n+import collections\n+import lxml.etree as ET\n+import pickle as pk\n+import math\n+import os\n+import argparse\n+from svglib.svglib import svg2rlg\n+from reportlab.graphics import renderPDF\n+\n+########################## argparse ##########################################\n+\n+def process_args(args):\n+    parser = argparse.ArgumentParser(usage = \'%(prog)s [options]\',\n+                                     description = \'process some value\\\'s\'+\n+                                     \' genes to create a comparison\\\'s map.\')\n+    parser.add_argument(\'-rs\', \'--rules_selector\', \n+                        type = str,\n+                        default = \'HMRcore\',\n+                        choices = [\'HMRcore\', \'Recon\', \'Custom\'], \n+                        help = \'chose which type of dataset you want use\')\n+    parser.add_argument(\'-cr\', \'--custom\',\n+                        type = str,\n+                        help=\'your dataset if you want custom rules\')\n+    parser.add_argument(\'-na\', \'--names\', \n+                        type = str,\n+                        nargs = \'+\', \n+                        help = \'input names\')\n+    parser.add_argument(\'-n\', \'--none\',\n+                        type = str,\n+                        default = \'true\',\n+                        choices = [\'true\', \'false\'], \n+                        help = \'compute Nan values\')\n+    parser.add_argument(\'-pv\' ,\'--pValue\', \n+                        type = float, \n+                        default = 0.05, \n+                        help = \'P-Value threshold (default: %(default)s)\')\n+    parser.add_argument(\'-fc\', \'--fChange\', \n+                        type = float, \n+                        default = 1.5, \n+                        help = \'Fold-Change threshold (default: %(default)s)\')\n+    parser.add_argument(\'-td\', \'--tool_dir\',\n+                        type = str,\n+                        required = True,\n+                        help = \'your tool directory\')\n+    parser.add_argument(\'-op\', \'--option\', \n+                        type = str, \n+                        choices = [\'datasets\', \'dataset_class\', \'datasets_rasonly\'],\n+                        help=\'dataset or dataset and class\')\n+    parser.add_argument(\'-ol\', \'--out_log\', \n+                        help = "Output log")    \n+    parser.add_argument(\'-ids\', \'--input_datas\', \n+                        type = str,\n+                        nargs = \'+\', \n+                        help = \'input datasets\')\n+    parser.add_argument(\'-id\', \'--input_data\',\n+                        type = str,\n+                        help = \'input dataset\')\n+    parser.add_argument(\'-ic\', \'--input_class\', \n+                        type = str, \n+                        help = \'sample group specification\')\n+    parser.add_argument(\'-cm\', \'--custom_map\', \n+                        type = str, \n+                        help = \'custom map\')\n+    parser.add_argument(\'-yn\', \'--yes_no\', \n+                        type = str,\n+                        choices = [\'yes\', \'no\'],\n+                        help = \'if make or not custom map\')\n+    parser.add_argument(\'-gs\', \'--generate_svg\',\n+                        type = str,\n+                        default = \'true\',\n+                        choices = [\'true\', \'false\'], \n+                        help = \'generate svg map\')\n+    parser.add_argument(\'-gp\', \'--generate_pdf\',\n+                        type = str,\n+                        default = \'true\',\n+                        choices = [\'true\', \'false\'], \n+                        help = \'generate pdf map\')\n+    parser.add_argument(\'-gr\', \'--generate_ras\',\n+                        type = str,\n+                        default = \'true\',\n+                        choices = [\'true\', \'false\'],\n+                        help = \'generate reaction activity score\')\n+    parser.add_argument(\'-sr\', \'--single_ras_file\',  \n+                         type = s'..b'e, name, None)\n+            ids, rules = load_id_rules(recon.get(type_gene))\n+        elif args.rules_selector == \'Custom\':\n+            genes = data_gene(dataset, type_gene, name, gene_in_rule)\n+        \n+        resolve_rules, err = resolve(genes, rules, ids, resolve_none, name)\n+\n+        create_ras(resolve_rules, name, True, rules, ids)\n+          \n+        if err != None and err:\n+            warning(\'Warning: gene\\n\' + str(err) + \'\\nnot found in class \'\n+                + name + \', the expression level for this gene \' +\n+                \'will be considered NaN\\n\')\n+        \n+        print(\'execution succeded\')\n+        return None\n+    \n+    \n+    elif args.option == \'datasets\':\n+        num = 1\n+        for i, j in zip(args.input_datas, args.names):\n+\n+            name = name_dataset(j, num)\n+            dataset = read_dataset(i, name)\n+\n+            dataset.iloc[:, 0] = (dataset.iloc[:, 0]).astype(str)\n+\n+            type_gene = gene_type(dataset.iloc[0, 0], name) \n+            \n+            if args.rules_selector != \'Custom\':\n+                genes = data_gene(dataset, type_gene, name, None)\n+                ids, rules = load_id_rules(recon.get(type_gene))\n+            elif args.rules_selector == \'Custom\':\n+                genes = data_gene(dataset, type_gene, name, gene_in_rule)\n+                \n+                \n+            resolve_rules, err = resolve(genes, rules, ids, resolve_none, name)\n+\n+            if generate_ras:\n+                create_ras(resolve_rules, name, False, rules, ids)\n+            \n+            if err != None and err:\n+                warning(\'Warning: gene\\n\' + str(err) + \'\\nnot found in class \'\n+                    + name + \', the expression level for this gene \' +\n+                    \'will be considered NaN\\n\')\n+            if resolve_rules != None:\n+                class_pat[name] = list(map(list, zip(*resolve_rules.values())))\n+            num += 1\n+    elif args.option == \'dataset_class\':\n+        name = \'RNAseq\'\n+        dataset = read_dataset(args.input_data, name)\n+        dataset.iloc[:, 0] = (dataset.iloc[:, 0]).astype(str)\n+        type_gene = gene_type(dataset.iloc[0, 0], name)\n+        classes = read_dataset(args.input_class, \'class\')\n+        if not len(classes.columns) == 2:\n+            warning(\'Warning: more than 2 columns in class file. Extra\' +\n+                    \'columns have been disregarded\\n\')\n+        classes = classes.astype(str)\n+        if args.rules_selector != \'Custom\':\n+            genes = data_gene(dataset, type_gene, name, None)\n+            ids, rules = load_id_rules(recon.get(type_gene))\n+        elif args.rules_selector == \'Custom\':\n+            genes = data_gene(dataset, type_gene, name, gene_in_rule)\n+        resolve_rules, err = resolve(genes, rules, ids, resolve_none, name)\n+        if err != None and err:\n+            warning(\'Warning: gene\\n\'+str(err)+\'\\nnot found in class \'\n+                    + name + \', the expression level for this gene \' +\n+                    \'will be considered NaN\\n\')\n+        if resolve_rules != None:\n+            class_pat = split_class(classes, resolve_rules)\n+            if generate_ras:\n+                create_ras(resolve_rules, name, False, rules, ids)\n+    \n+    \t\n+    if args.rules_selector == \'Custom\':\n+        if args.yes_no == \'yes\':\n+            try:\n+                core_map = ET.parse(args.custom_map)\n+            except (ET.XMLSyntaxError, ET.XMLSchemaParseError):\n+                sys.exit(\'Execution aborted: custom map in wrong format\')\n+        elif args.yes_no == \'no\':\n+            core_map = ET.parse(args.tool_dir + \'/local/HMRcoreMap.svg\')\n+    else:       \n+        core_map = ET.parse(args.tool_dir+\'/local/HMRcoreMap.svg\')\n+        \n+    maps(core_map, class_pat, ids, args.pValue, args.fChange, create_svg, create_pdf)\n+        \n+    print(\'Execution succeded\')\n+\n+    return None\n+\n+###############################################################################\n+\n+if __name__ == "__main__":\n+    main()\n'