comparison change_title_to_metadata_value.py @ 0:98e12cc1f3a8 draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
author bgruening
date Sat, 20 May 2017 08:40:52 -0400
parents
children fc199b60875d
comparison
equal deleted inserted replaced
-1:000000000000 0:98e12cc1f3a8
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