Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added defining properties to def hash for mixtures. #370

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,29 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import gsrs.module.substance.definitional.ChemicalSubstanceDefinitionalElementImpl;
import gsrs.module.substance.definitional.DefinitionalElement;
import gsrs.module.substance.definitional.MixtureDefinitionalElementImpl;
import gsrs.module.substance.definitional.StructurallyDiverseDefinitionalElementImpl;
import gsrs.springUtils.AutowireHelper;
import gsrs.substances.tests.AbstractSubstanceJpaEntityTest;
import ix.core.chem.StructureProcessor;
import ix.core.models.Structure;
import ix.ginas.modelBuilders.ChemicalSubstanceBuilder;
import ix.ginas.models.v1.ChemicalSubstance;
import ix.ginas.models.v1.GinasChemicalStructure;
import ix.ginas.modelBuilders.MixtureSubstanceBuilder;
import ix.ginas.modelBuilders.StructurallyDiverseSubstanceBuilder;
import ix.ginas.modelBuilders.SubstanceBuilder;
import ix.ginas.models.v1.*;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Slf4j
public class DefHashCalcTest extends AbstractSubstanceJpaEntityTest {

@Autowired
Expand Down Expand Up @@ -85,4 +96,123 @@ public void testOpticalInDefinitionalHashCalcPos() throws Exception {
definitionalElements.forEach(de-> System.out.printf("key: %s = %s\n", de.getKey(), de.getValue()));
Assertions.assertTrue(definitionalElements.stream().anyMatch(de->de.getKey().equals(opticalActivityKey)));
}

@Test
public void testPropertiesInDefinitionalHashMixtures() throws Exception {
String propertyElementName = "properties.HYDROPHILLIC-LIPOPHILLIC BALANCE (HLB).value";
File mixtureFile = new ClassPathResource("testJSON/SURFHOPe C-1811_mixture.json").getFile();
MixtureSubstanceBuilder builder = SubstanceBuilder.from(mixtureFile);
MixtureSubstance mixtureSubstance = builder.build();
MixtureDefinitionalElementImpl definitionalElement = new MixtureDefinitionalElementImpl();
AutowireHelper.getInstance().autowireAndProxy(definitionalElement);

List<DefinitionalElement> definitionalElements = new ArrayList<>();
definitionalElement.computeDefinitionalElements(mixtureSubstance, definitionalElements::add);
definitionalElements.forEach(de-> log.trace("key: {} = {}", de.getKey(), de.getValue()));
Assertions.assertTrue(definitionalElements.stream().anyMatch(de->de.getKey().equals(propertyElementName)));
}

@Test
public void testPropertiesInDefinitionalHashStrDiv() throws Exception {
String propertyElementNameDefining = "properties.DEGREE OF REACTION.value";
String propertyElementNameNotDefining = "properties.ABSORBING POWER.value";
File strDivSubFile = new ClassPathResource("testJSON/28927b6a-6b0d-4733-a1a4-b2b38a569daa_props.json").getFile();
StructurallyDiverseSubstanceBuilder builder = SubstanceBuilder.from(strDivSubFile);
StructurallyDiverseSubstance structurallyDiverseSubstance = builder.build();
StructurallyDiverseDefinitionalElementImpl definitionalElement = new StructurallyDiverseDefinitionalElementImpl();
AutowireHelper.getInstance().autowireAndProxy(definitionalElement);

List<DefinitionalElement> definitionalElements = new ArrayList<>();
definitionalElement.computeDefinitionalElements(structurallyDiverseSubstance, definitionalElements::add);
definitionalElements.forEach(de-> log.trace("key: {} = {}", de.getKey(), de.getValue()));
Assertions.assertEquals(1, definitionalElements.stream().filter(de->de.getKey().equals(propertyElementNameDefining)).count());
Assertions.assertEquals(0, definitionalElements.stream().filter(de->de.getKey().equals(propertyElementNameNotDefining)).count());
}

@Test
public void testTwoChemicalsNoDefPropertiesEqual() throws Exception {
String opticalActivityKey="structure.properties.opticalActivity";
String structureJson = "{\n" +
" \"opticalActivity\": \"UNSPECIFIED\",\n" +
" \"molfile\": \"\\n ACCLDraw07282209012D\\n\\n 5 4 0 0 0 0 0 0 0 0999 V2000\\n 10.5000 -8.5938 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\\n 11.5229 -8.0032 0.0000 C 0 0 3 0 0 0 0 0 0 0 0 0\\n 11.5229 -6.8217 0.0000 Cl 0 0 0 0 0 0 0 0 0 0 0 0\\n 12.5460 -8.5939 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\\n 13.5692 -8.0032 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\\n 1 2 1 0 0 0 0\\n 2 3 1 0 0 0 0\\n 2 4 1 0 0 0 0\\n 4 5 1 0 0 0 0\\nM END\",\n" +
" \"stereoCenters\": 1,\n" +
" \"definedStereo\": 0,\n" +
" \"ezCenters\": 0,\n" +
" \"charge\": 0,\n" +
" \"mwt\": 92.56726,\n" +
" \"count\": 1,\n" +
" \"stereochemistry\": \"RACEMIC\"\n" +
"}\n" +
"";
ObjectMapper om = new ObjectMapper();
Structure rawStructure = om.readValue(structureJson, Structure.class);
Structure instrumentedStructure =structureProcessor.instrument(rawStructure.toChemical(), true);
GinasChemicalStructure ginasChemicalStructure = new GinasChemicalStructure(instrumentedStructure);

ChemicalSubstanceBuilder builder = new ChemicalSubstanceBuilder();
ChemicalSubstance chem =builder
.setStructure(ginasChemicalStructure)
.addName("2-chlorobutane")
.build();
ChemicalSubstanceDefinitionalElementImpl defHashCalculator = new ChemicalSubstanceDefinitionalElementImpl();
List<DefinitionalElement> definitionalElements = new ArrayList<>();
defHashCalculator.computeDefinitionalElements(chem, definitionalElements::add);

ChemicalSubstance chem2 = builder
.setStructure(ginasChemicalStructure)
.addName("2-chlorobutane")
.build();
List<DefinitionalElement> definitionalElements2 = new ArrayList<>();
defHashCalculator.computeDefinitionalElements(chem2, definitionalElements2::add);
Assertions.assertArrayEquals(definitionalElements.toArray(), definitionalElements2.toArray());
}

@Test
public void testTwoChemicalsDefPropertiesNotEqual() throws Exception {
String opticalActivityKey="structure.properties.opticalActivity";
String structureJson = "{\n" +
" \"opticalActivity\": \"UNSPECIFIED\",\n" +
" \"molfile\": \"\\n ACCLDraw07282209012D\\n\\n 5 4 0 0 0 0 0 0 0 0999 V2000\\n 10.5000 -8.5938 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\\n 11.5229 -8.0032 0.0000 C 0 0 3 0 0 0 0 0 0 0 0 0\\n 11.5229 -6.8217 0.0000 Cl 0 0 0 0 0 0 0 0 0 0 0 0\\n 12.5460 -8.5939 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\\n 13.5692 -8.0032 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\\n 1 2 1 0 0 0 0\\n 2 3 1 0 0 0 0\\n 2 4 1 0 0 0 0\\n 4 5 1 0 0 0 0\\nM END\",\n" +
" \"stereoCenters\": 1,\n" +
" \"definedStereo\": 0,\n" +
" \"ezCenters\": 0,\n" +
" \"charge\": 0,\n" +
" \"mwt\": 92.56726,\n" +
" \"count\": 1,\n" +
" \"stereochemistry\": \"RACEMIC\"\n" +
"}\n" +
"";
ObjectMapper om = new ObjectMapper();
Structure rawStructure = om.readValue(structureJson, Structure.class);
Structure instrumentedStructure =structureProcessor.instrument(rawStructure.toChemical(), true);
GinasChemicalStructure ginasChemicalStructure = new GinasChemicalStructure(instrumentedStructure);

ChemicalSubstanceBuilder builder = new ChemicalSubstanceBuilder();
ChemicalSubstance chem =builder
.setStructure(ginasChemicalStructure)
.addName("2-chlorobutane")
.build();
ChemicalSubstanceDefinitionalElementImpl defHashCalculator = new ChemicalSubstanceDefinitionalElementImpl();
List<DefinitionalElement> definitionalElements = new ArrayList<>();
defHashCalculator.computeDefinitionalElements(chem, definitionalElements::add);

ChemicalSubstance chem2 = builder
.setStructure(ginasChemicalStructure)
.addName("2-chlorobutane")
.build();
Property definingBoilingPoint = new Property();
definingBoilingPoint.setName("Boiling Point");
definingBoilingPoint.setType("Physical");
Amount bpAmout = new Amount();
bpAmout.average = 70d;
bpAmout.units = "degrees C";

definingBoilingPoint.setValue(bpAmout);
definingBoilingPoint.setDefining(true);
chem2.properties.add(definingBoilingPoint);

List<DefinitionalElement> definitionalElements2 = new ArrayList<>();
defHashCalculator.computeDefinitionalElements(chem2, definitionalElements::add);
Assertions.assertFalse(Arrays.equals(definitionalElements.toArray(), definitionalElements2.toArray()));
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
{
"deprecated": false,
"definitionType": "PRIMARY",
"definitionLevel": "COMPLETE",
"substanceClass": "mixture",
"status": "pending",
"names": [
{
"references": [
"9a03fb0b-f473-0e4c-47e4-5f5f91748eb1"
],
"access": [],
"languages": [
"en"
],
"type": "cn",
"name": "Sucrose stearate (HLB 11)",
"displayName": true,
"nameOrgs": [
{
"nameOrg": "BAN"
}
]
},
{
"references": [
"6bc5629f-4183-6271-4c9f-7dc9b38165f9"
],
"access": [],
"languages": [
"en"
],
"type": "cn",
"name": "SURFHOPe C-1811",
"displayName": false
},
{
"references": [
"9a03fb0b-f473-0e4c-47e4-5f5f91748eb1"
],
"access": [],
"languages": [
"en"
],
"type": "cn",
"name": "Sucrose sequipalmitostearate (HLB 11)"
},
{
"references": [
"6bc5629f-4183-6271-4c9f-7dc9b38165f9"
],
"access": [],
"languages": [
"en"
],
"type": "cn",
"name": "Surfhope SE Cosme C-1811",
"displayName": false
}
],
"codes": [
{
"references": [
"755dd19f-ee8b-8153-6554-6846415a133a"
],
"access": [],
"code": "25168-73-4",
"type": "GENERIC (FAMILY)",
"codeSystem": "CAS"
}
],
"notes": [],
"properties": [
{
"value": {
"average": "11",
"type": "EXACT"
},
"references": [
"6bc5629f-4183-6271-4c9f-7dc9b38165f9"
],
"access": [],
"name": "HYDROPHILLIC-LIPOPHILLIC BALANCE (HLB)",
"propertyType": "PHYSICAL",
"defining": true
}
],
"relationships": [],
"references": [
{
"tags": [],
"access": [],
"docType": "STN (SCIFINDER)",
"citation": "STN",
"publicDomain": true,
"uuid": "755dd19f-ee8b-8153-6554-6846415a133a"
},
{
"tags": [],
"access": [],
"docType": "MANUFACTURER PRODUCT DESCRIPTION",
"url": "https://www.pharmacompass.com/pAssets/pdf/edqm/application/JRS-Pharma-LLP-edqm-application-1457952389.pdf",
"citation": "https://www.pharmacompass.com/pAssets/pdf/edqm/application/JRS-Pharma-LLP-edqm-application-1457952389.pdf",
"publicDomain": true,
"uuid": "6bc5629f-4183-6271-4c9f-7dc9b38165f9"
},
{
"deprecated": false,
"uuid": "9a03fb0b-f473-0e4c-47e4-5f5f91748eb1",
"citation": "SRS",
"docType": "SRS",
"publicDomain": true,
"tags": [
"PUBLIC_DOMAIN_RELEASE"
],
"access": []
}
],
"tags": [],
"mixture": {
"deprecated": false,
"uuid": "ff244317-9e59-3b8f-548e-3f4b9fe94161",
"components": [
{
"deprecated": false,
"uuid": "915c7458-30d1-f6e1-acbb-0dffdc1a44ad",
"type": "MUST_BE_PRESENT",
"substance": {
"deprecated": false,
"uuid": "a56a9250-17ed-61fc-5c18-e0c34e556398",
"refPname": "SUCROSE, 6-STEARATE",
"refuuid": "6eefb92b-e55d-4e27-8730-5880a236ca4f",
"substanceClass": "reference",
"approvalID": "114S1GA41U",
"linkingID": "114S1GA41U",
"name": "SUCROSE, 6-STEARATE",
"references": [],
"access": []
},
"references": [],
"access": []
},
{
"deprecated": false,
"uuid": "7c40417f-e68a-b952-dd39-3e9a3e383cc0",
"type": "MUST_BE_PRESENT",
"substance": {
"deprecated": false,
"uuid": "1b087160-2ab6-887f-2b8a-20a46089c6cb",
"refPname": "SUCROSE, 6'-STEARATE",
"refuuid": "efded1a3-de59-4642-b74b-79fc2a65005f",
"substanceClass": "reference",
"approvalID": "J7MT237SNW",
"linkingID": "J7MT237SNW",
"name": "SUCROSE, 6'-STEARATE",
"references": [],
"access": []
},
"references": [],
"access": []
},
{
"deprecated": false,
"uuid": "da434958-79f6-c2bf-81b4-1a050289c324",
"type": "MUST_BE_PRESENT",
"substance": {
"deprecated": false,
"uuid": "0a558e0c-3b5f-2e3e-c3e0-ce76b0139294",
"refPname": "SUCROSE, 1-STEARATE",
"refuuid": "a8db9c64-9fca-4cec-80d4-5daa7111ff03",
"substanceClass": "reference",
"approvalID": "58RP7JU52K",
"linkingID": "58RP7JU52K",
"name": "SUCROSE, 1-STEARATE",
"references": [],
"access": []
},
"references": [],
"access": []
}
],
"references": [
"9a03fb0b-f473-0e4c-47e4-5f5f91748eb1"
],
"access": []
},
"_approvalIDDisplay": "274KW0O50M",
"access": [],
"_self": "https://gsrs.preprod.fda.gov/api/v1/substances(91c883d0-b404-4252-8c50-6896e7df0bfb)?view=full",
"modifications": {
"agentModifications": [],
"structuralModifications": [],
"physicalModifications": []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public boolean supports(Object s) {

@Override
public void computeDefinitionalElements(Object s, Consumer<DefinitionalElement> consumer) {
DefinitionalElementImplementation.super.computeDefinitionalElements(s, consumer);
ChemicalSubstance chemicalSubstance = (ChemicalSubstance) s;
Structure structure = chemicalSubstance.getStructure();
if(structure==null){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public boolean supports(Object s) {

@Override
public void computeDefinitionalElements(Object s, Consumer<DefinitionalElement> consumer) {
log.trace("performAddition of mixture substance");
log.trace("computeDefinitionalElements of mixture substance");
DefinitionalElementImplementation.super.computeDefinitionalElements(s, consumer);
MixtureSubstance mixtureSubstance = (MixtureSubstance)s;
Mixture mix = mixtureSubstance.mixture;
if (mix != null && !mix.components.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public boolean supports(Object s) {

@Override
public void computeDefinitionalElements(Object s, Consumer<DefinitionalElement> consumer) {
DefinitionalElementImplementation.super.computeDefinitionalElements(s, consumer);
String primaryName = "";
for(Name name : ((Substance)s).getAllNames()) {
if( name.displayName ){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public boolean supports(Object s) {

@Override
public void computeDefinitionalElements(Object substance, Consumer<DefinitionalElement> consumer) {
DefinitionalElementImplementation.super.computeDefinitionalElements(substance, consumer);
NucleicAcidSubstance nucleicAcidSubstance = (NucleicAcidSubstance) substance;
if(nucleicAcidSubstance.nucleicAcid ==null || nucleicAcidSubstance.nucleicAcid.subunits ==null){
return;
Expand Down Expand Up @@ -75,10 +76,8 @@ public void computeDefinitionalElements(Object substance, Consumer<DefinitionalE
}
}


if( nucleicAcidSubstance.modifications != null ){
definitionalElementFactory.addDefinitionalElementsFor(nucleicAcidSubstance.modifications, consumer);
}

}
}
Loading