Mercurial > repos > bgruening > openbabel_subsearch
comparison ob_filter.py @ 10:fc199b60875d draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 6c84abdd07f292048bf2194073e2e938e94158c4"
author | bgruening |
---|---|
date | Wed, 25 Mar 2020 16:41:26 -0400 |
parents | 30a6c37e95ac |
children | c4abd2c7d5f6 |
comparison
equal
deleted
inserted
replaced
9:202e3a64859b | 10:fc199b60875d |
---|---|
26 help='Output file name', | 26 help='Output file name', |
27 required=True) | 27 required=True) |
28 parser.add_argument('--filters', | 28 parser.add_argument('--filters', |
29 help="Specify the filters to apply", | 29 help="Specify the filters to apply", |
30 required=True, | 30 required=True, |
31 ) | |
32 parser.add_argument('--list_of_names', | |
33 help="A file with list of molecule names to extract. Every name is in one line.", | |
34 required=False, | |
31 ) | 35 ) |
32 return parser.parse_args() | 36 return parser.parse_args() |
33 | 37 |
34 def filter_precalculated_compounds(args, filters): | 38 def filter_precalculated_compounds(args, filters): |
35 outfile = pybel.Outputfile(args.oformat, args.output, overwrite=True) | 39 outfile = pybel.Outputfile(args.oformat, args.output, overwrite=True) |
81 sys.stderr.write("%s\n" % cmd) | 85 sys.stderr.write("%s\n" % cmd) |
82 else: | 86 else: |
83 sys.stdout.write(stdout.decode('utf-8')) | 87 sys.stdout.write(stdout.decode('utf-8')) |
84 sys.stdout.write(stderr.decode('utf-8')) | 88 sys.stdout.write(stderr.decode('utf-8')) |
85 | 89 |
90 def filter_by_name(args): | |
91 outfile = pybel.Outputfile(args.oformat, args.output, overwrite=True) | |
92 for mol in pybel.readfile('sdf', args.input): | |
93 for name in open(args.list_of_names): | |
94 if mol.title.strip() == name.strip(): | |
95 outfile.write(mol) | |
96 outfile.close() | |
86 | 97 |
87 def __main__(): | 98 def __main__(): |
88 """ | 99 """ |
89 Select compounds with certain properties from a small library | 100 Select compounds with certain properties from a small library |
90 """ | 101 """ |
91 args = parse_command_line() | 102 args = parse_command_line() |
103 | |
104 if args.filters == '__filter_by_name__': | |
105 filter_by_name(args) | |
106 return | |
107 | |
92 # Its a small trick to get the parameters in an easy way from the xml file. | 108 # Its a small trick to get the parameters in an easy way from the xml file. |
93 # To keep it readable in the xml file, many white-spaces are included in that string it needs to be removed. | 109 # To keep it readable in the xml file, many white-spaces are included in that string it needs to be removed. |
94 # Also the last loop creates a ',{' that is not an valid jason expression. | 110 # Also the last loop creates a ',{' that is not an valid jason expression. |
95 filters = json.loads((args.filters).replace(' ', '').replace(',}', '}')) | 111 filters = json.loads((args.filters).replace(' ', '').replace(',}', '}')) |
96 if args.iformat == 'sdf': | 112 if args.iformat == 'sdf': |