Source code for deepchem.molnet.load_function.toxcast_datasets

"""
TOXCAST dataset loader.
"""
from __future__ import print_function
from __future__ import division
from __future__ import unicode_literals

import os
import deepchem


[docs]def load_toxcast(featurizer='ECFP', split='index', reload=True): data_dir = deepchem.utils.get_data_dir() if reload: save_dir = os.path.join(data_dir, "toxcast/" + featurizer + "/" + split) dataset_file = os.path.join(data_dir, "toxcast_data.csv.gz") if not os.path.exists(dataset_file): deepchem.utils.download_url( 'http://deepchem.io.s3-website-us-west-1.amazonaws.com/datasets/toxcast_data.csv.gz' ) dataset = deepchem.utils.save.load_from_disk(dataset_file) print("Columns of dataset: %s" % str(dataset.columns.values)) print("Number of examples in dataset: %s" % str(dataset.shape[0])) TOXCAST_tasks = dataset.columns.values[1:].tolist() if reload: loaded, all_dataset, transformers = deepchem.utils.save.load_dataset_from_disk( save_dir) if loaded: return TOXCAST_tasks, all_dataset, transformers # Featurize TOXCAST dataset print("About to featurize TOXCAST dataset.") if featurizer == 'ECFP': featurizer = deepchem.feat.CircularFingerprint(size=1024) elif featurizer == 'GraphConv': featurizer = deepchem.feat.ConvMolFeaturizer() elif featurizer == 'Weave': featurizer = deepchem.feat.WeaveFeaturizer() elif featurizer == 'Raw': featurizer = deepchem.feat.RawFeaturizer() loader = deepchem.data.CSVLoader( tasks=TOXCAST_tasks, smiles_field="smiles", featurizer=featurizer) dataset = loader.featurize(dataset_file) # Initialize transformers transformers = [ deepchem.trans.BalancingTransformer(transform_w=True, dataset=dataset) ] print("About to transform data") for transformer in transformers: dataset = transformer.transform(dataset) splitters = { 'index': deepchem.splits.IndexSplitter(), 'random': deepchem.splits.RandomSplitter(), 'scaffold': deepchem.splits.ScaffoldSplitter() } splitter = splitters[split] train, valid, test = splitter.train_valid_test_split(dataset) if reload: deepchem.utils.save.save_dataset_to_disk(save_dir, train, valid, test, transformers) return TOXCAST_tasks, (train, valid, test), transformers