Mercurial > repos > bgruening > openbabel_remduplicates
annotate change_title_to_metadata_value.py @ 0:112341e4fc94 draft
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
| author | bgruening | 
|---|---|
| date | Sat, 20 May 2017 08:34:54 -0400 | 
| parents | |
| children | e185dfd1dfea | 
| rev | line source | 
|---|---|
| 
0
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
1 #!/usr/bin/env python | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
2 # -*- coding: UTF-8 -*- | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
3 | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
4 """ | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
5 Change the title from a molecule file to metadata | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
6 value of a given-id of the same molecule file. | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
7 """ | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
8 | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
9 import os | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
10 import sys | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
11 import argparse | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
12 import openbabel | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
13 openbabel.obErrorLog.StopLogging() | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
14 import pybel | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
15 | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
16 | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
17 def main(): | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
18 parser = argparse.ArgumentParser( | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
19 description="Change the title from a molecule file to metadata \ | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
20 value of a given-id of the same molecule file.", | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
21 ) | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
22 parser.add_argument('--infile', '-i', | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
23 required=True, help="path to the input file") | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
24 parser.add_argument('--outfile', '-o', | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
25 required=True, help="path to the output file") | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
26 parser.add_argument('--key', '-k', | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
27 required=True, help="the metadata key from the sdf file which should inlcude the new title") | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
28 | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
29 args = parser.parse_args() | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
30 | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
31 output = pybel.Outputfile("sdf", args.outfile, overwrite=True) | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
32 | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
33 for mol in pybel.readfile("sdf", args.infile): | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
34 if args.key in mol.data: | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
35 mol.title = mol.data[args.key] | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
36 output.write( mol ) | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
37 | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
38 output.close() | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
39 | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
40 | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
41 if __name__ == "__main__": | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
42 main() | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
43 | 
