comparison Marea/marea.py @ 53:7b57a93ac594 draft

Uploaded
author bimib
date Sun, 15 Mar 2020 11:19:36 -0400
parents e4235b5231e4
children 68375ead0ee4
comparison
equal deleted inserted replaced
52:88b7180d7b79 53:7b57a93ac594
535 split_rules.append([]) 535 split_rules.append([])
536 if err_rules: 536 if err_rules:
537 warning('Warning: wrong format rule in ' + str(err_rules) + '\n') 537 warning('Warning: wrong format rule in ' + str(err_rules) + '\n')
538 return (split_rules, list(set(tmp_gene_in_rule))) 538 return (split_rules, list(set(tmp_gene_in_rule)))
539 539
540 def make_recon(data):
541 try:
542 import cobra as cb
543 import warnings
544 with warnings.catch_warnings():
545 warnings.simplefilter('ignore')
546 recon = cb.io.read_sbml_model(data)
547 react = recon.reactions
548 rules = [react[i].gene_reaction_rule for i in range(len(react))]
549 ids = [react[i].id for i in range(len(react))]
550 except cb.io.sbml.CobraSBMLError:
551 try:
552 data = (pd.read_csv(data, sep = '\t', dtype = str, engine='python')).fillna('')
553 if len(data.columns) < 2:
554 sys.exit('Execution aborted: wrong format of '+
555 'custom datarules\n')
556 if not len(data.columns) == 2:
557 warning('Warning: more than 2 columns in custom datarules.\n' +
558 'Extra columns have been disregarded\n')
559 ids = list(data.iloc[:, 0])
560 rules = list(data.iloc[:, 1])
561 except pd.errors.EmptyDataError:
562 sys.exit('Execution aborted: wrong format of custom datarules\n')
563 except pd.errors.ParserError:
564 sys.exit('Execution aborted: wrong format of custom datarules\n')
565 split_rules, tmp_genes = do_rules(rules)
566 gene_in_rule = {}
567 for i in tmp_genes:
568 gene_in_rule[i] = 'ok'
569 return (ids, split_rules, gene_in_rule)
570 540
571 ############################ gene ############################################# 541 ############################ gene #############################################
572 542
573 def data_gene(gene, type_gene, name, gene_custom): 543 def data_gene(gene, type_gene, name, gene_custom):
574 args = process_args(sys.argv) 544 args = process_args(sys.argv)
810 create_svg = check_bool(args.generate_svg) 780 create_svg = check_bool(args.generate_svg)
811 create_pdf = check_bool(args.generate_pdf) 781 create_pdf = check_bool(args.generate_pdf)
812 782
813 if os.path.isdir('result') == False: 783 if os.path.isdir('result') == False:
814 os.makedirs('result') 784 os.makedirs('result')
815
816 if args.custom_rules == 'true':
817 ids, rules, gene_in_rule = make_recon(args.custom_rule)
818 785
819 class_pat = {} 786 class_pat = {}
820 787
821 if args.option == 'datasets': 788 if args.option == 'datasets':
822 num = 1 789 num = 1