-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #357 from ncats/feature_test
Feature test
- Loading branch information
Showing
8 changed files
with
249 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
83 changes: 83 additions & 0 deletions
83
gsrs-module-substance-example/src/test/java/example/chem/FeatureGenerationTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package example.chem; | ||
|
||
import gov.fda.gsrs.ndsri.FeaturizeNitrosamine; | ||
import gov.nih.ncats.molwitch.Chemical; | ||
import gsrs.module.substance.utils.FeatureUtils; | ||
import ix.ginas.models.v1.GinasChemicalStructure; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.io.IOUtils; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
@Slf4j | ||
public class FeatureGenerationTest { | ||
|
||
@Test | ||
void testOneMol() throws Exception{ | ||
String molfileText = IOUtils.toString( | ||
this.getClass().getResourceAsStream("/molfiles/1~{H}-quinolin-4-one.mol"), | ||
"UTF-8" | ||
); | ||
GinasChemicalStructure structure = new GinasChemicalStructure(); | ||
structure.molfile = molfileText; | ||
List<Map<String, String>> properties = FeatureUtils.calculateFeatures( structure.toChemical()); | ||
//properties.get(0).entrySet().forEach(e-> System.out.printf("key: %s = value: %s\n", e.getKey(), e.getValue())); | ||
Assertions.assertEquals("5", properties.get(0).get("categoryScore")); | ||
} | ||
|
||
@Test | ||
void testIVACAFTORType() throws Exception { | ||
Chemical c1= Chemical.parse("c1ccc2c(c1)c(=O)cc[nH]2"); | ||
|
||
List<Map<String, String>> properties = FeatureUtils.calculateFeatures( c1); | ||
assertEquals(1, properties.size()); | ||
assertEquals("A. Secondary Amine" ,properties.get(0).get("type")); | ||
assertEquals("0,1", properties.get(0).get("Alpha-Hydrogens")); | ||
} | ||
|
||
@Test | ||
void testFostamatibib() throws Exception { | ||
Chemical c1= Chemical.parse("O.O.O.O.O.O.[Na+].[Na+].COC1=CC([NH:1]C2=NC=C(F)C(NC3=NC4=C(OC(C)(C)C(=O)N4COP([O-])([O-])=O)C=C3)=N2)=CC(OC)=C1OC"); | ||
|
||
List<Map<String, String>> properties = FeatureUtils.calculateFeatures( c1); | ||
|
||
assertEquals(2,properties.size()); | ||
assertEquals("A. Multiple Secondary Amine", properties.get(0).get("type")); | ||
assertEquals("0,0", properties.get(0).get("Alpha-Hydrogens")); | ||
} | ||
|
||
@Test | ||
public void testIsPiperazine() throws Exception { | ||
FeaturizeNitrosamine.GLOBAL_SETTINGS.DO_EXTENDED_FEATURES_TOO=true; | ||
|
||
Chemical c1= Chemical.parse("N1CCNCC1"); | ||
List<Map<String, String>> properties = FeatureUtils.calculateFeatures( c1); | ||
|
||
assertEquals(2,properties.size()); | ||
assertEquals("A. Multiple Secondary Amine", properties.get(0).get("type")); | ||
assertEquals("2,2", properties.get(0).get("Alpha-Hydrogens")); | ||
assertEquals("YES", properties.get(0).get( FeaturizeNitrosamine.FeaturePairRegistry.PIPERAZINE.getFeatureName())); | ||
} | ||
|
||
@Test | ||
public void testCarboxylicAcidOnSaltDoesNotCount() throws Exception { | ||
Chemical c1= Chemical.parse("O[C@H]([C@@H](O)C(O)=O)C(O)=O.COC1=CC=C(C[C@@H](C)[NH:20]C[C@H](O)C2=CC=C(O)C(NC=O)=C2)C=C1"); | ||
List<Map<String, String>> properties = FeatureUtils.calculateFeatures( c1); | ||
assertEquals(1, properties.size()); | ||
assertEquals("A. Secondary Amine", properties.get(0).get("type")); | ||
assertEquals("NO" ,properties.get(0).get(FeaturizeNitrosamine.FeaturePairRegistry.COOH.getFeatureName())); | ||
} | ||
|
||
@Test | ||
public void testBenzylLikeFeatureShouldNotFindPsuedoAromaticity() throws Exception { | ||
Chemical c1= Chemical.parse("C[C@H]([NH:3]C1=C2N=CNC2=NC=N1)C3=CC4=C(C(Cl)=CC=C4)C(=O)N3C5=CC=CC=C5"); | ||
List<Map<String, String>> properties = FeatureUtils.calculateFeatures( c1); | ||
assertEquals(1, properties.size()); | ||
assertEquals("A. Secondary Amine", properties.get(0).get("type")); | ||
assertEquals("NO", properties.get(0).get(FeaturizeNitrosamine.FeaturePairRegistry.ARYL_ALPHA.getFeatureName())); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
gsrs-module-substance-example/src/test/resources/molfiles/1~{H}-quinolin-4-one.mol
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
|
||
|
||
11 12 0 0 0 0 0 0 0 0999 V2000 | ||
6.9665 -11.7372 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
6.9665 -12.9183 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
5.9436 -13.5088 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
4.9207 -12.9183 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
4.9207 -11.7372 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
5.9436 -11.1466 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
5.9436 -9.9655 0.0000 N 0 0 3 0 0 0 0 0 0 0 0 0 | ||
6.9665 -9.3750 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
7.9893 -9.9655 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
7.9893 -11.1466 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
9.0122 -11.7372 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 | ||
1 6 1 0 0 0 0 | ||
1 10 1 0 0 0 0 | ||
2 1 2 0 0 0 0 | ||
3 2 1 0 0 0 0 | ||
4 3 2 0 0 0 0 | ||
5 4 1 0 0 0 0 | ||
6 5 2 0 0 0 0 | ||
7 6 1 0 0 0 0 | ||
8 7 1 0 0 0 0 | ||
9 8 2 0 0 0 0 | ||
10 9 1 0 0 0 0 | ||
11 10 2 0 0 0 0 | ||
M END |
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
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
38 changes: 38 additions & 0 deletions
38
gsrs-module-substances-core/src/main/java/gsrs/module/substance/utils/FeatureUtils.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package gsrs.module.substance.utils; | ||
|
||
import gov.nih.ncats.molwitch.Chemical; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import gov.fda.gsrs.ndsri.FeaturizeNitrosamine; | ||
import gov.fda.gsrs.ndsri.FeaturizeNitrosamine.FeatureJob; | ||
import gov.fda.gsrs.ndsri.FeaturizeNitrosamine.FeatureResponse; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class FeatureUtils { | ||
public static List<Map<String, String>> calculateFeatures(Chemical chemical) throws Exception{ | ||
FeatureJob fj; | ||
try{ | ||
fj = FeatureJob.forOneNitrosamine(chemical); | ||
} catch (Exception ex) { | ||
log.info("forOneNitrosamine failed; using regular constructor"); | ||
fj = new FeatureJob(chemical); | ||
} | ||
|
||
List<FeatureResponse> resp = FeaturizeNitrosamine.fingerprintNitrosamine(fj); | ||
|
||
List<Map<String,String>> maps = new ArrayList<>(); | ||
resp.forEach(r->{ | ||
Map<String, String> ret = new HashMap<>(); | ||
r.getFeatureSet().entrySet().forEach(e-> ret.put(e.getKey(), e.getValue())); | ||
ret.put("categoryScore", Integer.toString( r.getCategoryScore())); | ||
ret.put("sumOfScores", Integer.toString(r.getSumOfScores())); | ||
ret.put("type", r.getType()); | ||
maps.add(ret); | ||
}); | ||
return maps; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
mvnw.cmd install:install-file -Dfile=extraJars/applications-api-3.1-SNAPSHOT.jar | ||
mvnw.cmd install:install-file -Dfile=extraJars/products-api-3.1.1-SNAPSHOT.jar | ||
mvnw.cmd install:install-file -Dfile=extraJars/clinical-trials-api-3.1.1-SNAPSHOT.jar | ||
|
||
mvnw.cmd install:install-file -Dfile=extraJars/Featureize-Nitrosamines-0.0.2-SNAPSHOT.jar |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
./mvnw install:install-file -Dfile=extraJars/applications-api-3.1-SNAPSHOT.jar | ||
./mvnw install:install-file -Dfile=extraJars/products-api-3.1.1-SNAPSHOT.jar | ||
./mvnw install:install-file -Dfile=extraJars/clinical-trials-api-3.1.1-SNAPSHOT.jar | ||
./mvnw install:install-file -Dfile=extraJars/Featureize-Nitrosamines-0.0.2-SNAPSHOT.jar |