diff change_title_to_metadata_value.py @ 10:1dd562ae055d draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 6c84abdd07f292048bf2194073e2e938e94158c4"
author bgruening
date Wed, 25 Mar 2020 16:47:58 -0400
parents 75d6c2b7907a
children 50ca8845e7f5
line wrap: on
line diff
--- a/change_title_to_metadata_value.py	Thu Aug 22 10:27:29 2019 -0400
+++ b/change_title_to_metadata_value.py	Wed Mar 25 16:47:58 2020 -0400
@@ -12,6 +12,8 @@
 import openbabel
 openbabel.obErrorLog.StopLogging()
 import pybel
+import random
+import string
 
 
 def main():
@@ -25,14 +27,18 @@
         required=True, help="path to the output file")
     parser.add_argument('--key', '-k',
         required=True, help="the metadata key from the sdf file which should inlcude the new title")
+    parser.add_argument('--random', '-r',
+        action="store_true", help="Add random suffix to the title.")
 
     args = parser.parse_args()
 
     output = pybel.Outputfile("sdf", args.outfile, overwrite=True)
-
     for mol in pybel.readfile("sdf", args.infile):
         if args.key in mol.data:
             mol.title = mol.data[args.key]
+            if args.random:
+                suffix = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(13))
+                mol.title += '__%s' % suffix
         output.write( mol )
 
     output.close()