Skip to content
Snippets Groups Projects
Commit d9d0f09c authored by Piotr Gawron's avatar Piotr Gawron
Browse files

list of chemicals can be obtained by synonym name

parent 67c456b0
No related branches found
No related tags found
1 merge request!156Resolve "search by chemical names"
......@@ -741,4 +741,18 @@ public class ChemicalParser extends CachableInterface implements IExternalServic
return result;
}
public List<Chemical> getChemicalsBySynonym(MiriamData diseaseId, String synonym) throws ChemicalSearchException {
try {
Collection<MeSH> meshList;
meshList = meshParser.getMeshBySynonym(synonym);
List<MiriamData> chemicalIds = new ArrayList<>();
for (MeSH mesh : meshList) {
chemicalIds.add(new MiriamData(MiriamType.TOXICOGENOMIC_CHEMICAL, mesh.getMeSHId()));
}
return getChemicals(diseaseId, chemicalIds);
} catch (AnnotatorException e) {
throw new ChemicalSearchException(e);
}
}
}
......@@ -51,7 +51,7 @@ public class ChemicalParserTest extends AnnotationTestFunctions {
@Before
public void setUp() throws Exception {
chemicalParser.setCache(new GeneralCacheWithExclusion(cache, 10));
chemicalParser.setCache(new GeneralCacheWithExclusion(cache, 1));
}
@After
......@@ -177,16 +177,32 @@ public class ChemicalParserTest extends AnnotationTestFunctions {
@Test
public void testGetGlutathioneDisulfideData() throws Exception {
try {
MiriamData dopamineId = new MiriamData(MiriamType.TOXICOGENOMIC_CHEMICAL, "D019803");
MiriamData glutathioneDisulfideId = new MiriamData(MiriamType.TOXICOGENOMIC_CHEMICAL, "D019803");
List<MiriamData> idsList = new ArrayList<>();
idsList.add(dopamineId);
idsList.add(glutathioneDisulfideId);
List<Chemical> chemicals = chemicalParser.getChemicals(parkinsonDiseaseId, idsList);
assertEquals(1, chemicals.size());
Chemical dopamine = chemicals.get(0);
Chemical glutathioneDisulfide = chemicals.get(0);
assertTrue(dopamine.getSynonyms().size() > 0);
assertTrue(glutathioneDisulfide.getSynonyms().size() > 0);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetChemicalBySynonym() throws Exception {
try {
List<Chemical> chemicals = chemicalParser.getChemicalsBySynonym(parkinsonDiseaseId, "MPTP");
assertEquals(1, chemicals.size());
Chemical mptp = chemicals.get(0);
assertTrue(mptp.getSynonyms().contains("MPTP"));
} catch (Exception e) {
e.printStackTrace();
throw e;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment