annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
1 #!/usr/bin/env python
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
2 # -*- coding: UTF-8 -*-
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
3
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
4 """
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
5 Change the title from a molecule file to metadata
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
6 value of a given-id of the same molecule file.
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
7 """
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
8
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
9 import os
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
10 import sys
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
11 import argparse
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
12 import openbabel
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
13 openbabel.obErrorLog.StopLogging()
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
14 import pybel
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
15
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
16
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
17 def main():
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
18 parser = argparse.ArgumentParser(
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
19 description="Change the title from a molecule file to metadata \
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
20 value of a given-id of the same molecule file.",
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
21 )
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
22 parser.add_argument('--infile', '-i',
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
23 required=True, help="path to the input file")
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
24 parser.add_argument('--outfile', '-o',
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
25 required=True, help="path to the output file")
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
26 parser.add_argument('--key', '-k',
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
27 required=True, help="the metadata key from the sdf file which should inlcude the new title")
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
28
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
29 args = parser.parse_args()
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
30
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
31 output = pybel.Outputfile("sdf", args.outfile, overwrite=True)
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
32
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
33 for mol in pybel.readfile("sdf", args.infile):
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
34 if args.key in mol.data:
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
35 mol.title = mol.data[args.key]
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
36 output.write( mol )
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
37
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
38 output.close()
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
39
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
40
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
41 if __name__ == "__main__":
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
42 main()
06340f46ecb8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
bgruening
parents:
diff changeset
43