Skip to content

Commit

Permalink
Merge pull request #398 from ncats/springBoot27x_temp
Browse files Browse the repository at this point in the history
Is this right? Merge master into springBoot27x_temp to fix merge conflict.
  • Loading branch information
alx652 authored Feb 22, 2025
2 parents ce8d6f1 + d0c2b36 commit f6229db
Show file tree
Hide file tree
Showing 13 changed files with 350 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<InChIFullRegisteredFunction.InChIFullPath, Structure, Optional<String>> fun = functionHolder.getOperation();
Optional<String> 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<InChIRegisteredFunction.InChIPath, Structure, Optional<String>> fun = functionHolder.getOperation();
Optional<String> 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<Arguments> 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)

);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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<? extends AbstractStructureStandardizer> standardizerClass = InchiStandardizer.class;
@Bean
public StructureStandardizer getStructureStandardizer() throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
InchiStandardizer istd = new InchiStandardizer();
Expand Down Expand Up @@ -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<Object> 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);
}


}
Original file line number Diff line number Diff line change
@@ -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<String> inchiKeys=testStructure.getInChIKeysAndThrow();
Assertions.assertEquals(2, inchiKeys.size());
inchiKeys.forEach(r-> System.out.printf("inchikey: %s\n", r));
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -208,9 +211,13 @@ public Map<Column, ColumnValueRecipe<Substance>> createColumnRecipes(Parameters

try {
Chemical chem = s.toChemical();
cell.writeString(Inchi.asStdInchi(Chem.RemoveQueryFeaturesForPseudoInChI(chem))
InChIRegisteredFunction functionHolder = new InChIRegisteredFunction();
BiFunction<InChIRegisteredFunction.InChIPath, Structure, Optional<String>> fun = functionHolder.getOperation();
Optional<String> 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) {

}
Expand Down
Loading

0 comments on commit f6229db

Please sign in to comment.