Commit 90356704 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

unnecessary code from biocompendium removed and tests added

parent 8a908bbf
......@@ -6,11 +6,8 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
......@@ -94,30 +91,6 @@ public class BiocompendiumAnnotator extends ElementAnnotator implements IExterna
return result;
}
/**
* Returns a map with annotation for every {@link MiriamType#HGNC_SYMBOL}
* entry.
*
* @param miriamData
* list of hgnc symbols.
* @return a map with annotation for every {@link MiriamType#HGNC_SYMBOL}
* entry
* @throws IOException
* thrown when there is a problem with accessing external resource
*/
protected Map<MiriamData, String> getAnnotations(List<MiriamData> miriamData) throws IOException {
for (MiriamData md : miriamData) {
if (!MiriamType.HGNC_SYMBOL.equals(md.getDataType())) {
throw new InvalidArgumentException("Only " + MiriamType.HGNC_SYMBOL.getCommonName() + " miriam registry is supported.");
}
}
Map<MiriamData, String> result = new HashMap<>();
for (MiriamData md : miriamData) {
result.put(md, getAnnotation(md));
}
return result;
}
/**
* Returns String with annotations for species described by {@link MiriamData}
* with {@link MiriamType#HGNC_SYMBOL} entry.
......@@ -299,38 +272,6 @@ public class BiocompendiumAnnotator extends ElementAnnotator implements IExterna
return xml;
}
/**
* Pattern used to get hgnc symbol from response from venkata server.
*/
private Pattern hgncSymbolPattern = Pattern.compile("Symbol: ([a-zA-Z0-9_]+)");
/**
* Checks if the result from venkata server is valid (based on hgnc symbol
* information).
*
* @param hgnc
* {@link MiriamData} with {@link MiriamType#HGNC_SYMBOL}
* @return <code>true</code> if venkata annotation is valid,
* <code>false</code> otherwise
* @throws IOException
* throw when there is a problem with accessing external service
*/
public boolean validAnnotation(MiriamData hgnc) throws IOException {
if (!MiriamType.HGNC_SYMBOL.equals(hgnc.getDataType())) {
throw new InvalidArgumentException("Only " + MiriamType.HGNC_SYMBOL.getCommonName() + " miriam registry is supported.");
}
String annotation = getAnnotation(hgnc);
if (annotation == null) {
return false;
}
Matcher m = hgncSymbolPattern.matcher(annotation);
String id = null;
if (m.find()) {
id = m.group(1);
}
return hgnc.getResource().equals(id);
}
@Override
public ExternalServiceStatus getServiceStatus() {
ExternalServiceStatus status = new ExternalServiceStatus(getCommonName(), getUrl());
......@@ -358,9 +299,8 @@ public class BiocompendiumAnnotator extends ElementAnnotator implements IExterna
@Override
public void annotateElement(AnnotatedObject element) throws AnnotatorException {
if (isAnnotatable(element)) {
String annotationString;
try {
annotationString = getAnnotation(new MiriamData(MiriamType.HGNC_SYMBOL, element.getName()));
String annotationString = getAnnotation(new MiriamData(MiriamType.HGNC_SYMBOL, element.getName()));
if (annotationString != null) {
if (element.getMiriamData().size() == 0) {
element.addMiriamData(rap.getMiriamData(annotationString));
......
......@@ -9,7 +9,6 @@ import static org.junit.Assert.fail;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
......@@ -52,17 +51,13 @@ public class BiocompendiumAnnotatorTest extends AnnotationTestFunctions {
@Test
@Ignore("Bug 32")
public void testGetAnnotationsForSpecies() throws Exception {
ArrayList<MiriamData> data = new ArrayList<MiriamData>();
data.add(camk4);
data.add(slc25a27);
try {
Map<MiriamData, String> res = restService.getAnnotations(data);
assertEquals(2, res.keySet().size());
String response = res.get(camk4);
String response = restService.getAnnotation(camk4);
assertNotNull(response);
assertTrue(response.contains("Symbol: CAMK4"));
assertNotNull(res.get(slc25a27));
response = restService.getAnnotation(slc25a27);
assertNotNull(response);
} catch (Exception e) {
e.printStackTrace();
......@@ -71,14 +66,11 @@ public class BiocompendiumAnnotatorTest extends AnnotationTestFunctions {
}
@Test
public void testGetAnnotationsForInvalidMiriam() throws Exception {
public void testGetters() throws Exception {
try {
ArrayList<MiriamData> data = new ArrayList<>();
data.add(new MiriamData());
restService.getAnnotations(data);
fail("Exception expected");
assertNotNull(restService.getCommonName());
assertNotNull(restService.getUrl());
} catch (InvalidArgumentException e) {
} catch (Exception e) {
e.printStackTrace();
throw e;
......@@ -86,25 +78,12 @@ public class BiocompendiumAnnotatorTest extends AnnotationTestFunctions {
}
@Test
@Ignore("Bug 32")
public void testGetAnnotationsForSpeciesWithCache() throws Exception {
ArrayList<MiriamData> data = new ArrayList<MiriamData>();
data.add(camk4);
data.add(slc25a27);
public void testGetAnnotationsForInvalidMiriam() throws Exception {
try {
restService.getAnnotations(data);
// second call should be taken from cache
// this test doesn't check if it's taken from cache, it only checks if
// there were no problems with it
Map<MiriamData, String> res = restService.getAnnotations(data);
assertEquals(2, res.keySet().size());
String response = res.get(camk4);
assertNotNull(response);
assertTrue(response.contains("Symbol: CAMK4"));
assertNotNull(res.get(slc25a27));
restService.getAnnotation(new MiriamData());
fail("Exception expected");
} catch (InvalidArgumentException e) {
} catch (Exception e) {
e.printStackTrace();
throw e;
......@@ -221,18 +200,13 @@ public class BiocompendiumAnnotatorTest extends AnnotationTestFunctions {
// names.add("Hsp70");
names.add("Hsp90ab1");
List<MiriamData> data = new ArrayList<MiriamData>();
for (int i = 0; i < names.size(); i++) {
data.add(new MiriamData(MiriamType.HGNC_SYMBOL, names.get(i)));
}
try {
Map<MiriamData, String> res = restService.getAnnotations(data);
for (MiriamData string : data) {
assertNotNull("Problem with annotation of mouse gene: " + string, res.get(string));
assertTrue("Problem with annotation of mouse gene: " + string, !res.get(string).trim().equals(""));
for (int i = 0; i < names.size(); i++) {
String geneName = names.get(i);
String annotation = restService.getAnnotation(new MiriamData(MiriamType.HGNC_SYMBOL, geneName));
assertNotNull("Problem with annotation of mouse gene: " + geneName, annotation);
assertTrue("Problem with annotation of mouse gene: " + geneName, !annotation.trim().equals(""));
}
} catch (Exception e) {
e.printStackTrace();
throw e;
......@@ -306,19 +280,6 @@ public class BiocompendiumAnnotatorTest extends AnnotationTestFunctions {
}
}
@Test
public void testValidAnnotation() throws Exception {
try {
MiriamData data1 = new MiriamData(MiriamType.HGNC_SYMBOL, "bdskjbfgdkjbgdfj");
boolean res = restService.validAnnotation(data1);
assertFalse(res);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testRefreshInvalidValue() throws Exception {
try {
......
......@@ -331,7 +331,6 @@ public class HgncAnnotatorTest extends AnnotationTestFunctions {
public void testIsValidHgnc() throws Exception {
try {
assertFalse(hgncAnnotator.isValidHgncMiriam(new MiriamData(MiriamType.CAS, "CASP8")));
} catch (InvalidArgumentException e) {
} catch (Exception e) {
e.printStackTrace();
throw e;
......@@ -342,7 +341,6 @@ public class HgncAnnotatorTest extends AnnotationTestFunctions {
public void testIsValidHgnc2() throws Exception {
try {
assertTrue(hgncAnnotator.isValidHgncMiriam(new MiriamData(MiriamType.HGNC_SYMBOL, "CASP8")));
} catch (InvalidArgumentException e) {
} catch (Exception e) {
e.printStackTrace();
throw e;
......
......@@ -19,7 +19,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.annotation.services.annotators.AnnotatorException;
import lcsb.mapviewer.annotation.services.annotators.BiocompendiumAnnotator;
import lcsb.mapviewer.annotation.services.annotators.HgncAnnotator;
import lcsb.mapviewer.common.IProgressUpdater;
import lcsb.mapviewer.common.Pair;
......@@ -111,13 +110,6 @@ public class DataMiningService extends XmlParser implements IDataMiningService {
@Autowired
private ILogService logService;
/**
* Service used for annotation of proteins (and finding annotation of
* proteins).
*/
@Autowired
private BiocompendiumAnnotator annotationRestService;
@Override
public Collection<DataMining> getMissingConnections(Element alias) {
return missingConnectionDao.getMissingConnectionForElement(alias);
......@@ -231,8 +223,8 @@ public class DataMiningService extends XmlParser implements IDataMiningService {
Boolean status = isHgnc.get(string);
if (status == null) {
try {
status = annotationRestService.validAnnotation(new MiriamData(MiriamType.HGNC_SYMBOL, string));
} catch (IOException e) {
status = hgncAnnotator.isValidHgncMiriam(new MiriamData(MiriamType.HGNC_SYMBOL, string));
} catch (AnnotatorException e) {
logger.error(e);
status = false;
}
......
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