comparison sdf_to_tab.py @ 5:351fbd750a6d draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
author bgruening
date Wed, 17 Feb 2021 13:00:12 +0000
parents 71bc02c59d3a
children 4beb3e026bbb
comparison
equal deleted inserted replaced
4:55553120df69 5:351fbd750a6d
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2 import argparse 2 import argparse
3
3 import pandas as pd 4 import pandas as pd
4 from rdkit import Chem 5 from rdkit import Chem
6
5 7
6 def sdf_to_tab(vars): 8 def sdf_to_tab(vars):
7 mols = Chem.SDMolSupplier(vars.inp, sanitize=False) 9 mols = Chem.SDMolSupplier(vars.inp, sanitize=False)
8 df = pd.DataFrame() # for output 10 df = pd.DataFrame() # for output
9 11
27 29
28 df = df.astype({'Index': int}).set_index('Index') 30 df = df.astype({'Index': int}).set_index('Index')
29 sorted_cols = sorted(df.columns.values.tolist()) 31 sorted_cols = sorted(df.columns.values.tolist())
30 df.to_csv(vars.out, sep='\t', header=vars.header, columns=sorted_cols) 32 df.to_csv(vars.out, sep='\t', header=vars.header, columns=sorted_cols)
31 33
34
32 def main(): 35 def main():
33 parser = argparse.ArgumentParser(description="Convert SDF to tabular") 36 parser = argparse.ArgumentParser(description="Convert SDF to tabular")
34 parser.add_argument('--inp', '-i', help="The input file", required=True) 37 parser.add_argument('--inp', '-i', help="The input file", required=True)
35 parser.add_argument('--out', '-o', help="The output file", required=True) 38 parser.add_argument('--out', '-o', help="The output file", required=True)
36 parser.add_argument('--props', '-p', help="Properties to filter (leave blank for all)", required=True) 39 parser.add_argument('--props', '-p', help="Properties to filter (leave blank for all)", required=True)
39 parser.add_argument('--smiles', '-s', action='store_true', 42 parser.add_argument('--smiles', '-s', action='store_true',
40 help="Include SMILES in output.") 43 help="Include SMILES in output.")
41 parser.add_argument('--name', '-n', action='store_true', 44 parser.add_argument('--name', '-n', action='store_true',
42 help="Include molecule name in output.") 45 help="Include molecule name in output.")
43 sdf_to_tab(parser.parse_args()) 46 sdf_to_tab(parser.parse_args())
44 47
45 48
46 if __name__ == "__main__": 49 if __name__ == "__main__":
47 main() 50 main()