@datagrok/compute 0.2.6 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +6 -1
- package/icons/Blob.svg +3 -0
- package/icons/Bool.svg +3 -0
- package/icons/Column-list.svg +3 -0
- package/icons/Column.svg +3 -0
- package/icons/Dataframe.svg +3 -0
- package/icons/Datetime.svg +3 -0
- package/icons/Double.svg +5 -0
- package/icons/File.svg +3 -0
- package/icons/Graphics.svg +3 -0
- package/icons/Int.svg +3 -0
- package/icons/String.svg +3 -0
- package/package.json +4 -2
- package/scripts/pMax.js +64 -36
- package/scripts/vMaxJS.js +57 -7
- package/src/export-funccall.ts +117 -27
- package/src/function-editor/function-editor.ts +442 -0
- package/src/outliers-selection/outliers-selection-viewer.ts +259 -0
- package/src/{outliers-selection.ts → outliers-selection/outliers-selection.ts} +6 -1
- package/src/package.ts +76 -1
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import * as grok from 'datagrok-api/grok';
|
|
2
2
|
import * as ui from 'datagrok-api/ui';
|
|
3
3
|
import * as DG from 'datagrok-api/dg';
|
|
4
|
-
import {_package} from '
|
|
4
|
+
import {_package} from '../package';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @param inputData The data to select the outliers in
|
|
8
|
+
* @returns Two dataframes: 1) with selected outliers and 2) with removed outliers
|
|
9
|
+
* @deprecated Use the OutliersSelectionViewer instead
|
|
10
|
+
*/
|
|
6
11
|
export async function selectOutliersManually(inputData: DG.DataFrame) {
|
|
7
12
|
const IS_OUTLIER_COL_LABEL = 'isOutlier';
|
|
8
13
|
const OUTLIER_RATIONALE_COL_LABEL = 'Rationale';
|
package/src/package.ts
CHANGED
|
@@ -3,11 +3,13 @@ import * as grok from 'datagrok-api/grok';
|
|
|
3
3
|
import * as ui from 'datagrok-api/ui';
|
|
4
4
|
import * as DG from 'datagrok-api/dg';
|
|
5
5
|
import {ModelHandler} from './model-handler';
|
|
6
|
-
import {selectOutliersManually} from './outliers-selection';
|
|
6
|
+
import {selectOutliersManually} from './outliers-selection/outliers-selection';
|
|
7
7
|
import {exportFuncCall} from './export-funccall';
|
|
8
8
|
import {_functionParametersGrid} from './function-views/function-parameters-grid';
|
|
9
9
|
import {ModelCatalogView} from './model-catalog-view';
|
|
10
10
|
import wu from 'wu';
|
|
11
|
+
import {_functionEditor} from './function-editor/function-editor';
|
|
12
|
+
import {OutliersSelectionViewer} from './outliers-selection/outliers-selection-viewer';
|
|
11
13
|
|
|
12
14
|
let initCompleted: boolean = false;
|
|
13
15
|
export const _package = new DG.Package();
|
|
@@ -45,6 +47,14 @@ export async function manualOutlierSelectionDialog(inputData: DG.DataFrame) {
|
|
|
45
47
|
});
|
|
46
48
|
}
|
|
47
49
|
|
|
50
|
+
//name: OutliersSelectionViewer
|
|
51
|
+
//description: Creates an outliers selection viewer
|
|
52
|
+
//tags: viewer
|
|
53
|
+
//output: viewer
|
|
54
|
+
export function OutliersSelection() {
|
|
55
|
+
return new OutliersSelectionViewer();
|
|
56
|
+
}
|
|
57
|
+
|
|
48
58
|
//name: export To Excel
|
|
49
59
|
//input: funccall call
|
|
50
60
|
//tags: export
|
|
@@ -52,6 +62,71 @@ export function exportToExcel(call: DG.FuncCall) {
|
|
|
52
62
|
exportFuncCall(call);
|
|
53
63
|
}
|
|
54
64
|
|
|
65
|
+
//name: Function Editor
|
|
66
|
+
export function functionEditor() {
|
|
67
|
+
const sampleScript = `
|
|
68
|
+
#name: Chemical Space Using tSNE
|
|
69
|
+
#description: Chemical space using t-distributed Stochastic Neighbor Embedding
|
|
70
|
+
#help-url: https://datagrok.ai/help/domains/chem/functions/tsne
|
|
71
|
+
#language: python
|
|
72
|
+
#sample: chem/smiles_coordinates.csv
|
|
73
|
+
#tags: demo, chem, rdkit
|
|
74
|
+
#input: dataframe data [Input data table]
|
|
75
|
+
#input: column smiles {type:categorical, semType: Molecule} [Molecules, in SMILES format]
|
|
76
|
+
#input: int components = 2 [Number of components]
|
|
77
|
+
#input: int minClusterSize = 3 [Minimum cluster size]
|
|
78
|
+
#output: graphics spanningTree
|
|
79
|
+
#output: graphics linkageTree
|
|
80
|
+
#output: graphics chemSpace
|
|
81
|
+
|
|
82
|
+
import numba
|
|
83
|
+
import hdbscan
|
|
84
|
+
import numpy as np
|
|
85
|
+
import matplotlib.pyplot as plt
|
|
86
|
+
from sklearn.manifold import TSNE
|
|
87
|
+
from rdkit import Chem
|
|
88
|
+
from rdkit.Chem import AllChem
|
|
89
|
+
from rdkit.Chem import Draw
|
|
90
|
+
from rdkit.Chem import DataStructs
|
|
91
|
+
|
|
92
|
+
smiles = data[smiles]
|
|
93
|
+
mols = [Chem.MolFromSmiles(mol) for mol in smiles]
|
|
94
|
+
mols = [mol for mol in mols if mol is not None]
|
|
95
|
+
for mol in mols:
|
|
96
|
+
AllChem.Compute2DCoords(mol)
|
|
97
|
+
X = []
|
|
98
|
+
for mol in mols:
|
|
99
|
+
arr = np.zeros((0,))
|
|
100
|
+
fp = AllChem.GetMorganFingerprintAsBitVect(mol, 2)
|
|
101
|
+
DataStructs.ConvertToNumpyArray(fp, arr)
|
|
102
|
+
X.append(arr)
|
|
103
|
+
|
|
104
|
+
@numba.njit()
|
|
105
|
+
def tanimoto_dist(a, b):
|
|
106
|
+
dotprod = np.dot(a, b)
|
|
107
|
+
tc = dotprod / (np.sum(a) + np.sum(b) - dotprod)
|
|
108
|
+
return 1.0 - tc
|
|
109
|
+
|
|
110
|
+
tsne = TSNE(n_components=components, metric=tanimoto_dist)
|
|
111
|
+
tsne_X = tsne.fit_transform(X)
|
|
112
|
+
cluster_tsne = hdbscan.HDBSCAN(min_cluster_size=minClusterSize, gen_min_span_tree=True)
|
|
113
|
+
cluster_tsne.fit(tsne_X)
|
|
114
|
+
|
|
115
|
+
plt.figure(0)
|
|
116
|
+
cluster_tsne.minimum_spanning_tree_.plot(
|
|
117
|
+
edge_cmap='viridis', edge_alpha=0.6,
|
|
118
|
+
node_size=90, edge_linewidth=2)
|
|
119
|
+
|
|
120
|
+
plt.figure(1)
|
|
121
|
+
cluster_tsne.single_linkage_tree_.plot(cmap='viridis', colorbar=True)
|
|
122
|
+
|
|
123
|
+
plt.figure(2)
|
|
124
|
+
plt.scatter(tsne_X.T[0], tsne_X.T[1], c=cluster_tsne.labels_, cmap='plasma')
|
|
125
|
+
plt.title('Chemical space')
|
|
126
|
+
`;
|
|
127
|
+
_functionEditor(sampleScript);
|
|
128
|
+
}
|
|
129
|
+
|
|
55
130
|
/* eslint-disable */
|
|
56
131
|
|
|
57
132
|
//description: A spreadsheet that lets you interactively edit parameters and evaluate functions
|