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; ...@@ -6,11 +6,8 @@ import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Scanner; import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
...@@ -94,30 +91,6 @@ public class BiocompendiumAnnotator extends ElementAnnotator implements IExterna ...@@ -94,30 +91,6 @@ public class BiocompendiumAnnotator extends ElementAnnotator implements IExterna
return result; 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} * Returns String with annotations for species described by {@link MiriamData}
* with {@link MiriamType#HGNC_SYMBOL} entry. * with {@link MiriamType#HGNC_SYMBOL} entry.
...@@ -299,38 +272,6 @@ public class BiocompendiumAnnotator extends ElementAnnotator implements IExterna ...@@ -299,38 +272,6 @@ public class BiocompendiumAnnotator extends ElementAnnotator implements IExterna
return xml; 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 @Override
public ExternalServiceStatus getServiceStatus() { public ExternalServiceStatus getServiceStatus() {
ExternalServiceStatus status = new ExternalServiceStatus(getCommonName(), getUrl()); ExternalServiceStatus status = new ExternalServiceStatus(getCommonName(), getUrl());
...@@ -358,9 +299,8 @@ public class BiocompendiumAnnotator extends ElementAnnotator implements IExterna ...@@ -358,9 +299,8 @@ public class BiocompendiumAnnotator extends ElementAnnotator implements IExterna
@Override @Override
public void annotateElement(AnnotatedObject element) throws AnnotatorException { public void annotateElement(AnnotatedObject element) throws AnnotatorException {
if (isAnnotatable(element)) { if (isAnnotatable(element)) {
String annotationString;
try { try {
annotationString = getAnnotation(new MiriamData(MiriamType.HGNC_SYMBOL, element.getName())); String annotationString = getAnnotation(new MiriamData(MiriamType.HGNC_SYMBOL, element.getName()));
if (annotationString != null) { if (annotationString != null) {
if (element.getMiriamData().size() == 0) { if (element.getMiriamData().size() == 0) {
element.addMiriamData(rap.getMiriamData(annotationString)); element.addMiriamData(rap.getMiriamData(annotationString));
......
...@@ -9,7 +9,6 @@ import static org.junit.Assert.fail; ...@@ -9,7 +9,6 @@ import static org.junit.Assert.fail;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.FileReader; import java.io.FileReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
...@@ -52,17 +51,13 @@ public class BiocompendiumAnnotatorTest extends AnnotationTestFunctions { ...@@ -52,17 +51,13 @@ public class BiocompendiumAnnotatorTest extends AnnotationTestFunctions {
@Test @Test
@Ignore("Bug 32") @Ignore("Bug 32")
public void testGetAnnotationsForSpecies() throws Exception { public void testGetAnnotationsForSpecies() throws Exception {
ArrayList<MiriamData> data = new ArrayList<MiriamData>();
data.add(camk4);
data.add(slc25a27);
try { try {
Map<MiriamData, String> res = restService.getAnnotations(data); String response = restService.getAnnotation(camk4);
assertEquals(2, res.keySet().size());
String response = res.get(camk4);
assertNotNull(response); assertNotNull(response);
assertTrue(response.contains("Symbol: CAMK4")); assertTrue(response.contains("Symbol: CAMK4"));
assertNotNull(res.get(slc25a27)); response = restService.getAnnotation(slc25a27);
assertNotNull(response);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -71,14 +66,11 @@ public class BiocompendiumAnnotatorTest extends AnnotationTestFunctions { ...@@ -71,14 +66,11 @@ public class BiocompendiumAnnotatorTest extends AnnotationTestFunctions {
} }
@Test @Test
public void testGetAnnotationsForInvalidMiriam() throws Exception { public void testGetters() throws Exception {
try { try {
ArrayList<MiriamData> data = new ArrayList<>(); assertNotNull(restService.getCommonName());
data.add(new MiriamData()); assertNotNull(restService.getUrl());
restService.getAnnotations(data);
fail("Exception expected");
} catch (InvalidArgumentException e) {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
...@@ -86,25 +78,12 @@ public class BiocompendiumAnnotatorTest extends AnnotationTestFunctions { ...@@ -86,25 +78,12 @@ public class BiocompendiumAnnotatorTest extends AnnotationTestFunctions {
} }
@Test @Test
@Ignore("Bug 32") public void testGetAnnotationsForInvalidMiriam() throws Exception {
public void testGetAnnotationsForSpeciesWithCache() throws Exception {
ArrayList<MiriamData> data = new ArrayList<MiriamData>();
data.add(camk4);
data.add(slc25a27);
try { try {
restService.getAnnotations(data); restService.getAnnotation(new MiriamData());
// second call should be taken from cache fail("Exception expected");
// 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));
} catch (InvalidArgumentException e) {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
...@@ -221,18 +200,13 @@ public class BiocompendiumAnnotatorTest extends AnnotationTestFunctions { ...@@ -221,18 +200,13 @@ public class BiocompendiumAnnotatorTest extends AnnotationTestFunctions {
// names.add("Hsp70"); // names.add("Hsp70");
names.add("Hsp90ab1"); 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 { try {
Map<MiriamData, String> res = restService.getAnnotations(data); for (int i = 0; i < names.size(); i++) {
for (MiriamData string : data) { String geneName = names.get(i);
assertNotNull("Problem with annotation of mouse gene: " + string, res.get(string)); String annotation = restService.getAnnotation(new MiriamData(MiriamType.HGNC_SYMBOL, geneName));
assertTrue("Problem with annotation of mouse gene: " + string, !res.get(string).trim().equals("")); assertNotNull("Problem with annotation of mouse gene: " + geneName, annotation);
assertTrue("Problem with annotation of mouse gene: " + geneName, !annotation.trim().equals(""));
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
...@@ -306,19 +280,6 @@ public class BiocompendiumAnnotatorTest extends AnnotationTestFunctions { ...@@ -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 @Test
public void testRefreshInvalidValue() throws Exception { public void testRefreshInvalidValue() throws Exception {
try { try {
......
...@@ -331,7 +331,6 @@ public class HgncAnnotatorTest extends AnnotationTestFunctions { ...@@ -331,7 +331,6 @@ public class HgncAnnotatorTest extends AnnotationTestFunctions {
public void testIsValidHgnc() throws Exception { public void testIsValidHgnc() throws Exception {
try { try {
assertFalse(hgncAnnotator.isValidHgncMiriam(new MiriamData(MiriamType.CAS, "CASP8"))); assertFalse(hgncAnnotator.isValidHgncMiriam(new MiriamData(MiriamType.CAS, "CASP8")));
} catch (InvalidArgumentException e) {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
...@@ -342,7 +341,6 @@ public class HgncAnnotatorTest extends AnnotationTestFunctions { ...@@ -342,7 +341,6 @@ public class HgncAnnotatorTest extends AnnotationTestFunctions {
public void testIsValidHgnc2() throws Exception { public void testIsValidHgnc2() throws Exception {
try { try {
assertTrue(hgncAnnotator.isValidHgncMiriam(new MiriamData(MiriamType.HGNC_SYMBOL, "CASP8"))); assertTrue(hgncAnnotator.isValidHgncMiriam(new MiriamData(MiriamType.HGNC_SYMBOL, "CASP8")));
} catch (InvalidArgumentException e) {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
......
...@@ -19,7 +19,6 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -19,7 +19,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.annotation.services.annotators.AnnotatorException; import lcsb.mapviewer.annotation.services.annotators.AnnotatorException;
import lcsb.mapviewer.annotation.services.annotators.BiocompendiumAnnotator;
import lcsb.mapviewer.annotation.services.annotators.HgncAnnotator; import lcsb.mapviewer.annotation.services.annotators.HgncAnnotator;
import lcsb.mapviewer.common.IProgressUpdater; import lcsb.mapviewer.common.IProgressUpdater;
import lcsb.mapviewer.common.Pair; import lcsb.mapviewer.common.Pair;
...@@ -58,65 +57,58 @@ public class DataMiningService extends XmlParser implements IDataMiningService { ...@@ -58,65 +57,58 @@ public class DataMiningService extends XmlParser implements IDataMiningService {
* Name of the source column (element that misses connection) in the input * Name of the source column (element that misses connection) in the input
* file containing information about data mining. * file containing information about data mining.
*/ */
private static final String SOURCE_COLUMN_NAME = "Source"; private static final String SOURCE_COLUMN_NAME = "Source";
/** /**
* Name of the target column (connection that is missing) in the input file. * Name of the target column (connection that is missing) in the input file.
*/ */
private static final String TARGET_COLUMN_NAME = "Target"; private static final String TARGET_COLUMN_NAME = "Target";
/** /**
* Name of the description column in the input file. * Name of the description column in the input file.
*/ */
private static final String DESC_COLUMN_NAME = "Description"; private static final String DESC_COLUMN_NAME = "Description";
/** /**
* Name of the column where references are kept in the input file. * Name of the column where references are kept in the input file.
*/ */
private static final String REF_COLUMN_NAME = "References"; private static final String REF_COLUMN_NAME = "References";
/** /**
* Default class logger. * Default class logger.
*/ */
private final Logger logger = Logger.getLogger(DataMiningService.class); private final Logger logger = Logger.getLogger(DataMiningService.class);
/** /**
* Data access object for data mining information. * Data access object for data mining information.
*/ */
@Autowired @Autowired
private DataMiningDao missingConnectionDao; private DataMiningDao missingConnectionDao;
/** /**
* Utils that help to manage the sessions in custom multithreaded * Utils that help to manage the sessions in custom multithreaded
* implementation. * implementation.
*/ */
@Autowired @Autowired
private DbUtils dbUtils; private DbUtils dbUtils;
/** /**
* Data access object for {@link DataMiningSet} objects. * Data access object for {@link DataMiningSet} objects.
*/ */
@Autowired @Autowired
private DataMiningSetDao dataMinigSetDao; private DataMiningSetDao dataMinigSetDao;
/** /**
* Class used to work on {@link MiriamType#HGNC} annotations. * Class used to work on {@link MiriamType#HGNC} annotations.
*/ */
@Autowired @Autowired
private HgncAnnotator hgncAnnotator; private HgncAnnotator hgncAnnotator;
/** /**
* Service that allows to log system messages. * Service that allows to log system messages.
*/ */
@Autowired @Autowired
private ILogService logService; private ILogService logService;
/**
* Service used for annotation of proteins (and finding annotation of
* proteins).
*/
@Autowired
private BiocompendiumAnnotator annotationRestService;
@Override @Override
public Collection<DataMining> getMissingConnections(Element alias) { public Collection<DataMining> getMissingConnections(Element alias) {
...@@ -231,8 +223,8 @@ public class DataMiningService extends XmlParser implements IDataMiningService { ...@@ -231,8 +223,8 @@ public class DataMiningService extends XmlParser implements IDataMiningService {
Boolean status = isHgnc.get(string); Boolean status = isHgnc.get(string);
if (status == null) { if (status == null) {
try { try {
status = annotationRestService.validAnnotation(new MiriamData(MiriamType.HGNC_SYMBOL, string)); status = hgncAnnotator.isValidHgncMiriam(new MiriamData(MiriamType.HGNC_SYMBOL, string));
} catch (IOException e) { } catch (AnnotatorException e) {
logger.error(e); logger.error(e);
status = false; status = false;
} }
......
Supports Markdown
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