comparison 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
comparison
equal deleted inserted replaced
27:8c480c977a12 28:e6831924df01
48 type = str, 48 type = str,
49 required = True, 49 required = True,
50 help = 'your tool directory') 50 help = 'your tool directory')
51 parser.add_argument('-op', '--option', 51 parser.add_argument('-op', '--option',
52 type = str, 52 type = str,
53 choices = ['datasets', 'dataset_class'], 53 choices = ['datasets', 'dataset_class', 'datasets_rasonly'],
54 help='dataset or dataset and class') 54 help='dataset or dataset and class')
55 parser.add_argument('-ol', '--out_log', 55 parser.add_argument('-ol', '--out_log',
56 help = "Output log") 56 help = "Output log")
57 parser.add_argument('-ids', '--input_datas', 57 parser.add_argument('-ids', '--input_datas',
58 type = str, 58 type = str,
84 parser.add_argument('-gr', '--generate_ras', 84 parser.add_argument('-gr', '--generate_ras',
85 type = str, 85 type = str,
86 default = 'true', 86 default = 'true',
87 choices = ['true', 'false'], 87 choices = ['true', 'false'],
88 help = 'generate reaction activity score') 88 help = 'generate reaction activity score')
89 parser.add_argument('-sr', '--single_ras_file',
90 type = str,
91 help = 'file that will contain ras')
92
89 args = parser.parse_args() 93 args = parser.parse_args()
90 return args 94 return args
91 95
92 ########################### warning ########################################### 96 ########################### warning ###########################################
93 97
656 ', the class has been disregarded\n') 660 ', the class has been disregarded\n')
657 return class_pat 661 return class_pat
658 662
659 ############################ create_ras ####################################### 663 ############################ create_ras #######################################
660 664
661 def create_ras (resolve_rules, dataset_name): 665 def create_ras (resolve_rules, dataset_name, single_ras):
662 666
663 if resolve_rules == None: 667 if resolve_rules == None:
664 warning("Couldn't generate RAS for current dataset: " + dataset_name) 668 warning("Couldn't generate RAS for current dataset: " + dataset_name)
665 669
666 for geni in resolve_rules.values(): 670 for geni in resolve_rules.values():
668 if valori == None: 672 if valori == None:
669 geni[i] = 'None' 673 geni[i] = 'None'
670 674
671 output_ras = pd.DataFrame.from_dict(resolve_rules) 675 output_ras = pd.DataFrame.from_dict(resolve_rules)
672 output_to_csv = pd.DataFrame.to_csv(output_ras, sep = '\t', index = False) 676 output_to_csv = pd.DataFrame.to_csv(output_ras, sep = '\t', index = False)
673 677
674 text_file = open("ras/Reaction_Activity_Score_Of_" + dataset_name + ".tsv", "w") 678 if (single_ras):
679 args = process_args(sys.argv)
680 text_file = open(args.single_ras_file, "w")
681 else:
682 text_file = open("ras/Reaction_Activity_Score_Of_" + dataset_name + ".tsv", "w")
683
675 text_file.write(output_to_csv) 684 text_file.write(output_to_csv)
676 text_file.close() 685 text_file.close()
677 686
678 ############################ map ############################################## 687 ############################ map ##############################################
679 688
747 756
748 resolve_none = check_bool(args.none) 757 resolve_none = check_bool(args.none)
749 758
750 class_pat = {} 759 class_pat = {}
751 760
752 if args.option == 'datasets': 761 if args.option == 'datasets_rasonly':
762 name = "RAS Dataset"
763 dataset = read_dataset(args.input_datas[0],"dataset")
764
765 dataset.iloc[:, 0] = (dataset.iloc[:, 0]).astype(str)
766
767 type_gene = gene_type(dataset.iloc[0, 0], name)
768
769 if args.rules_selector != 'Custom':
770 genes = data_gene(dataset, type_gene, name, None)
771 ids, rules = load_id_rules(recon.get(type_gene))
772 elif args.rules_selector == 'Custom':
773 genes = data_gene(dataset, type_gene, name, gene_in_rule)
774
775 resolve_rules, err = resolve(genes, rules, ids, resolve_none, name)
776
777 create_ras(resolve_rules, name, True)
778
779 if err != None and err:
780 warning('Warning: gene\n' + str(err) + '\nnot found in class '
781 + name + ', the expression level for this gene ' +
782 'will be considered NaN\n')
783
784 print('execution succeded')
785 return None
786
787
788 elif args.option == 'datasets':
753 num = 1 789 num = 1
754 for i, j in zip(args.input_datas, args.names): 790 for i, j in zip(args.input_datas, args.names):
755 791
756 name = name_dataset(j, num) 792 name = name_dataset(j, num)
757 dataset = read_dataset(i, name) 793 dataset = read_dataset(i, name)
767 genes = data_gene(dataset, type_gene, name, gene_in_rule) 803 genes = data_gene(dataset, type_gene, name, gene_in_rule)
768 804
769 resolve_rules, err = resolve(genes, rules, ids, resolve_none, name) 805 resolve_rules, err = resolve(genes, rules, ids, resolve_none, name)
770 806
771 if generate_ras: 807 if generate_ras:
772 create_ras(resolve_rules, name) 808 create_ras(resolve_rules, name, False)
773
774 809
775 if err != None and err: 810 if err != None and err:
776 warning('Warning: gene\n' + str(err) + '\nnot found in class ' 811 warning('Warning: gene\n' + str(err) + '\nnot found in class '
777 + name + ', the expression level for this gene ' + 812 + name + ', the expression level for this gene ' +
778 'will be considered NaN\n') 813 'will be considered NaN\n')
799 warning('Warning: gene\n'+str(err)+'\nnot found in class ' 834 warning('Warning: gene\n'+str(err)+'\nnot found in class '
800 + name + ', the expression level for this gene ' + 835 + name + ', the expression level for this gene ' +
801 'will be considered NaN\n') 836 'will be considered NaN\n')
802 if resolve_rules != None: 837 if resolve_rules != None:
803 class_pat = split_class(classes, resolve_rules) 838 class_pat = split_class(classes, resolve_rules)
804 839
840
805 if args.rules_selector == 'Custom': 841 if args.rules_selector == 'Custom':
806 if args.yes_no == 'yes': 842 if args.yes_no == 'yes':
807 try: 843 try:
808 core_map = ET.parse(args.custom_map) 844 core_map = ET.parse(args.custom_map)
809 except (ET.XMLSyntaxError, ET.XMLSchemaParseError): 845 except (ET.XMLSyntaxError, ET.XMLSchemaParseError):