Commit 63a7722e authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge remote-tracking branch 'origin/master' into...

Merge remote-tracking branch 'origin/master' into 566-merge-rest-api-services-into-main-service-module
parents f17da18e a5b36a0a
Pipeline #45288 failed with stage
in 13 minutes and 55 seconds
......@@ -38,7 +38,7 @@ minerva (16.0.0~beta.1) stable; urgency=medium
* Bug fix: search tab becomes active when drug/chemical/mirna result are
available (#1491)
-- Piotr Gawron <piotr.gawron@uni.lu> Wed, 9 Jun 2021 15:00:00 +0200
-- Piotr Gawron <piotr.gawron@uni.lu> Fri, 25 Jun 2021 08:00:00 +0200
minerva (16.0.0~beta.0) stable; urgency=medium
* Backward incompatibility: debian package cannot be upgraded from version
......
package lcsb.mapviewer.annotation.services.annotators;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -12,15 +16,23 @@ import org.springframework.stereotype.Service;
import lcsb.mapviewer.annotation.cache.GeneralCacheInterface;
import lcsb.mapviewer.annotation.cache.WebPageDownloader;
import lcsb.mapviewer.annotation.services.*;
import lcsb.mapviewer.annotation.services.ExternalServiceStatus;
import lcsb.mapviewer.annotation.services.ExternalServiceStatusType;
import lcsb.mapviewer.annotation.services.IExternalService;
import lcsb.mapviewer.annotation.services.WrongResponseCodeIOException;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.species.*;
import lcsb.mapviewer.model.user.annotator.*;
import lcsb.mapviewer.model.map.species.Gene;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.map.species.Rna;
import lcsb.mapviewer.model.user.annotator.AnnotatorData;
import lcsb.mapviewer.model.user.annotator.AnnotatorInputParameter;
import lcsb.mapviewer.model.user.annotator.AnnotatorOutputParameter;
/**
* This is a class that implements a backend to CAZy.
......@@ -120,7 +132,7 @@ public class CazyAnnotator extends ElementAnnotator implements IExternalService
@Override
public MiriamData getExampleValidAnnotation() {
return new MiriamData(MiriamType.UNIPROT, "Q9SG95");
return new MiriamData(MiriamType.UNIPROT, "Q00012");
}
/**
......@@ -143,7 +155,7 @@ public class CazyAnnotator extends ElementAnnotator implements IExternalService
* @return CAZy family identifier found on the page
*/
private Collection<MiriamData> parseCazy(String pageContent) {
Collection<MiriamData> result = new HashSet<MiriamData>();
Collection<MiriamData> result = new HashSet<>();
Matcher m = cazyIdMatcher.matcher(pageContent);
if (m.find()) {
result.add(new MiriamData(MiriamType.CAZY, m.group(1)));
......@@ -176,12 +188,16 @@ public class CazyAnnotator extends ElementAnnotator implements IExternalService
if (collection.size() > 0) {
return collection.iterator().next();
} else {
marker.getEntry().setType(ProjectLogEntryType.INVALID_IDENTIFIER);
if (marker != null) {
marker.getEntry().setType(ProjectLogEntryType.INVALID_IDENTIFIER);
}
logger.warn(marker, "Cannot find CAZy data for UniProt id: " + uniprot.getResource());
return null;
}
} catch (WrongResponseCodeIOException exception) {
marker.getEntry().setType(ProjectLogEntryType.OTHER);
if (marker != null) {
marker.getEntry().setType(ProjectLogEntryType.OTHER);
}
logger.warn(marker, "Wrong response code when retrieving CAZy data for UniProt id: " + uniprot.getResource());
return null;
} catch (IOException exception) {
......
......@@ -36,14 +36,14 @@ public class CazyAnnotatorTest extends AnnotationTestFunctions {
@Test
public void testUniprotToCazy() throws Exception {
assertEquals(new MiriamData(MiriamType.CAZY, "GH5_7"),
cazyAnnotator.uniprotToCazy(new MiriamData(MiriamType.UNIPROT, "Q9SG95"), null));
cazyAnnotator.uniprotToCazy(new MiriamData(MiriamType.UNIPROT, "Q00012"), null));
}
@Test
public void testAnnotateFromUniprot() throws Exception {
Species protein = new GenericProtein("id");
protein.setName("bla");
protein.addMiriamData(new MiriamData(MiriamType.UNIPROT, "Q9SG95"));
protein.addMiriamData(new MiriamData(MiriamType.UNIPROT, "Q00012"));
cazyAnnotator.annotateElement(protein);
......@@ -85,8 +85,8 @@ public class CazyAnnotatorTest extends AnnotationTestFunctions {
public void testAnnotateMultipleUniprots() throws Exception {
Species protein = new GenericProtein("id");
protein.setName("bla");
protein.addMiriamData(new MiriamData(MiriamType.UNIPROT, "Q9SG95"));
protein.addMiriamData(new MiriamData(MiriamType.UNIPROT, "Q12540"));
protein.addMiriamData(new MiriamData(MiriamType.UNIPROT, "Q00012"));
protein.addMiriamData(new MiriamData(MiriamType.UNIPROT, "A8MCI6"));
cazyAnnotator.annotateElement(protein);
......@@ -98,7 +98,7 @@ public class CazyAnnotatorTest extends AnnotationTestFunctions {
}
}
assertTrue("Wrong number of CAZy identifiers extracted from CAZy annotator", cntMDs == 2);
assertEquals("Wrong number of CAZy identifiers extracted from CAZy annotator", 2, cntMDs);
}
@Test
......
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