comparison change_title_to_metadata_value.py @ 0:06340f46ecb8 draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
author bgruening
date Fri, 10 May 2019 08:55:09 -0400
parents
children b8838a9aa31a
comparison
equal deleted inserted replaced
-1:000000000000 0:06340f46ecb8
1 #!/usr/bin/env python
2 # -*- coding: UTF-8 -*-
3
4 """
5 Change the title from a molecule file to metadata
6 value of a given-id of the same molecule file.
7 """
8
9 import os
10 import sys
11 import argparse
12 import openbabel
13 openbabel.obErrorLog.StopLogging()
14 import pybel
15
16
17 def main():
18 parser = argparse.ArgumentParser(
19 description="Change the title from a molecule file to metadata \
20 value of a given-id of the same molecule file.",
21 )
22 parser.add_argument('--infile', '-i',
23 required=True, help="path to the input file")
24 parser.add_argument('--outfile', '-o',
25 required=True, help="path to the output file")
26 parser.add_argument('--key', '-k',
27 required=True, help="the metadata key from the sdf file which should inlcude the new title")
28
29 args = parser.parse_args()
30
31 output = pybel.Outputfile("sdf", args.outfile, overwrite=True)
32
33 for mol in pybel.readfile("sdf", args.infile):
34 if args.key in mol.data:
35 mol.title = mol.data[args.key]
36 output.write( mol )
37
38 output.close()
39
40
41 if __name__ == "__main__":
42 main()
43