Mercurial > repos > bgruening > openbabel_remduplicates
comparison ob_remIons.py @ 15:c5de6c19eb06 draft default tip
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
author | bgruening |
---|---|
date | Thu, 15 Aug 2024 11:00:46 +0000 |
parents | b2569e22b40c |
children |
comparison
equal
deleted
inserted
replaced
14:b2569e22b40c | 15:c5de6c19eb06 |
---|---|
6 Copyright 2012, Bjoern Gruening and Xavier Lucas | 6 Copyright 2012, Bjoern Gruening and Xavier Lucas |
7 """ | 7 """ |
8 import argparse | 8 import argparse |
9 | 9 |
10 from openbabel import openbabel, pybel | 10 from openbabel import openbabel, pybel |
11 | |
11 openbabel.obErrorLog.StopLogging() | 12 openbabel.obErrorLog.StopLogging() |
12 | 13 |
13 | 14 |
14 def parse_command_line(): | 15 def parse_command_line(): |
15 parser = argparse.ArgumentParser() | 16 parser = argparse.ArgumentParser() |
16 parser.add_argument('-iformat', default='sdf', help='input file format') | 17 parser.add_argument("-iformat", default="sdf", help="input file format") |
17 parser.add_argument('-i', '--input', required=True, help='input file name') | 18 parser.add_argument("-i", "--input", required=True, help="input file name") |
18 parser.add_argument('-o', '--output', required=True, help='output file name') | 19 parser.add_argument("-o", "--output", required=True, help="output file name") |
19 parser.add_argument('-idx', default=False, action='store_true', help='should output be an indexed text table? works only for inchi/smiles, otherwise is ignored') | 20 parser.add_argument( |
21 "-idx", | |
22 default=False, | |
23 action="store_true", | |
24 help="should output be an indexed text table? works only for inchi/smiles, otherwise is ignored", | |
25 ) | |
20 return parser.parse_args() | 26 return parser.parse_args() |
21 | 27 |
22 | 28 |
23 def remove_ions(args): | 29 def remove_ions(args): |
24 with open(args.output, 'w') as outfile: | 30 with open(args.output, "w") as outfile: |
25 for index, mol in enumerate(pybel.readfile(args.iformat, args.input)): | 31 for index, mol in enumerate(pybel.readfile(args.iformat, args.input)): |
26 if mol.OBMol.NumHvyAtoms() > 5: | 32 if mol.OBMol.NumHvyAtoms() > 5: |
27 mol.OBMol.StripSalts(0) | 33 mol.OBMol.StripSalts(0) |
28 if 'inchi' in mol.data: | 34 if "inchi" in mol.data: |
29 del mol.data['inchi'] # remove inchi cache so modified mol is saved | 35 del mol.data["inchi"] # remove inchi cache so modified mol is saved |
30 | 36 |
31 mol = mol.write(args.iformat) if mol.OBMol.NumHvyAtoms() > 5 else '\n' | 37 mol = mol.write(args.iformat) if mol.OBMol.NumHvyAtoms() > 5 else "\n" |
32 | 38 |
33 if args.idx and args.iformat in ['inchi', 'smi']: | 39 if args.idx and args.iformat in ["inchi", "smi"]: |
34 outfile.write(f'{index}\t{mol}') | 40 outfile.write(f"{index}\t{mol}") |
35 elif mol != '\n': | 41 elif mol != "\n": |
36 outfile.write(f'{mol}') | 42 outfile.write(f"{mol}") |
37 | 43 |
38 | 44 |
39 def __main__(): | 45 def __main__(): |
40 """ | 46 """ |
41 Remove any counterion and delete any fragment but the largest one for each molecule. | 47 Remove any counterion and delete any fragment but the largest one for each molecule. |
42 """ | 48 """ |
43 args = parse_command_line() | 49 args = parse_command_line() |
44 remove_ions(args) | 50 remove_ions(args) |
45 | 51 |
46 | 52 |