Skip to content
Snippets Groups Projects
Commit 2a99d60a authored by David Hoksza's avatar David Hoksza
Browse files

Working REST API

parent cd0e6c02
No related branches found
No related tags found
1 merge request!117Pdb annotation
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;
}
}
......@@ -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<>();
......
......@@ -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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment