Skip to content

Instantly share code, notes, and snippets.

@sshojiro
Created January 10, 2019 22:45
Show Gist options
  • Save sshojiro/3f1320643eca9680778030698ec4616b to your computer and use it in GitHub Desktop.
Save sshojiro/3f1320643eca9680778030698ec4616b to your computer and use it in GitHub Desktop.
Command like `wc -l`. Ex: `$ count_compounds.py chembl24_1.sdf.gz --gzip` or `$ count_compounds.py chembl24_1.sdf`
# command like `wc -l`
from rdkit.Chem.rdmolfiles import ForwardSDMolSupplier, SDMolSupplier
import sys
import gzip
argv = sys.argv[1:]
filename = argv[0]
if len(argv) > 1:
option = argv[1]
else:
option = []
if option == '--gzip':
sppl = ForwardSDMolSupplier(gzip.open(filename, 'r'))
count = 0
for x in sppl:
if x is not None: count += 1
print(f'{filename} {count}')
else:
sppl = SDMolSupplier(filename)
count = len(sppl)
print(f'{filename} {count}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment