diff --git a/gsrs-module-substance-example/src/main/java/example/GsrsModuleSubstanceApplication.java b/gsrs-module-substance-example/src/main/java/example/GsrsModuleSubstanceApplication.java index e1c65a2e5..75aae0d51 100644 --- a/gsrs-module-substance-example/src/main/java/example/GsrsModuleSubstanceApplication.java +++ b/gsrs-module-substance-example/src/main/java/example/GsrsModuleSubstanceApplication.java @@ -10,7 +10,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; //import org.springframework.cloud.netflix.eureka.EnableEurekaClient; diff --git a/gsrs-module-substance-example/src/test/java/example/chem/DefHashCalcTest.java b/gsrs-module-substance-example/src/test/java/example/chem/DefHashCalcTest.java index 3038db4c3..660c879eb 100644 --- a/gsrs-module-substance-example/src/test/java/example/chem/DefHashCalcTest.java +++ b/gsrs-module-substance-example/src/test/java/example/chem/DefHashCalcTest.java @@ -10,11 +10,9 @@ import ix.core.chem.StructureProcessor; import ix.core.models.Structure; import ix.ginas.modelBuilders.ChemicalSubstanceBuilder; -import ix.ginas.modelBuilders.SubstanceBuilder; -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; diff --git a/gsrs-module-substance-example/src/test/java/example/chem/InchiFunctionTest.java b/gsrs-module-substance-example/src/test/java/example/chem/InchiFunctionTest.java new file mode 100644 index 000000000..b49efe2ee --- /dev/null +++ b/gsrs-module-substance-example/src/test/java/example/chem/InchiFunctionTest.java @@ -0,0 +1,65 @@ +package example.chem; + +import ix.core.models.Structure; +import ix.core.util.pojopointer.extensions.InChIFullRegisteredFunction; +import ix.core.util.pojopointer.extensions.InChIRegisteredFunction; +import ix.ginas.models.v1.GinasChemicalStructure; +import org.apache.commons.io.IOUtils; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.io.IOException; +import java.util.Optional; +import java.util.function.BiFunction; +import java.util.stream.Stream; + +public class InchiFunctionTest { + + @ParameterizedTest + @MethodSource("inputData") + void testInchi(String molname, String description, Structure.Stereo stereo, boolean expectDelimiter) throws IOException { + String molfileText = IOUtils.toString( + this.getClass().getResourceAsStream("/molfiles/" + molname + ".mol"), + "UTF-8" + ); + GinasChemicalStructure structure = new GinasChemicalStructure(); + structure.molfile = molfileText; + structure.stereoChemistry = stereo; + InChIFullRegisteredFunction functionHolder = new InChIFullRegisteredFunction(); + BiFunction> fun = functionHolder.getOperation(); + Optional result =fun.apply(new InChIFullRegisteredFunction.InChIFullPath(), structure); + System.out.printf("InChIs for %s: %s\n", description, result.get()); + Assertions.assertEquals(expectDelimiter, result.get().contains(InChIFullRegisteredFunction.MULTIPLE_VALUE_DELIMITER)); + } + + @ParameterizedTest + @MethodSource("inputData") + void testInchiKey(String molname, String description, Structure.Stereo stereo, boolean expectDelimiter) throws IOException { + String molfileText = IOUtils.toString( + this.getClass().getResourceAsStream("/molfiles/" + molname + ".mol"), + "UTF-8" + ); + GinasChemicalStructure structure = new GinasChemicalStructure(); + structure.molfile = molfileText; + structure.stereoChemistry = stereo; + InChIRegisteredFunction functionHolder = new InChIRegisteredFunction(); + BiFunction> fun = functionHolder.getOperation(); + Optional result =fun.apply(new InChIRegisteredFunction.InChIPath(), structure); + System.out.printf("InChIKeys for %s: %s\n", description, result.get()); + Assertions.assertEquals(expectDelimiter, result.get().contains(InChIRegisteredFunction.MULTIPLE_VALUE_DELIMITER)); + } + + private static Stream inputData() { + return Stream.of( + Arguments.of("N9Y5G2T2T5", "N9Y5G2T2T5 with unknown stereo", Structure.Stereo.UNKNOWN, false), + Arguments.of("N9Y5G2T2T5", "N9Y5G2T2T5 with racemic stereo", Structure.Stereo.RACEMIC, true), + Arguments.of("N9Y5G2T2T5", "N9Y5G2T2T5 with epimeric stereo", Structure.Stereo.EPIMERIC, true), + Arguments.of("SV1ATP0KYY", "SV1ATP0KYY with unknown stereo", Structure.Stereo.UNKNOWN, false), + Arguments.of("SV1ATP0KYY", "SV1ATP0KYY with racemic stereo", Structure.Stereo.RACEMIC, true), + Arguments.of("SV1ATP0KYY", "SV1ATP0KYY with epimeric stereo", Structure.Stereo.EPIMERIC, true) + + ); + } +} diff --git a/gsrs-module-substance-example/src/test/java/example/substance/FlexAndExactSearchFullStackTest.java b/gsrs-module-substance-example/src/test/java/example/substance/FlexAndExactSearchFullStackTest.java index 9514e79b2..2cb6eacc3 100644 --- a/gsrs-module-substance-example/src/test/java/example/substance/FlexAndExactSearchFullStackTest.java +++ b/gsrs-module-substance-example/src/test/java/example/substance/FlexAndExactSearchFullStackTest.java @@ -1,8 +1,5 @@ package example.substance; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.Collection; @@ -15,6 +12,7 @@ import javax.servlet.http.HttpServletRequest; +import com.fasterxml.jackson.databind.node.ObjectNode; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; @@ -41,6 +39,9 @@ import ix.core.chem.StructureStandardizer; import ix.core.models.Structure; import ix.ginas.modelBuilders.SubstanceBuilder; + +import static org.junit.jupiter.api.Assertions.*; + @SpringBootTest(classes = GsrsModuleSubstanceApplication.class) @ActiveProfiles("test") @RecordApplicationEvents @@ -60,10 +61,6 @@ public class FlexAndExactSearchFullStackTest extends AbstractSubstanceJpaFullSt @TestConfiguration public static class Configuration{ -// @Value("${ix.core.structureIndex.atomLimit}") -// private int maxNumberOfAtoms = 240; -// @Value(value ="${ix.structure-standardizer}") -// private Class standardizerClass = InchiStandardizer.class; @Bean public StructureStandardizer getStructureStandardizer() throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { InchiStandardizer istd = new InchiStandardizer(); @@ -262,4 +259,38 @@ public void ensureAFlexSearchForADirectSmilesGetsStandardized() throws Exception } + @Test + public void ensureSmilesLeadsToReasonableMolfile() throws Exception { + + ObjectMapper om = new ObjectMapper(); + String smiles = "c1ccc(cc1)P(CCCC#N)(c2ccccc2)c3ccccc3"; + UUID uuid1 = UUID.randomUUID(); + new SubstanceBuilder() + .asChemical() + .setStructureWithDefaultReference(smiles) + .addName("triphenyl-Phosphene,(3-cyanopropyl)") + .setUUID(uuid1) + .buildJsonAnd(this::assertCreatedAPI); + + HttpServletRequest mockedRequest = Mockito.mock(HttpServletRequest.class); + Mockito.when(mockedRequest.getRequestURI()).thenReturn("http://mock"); + Mockito.when(mockedRequest.getRequestURL()).thenReturn(new StringBuffer("http://mock")); + + LoggingStructureStandardizer lstd=(LoggingStructureStandardizer)standardizer; + + lstd.reset(); + assertEquals(0,lstd.getStdCallCount()); + + ResponseEntity response= substanceController.interpretStructure(smiles, new HashMap<>()); + assertTrue(response.getBody() instanceof ObjectNode); + ObjectNode baseNode = (ObjectNode)response.getBody(); + ObjectNode structureNode = (ObjectNode) baseNode.get("structure"); + String molfile = structureNode.get("molfile").asText(); + assertNotNull(molfile); + Chemical chem = Chemical.parseMol(molfile); + assertTrue(chem.bonds().allMatch(b->b.isQueryBond())); + System.out.printf("molfile=%s\n", molfile); + } + + } diff --git a/gsrs-module-substance-example/src/test/java/example/substance/StructureMethodTest.java b/gsrs-module-substance-example/src/test/java/example/substance/StructureMethodTest.java new file mode 100644 index 000000000..28a005125 --- /dev/null +++ b/gsrs-module-substance-example/src/test/java/example/substance/StructureMethodTest.java @@ -0,0 +1,24 @@ +package example.substance; + +import ix.core.models.Structure; +import ix.ginas.models.v1.GinasChemicalStructure; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.nio.file.Files; +import java.util.List; + +public class StructureMethodTest { + + @Test + void testGetInchiSet() throws Exception { + File molfile =new File(getClass().getResource("/molfiles/SV1ATP0KYY.mol").getFile()); + Structure testStructure = new GinasChemicalStructure(); + testStructure.stereoChemistry = Structure.Stereo.EPIMERIC; + testStructure.molfile = Files.readString(molfile.toPath()); + List inchiKeys=testStructure.getInChIKeysAndThrow(); + Assertions.assertEquals(2, inchiKeys.size()); + inchiKeys.forEach(r-> System.out.printf("inchikey: %s\n", r)); + } +} diff --git a/gsrs-module-substance-example/src/test/resources/molfiles/N9Y5G2T2T5.mol b/gsrs-module-substance-example/src/test/resources/molfiles/N9Y5G2T2T5.mol new file mode 100644 index 000000000..5498b92c2 --- /dev/null +++ b/gsrs-module-substance-example/src/test/resources/molfiles/N9Y5G2T2T5.mol @@ -0,0 +1,65 @@ + + JSDraw201032415472D + + 29 31 0 0 0 0 0 V2000 + 20.2131 -5.2149 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 + 20.2131 -6.7749 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 21.5640 -7.5549 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 22.9151 -6.7749 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 24.2661 -7.5549 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 24.2661 -9.1149 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 + 25.6171 -6.7749 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 + 26.9681 -7.5549 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 26.9681 -9.1149 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 28.3201 -9.8949 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 28.3201 -11.4549 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 26.9681 -12.2349 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 25.6161 -11.4549 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 25.6161 -9.8949 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 28.5044 -7.8258 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 29.5073 -6.6298 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 31.0436 -6.9006 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 31.5769 -8.3675 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 30.5741 -9.5635 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 29.0378 -9.2927 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 27.5016 -6.0890 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 26.4979 -4.8936 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 27.0315 -3.4276 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 28.5687 -3.1571 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 29.5725 -4.3525 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 29.0388 -5.8184 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 18.8621 -7.5549 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 17.5111 -6.7749 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 + 18.8621 -9.1149 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 + 2 1 1 0 0 0 0 + 2 3 1 0 0 0 0 + 3 4 1 0 0 0 0 + 4 5 1 0 0 0 0 + 5 6 2 0 0 0 0 + 5 7 1 0 0 0 0 + 7 8 1 0 0 0 0 + 8 9 1 0 0 0 0 + 9 10 2 0 0 0 0 + 10 11 1 0 0 0 0 + 11 12 2 0 0 0 0 + 12 13 1 0 0 0 0 + 13 14 2 0 0 0 0 + 9 14 1 0 0 0 0 + 8 15 1 0 0 0 0 + 15 16 2 0 0 0 0 + 16 17 1 0 0 0 0 + 17 18 2 0 0 0 0 + 18 19 1 0 0 0 0 + 19 20 2 0 0 0 0 + 15 20 1 0 0 0 0 + 8 21 1 0 0 0 0 + 21 22 2 0 0 0 0 + 22 23 1 0 0 0 0 + 23 24 2 0 0 0 0 + 24 25 1 0 0 0 0 + 25 26 2 0 0 0 0 + 21 26 1 0 0 0 0 + 2 27 1 0 0 0 0 + 27 28 1 0 0 0 0 + 27 29 2 0 0 0 0 +M END \ No newline at end of file diff --git a/gsrs-module-substance-example/src/test/resources/molfiles/SV1ATP0KYY.mol b/gsrs-module-substance-example/src/test/resources/molfiles/SV1ATP0KYY.mol new file mode 100644 index 000000000..1a87037d8 --- /dev/null +++ b/gsrs-module-substance-example/src/test/resources/molfiles/SV1ATP0KYY.mol @@ -0,0 +1,29 @@ +.alpha.-D-Allopyranose + Marvin 01132101232D + + 12 12 0 0 1 0 999 V2000 + 16.3342 -4.8950 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 17.0487 -4.4824 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 + 15.6197 -4.4824 0.0000 C 0 0 2 0 0 0 0 0 0 0 0 0 + 14.9053 -4.8950 0.0000 C 0 0 1 0 0 0 0 0 0 0 0 0 + 14.9053 -5.7200 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 + 14.1907 -4.4824 0.0000 C 0 0 1 0 0 0 0 0 0 0 0 0 + 13.4763 -4.8950 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 + 14.1907 -3.6574 0.0000 C 0 0 2 0 0 0 0 0 0 0 0 0 + 14.9053 -3.2450 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 15.6197 -3.6574 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 + 14.9053 -2.4200 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 + 13.4763 -3.2450 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 + 1 2 1 0 0 0 0 + 3 1 1 6 0 0 0 + 3 4 1 0 0 0 0 + 4 5 1 1 0 0 0 + 4 6 1 0 0 0 0 + 6 7 1 1 0 0 0 + 6 8 1 0 0 0 0 + 9 8 1 0 0 0 0 + 10 9 1 0 0 0 0 + 3 10 1 0 0 0 0 + 9 11 1 0 0 0 0 + 8 12 1 1 0 0 0 +M END \ No newline at end of file diff --git a/gsrs-module-substances-core/src/main/java/gsrs/module/substance/controllers/GsrsSubstanceControllerUtil.java b/gsrs-module-substances-core/src/main/java/gsrs/module/substance/controllers/GsrsSubstanceControllerUtil.java index ccfca51a2..18a1dd989 100644 --- a/gsrs-module-substances-core/src/main/java/gsrs/module/substance/controllers/GsrsSubstanceControllerUtil.java +++ b/gsrs-module-substances-core/src/main/java/gsrs/module/substance/controllers/GsrsSubstanceControllerUtil.java @@ -1,6 +1,7 @@ package gsrs.module.substance.controllers; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; import gsrs.cache.GsrsCache; import ix.core.controllers.EntityFactory; diff --git a/gsrs-module-substances-core/src/main/java/gsrs/module/substance/exporters/DefaultSubstanceSpreadsheetExporterFactory.java b/gsrs-module-substances-core/src/main/java/gsrs/module/substance/exporters/DefaultSubstanceSpreadsheetExporterFactory.java index af0b4dfd0..e535e79c8 100644 --- a/gsrs-module-substances-core/src/main/java/gsrs/module/substance/exporters/DefaultSubstanceSpreadsheetExporterFactory.java +++ b/gsrs-module-substances-core/src/main/java/gsrs/module/substance/exporters/DefaultSubstanceSpreadsheetExporterFactory.java @@ -10,6 +10,8 @@ import ix.core.models.Group; import ix.core.models.Structure; import ix.core.util.EntityUtils.Key; +import ix.core.util.pojopointer.extensions.InChIFullRegisteredFunction; +import ix.core.util.pojopointer.extensions.InChIRegisteredFunction; import ix.ginas.exporters.*; import ix.ginas.exporters.Spreadsheet.SpreadsheetRow; import ix.ginas.models.v1.*; @@ -20,6 +22,7 @@ import java.io.IOException; import java.io.OutputStream; import java.util.*; +import java.util.function.BiFunction; import java.util.stream.Stream; /** @@ -208,9 +211,13 @@ public Map> createColumnRecipes(Parameters try { Chemical chem = s.toChemical(); - cell.writeString(Inchi.asStdInchi(Chem.RemoveQueryFeaturesForPseudoInChI(chem)) + InChIRegisteredFunction functionHolder = new InChIRegisteredFunction(); + BiFunction> fun = functionHolder.getOperation(); + Optional result =fun.apply(new InChIRegisteredFunction.InChIPath(), ((ChemicalSubstance) s).getStructure()); + cell.writeString(result.orElse("")); + /*cell.writeString(Inchi.asStdInchi(Chem.RemoveQueryFeaturesForPseudoInChI(chem)) .getKey() - .replace("InChIKey=", "")); + .replace("InChIKey=", ""));*/ } catch (Exception e) { } diff --git a/gsrs-module-substances-core/src/main/java/ix/core/models/Structure.java b/gsrs-module-substances-core/src/main/java/ix/core/models/Structure.java index 33e7510ff..fc01719fc 100644 --- a/gsrs-module-substances-core/src/main/java/ix/core/models/Structure.java +++ b/gsrs-module-substances-core/src/main/java/ix/core/models/Structure.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import gov.nih.ncats.common.util.TimeUtil; +import gov.nih.ncats.molwitch.Bond; import gov.nih.ncats.molwitch.Chemical; import gov.nih.ncats.molwitch.inchi.Inchi; import gov.nih.ncats.molwitch.io.CtTableCleaner; @@ -26,6 +27,7 @@ import javax.persistence.*; import java.io.IOException; import java.util.*; +import java.util.stream.Collectors; //@MappedSuperclass @Entity @@ -456,6 +458,27 @@ public String getInChIKey() { } } + + /*@JsonProperty("_inchiKeySet") + @Transient + public String getInChIKeySet() { + try{ + if(this.stereoChemistry.equals(Stereo.RACEMIC) && this.opticalActivity.equals(Optical.PLUS_MINUS)) { + this.toChemical().getExtendedTetrahedrals() + } + for (Value val : this.properties) { + if(val==null) continue; + if (Structure.H_InChI_Key.equals(val.label)) { + return Objects.toString(val.getValue()).replaceAll("_", "-"); + } + } + return getInChIKeyAndThrow(); + }catch(Exception e){ + e.printStackTrace(); + return null; + } + }*/ + @JsonIgnore @Transient public String getInChIKeyAndThrow() throws Exception{ @@ -463,6 +486,67 @@ public String getInChIKeyAndThrow() throws Exception{ } + @JsonProperty("_inchiKeySet") + @JsonIgnore + @Transient + public List getInChIKeysAndThrow() { + + log.trace("in getInChIKeysAndThrow(), stereoChemistry: {}", this.stereoChemistry); + try { + + if( this.stereoChemistry == null || !(this.stereoChemistry.toString().equalsIgnoreCase(Stereo.EPIMERIC.toString()) + || this.stereoChemistry.toString().equalsIgnoreCase(Stereo.RACEMIC.toString() ))) { + //handle non-epimers + return Collections.singletonList(getInChIKey()); + } + List epimers = toChemical().getImpl().permuteEpimersAndEnantiomers(); + return epimers.stream() + .map(c -> { + try { + return Inchi.asStdInchi(Chem.RemoveQueryFeaturesForPseudoInChI(c), true).getKey(); + } catch (IOException e) { + log.warn("Error calculating InChIKey", e); + return null; + } + }).filter(i -> i != null) + .collect(Collectors.toList()); + } + catch (Exception ex) { + ex.printStackTrace(); + return Collections.singletonList("[Error]"); + } + } + + @JsonProperty("_inchiSet") + @JsonIgnore + @Transient + public List getInChIsAndThrow() { + + log.trace("in getInChIsAndThrow(), stereoChemistry: {}", this.stereoChemistry); + try { + + if( this.stereoChemistry == null || !(this.stereoChemistry.toString().equalsIgnoreCase(Stereo.EPIMERIC.toString()) + || this.stereoChemistry.toString().equalsIgnoreCase(Stereo.RACEMIC.toString() ))) { + //handle non-epimers + return Collections.singletonList(getInChI()); + } + List epimers = toChemical().getImpl().permuteEpimersAndEnantiomers(); + return epimers.stream() + .map(c -> { + try { + return Inchi.asStdInchi(Chem.RemoveQueryFeaturesForPseudoInChI(c), true).getInchi(); + } catch (IOException e) { + log.warn("Error calculating InChI", e); + return null; + } + }).filter(i -> i != null) + .collect(Collectors.toList()); + } + catch (Exception ex) { + ex.printStackTrace(); + return Collections.singletonList("[Error]"); + } + } @JsonIgnore @Transient @@ -566,4 +650,9 @@ public String getStereoChemistry() { } return this.stereoChemistry.toString(); } + + private boolean hasAnyStereoBond() { + return !this.toChemical().bonds().allMatch(b->b.getStereo().equals(Bond.Stereo.NONE)); + } + } diff --git a/gsrs-module-substances-core/src/main/java/ix/core/util/pojopointer/extensions/InChIFullRegisteredFunction.java b/gsrs-module-substances-core/src/main/java/ix/core/util/pojopointer/extensions/InChIFullRegisteredFunction.java index 1d3602bbc..7fb3f7313 100644 --- a/gsrs-module-substances-core/src/main/java/ix/core/util/pojopointer/extensions/InChIFullRegisteredFunction.java +++ b/gsrs-module-substances-core/src/main/java/ix/core/util/pojopointer/extensions/InChIFullRegisteredFunction.java @@ -6,11 +6,13 @@ import ix.core.util.pojopointer.extensions.InChIFullRegisteredFunction.InChIFullPath; import lombok.extern.slf4j.Slf4j; +import java.util.List; import java.util.Optional; import java.util.function.BiFunction; @Slf4j public class InChIFullRegisteredFunction implements RegisteredFunction { public static String name = "$inchi"; + public final static String MULTIPLE_VALUE_DELIMITER = "|"; public static class InChIFullPath extends LambdaPath{ @Override @@ -33,6 +35,13 @@ public LambdaArgumentParser getFunctionURIParser() { public BiFunction> getOperation() { return (fp, s)->{ try{ + List firstGo = s.getInChIsAndThrow(); + log.trace("firstGo: {}", firstGo); + if(firstGo != null && firstGo.size() > 0){ + log.trace("firstGot produced data"); + return Optional.of(String.join(MULTIPLE_VALUE_DELIMITER, firstGo)); + } + log.trace("firstGot produced NO data"); return Optional.ofNullable(s.getInChIAndThrow()); }catch(Exception e){ log.error("error computing inchi of structure ID " + s.id, e); diff --git a/gsrs-module-substances-core/src/main/java/ix/core/util/pojopointer/extensions/InChIRegisteredFunction.java b/gsrs-module-substances-core/src/main/java/ix/core/util/pojopointer/extensions/InChIRegisteredFunction.java index b32d5e4d0..d3fe81bb9 100644 --- a/gsrs-module-substances-core/src/main/java/ix/core/util/pojopointer/extensions/InChIRegisteredFunction.java +++ b/gsrs-module-substances-core/src/main/java/ix/core/util/pojopointer/extensions/InChIRegisteredFunction.java @@ -6,12 +6,14 @@ import ix.core.util.pojopointer.extensions.InChIRegisteredFunction.InChIPath; import lombok.extern.slf4j.Slf4j; +import java.util.List; import java.util.Optional; import java.util.function.BiFunction; @Slf4j public class InChIRegisteredFunction implements RegisteredFunction { public static String name = "$inchikey"; - + public final static String MULTIPLE_VALUE_DELIMITER = ";"; + public static class InChIPath extends LambdaPath{ @Override protected String thisURIPath() { @@ -31,10 +33,18 @@ public LambdaArgumentParser getFunctionURIParser() { @Override public BiFunction> getOperation() { + log.trace("getOperation"); return (fp, s)->{ try{ - return Optional.ofNullable(s.getInChIKeyAndThrow()); + List firstGo = s.getInChIKeysAndThrow(); + log.trace("firstGo: {}", firstGo); + if(firstGo != null && firstGo.size() > 0){ + log.trace("firstGot produced data"); + return Optional.of(String.join(MULTIPLE_VALUE_DELIMITER, firstGo)); + } + log.trace("firstGot produced NO data"); + return Optional.ofNullable(s.getInChIKey()); }catch(Exception e){ log.error("error computing inchi key of structure ID " + s.id, e); throw new RuntimeException("error computing inchi key of structure ID " + s.id, e); diff --git a/gsrs-module-substances-tests/src/main/java/gsrs/substances/tests/AbstractSubstanceJpaEntityTestSuperClass.java b/gsrs-module-substances-tests/src/main/java/gsrs/substances/tests/AbstractSubstanceJpaEntityTestSuperClass.java index f8f535691..f4d45ca0c 100644 --- a/gsrs-module-substances-tests/src/main/java/gsrs/substances/tests/AbstractSubstanceJpaEntityTestSuperClass.java +++ b/gsrs-module-substances-tests/src/main/java/gsrs/substances/tests/AbstractSubstanceJpaEntityTestSuperClass.java @@ -17,6 +17,7 @@ import javax.persistence.EntityManager; +import gsrs.scheduler.GsrsSchedulerTaskPropertiesConfiguration; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.RegisterExtension; import org.quartz.Scheduler; @@ -151,6 +152,13 @@ protected GsrsExportConfiguration mockGsrsExportConfiguration(){ return mock(GsrsExportConfiguration.class); } + @Bean + @ConditionalOnMissingBean + @Primary + public GsrsSchedulerTaskPropertiesConfiguration getGsrsSchedulerTaskPropertiesConfiguration() { + return new GsrsSchedulerTaskPropertiesConfiguration(); + } + } static class Initializer implements ApplicationContextInitializer {