Mercurial > repos > bimib > marea
comparison Marea/marea.py @ 48:e4235b5231e4 draft
Uploaded
author | bimib |
---|---|
date | Sun, 23 Feb 2020 09:41:14 -0500 |
parents | 3af9d394367c |
children | 7b57a93ac594 |
comparison
equal
deleted
inserted
replaced
47:3af9d394367c | 48:e4235b5231e4 |
---|---|
16 | 16 |
17 def process_args(args): | 17 def process_args(args): |
18 parser = argparse.ArgumentParser(usage = '%(prog)s [options]', | 18 parser = argparse.ArgumentParser(usage = '%(prog)s [options]', |
19 description = 'process some value\'s'+ | 19 description = 'process some value\'s'+ |
20 ' genes to create a comparison\'s map.') | 20 ' genes to create a comparison\'s map.') |
21 parser.add_argument('-rs', '--rules_selector', | 21 parser.add_argument('-cr', '--custom_rules', |
22 type = str, | 22 type = str, |
23 default = 'HMRcore', | 23 default = 'false', |
24 choices = ['HMRcore', 'Recon', 'Custom'], | 24 choices = ['true', 'false'], |
25 help = 'chose which type of dataset you want use') | 25 help = 'choose whether to use custom rules') |
26 parser.add_argument('-cr', '--custom', | 26 parser.add_argument('-cc', '--custom_rule', |
27 type = str, | 27 type = str, |
28 help='your dataset if you want custom rules') | 28 help='custom rules to use') |
29 parser.add_argument('-cm', '--custom_map', | |
30 type = str, | |
31 help='custom map to use') | |
29 parser.add_argument('-n', '--none', | 32 parser.add_argument('-n', '--none', |
30 type = str, | 33 type = str, |
31 default = 'true', | 34 default = 'true', |
32 choices = ['true', 'false'], | 35 choices = ['true', 'false'], |
33 help = 'compute Nan values') | 36 help = 'compute Nan values') |
53 type = str, | 56 type = str, |
54 help = 'input dataset') | 57 help = 'input dataset') |
55 parser.add_argument('-ic', '--input_class', | 58 parser.add_argument('-ic', '--input_class', |
56 type = str, | 59 type = str, |
57 help = 'sample group specification') | 60 help = 'sample group specification') |
58 parser.add_argument('-cm', '--custom_map', | |
59 type = str, | |
60 help = 'custom map') | |
61 parser.add_argument('-yn', '--yes_no', | |
62 type = str, | |
63 choices = ['yes', 'no'], | |
64 help = 'if make or not custom map') | |
65 parser.add_argument('-gs', '--generate_svg', | 61 parser.add_argument('-gs', '--generate_svg', |
66 type = str, | 62 type = str, |
67 default = 'true', | 63 default = 'true', |
68 choices = ['true', 'false'], | 64 choices = ['true', 'false'], |
69 help = 'generate svg map') | 65 help = 'generate svg map') |
549 warnings.simplefilter('ignore') | 545 warnings.simplefilter('ignore') |
550 recon = cb.io.read_sbml_model(data) | 546 recon = cb.io.read_sbml_model(data) |
551 react = recon.reactions | 547 react = recon.reactions |
552 rules = [react[i].gene_reaction_rule for i in range(len(react))] | 548 rules = [react[i].gene_reaction_rule for i in range(len(react))] |
553 ids = [react[i].id for i in range(len(react))] | 549 ids = [react[i].id for i in range(len(react))] |
554 except cb.io.sbml3.CobraSBMLError: | 550 except cb.io.sbml.CobraSBMLError: |
555 try: | 551 try: |
556 data = (pd.read_csv(data, sep = '\t', dtype = str, engine='python')).fillna('') | 552 data = (pd.read_csv(data, sep = '\t', dtype = str, engine='python')).fillna('') |
557 if len(data.columns) < 2: | 553 if len(data.columns) < 2: |
558 sys.exit('Execution aborted: wrong format of '+ | 554 sys.exit('Execution aborted: wrong format of '+ |
559 'custom datarules\n') | 555 'custom datarules\n') |
691 tmp_csv = tmp_csv.reset_index() | 687 tmp_csv = tmp_csv.reset_index() |
692 header = ['ids', 'P_Value', 'Log2(fold change)'] | 688 header = ['ids', 'P_Value', 'Log2(fold change)'] |
693 tmp_csv.to_csv(tab, sep = '\t', index = False, header = header) | 689 tmp_csv.to_csv(tab, sep = '\t', index = False, header = header) |
694 | 690 |
695 if create_svg or create_pdf: | 691 if create_svg or create_pdf: |
696 if args.rules_selector == 'HMRcore' or (args.rules_selector == 'Custom' | 692 if args.custom_rules == 'false' or (args.custom_rules == 'true' |
697 and args.yes_no == 'yes'): | 693 and args.custom_map != ''): |
698 fix_map(tmp, core_map, threshold_P_V, threshold_F_C, max_F_C) | 694 fix_map(tmp, core_map, threshold_P_V, threshold_F_C, max_F_C) |
699 file_svg = 'result/' + i + '_vs_' + j + ' (SVG Map).svg' | 695 file_svg = 'result/' + i + '_vs_' + j + ' (SVG Map).svg' |
700 with open(file_svg, 'wb') as new_map: | 696 with open(file_svg, 'wb') as new_map: |
701 new_map.write(ET.tostring(core_map)) | 697 new_map.write(ET.tostring(core_map)) |
702 | 698 |
758 if not create_svg: | 754 if not create_svg: |
759 os.remove('result/' + single_cluster + '_vs_ rest (SVG Map).svg') | 755 os.remove('result/' + single_cluster + '_vs_ rest (SVG Map).svg') |
760 | 756 |
761 elif comparison == "onevsmany": | 757 elif comparison == "onevsmany": |
762 for i, j in it.combinations(class_pat.keys(), 2): | 758 for i, j in it.combinations(class_pat.keys(), 2): |
763 | |
764 if i != control and j != control: | |
765 print(str(control) + " " + str(i) + " " + str(j)) | |
766 #Se รจ un confronto fra elementi diversi dal controllo, skippo | |
767 continue | |
768 | |
769 print('vado') | |
770 tmp = {} | 759 tmp = {} |
771 count = 0 | 760 count = 0 |
772 max_F_C = 0 | 761 max_F_C = 0 |
773 for l1, l2 in zip(class_pat.get(i), class_pat.get(j)): | 762 for l1, l2 in zip(class_pat.get(i), class_pat.get(j)): |
774 try: | 763 try: |
821 create_svg = check_bool(args.generate_svg) | 810 create_svg = check_bool(args.generate_svg) |
822 create_pdf = check_bool(args.generate_pdf) | 811 create_pdf = check_bool(args.generate_pdf) |
823 | 812 |
824 if os.path.isdir('result') == False: | 813 if os.path.isdir('result') == False: |
825 os.makedirs('result') | 814 os.makedirs('result') |
826 | 815 |
827 if args.rules_selector == 'HMRcore': | 816 if args.custom_rules == 'true': |
828 recon = pk.load(open(args.tool_dir + '/local/HMRcore_rules.p', 'rb')) | 817 ids, rules, gene_in_rule = make_recon(args.custom_rule) |
829 elif args.rules_selector == 'Recon': | |
830 recon = pk.load(open(args.tool_dir + '/local/Recon_rules.p', 'rb')) | |
831 elif args.rules_selector == 'Custom': | |
832 ids, rules, gene_in_rule = make_recon(args.custom) | |
833 | 818 |
834 class_pat = {} | 819 class_pat = {} |
835 | 820 |
836 if args.option == 'datasets': | 821 if args.option == 'datasets': |
837 num = 1 | 822 num = 1 |
883 classes = classes.astype(str) | 868 classes = classes.astype(str) |
884 | 869 |
885 if resolve_rules_float != None: | 870 if resolve_rules_float != None: |
886 class_pat = split_class(classes, resolve_rules_float) | 871 class_pat = split_class(classes, resolve_rules_float) |
887 | 872 |
888 if args.rules_selector == 'Custom': | 873 |
889 if args.yes_no == 'yes': | 874 if args.custom_rules == 'true': |
890 try: | 875 try: |
891 core_map = ET.parse(args.custom_map) | 876 core_map = ET.parse(args.custom_map) |
892 except (ET.XMLSyntaxError, ET.XMLSchemaParseError): | 877 except (ET.XMLSyntaxError, ET.XMLSchemaParseError): |
893 sys.exit('Execution aborted: custom map in wrong format') | 878 sys.exit('Execution aborted: custom map in wrong format') |
894 elif args.yes_no == 'no': | 879 else: |
895 core_map = ET.parse(args.tool_dir + '/local/HMRcoreMap.svg') | |
896 else: | |
897 core_map = ET.parse(args.tool_dir+'/local/HMRcoreMap.svg') | 880 core_map = ET.parse(args.tool_dir+'/local/HMRcoreMap.svg') |
898 | 881 |
899 maps(core_map, class_pat, ids, args.pValue, args.fChange, create_svg, create_pdf, args.comparison, args.control) | 882 maps(core_map, class_pat, ids, args.pValue, args.fChange, create_svg, create_pdf, args.comparison, args.control) |
900 | 883 |
901 print('Execution succeded') | 884 print('Execution succeded') |