Commit 8ab50bcc authored by Piotr Gawron's avatar Piotr Gawron
Browse files

additional tests for recon annotator

parent 8bc9b785
......@@ -17,11 +17,10 @@ import lcsb.mapviewer.annotation.services.ExternalServiceStatusType;
import lcsb.mapviewer.annotation.services.IExternalService;
import lcsb.mapviewer.common.EventStorageLoggerAppender;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerChemical;
import lcsb.mapviewer.model.map.AnnotatedObject;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Chemical;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.SimpleMolecule;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.modelutils.map.ElementUtils;
......@@ -129,7 +128,7 @@ public class ReconAnnotator extends ElementAnnotator implements IExternalService
} else if (annotatedObject instanceof Reaction) {
url = REACTION_ANNOTATION_URL_PREFIX + id;
} else {
logger.warn(elementUtils.getElementTag(annotatedObject) + " Unknown class type: " + annotatedObject.getClass());
logger.warn("Unknown class type: " + annotatedObject.getClass());
return;
}
try {
......@@ -181,14 +180,8 @@ public class ReconAnnotator extends ElementAnnotator implements IExternalService
continue;
} else if (key.equals("lastModified")) {
continue;
} else if (key.equals("modifiedBy")) {
continue;
} else if (key.equals("addedBy")) {
continue;
} else if (key.equals("met_id")) {
continue;
} else if (key.equals("neutralFormula")) {
continue;
} else if (key.equals("csecoida")) {
continue;
} else if (key.equals("chargedFormula")) {
......@@ -205,16 +198,14 @@ public class ReconAnnotator extends ElementAnnotator implements IExternalService
} else {
unknown = true;
}
} else if (key.equals("smile")) {
if (annotatedObject instanceof CellDesignerChemical) {
setSmile((Chemical) annotatedObject, value, prefix);
} else {
unknown = true;
}
} else if (key.equals("cheBlId")) {
addChebiMiriam(annotatedObject, value);
} else if (key.equals("subsystem")) {
setSubsystem((Reaction) annotatedObject, value, prefix);
if (annotatedObject instanceof Reaction) {
setSubsystem((Reaction) annotatedObject, value, prefix);
} else {
unknown = true;
}
} else if (key.equals("keggId")) {
addKeggMiriam(annotatedObject, value, prefix);
} else if (key.equals("keggorthology")) {
......
......@@ -148,6 +148,20 @@ public class ElementAnnotatorTest extends AnnotationTestFunctions {
assertEquals(1, getWarnings().size());
}
@Test
public void testSetTheSameMcs() throws Exception {
try {
Reaction reaction = new Reaction();
reaction.setMechanicalConfidenceScore(4);
annotator.setMcs(reaction, "4", null);
assertEquals(0, getWarnings().size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAddKegg() {
Reaction species = new Reaction();
......
......@@ -5,7 +5,9 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;
import java.io.IOException;
......@@ -18,10 +20,14 @@ import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import lcsb.mapviewer.annotation.AnnotationTestFunctions;
import lcsb.mapviewer.annotation.cache.GeneralCacheInterface;
import lcsb.mapviewer.annotation.cache.SourceNotAvailable;
import lcsb.mapviewer.annotation.cache.WebPageDownloader;
import lcsb.mapviewer.annotation.services.ExternalServiceStatusType;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.map.AnnotatedObject;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Ion;
import lcsb.mapviewer.model.map.species.SimpleMolecule;
import lcsb.mapviewer.model.map.species.Species;
......@@ -52,6 +58,150 @@ public class ReconAnnotatorTest extends AnnotationTestFunctions {
}
}
@Test
public void testAnnotating_O16G2e_Reaction() throws Exception {
try {
Reaction reaction = new Reaction();
reaction.setName("O16G2e");
reconAnnotator.annotateElement(reaction);
assertEquals(0, getWarnings().size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testSpeciesAnnotationWithInvalidResponse() throws Exception {
WebPageDownloader downloader = reconAnnotator.getWebPageDownloader();
GeneralCacheInterface originalCache = reconAnnotator.getCache();
try {
Ion ion = new Ion("id");
ion.setName("O16G2e");
// exclude first cached value
reconAnnotator.setCache(null);
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenReturn("");
reconAnnotator.setWebPageDownloader(mockDownloader);
reconAnnotator.annotateElement(ion);
assertEquals(1, getWarnings().size());
assertTrue(getWarnings().get(0).getMessage().toString().contains("No recon annotations"));
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
reconAnnotator.setWebPageDownloader(downloader);
reconAnnotator.setCache(originalCache);
}
}
@Test
public void testSpeciesAnnotationWithReactionResponse() throws Exception {
WebPageDownloader downloader = reconAnnotator.getWebPageDownloader();
GeneralCacheInterface originalCache = reconAnnotator.getCache();
try {
Ion ion = new Ion("id");
ion.setName("O16G2e");
// exclude first cached value
reconAnnotator.setCache(null);
String response = super.readFile("testFiles/annotation/recon_reaction_response.json");
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenReturn(response);
reconAnnotator.setWebPageDownloader(mockDownloader);
reconAnnotator.annotateElement(ion);
assertEquals(2, getWarnings().size());
assertTrue(getWarnings().get(0).getMessage().toString().contains("Unknown field"));
assertTrue(getWarnings().get(1).getMessage().toString().contains("Unknown field"));
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
reconAnnotator.setWebPageDownloader(downloader);
reconAnnotator.setCache(originalCache);
}
}
@Test
public void testReactionAnnotationWithChemicalResponse() throws Exception {
WebPageDownloader downloader = reconAnnotator.getWebPageDownloader();
GeneralCacheInterface originalCache = reconAnnotator.getCache();
try {
Reaction reaction = new Reaction();
reaction.setName("nad[m]");
// exclude first cached value
reconAnnotator.setCache(null);
String response = super.readFile("testFiles/annotation/recon_chemical_response.json");
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenReturn(response);
reconAnnotator.setWebPageDownloader(mockDownloader);
reconAnnotator.annotateElement(reaction);
assertEquals(2, getWarnings().size());
assertTrue(getWarnings().get(0).getMessage().toString().contains("Unknown field"));
assertTrue(getWarnings().get(1).getMessage().toString().contains("Unknown field"));
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
reconAnnotator.setWebPageDownloader(downloader);
reconAnnotator.setCache(originalCache);
}
}
@Test
public void testAnnotateUnknownElement() throws Exception {
try {
AnnotatedObject obj = Mockito.mock(AnnotatedObject.class);
when(obj.getName()).thenReturn("O16G2e");
ReconAnnotator tweakedReconAnnotator = Mockito.spy(reconAnnotator);
doReturn(true).when(tweakedReconAnnotator).isAnnotatable(any(AnnotatedObject.class));
tweakedReconAnnotator.annotateElement(obj);
assertEquals(1, getWarnings().size());
assertTrue(getWarnings().get(0).getMessage().toString().contains("Unknown class type"));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAnnotatingWithParentehesis() throws Exception {
try {
Reaction reaction = new Reaction();
reaction.setName("gm2_hs[g]");
reconAnnotator.annotateElement(reaction);
assertEquals(0, getWarnings().size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAnnotatingWithWhitespace() throws Exception {
try {
Reaction reaction = new Reaction();
reaction.setName("NDPK4m ");
reconAnnotator.annotateElement(reaction);
assertEquals(0, getWarnings().size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAnnotateElement() throws Exception {
try {
......@@ -175,4 +325,27 @@ public class ReconAnnotatorTest extends AnnotationTestFunctions {
}
}
@Test
public void testRefreshCacheQueryNotAvailable() throws Exception {
WebPageDownloader downloader = reconAnnotator.getWebPageDownloader();
GeneralCacheInterface originalCache = reconAnnotator.getCache();
try {
// exclude first cached value
reconAnnotator.setCache(null);
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
reconAnnotator.setWebPageDownloader(mockDownloader);
reconAnnotator.refreshCacheQuery("http://google.pl/");
fail("Exception expected");
} catch (SourceNotAvailable e) {
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
reconAnnotator.setWebPageDownloader(downloader);
reconAnnotator.setCache(originalCache);
}
}
}
{"count":7,"next":null,"previous":null,"results":[{"url":"http://vmh.uni.lu/_api/metabolites/15/?format=json","met_id":15,"abbreviation":"nadph","fullName":null,"description":"Nicotinamide adenine dinucleotide phosphate - reduced","neutralFormula":"","chargedFormula":"C21H26N7O17P3","charge":-4,"miriam":null,"biggId":null,"lmId":null,"ehmnId":null,"hepatonetId":null,"keggId":"C00005","pubChemId":"22833512","cheBlId":"CHEBI:16474","cheBlId2":null,"inchiString":"InChI=1S/C21H30N7O17P3/c22-17-12-19(25-7-24-17)28(8-26-12)21-16(44-46(33,34)35)14(30)11(43-21)6-41-48(38,39)45-47(36,37)40-5-10-13(29)15(31)20(42-10)27-3-1-2-9(4-27)18(23)32/h1,3-4,7-8,10-11,13-16,20-21,29-31H,2,5-6H2,(H2,23,32)(H,36,37)(H,38,39)(H2,22,24,25)(H2,33,34,35)/p-4/t10-,11-,13-,14-,15-,16-,20-,21-/m1/s1","smile":"","hmdb":"HMDB00221","pdmapName":"NADPH","reconMap":"nadph","synonyms":null,"lastModified":"2016-06-30T14:13:35Z","modifiedBy":"","addedBy":""},{"url":"http://vmh.uni.lu/_api/metabolites/17/?format=json","met_id":17,"abbreviation":"nadp","fullName":null,"description":"Nicotinamide adenine dinucleotide phosphate","neutralFormula":"","chargedFormula":"C21H25N7O17P3","charge":-3,"miriam":null,"biggId":null,"lmId":null,"ehmnId":null,"hepatonetId":null,"keggId":"C00006","pubChemId":"5886","cheBlId":"CHEBI:18009","cheBlId2":null,"inchiString":"InChI=1S/C21H28N7O17P3/c22-17-12-19(25-7-24-17)28(8-26-12)21-16(44-46(33,34)35)14(30)11(43-21)6-41-48(38,39)45-47(36,37)40-5-10-13(29)15(31)20(42-10)27-3-1-2-9(4-27)18(23)32/h1-4,7-8,10-11,13-16,20-21,29-31H,5-6H2,(H7-,22,23,24,25,32,33,34,35,36,37,38,39)/p-3/t10-,11-,13-,14-,15-,16-,20-,21-/m1/s1","smile":"","hmdb":"HMDB00217","pdmapName":"NADP(+);NADP+","reconMap":"nadp","synonyms":null,"lastModified":"2016-06-30T14:13:35Z","modifiedBy":"","addedBy":""},{"url":"http://vmh.uni.lu/_api/metabolites/27/?format=json","met_id":27,"abbreviation":"nadh","fullName":null,"description":"Nicotinamide adenine dinucleotide - reduced","neutralFormula":"","chargedFormula":"C21H27N7O14P2","charge":-2,"miriam":null,"biggId":null,"lmId":null,"ehmnId":null,"hepatonetId":null,"keggId":"C00004","pubChemId":"439153","cheBlId":"CHEBI:16908","cheBlId2":null,"inchiString":"InChI=1S/C21H29N7O14P2/c22-17-12-19(25-7-24-17)28(8-26-12)21-16(32)14(30)11(41-21)6-39-44(36,37)42-43(34,35)38-5-10-13(29)15(31)20(40-10)27-3-1-2-9(4-27)18(23)33/h1,3-4,7-8,10-11,13-16,20-21,29-32H,2,5-6H2,(H2,23,33)(H,34,35)(H,36,37)(H2,22,24,25)/p-2/t10-,11-,13-,14-,15-,16-,20-,21-/m1/s1","smile":"","hmdb":"HMDB01487","pdmapName":"NADH","reconMap":"nadh","synonyms":null,"lastModified":"2016-06-30T14:13:35Z","modifiedBy":"","addedBy":""},{"url":"http://vmh.uni.lu/_api/metabolites/29/?format=json","met_id":29,"abbreviation":"nad","fullName":null,"description":"Nicotinamide adenine dinucleotide","neutralFormula":"","chargedFormula":"C21H26N7O14P2","charge":-1,"miriam":null,"biggId":null,"lmId":null,"ehmnId":null,"hepatonetId":null,"keggId":"C00003","pubChemId":"5893","cheBlId":"CHEBI:15846","cheBlId2":null,"inchiString":"InChI=1S/C21H27N7O14P2/c22-17-12-19(25-7-24-17)28(8-26-12)21-16(32)14(30)11(41-21)6-39-44(36,37)42-43(34,35)38-5-10-13(29)15(31)20(40-10)27-3-1-2-9(4-27)18(23)33/h1-4,7-8,10-11,13-16,20-21,29-32H,5-6H2,(H5-,22,23,24,25,33,34,35,36,37)/p-1/t10-,11-,13-,14-,15-,16-,20-,21-/m1/s1","smile":"","hmdb":"HMDB00902","pdmapName":"NAD(+);NAD+","reconMap":"nad","synonyms":null,"lastModified":"2016-06-30T14:13:35Z","modifiedBy":"","addedBy":""},{"url":"http://vmh.uni.lu/_api/metabolites/738/?format=json","met_id":738,"abbreviation":"dnad","fullName":null,"description":"Deamino-NAD+","neutralFormula":"","chargedFormula":"C21H24N6O15P2","charge":-2,"miriam":null,"biggId":null,"lmId":null,"ehmnId":null,"hepatonetId":null,"keggId":"C00857","pubChemId":"165491","cheBlId":"CHEBI:18304","cheBlId2":null,"inchiString":"InChI=1S/C21H26N6O15P2/c22-17-12-18(24-7-23-17)27(8-25-12)20-16(31)14(29)11(41-20)6-39-44(36,37)42-43(34,35)38-5-10-13(28)15(30)19(40-10)26-3-1-2-9(4-26)21(32)33/h1-4,7-8,10-11,13-16,19-20,28-31H,5-6H2,(H4-,22,23,24,32,33,34,35,36,37)/p+1/t10-,11-,13-,14-,15-,16-,19-,20-/m1/s1","smile":"","hmdb":"HMDB01179","pdmapName":null,"reconMap":"dnad","synonyms":null,"lastModified":"2016-06-30T14:05:18Z","modifiedBy":"","addedBy":""},{"url":"http://vmh.uni.lu/_api/metabolites/1643/?format=json","met_id":1643,"abbreviation":"HC02112","fullName":null,"description":"NADH-redox-potential","neutralFormula":"","chargedFormula":"","charge":0,"miriam":null,"biggId":null,"lmId":null,"ehmnId":null,"hepatonetId":null,"keggId":"","pubChemId":"","cheBlId":"","cheBlId2":null,"inchiString":"","smile":"","hmdb":"","pdmapName":null,"reconMap":null,"synonyms":null,"lastModified":"2016-05-03T09:37:28Z","modifiedBy":"","addedBy":""},{"url":"http://vmh.uni.lu/_api/metabolites/1644/?format=json","met_id":1644,"abbreviation":"HC02113","fullName":null,"description":"NADPH-redox-potential","neutralFormula":"","chargedFormula":"","charge":0,"miriam":null,"biggId":null,"lmId":null,"ehmnId":null,"hepatonetId":null,"keggId":"","pubChemId":"","cheBlId":"","cheBlId2":null,"inchiString":"","smile":"","hmdb":"","pdmapName":null,"reconMap":null,"synonyms":null,"lastModified":"2016-05-03T09:37:28Z","modifiedBy":"","addedBy":""}]}
\ No newline at end of file
{"count":1,"next":null,"previous":null,"results":[{"url":"http://vmh.uni.lu/_api/reactions/2806/?format=json","rxn_id":2806,"abbreviation":"O16G2e","description":"oligo-1,6-glucosidase (strch2 ->strch3), extracellular","formula":"h2o[e] + strch2[e] -> glc_D[e] + malt[e] ","reversible":0,"mcs":0,"csecoida":"3A0000000","notes":"NCD","ref":"","ecnumber":"3.2.1.10","keggId":"","lastModified":"2016-06-30T14:01:25Z","modifiedBy":"","addedBy":"","keggorthology":"K01182","cog":"COG0366","pdmapName":"O16G2e","subsystem":"Starch and sucrose metabolism"}]}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment