Created
January 10, 2019 22:45
-
-
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`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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