forked from bioclipse/bioclipse.qsar
/
TestCDKQsar.java
536 lines (380 loc) · 17.1 KB
/
TestCDKQsar.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
package net.bioclipse.cdk.qsar.test;
import static org.junit.Assert.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.bioclipse.cdk.business.ICDKManager;
import net.bioclipse.cdk.domain.ICDKMolecule;
import net.bioclipse.core.MockIFile;
import net.bioclipse.core.business.BioclipseException;
import net.bioclipse.core.domain.IMolecule;
import net.bioclipse.core.domain.SMILESMolecule;
import net.bioclipse.qsar.DescriptorType;
import net.bioclipse.qsar.QSARConstants;
import net.bioclipse.qsar.business.IQsarManager;
import net.bioclipse.qsar.business.QsarManager;
import net.bioclipse.qsar.descriptor.IDescriptorResult;
import net.bioclipse.qsar.descriptor.model.Descriptor;
import net.bioclipse.qsar.descriptor.model.DescriptorImpl;
import net.bioclipse.qsar.descriptor.model.DescriptorParameter;
import net.bioclipse.qsar.descriptor.model.DescriptorProvider;
import net.bioclipse.qsar.init.Activator;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.junit.Test;
import org.osgi.framework.Bundle;
public class TestCDKQsar {
IQsarManager qsar;
private String cdkProviderID="net.bioclipse.cdk.descriptorprovider";
private String cdkProviderName="Chemistry Development Kit";
String bpolID="http://www.blueobelisk.org/ontologies/chemoinformatics-algorithms/#bpol";
String xlogpID="http://www.blueobelisk.org/ontologies/chemoinformatics-algorithms/#xlogP";
String chiChainID="http://www.blueobelisk.org/ontologies/chemoinformatics-algorithms/#chiChain";
String bcutID="http://www.blueobelisk.org/ontologies/chemoinformatics-algorithms/#BCUT";
String atomCountlID="http://www.blueobelisk.org/ontologies/chemoinformatics-algorithms/#atomCount";
String rotBondsCntID="http://www.blueobelisk.org/ontologies/chemoinformatics-algorithms/#rotatableBondsCount";
public TestCDKQsar() {
//Unnecessary to use OSGI.
qsar=new QsarManager();
}
@Test
public void testGetProviders(){
//Get provider by ID
DescriptorProvider provider=qsar.getProviderByID(cdkProviderID);
assertNotNull(provider);
assertEquals(cdkProviderID, provider.getId());
assertEquals("Chemistry Development Kit", provider.getVendor());
assertEquals("Chemistry Development Kit", provider.getName());
assertEquals("http://cdk.sourceforge.net", provider.getNamesapce());
assertEquals("CDK", provider.getShortName());
assertEquals("1.1.0.v20080808", provider.getVersion());
//Get provider classes
List<DescriptorProvider> lstFull = qsar.getFullProviders();
assertNotNull(lstFull);
assertTrue(lstFull.contains(provider));
}
@Test
public void testGetDescriptors(){
//Matches plugin.xml, just test some classes
//Get provider by ID
DescriptorProvider provider=qsar.getProviderByID(cdkProviderID);
assertNotNull(provider);
List<String> descImplIDs=qsar.getDescriptorImplsByProvider(cdkProviderID);
List<DescriptorImpl> descs=qsar.getFullDescriptorImpls(provider);
//Check list of IDs and list of classes equal size
assertEquals(descImplIDs.size(), descs.size());
List<String> descIDs=new ArrayList<String>();
for (DescriptorImpl impl : descs){
descIDs.add(impl.getDefinition());
}
assertTrue(descIDs.contains(xlogpID));
assertTrue(descIDs.contains(bpolID));
}
@Test
public void testGetDescriptorsByID(){
//Get decriptor by hardcoded id
DescriptorImpl desc=qsar.getDescriptorImpl(bpolID, cdkProviderID);
assertNotNull(desc);
assertNull(desc.getParameters());
assertFalse(desc.isRequires3D());
assertEquals(cdkProviderID, desc.getProvider().getId());
assertNotNull(desc.getDescription());
assertNotNull(desc.getDefinition());
}
@Test
public void testGetDescriptorsByIDWithParameters(){
//Get decriptor by hardcoded id with parameters
DescriptorImpl desc=qsar.getDescriptorImpl(xlogpID, cdkProviderID);
assertNotNull(desc);
assertNotNull(desc.getParameters());
assertNotNull(desc.getDescription());
assertNotNull(desc.getDefinition());
List<String> paramKeys=new ArrayList<String>();
List<String> paramVals=new ArrayList<String>();
List<String> paramDesc=new ArrayList<String>();
for (DescriptorParameter param: desc.getParameters()){
System.out.println("Param: " + param.getKey() + " = " + param.getDefaultvalue() + " ; " + param.getDescription());
paramKeys.add(param.getKey());
paramVals.add(param.getDefaultvalue());
paramDesc.add(param.getDescription());
}
assertEquals("salicylFlag", paramKeys.get(0));
assertEquals("true", paramVals.get(0));
assertNotNull(paramDesc.get(0));
}
@Test
public void testGetDescriptorImplNotInOntology(){
System.out.println("=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.");
System.out.println("Impl not in onology:");
System.out.println("=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.");
boolean toFail=false;
for (DescriptorImpl impl : qsar.getFullDescriptorImpls()){
if (qsar.getDescriptorIDs().contains(impl.getDefinition())){
//All is well
}
else{
System.out.println("=.= Descriptor impl: " + impl.getName() + " with def: " + impl.getDefinition());
toFail=true;
}
}
System.out.println("=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.");
assertFalse( "Not all CDK impl are present in ontology, see list on stdout"
, toFail );
}
@Test
public void testGetPrefferedImplByDescriptorID(){
IEclipsePreferences prefs = new DefaultScope().getNode(Activator.PLUGIN_ID);
assertNotNull(prefs);
String prefsString=prefs.get(QSARConstants.QSAR_PROVIDERS_ORDER_PREFERENCE, null);
assertNotNull(prefsString);
System.out.println("Got prefs string: " + prefsString);
assertTrue(prefsString.contains(cdkProviderName));
DescriptorImpl impl=qsar.getPreferredImpl(chiChainID);
assertNotNull(impl);
System.out.println("pref impl: " + impl.getId());
// assertEquals("net.bioclipse.qsar.test.descriptor2", impl.getId());
System.out.println("wee");
}
@Test
public void testCalculateBpolFromSmiles() throws BioclipseException{
IMolecule mol=new SMILESMolecule("C1CNCCC1CC(COC)CCNC");
IDescriptorResult dres = qsar.calculate(mol, bpolID);
//We know only one result as we only asked for one descriptor
assertNotNull(dres);
assertNull(dres.getErrorMessage());
assertEquals(bpolID, dres.getDescriptorId());
System.out.println("Mol: " + mol.getSMILES() +
" ; Desc: " + dres.getDescriptorId() +": ");
for (int i=0; i<dres.getValues().length;i++){
System.out.println(" " + dres.getLabels()[i]
+ "=" + dres.getValues()[i] );
}
assertEquals("bpol", dres.getLabels()[0]);
assertEquals(31.659382, dres.getValues()[0]);
}
@Test
public void testCalculateXlogPFromSMILES() throws BioclipseException{
IMolecule mol=new SMILESMolecule("C1CNCCC1CC(COC)CCNC");
IDescriptorResult dres1=qsar.calculate(mol, xlogpID);
assertNotNull(dres1);
assertNull(dres1.getErrorMessage());
assertEquals(xlogpID, dres1.getDescriptorId());
System.out.println("Mol: " + mol.getSMILES() +
" ; Desc: " + dres1.getDescriptorId() +": ");
for (int i=0; i<dres1.getValues().length;i++){
System.out.println(" " + dres1.getLabels()[i]
+ "=" + dres1.getValues()[i] );
}
assertEquals("XLogP", dres1.getLabels()[0]);
assertEquals(0.184, dres1.getValues()[0]);
}
@Test
public void testCalculateXlogPFromCML() throws BioclipseException, FileNotFoundException, IOException, CoreException{
ICDKManager cdk=net.bioclipse.cdk.business.Activator.getDefault().getCDKManager();
Bundle bun=Platform.getBundle(net.bioclipse.cdk.qsar.test.Activator.PLUGIN_ID);
System.out.println("wee bun: " + bun);
URL url=FileLocator.find(bun, new Path("src/testFiles/0037.cml"), null);
System.out.println("wee url: " + url);
String str=FileLocator.toFileURL(url).getFile();
System.out.println("wee File: " + str);
ICDKMolecule mol = cdk.loadMolecule( new MockIFile(str), null );
IDescriptorResult dres1=qsar.calculate(mol, xlogpID);
assertNotNull(dres1);
assertNull(dres1.getErrorMessage(),dres1.getErrorMessage());
assertEquals(xlogpID, dres1.getDescriptorId());
System.out.println("Mol: " + mol.getSMILES() +
" ; Desc: " + dres1.getDescriptorId() +": ");
for (int i=0; i<dres1.getValues().length;i++){
System.out.println(" " + dres1.getLabels()[i]
+ "=" + dres1.getValues()[i] );
}
assertEquals("XLogP", dres1.getLabels()[0]);
assertEquals(0.184, dres1.getValues()[0]);
}
@Test
public void testCalculateBCUTFromSMILES() throws BioclipseException{
IMolecule mol=new SMILESMolecule("C1CNCCC1CC(COC)CCNC");
IDescriptorResult dres1=qsar.calculate(mol, bcutID);
assertNotNull(dres1);
assertNull(dres1.getErrorMessage());
assertEquals(bcutID, dres1.getDescriptorId());
System.out.println("Mol: " + mol.getSMILES() +
" ; Desc: " + dres1.getDescriptorId() +": ");
for (int i=0; i<dres1.getValues().length;i++){
System.out.println(" " + dres1.getLabels()[i]
+ "=" + dres1.getValues()[i] );
}
assertEquals(6, dres1.getValues().length);
assertEquals(6, dres1.getLabels().length);
assertEquals("BCUTw-1l", dres1.getLabels()[0]);
assertEquals(11.993387, dres1.getValues()[0]);
assertEquals("BCUTw-1h", dres1.getLabels()[1]);
assertEquals(15.994919, dres1.getValues()[1]);
assertEquals("BCUTc-1l", dres1.getLabels()[2]);
assertEquals(0.89, dres1.getValues()[2]);
assertEquals("BCUTc-1h", dres1.getLabels()[3]);
assertEquals(1.1102645, dres1.getValues()[3]);
assertEquals("BCUTp-1l", dres1.getLabels()[4]);
assertEquals(4.6727624, dres1.getValues()[4]);
assertEquals("BCUTp-1h", dres1.getLabels()[5]);
assertEquals(9.596294, dres1.getValues()[5]);
}
@Test
public void testCalculateMultipleMolMultipleDescriptor() throws BioclipseException{
IMolecule mol1=new SMILESMolecule("C1CNCCC1CC(COC)CCNC");
IMolecule mol2=new SMILESMolecule("C1CCCCC1CC(CC)CCCCCOCCCN");
List<IMolecule> mols=new ArrayList<IMolecule>();
List<String> descs=new ArrayList<String>();
mols.add(mol1);
mols.add(mol2);
descs.add(bpolID);
descs.add(xlogpID);
Map<? extends IMolecule, List<IDescriptorResult>> res = qsar.calculateNoParams(mols, descs);
assertNotNull(res);
List<IDescriptorResult> res1=res.get(mol1);
List<IDescriptorResult> res2=res.get(mol2);
assertEquals(2, res1.size());
assertEquals(2, res2.size());
IDescriptorResult dres1=res1.get(0);
IDescriptorResult dres11=res1.get(1);
IDescriptorResult dres2=res2.get(0);
IDescriptorResult dres22=res2.get(1);
assertNull(dres1.getErrorMessage());
assertNull(dres11.getErrorMessage());
assertNull(dres2.getErrorMessage());
assertNull(dres22.getErrorMessage());
System.out.println("Mol: " + mol1.getSMILES() +
" ; Desc: " + dres1.getDescriptorId() +": ");
for (int i=0; i<dres1.getValues().length;i++){
System.out.println(" " + dres1.getLabels()[i]
+ "=" + dres1.getValues()[i] );
}
System.out.println("Mol: " + mol1.getSMILES() +
" ; Desc: " + dres11.getDescriptorId() +": ");
for (int i=0; i<dres11.getValues().length;i++){
System.out.println(" " + dres11.getLabels()[i]
+ "=" + dres11.getValues()[i] );
}
System.out.println("Mol: " + mol2.getSMILES() +
" ; Desc: " + dres2.getDescriptorId() +": ");
for (int i=0; i<dres2.getValues().length;i++){
System.out.println(" " + dres2.getLabels()[i]
+ "=" + dres2.getValues()[i] );
}
System.out.println("Mol: " + mol2.getSMILES() +
" ; Desc: " + dres22.getDescriptorId() +": ");
for (int i=0; i<dres22.getValues().length;i++){
System.out.println(" " + dres22.getLabels()[i]
+ "=" + dres22.getValues()[i] );
}
assertEquals("bpol", dres1.getLabels()[0]);
assertEquals(31.659382, dres1.getValues()[0]);
assertEquals("XLogP", dres11.getLabels()[0]);
assertEquals(0.184, dres11.getValues()[0]);
assertEquals("bpol", dres2.getLabels()[0]);
assertEquals(41.70466, dres2.getValues()[0]);
assertEquals("XLogP", dres22.getLabels()[0]);
assertEquals(6.749, dres22.getValues()[0]);
}
@Test
public void testCalculateAtomCountWithDefaultParams() throws BioclipseException{
//Calculate C and N from this SMILES mol
IMolecule mol=new SMILESMolecule("C1CNCCC1CC(COC)CCNC");
IDescriptorResult dres1=qsar.calculate(mol, atomCountlID);
assertNotNull(dres1);
assertNull(dres1.getErrorMessage());
assertEquals(atomCountlID, dres1.getDescriptorId());
assertEquals(1, dres1.getValues().length);
System.out.println("Mol with default param C: " + mol.getSMILES() +
" ; Desc: " + dres1.getDescriptorId() +": " + dres1.getValues()[0] );
}
@Test
public void testCalculateAtomCountWithStringParams() throws BioclipseException{
//Calculate C and N from this SMILES mol
IMolecule mol=new SMILESMolecule("C1CNCCC1CC(COC)CCNCCN");
DescriptorImpl impl=qsar.getDescriptorImpl(atomCountlID, cdkProviderID);
assertEquals(1, impl.getParameters().size());
//Work on a new instance
DescriptorParameter newParam=impl.getParameters().get(0).clone();
newParam.setValue("N");
DescriptorParameter newParam2=impl.getParameters().get(0).clone();
newParam2.setValue("C");
List<DescriptorParameter> params=new ArrayList<DescriptorParameter>();
params.add(newParam);
List<DescriptorParameter> params2=new ArrayList<DescriptorParameter>();
params2.add(newParam2);
Descriptor descriptor=qsar.getDescriptorByID(impl.getDefinition());
List<DescriptorType> descriptorInstances=new ArrayList<DescriptorType>();
DescriptorType descType1=qsar.createDescriptorType(null, null, descriptor, impl, params);
DescriptorType descType2=qsar.createDescriptorType(null, null, descriptor, impl, params2);
descriptorInstances.add(descType1);
descriptorInstances.add(descType2);
List<IDescriptorResult> resList = qsar.calculate(mol, descriptorInstances);
//We know only one result as we only asked for one descriptor
assertEquals(2, resList.size());
IDescriptorResult dres1=resList.get(0);
assertNotNull(dres1);
assertNull(dres1.getErrorMessage());
assertEquals(atomCountlID, dres1.getDescriptorId());
assertEquals(1, dres1.getValues().length);
System.out.println("Mol with param N: " + mol.getSMILES() +
" ; Desc: " + dres1.getDescriptorId() +": " + dres1.getValues()[0] );
IDescriptorResult dres2=resList.get(1);
assertNotNull(dres2);
assertNull(dres2.getErrorMessage());
assertEquals(atomCountlID, dres2.getDescriptorId());
assertEquals(1, dres2.getValues().length);
System.out.println("Mol with param C: " + mol.getSMILES() +
" ; Desc: " + dres2.getDescriptorId() +": " + dres2.getValues()[0] );
assertEquals(3, dres1.getValues()[0]);
assertEquals(13, dres2.getValues()[0]);
}
@Test
public void testCalculateAtomCountWithBooleanParams() throws BioclipseException{
//Calculate C and N from this SMILES mol
IMolecule mol=new SMILESMolecule("C1CNCCC1CC(COC)CCNCCN");
DescriptorImpl impl=qsar.getDescriptorImpl(rotBondsCntID, cdkProviderID);
assertEquals(1, impl.getParameters().size());
//Work on a new instance
DescriptorParameter newParam=impl.getParameters().get(0).clone();
newParam.setValue("true");
DescriptorParameter newParam2=impl.getParameters().get(0).clone();
newParam2.setValue("false");
List<DescriptorParameter> params=new ArrayList<DescriptorParameter>();
params.add(newParam);
List<DescriptorParameter> params2=new ArrayList<DescriptorParameter>();
params2.add(newParam2);
Descriptor descriptor=qsar.getDescriptorByID(impl.getDefinition());
List<DescriptorType> descriptorInstances=new ArrayList<DescriptorType>();
DescriptorType descType1=qsar.createDescriptorType(null, null, descriptor, impl, params);
DescriptorType descType2=qsar.createDescriptorType(null, null, descriptor, impl, params2);
descriptorInstances.add(descType1);
descriptorInstances.add(descType2);
List<IDescriptorResult> resList = qsar.calculate(mol, descriptorInstances);
//We know only one result as we only asked for one descriptor
assertEquals(2, resList.size());
IDescriptorResult dres1=resList.get(0);
assertNotNull(dres1);
assertNull(dres1.getErrorMessage());
assertEquals(rotBondsCntID, dres1.getDescriptorId());
assertEquals(1, dres1.getValues().length);
System.out.println("Mol with param TRUE: " + mol.getSMILES() +
" ; Desc: " + dres1.getDescriptorId() +": " + dres1.getValues()[0] );
IDescriptorResult dres2=resList.get(1);
assertNotNull(dres2);
assertNull(dres2.getErrorMessage());
assertEquals(rotBondsCntID, dres2.getDescriptorId());
assertEquals(1, dres2.getValues().length);
System.out.println("Mol with param FALSE: " + mol.getSMILES() +
" ; Desc: " + dres2.getDescriptorId() +": " + dres2.getValues()[0] );
assertEquals(40, dres1.getValues()[0]);
assertEquals(11, dres2.getValues()[0]);
}
}