This example describes a typical pipeline consisting of data processing, generating ChemSpace.js input format and its integration into the web page.
ChemSpace.js does not perform the calculation of 2D coordinates (dimensionality reduction) by itself. It is a visualization library to which data must be supplied in the JSON compliant ChemSpace.js format. This format is readily produced by our Python script chemspace.py. However, the user can use an arbitrary software provided that a valid ChemSpace.js input file is generated.
Data for visualization are typically supplied to chemspace.py as a csv (comma separated values) file. The first row of a csv file can optionally contain header names (recommended). The first column of data file is always taken as an ID column. Below is given an example snippet of data file used in this example. The data file represent the D(2) dopamine receptor ligands (Source: Probes & Drugs portal) with their name, potency and the SMILES representation of their molecular structure.
Recommended way of data processing is the use of the chemspace.py script. This script can not only perform dimensionality reduction, but also returns the chemical space as an ChemSpace.js input file. Below given is the command-line for processing of example.csv file. Data file has column headers (-dh option), header name determines the Name (label) field (-lf option) and header Smiles determines the structure field (-csf option). Coordinates are calculated by the t-SNE algorithm applied on the distance matrix of compounds (based on ECFP4 compound fingerprint and Tanimoto distance). To extend compounds' attributes that can be used in the output chemical space, basic physico-chemical properties are calculated and added (-pcp option). The output file example.json contains the chemical space in the ChemSpace.js input format. To decrease the size of the output data (JSON object), the minification of the JSON format is performed (-min option).
The file example.json describes coordinate system of compounds and it contains all data necessary for chemical space visualization. No other file is needed to render the chemical space. An example below demonstrates how easy it is to integrate ChemSpace.js visualization into your web page.
ChemSpace.js (and its dependencies jquery-3.3.1.min.js and konva-1.7.6.min.js) must be first imported in the <script> tag. ChemSpace.js is initialized immediately when the whole page is loaded (detected by the $(document).ready event), and it contains several attributes defining the appearance of the visualization (all attributes are documented here). Finally, example.json is loaded, and the chemical space is displayed.
Below is an example of a simple HTML web page with ChemSpace.js integration: