comparison modify/change_title_to_metadata_value.py @ 0:527ecd2fc500 draft

Uploaded
author bgruening
date Thu, 15 Aug 2013 03:25:06 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:527ecd2fc500
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, sys
10 import argparse
11 import openbabel
12 openbabel.obErrorLog.StopLogging()
13 import pybel
14
15
16 def main():
17 parser = argparse.ArgumentParser(
18 description="Change the title from a molecule file to metadata \
19 value of a given-id of the same molecule file.",
20 )
21 parser.add_argument('--infile', '-i',
22 required=True, help="path to the input file")
23 parser.add_argument('--outfile', '-o',
24 required=True, help="path to the output file")
25 parser.add_argument('--key', '-k',
26 required=True, help="the metadata key from the sdf file which should inlcude the new title")
27
28 args = parser.parse_args()
29
30 output = pybel.Outputfile("sdf", args.outfile, overwrite=True)
31
32 for mol in pybel.readfile("sdf", args.infile):
33 if args.key in mol.data:
34 mol.title = mol.data[args.key]
35 output.write( mol )
36
37 output.close()
38
39
40 if __name__ == "__main__":
41 main()
42