From 2a99d60a7538502272e1ee259914ee725d3bdd26 Mon Sep 17 00:00:00 2001 From: David Hoksza <david.hoksza@uni.lu> Date: Fri, 21 Jul 2017 13:44:43 +0200 Subject: [PATCH] Working REST API --- .../model/map/species/field/Structure.java | 23 ++++++++++++++-- .../elements/ElementsRestImpl.java | 27 ++++++++++++++----- .../elements/ElementRestImplTest.java | 8 +++--- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/field/Structure.java b/model/src/main/java/lcsb/mapviewer/model/map/species/field/Structure.java index 5dbe0b9053..5d92fdcce2 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/field/Structure.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/field/Structure.java @@ -1,6 +1,8 @@ package lcsb.mapviewer.model.map.species.field; import java.io.Serializable; +import java.util.Map; +import java.util.HashMap; import javax.persistence.Column; import javax.persistence.Entity; @@ -12,6 +14,8 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; +import org.apache.commons.collections.map.HashedMap; + import lcsb.mapviewer.common.exception.NotImplementedException; /** @@ -23,8 +27,8 @@ import lcsb.mapviewer.common.exception.NotImplementedException; * coverage: the percent coverage of the entire UniProt sequence * resolution: the resolution of the structure * start: the structure residue number which maps to the start of the mapped sequence - * end: the structure residue number which maps to the end of the mapped sequence * unp_start: the sequence residue number which maps to the structure start + * end: the structure residue number which maps to the end of the mapped sequence * unp_end: the sequence residue number which maps to the structure end * experimental_method: type of experiment used to determine structure * tax_id: taxonomic ID of the protein's original organism @@ -339,6 +343,21 @@ public class Structure implements Serializable { + ", unpEnd=" + unpEnd + ", experimentalMethod=" + experimentalMethod + ", taxId=" + taxId + "]"; } - + public Map<String, Object> toMap() { + Map<String, Object> result = new HashMap<>(); + + result.put("pdbId", this.pdbId); + result.put("chainId", this.chainId); + result.put("coverage", this.coverage); + result.put("resolution", this.resolution); + result.put("structStart", this.structStart); + result.put("structEnd", this.structEnd); + result.put("unpStart", this.unpStart); + result.put("unpEnd", this.unpEnd); + result.put("experimentalMethod", this.experimentalMethod); + result.put("taxId", this.taxId); + + return result; + } } diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementsRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementsRestImpl.java index 8c664dcdfa..40449080f1 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementsRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementsRestImpl.java @@ -21,6 +21,8 @@ import lcsb.mapviewer.model.map.species.Species; import lcsb.mapviewer.model.map.species.field.ElementModification; import lcsb.mapviewer.model.map.species.field.ModificationResidue; import lcsb.mapviewer.model.map.species.field.RnaRegion; +import lcsb.mapviewer.model.map.species.field.Structure; +import lcsb.mapviewer.model.map.species.field.UniprotRecord; import lcsb.mapviewer.services.SecurityException; import lcsb.mapviewer.services.UserAccessException; import lcsb.mapviewer.services.view.OverviewImageViewFactory; @@ -121,11 +123,7 @@ public class ElementsRestImpl extends BaseRestImpl { value = element.getSubmodel().getSubmodel().getId(); } } else if (column.equals("bounds")) { - value = createBounds(element.getX(), element.getY(), element.getWidth(), element.getHeight()); - } else if (column.equals("others")) { - if (element instanceof Species) { - value = ((Species)element).getUniprots(); - } + value = createBounds(element.getX(), element.getY(), element.getWidth(), element.getHeight()); } else { value = "Unknown column"; @@ -137,8 +135,9 @@ public class ElementsRestImpl extends BaseRestImpl { protected Map<String, Object> getOthersForElement(Element element) { Map<String, Object> result = new HashMap<>(); - List<Map<String, Object>> modifications = new ArrayList<>(); + List<Map<String, Object>> modifications = new ArrayList<>(); String structuralState = null; + Map<String, Object> structures = new HashMap<>(); if (element instanceof Protein) { Protein protein = ((Protein) element); modifications = getModifications(protein.getModificationResidues()); @@ -151,9 +150,13 @@ public class ElementsRestImpl extends BaseRestImpl { AntisenseRna antisenseRna = ((AntisenseRna) element); modifications = getModifications(((AntisenseRna) element).getRegions()); structuralState = antisenseRna.getState(); + } + if (element instanceof Species) { + structures = getStructures(((Species)element).getUniprots()); } result.put("modifications", modifications); result.put("structuralState", structuralState); + result.put("structures", structures); return result; } @@ -171,6 +174,18 @@ public class ElementsRestImpl extends BaseRestImpl { } return result; } + + private Map<String, Object> getStructures(Set<UniprotRecord> uniprots) { + Map<String, Object> result = new HashMap<>(); + for (UniprotRecord uniprotRec : uniprots) { + Set<Object> structs = new HashSet<>(); + for (Structure struct: uniprotRec.getStructures()) { + structs.add(struct.toMap()); + } + result.put(uniprotRec.getUniprotId(), structs); + } + return result; + } private Map<String, Object> createBounds(Double x, Double y, Double width, Double height) { Map<String, Object> result = new HashMap<>(); diff --git a/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementRestImplTest.java b/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementRestImplTest.java index 1a51fdfe6a..2cc1b522c5 100644 --- a/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementRestImplTest.java +++ b/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementRestImplTest.java @@ -156,20 +156,20 @@ public class ElementRestImplTest extends RestTestFunctions { } } - private ElementsRestImpl createMockElementRest(String string, Boolean annotate) throws Exception { + private ElementsRestImpl createMockElementRest(String string, Boolean annotate) throws Exception { Model model = super.getModelForFile(string, true); if (annotate) { - try { + try { Protein protein = new GenericProtein("SNCA"); protein.setElementId("SNCA"); pdbAnnotator.annotateElement(protein); - model.addElement(protein); + model.addElement(protein); } catch (Exception e) { } } IModelService mockModelService = Mockito.mock(IModelService.class); Mockito.when(mockModelService.getLastModelByProjectId(anyString(), any())).thenReturn(model); - _elementsRestImpl.setModelService(mockModelService); + _elementsRestImpl.setModelService(mockModelService); return _elementsRestImpl; } } -- GitLab